
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)
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)
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
December 9, 2011 at 12:18 pm - Permalink
Change this:
to this:
BTW, name is not a good name for a number.
December 9, 2011 at 01:15 pm - Permalink