Hi I want to use a variable string (wave_name) to read out certain columns of a 3D wave. With the code structure below I was able to use a string to read out 1D waves and also to read out the column [p][0][0] by just using the string "D3meanwave". However as soon as I use the string "D3meanwave[p][0][0]" it does not work and the error message appears "Attempt to operate on a null wave". For me this seems quite bizarre because putting the sentence "wave2=D3meanwave[p][0][0]" works well. Does anybody know how to get around that problem?
cheers,
Finn
Function test3()
//string wave_name = "D3meanwave"
string wave_name = "D3meanwave[p][0][0]"
wave D3meanwave
wave wave2
wave name = $wave_name
wave2 = name
//wave2=D3meanwave[p][0][0]
Function test3() String wave_name = "D3meanwave" WAVE myWave = $(wave_name) Make/O destWave
destWave = myWave[p][0][0] End
You can convert a string into a name using the $ operator. But the range specification is not part of the wave's name, so when you use the $ operator on a string that contains both the wave's name and the range specification Igor gives you a compiler error.
As a side note, if you are trying to get a single row of a multidimensional wave, what you are doing is fine but it's not terribly fast. If you are doing this in a loop and performance matters, I suggest you look at the command help for MatrixOp and/or ImageTransform. Both of those operations have keywords that can extract a specific row/column etc. from a multidimensional wave and store it in a 1D wave. For ImageTransform look for the getRow/getCol etc. keywords. For MatrixOp look for either getRow or row (I don't recall what the correct name is).
String wave_name = "D3meanwave"
WAVE myWave = $(wave_name)
Make/O destWave
destWave = myWave[p][0][0]
End
You can convert a string into a name using the $ operator. But the range specification is not part of the wave's name, so when you use the $ operator on a string that contains both the wave's name and the range specification Igor gives you a compiler error.
As a side note, if you are trying to get a single row of a multidimensional wave, what you are doing is fine but it's not terribly fast. If you are doing this in a loop and performance matters, I suggest you look at the command help for MatrixOp and/or ImageTransform. Both of those operations have keywords that can extract a specific row/column etc. from a multidimensional wave and store it in a 1D wave. For ImageTransform look for the getRow/getCol etc. keywords. For MatrixOp look for either getRow or row (I don't recall what the correct name is).
October 15, 2011 at 08:31 am - Permalink
cheers,
Finn
October 15, 2011 at 08:45 am - Permalink