StatsQuantiles operation

Hello all,

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


Cheers,
Emre
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
jtigor wrote:
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)



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:
Make $(w_name)
WAVE w = $(w_name)
tooprock wrote:
Hello all,

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


Cheers,
Emre


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.

Function buildQuantiles(inputwave)
    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

Thanks for both comments but the problem is that this function doesn't work at all. I get an error saying a wave read error  "Attempt to operate on a null(misssing) wave" Although I see that W_StatsQuantiles exists and not empty, I can't read the data from that wave.
aclight wrote:
jtigor wrote:
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)



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:
Make $(w_name)
WAVE w = $(w_name)


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.
Jeff,

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