A Better Way to Code?
ctmckee
Function VariableWaveLengthCreator()
variable n,o,LoopLength
n=1
o=0
LoopLength = AVariableWhichCanChange
do
make/o/n=(n) AWave
AWave[o]=SomethingThatIsVariable
o+=1
n+=1
while(n<=LoopLength)
end
variable n,o,LoopLength
n=1
o=0
LoopLength = AVariableWhichCanChange
do
make/o/n=(n) AWave
AWave[o]=SomethingThatIsVariable
o+=1
n+=1
while(n<=LoopLength)
end
I find I often run into issues when I do this. Is there a better way of doing this?
Clayton
Also, any time you are setting a point in a wave in a loop, if possible, you should change the loop to a wave assignment statement or MatrixOp command. For details execute:
April 3, 2015 at 01:52 pm - Permalink
April 3, 2015 at 04:29 pm - Permalink
RedimWave(wv, index)
which redimensions the wave so that index is a valid row index. The new real size of the wave might be much larger than index + 1, in most cases the new size is double the old size. With that kind of quadratic growth you minimize the number of redimensions.
But now you have to store the next unwritten row somewhere. I'll do that in the wave note using
NumberByKey
compatible format.So the sequence is basically:
variable index = ReadIndexFromWaveNote(wv)
RedimWave(wv, index)
wv[index] = 12345
SetIndexInWaveNote(wv, index + 1)
I'm sorry that I can't share the code.
April 4, 2015 at 05:53 am - Permalink