some help with this small iteration procedure
daviddoji
But I don´t know how to make the iterations! I mean the first value should be the point 3616 minus the point 16070, the next point should be 3615 minus 16071, and so on. The final point should be the last pair of values (that´s why I have put i>235, because for i=234 there is no more points in the wave.)
This points should be stored in a new wave with exactly the same number of points that iterations have been made.
I think that the problem in my procedure is in the definition of the for loop. As you can see, I don´t have any idea about programming, but I try to learn by myself :)
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
Function/D iteration ()
Wave wave
variable i, ii
i=3616
ii=16070
make/O/N=??? new_wave
for (i=3616;i>235;i-=1)
new_wave=wave[i]-wave[ii]
i -=1
ii+=1
endfor
end
Function/D iteration ()
Wave wave
variable i, ii
i=3616
ii=16070
make/O/N=??? new_wave
for (i=3616;i>235;i-=1)
new_wave=wave[i]-wave[ii]
i -=1
ii+=1
endfor
end
Attached you´ll find the graph with the wave.
Second, I've had difficulty in the past of getting a for loop to count down. I'll typically do something like
Make/o/n=3382 new_wave
variable i
for (i=235; i<3617; i+=1)
newwave = wave0[3849-i] - wave0[15835+i]
enfor
I know that for loops should be able to count down, but I've personally never gotten it to work, so I count up and just modify the wave indexing.
May 13, 2013 at 07:00 am - Permalink
Why?
// do something
endfor
May 13, 2013 at 07:29 am - Permalink
I don't know, when I try to run a decrementing for loop, it just never starts the loop, just as if you initialize the variable outside the end condition.
May 13, 2013 at 08:21 am - Permalink
Function/D cp2beta()
Wave X800__power
variable i
make/O/N=3850 '2cpbeta'
for (i=235;i<Numpnts('2cpbeta');i+=1)
'2cpbeta'=X800__power[4419-i] - X800__power[15385+i]
endfor
end
It gives always the same value.
I did it manualy and the result given by the procedure is different to the value calculated manually.
May 13, 2013 at 08:40 am - Permalink
you need to assign the value to a specific element of the wave '2cpbeta'. Sorry if i overlooked this in my quick example. The code you posted was assigning a single value to the entire wave. If your manual attempts and the code are giving different results, check the offset values for the waves (you have 4419 and 15385 : Make absolutely sure these are what you need).
May 13, 2013 at 08:44 am - Permalink
'2cpbeta'[i-235]=X800__power[4419-i] - X800__power[15385+i]
.But you can also use a simple wave assignment, something like this:
newwave = wave0[3849-p+235] - wave0[15835+p+235]
Note that the indexing is not efficient coding; I show the +235 in order to make the example clearer.
Read about wave assignment:
DisplayHelpTopic "Waveform Arithmetic and Assignment"
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 13, 2013 at 10:13 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 13, 2013 at 10:17 am - Permalink