Simple Wave Extract
mssmtrainee
Here I'm trying to copy multiple 1-D waves into an INDEX-D wave, where the 1-D waves vary between 3000-4000 points. But somehow, the code keeps copying the last value of the 1D wave until it reaches 5000th.
make/O/N = (5000, index) SubWave
Variable NewInd = 0
Variable Col = 0
do
Wave/Z w = WaveRefIndexed("", newInd, 4) // Next wave in current data folder
if (!WaveExists(w))
break // No more waves
endif
SubWave[][Col] = w[p] // Copy wave w into SubWave
NewInd += 1
Col += 1
while (1)
Variable NewInd = 0
Variable Col = 0
do
Wave/Z w = WaveRefIndexed("", newInd, 4) // Next wave in current data folder
if (!WaveExists(w))
break // No more waves
endif
SubWave[][Col] = w[p] // Copy wave w into SubWave
NewInd += 1
Col += 1
while (1)
I also tried an alternative:
make/O/N = (5000, index) SubWave
Variable NewInd = 0
Variable Col = 0
do
Wave/Z w = WaveRefIndexed("", newInd, 4) // Next wave in current data folder
if (!WaveExists(w))
break // No more waves
endif
Variable i =0
do
SubWave[i][Col] = w[i][0] //copy the i-th row of w to the i-th row of the SubWave while the i-th row is not 'not a number'
i += 1
while(numtype(w[i][0]!=NaN)
NewInd += 1
Col += 1
while (1)
Variable NewInd = 0
Variable Col = 0
do
Wave/Z w = WaveRefIndexed("", newInd, 4) // Next wave in current data folder
if (!WaveExists(w))
break // No more waves
endif
Variable i =0
do
SubWave[i][Col] = w[i][0] //copy the i-th row of w to the i-th row of the SubWave while the i-th row is not 'not a number'
i += 1
while(numtype(w[i][0]!=NaN)
NewInd += 1
Col += 1
while (1)
This looks pretty obvious to me, but it doesn't work. Another solution is to get the number of data points of the wave I want to copy, and create a while-loop etc. Is there a way to get the length of a wave (something similar to 'strlen')? Thanks.
-Cheers
December 8, 2011 at 02:39 pm - Permalink
You don't have to write a loop, you can use subrange indexing on the left side:
This line assumes that w is a 1D wave. You can read more than you ever wanted to know about these topics by executing the following command:
DisplayHelpTopix "Waveform Arithmetic and Assignment"
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
December 9, 2011 at 09:21 am - Permalink
At this point, I have one final problem: save my files in a "strange format"; something like this: dat.001, dat.002... dat.010, dat.011,...dat.999 (999 being the maximum number, Line 26) instead of dat.1, dat.2 etc. Any hints?Thanks
String pathName // Name of Igor symbolic path
String fileNameList = ""
Variable index = 0
Variable name = 1
do
Wave/Z w1 = WaveRefIndexed("", index, 4) // Next wave in current data folder ==ZSensor_Ext
Wave/Z w2 = WaveRefIndexed("",index+1,4) //Next+1 wave in current data folder ==Defl_Ext
if (!WaveExists(w1))
break // No more waves
endif
if (WaveDims(w1) != 1)
index += 1
continue // 1D waves only
endif
index += 2 //treat the next two files
Variable i = 0 //<<<<<<<<<<<< LINE 17
Variable PTs = numpnts(w1)
Make/O/N=(PTs,3) SubWave
Do
SubWave[i][0]=w1[i]*10^9 // ZSensor in nanometer is assigned to SubWave column 1
SubWave[i][1]=0
SubWave[i][2]=w2[i]*10^9 //Deflection in nm is assigned to SubWave column 3
i += 1
While(i<=PTs) //<<<<<<<<<<<< LINE 25
String fileName = "dat."+ num2istr(name) // Convert integer 'name' into string (trying to get dat.001, dat.002 instead of dat.1, dat.2...)
Save /P=$pathName /J /O SubWave as fileName // Save to text file
fileNameList += fileName + ";"
name += 1
while(1)
printf "%03.0f\r" name //<<<<<<<<<<<<< LINE 31
return fileNameList
End
December 9, 2011 at 12:18 pm - Permalink
Change this:
to this:
sprintf fileName, "dat.%03d", name
BTW, name is not a good name for a number.
December 9, 2011 at 01:15 pm - Permalink