StatsQuantiles operation
tooprock
I have a simple question about usage of output of
StatsQuantiles
. I wrote a function to work with individual 1D waves, since StatsQuantiles doesn't work for multidimensional waves. However I can't move the results from W_StatsQuantiles to a new wave. Here is my code. I will be appreciate for any suggestions.Function buildQuantiles(inputwave)
Wave inputwave
Wave W_StatsQuantiles
Variable numofRows, numofColumns, numofLayers
numofRows = dimSize(inputwave,0)
numofColumns = dimSize(inputwave,1)
numofLayers = dimSize(inputwave,2)
Variable i, j
for(j=0; j<=numofLayers; j+=1)
for(i=0; i<=numofColumns; i +=1)
String w_name = "temp_" + num2str(i)
MAKE/D/N=(numofRows) $(w_name)/Wave=w
w = inputwave[p][i][j]
if(dimSize(w,0) ==0)
break
endif
StatsQuantiles/Q/BOX/QW w
Make/O/N=(10,numofColumns,numofLayers) perctWave
perctWave[][i][j] = W_StatsQuantiles[p]
// Kill temporary waves so we can use them again
KillWaves w
endfor
endfor
End
Wave inputwave
Wave W_StatsQuantiles
Variable numofRows, numofColumns, numofLayers
numofRows = dimSize(inputwave,0)
numofColumns = dimSize(inputwave,1)
numofLayers = dimSize(inputwave,2)
Variable i, j
for(j=0; j<=numofLayers; j+=1)
for(i=0; i<=numofColumns; i +=1)
String w_name = "temp_" + num2str(i)
MAKE/D/N=(numofRows) $(w_name)/Wave=w
w = inputwave[p][i][j]
if(dimSize(w,0) ==0)
break
endif
StatsQuantiles/Q/BOX/QW w
Make/O/N=(10,numofColumns,numofLayers) perctWave
perctWave[][i][j] = W_StatsQuantiles[p]
// Kill temporary waves so we can use them again
KillWaves w
endfor
endfor
End
Cheers,
Emre
I could be way off here, but I don't think you are using the /WAVE flag correctly in this line...
MAKE/D/N=(numofRows) $(w_name)/Wave=w
.I'm surprised that you aren't getting a compile error.
From my reading of the help docs, the line should be
MAKE/D/N=(numofRows)/Wave $(w_name)
And you'll still need to assign the wave reference to something you can use. So I don't see the utility here.
I haven't thought about this syntax very much nor have I used it in practice. So, consider this advice from the ignorant.
Jeff
March 19, 2013 at 05:21 am - Permalink
Both your usage, and the original poster's usage, are correct, but they do different things. Using the /WAVE flag before the destination wave name (along with the other flags like /N, /O, etc) specifies the data type of wave to be wave reference. If you use the /WAVE= flag after the wave name, that tells Igor that you want to automatically create a wave reference (variable) to the new wave. The name of the wave reference variable comes from .
This second usage is equivalent to the following:
WAVE w = $(w_name)
March 19, 2013 at 06:04 am - Permalink
In the future I suggest you specify what "doesn't work" means.
In this case your original code was giving a runtime error on the "Wave W_StatsQuantiles" line the first time it was executed in an experiment because, at that point, the wave W_StatsQuantiles did not yet exist. You might not have ever gotten this message if you only ran your function after having previously executed StatsQuantiles on the command line, because in that situation W_StatsQuantiles would have already existed.
The fix (I believe) is for you to move the wave declaration to after the call to StatsQuantiles, which creates that wave. I'm not positive that the function below does what you want, but it compiles and executes without error.
Wave inputwave
Variable numofRows, numofColumns, numofLayers
numofRows = dimSize(inputwave,0)
numofColumns = dimSize(inputwave,1)
numofLayers = dimSize(inputwave,2)
Variable i, j
for(j=0; j<=numofLayers; j+=1)
for(i=0; i<=numofColumns; i +=1)
String w_name = "temp_" + num2str(i)
MAKE/D/N=(numofRows) $(w_name)/Wave=w
w = inputwave[p][i][j]
if(dimSize(w,0) ==0)
break
endif
StatsQuantiles/Q/BOX/QW w
WAVE W_StatsQuantiles
Make/O/N=(10,numofColumns,numofLayers) perctWave
perctWave[][i][j] = W_StatsQuantiles[p]
// Kill temporary waves so we can use them again
KillWaves w
endfor
endfor
End
March 19, 2013 at 06:11 am - Permalink
"Attempt to operate on a null(misssing) wave"
Although I see thatW_StatsQuantiles
exists and not empty, I can't read the data from that wave.March 19, 2013 at 06:17 am - Permalink
March 19, 2013 at 06:29 am - Permalink
I see my error, apologies for the misinformation. I did test this syntax under 6.2.2.2 and got a compile error. I must have done something wrong because, after trying it again, it seems to work.
My other source of confusion was not finding the syntax documented in the online Command Help in the Help Browser. I do see it documented elsewhere.
March 19, 2013 at 07:06 am - Permalink
Still thanks for informing. I have seen that kind of usage of
MAKE/D/N=(numofRows) $(w_name)/Wave=w
in a post as an example to another question and used for my problem. These are small details but very important as well.Cheers,
Emre
March 19, 2013 at 08:50 am - Permalink