# Standard deviation between layers of a 3DWave Hi,

I am using a sumbeams function of the MatrixOP to get the matrix of average values across the 3D wave. I simply sum them using the aforementioned function and divide the resulting sum by the number of layers. Now, additionally to the average values, I also need a standard deviation. Is there a way to obtain it across layers of a 3D wave for each element of each matrix? Can I subject each element in each matrix to an expression like SQRT(Variance)?

Thank you for help.

JB

If I understand your goal correctly and if speed is not a crucial issue, it seems you could you use WaveStats/RMD[row][col][] and iterate over all rows and columns, providing you with count, average, standard deviation for each beam, which you would then have to store during the loop.

It also seems like you could reorient the data so that you can use Wavestats/PCST, like so:

//untested but possibly correct...
make/o/d/n=(10,20,30) whatever = enoise(1)  //an example multidimensional wave for which stats for each beam are desired
imagetransform/g=3 transposevol whatever    //swap the layers into the rows so /PCST can run on each column (and what had been each row)
wavestats/pcst M_VolumeTranspose  //get statistics for each column, each layer is treated separately
imagetransform/g=3 transposevol M_wavestats     //swap the rows (statistics) back into the layers, so the original and row and column positions are restored.
//M_VolumeTranspose contains the results
copydimlabels/rows=2 M_wavestats,M_VolumeTranspose  //copy statistics dimension labels

//in case original wave had dimension labels:
copydimlabels/rows=0 whatever,M_VolumeTranspose //copy row labels to results wave
copydimlabels/cols=1 whatever,M_VolumeTranspose //copy col labels to results wave

//averages are stored in layer 3 and standard deviations in layer 4, so this provides each for all rows and columns:
duplicate/o/r=[][][finddimlabel(M_VolumeTranspose,2,"avg")] M_VolumeTranspose, results_avg
duplicate/o/r=[][][finddimlabel(M_VolumeTranspose,2,"sdev")] M_VolumeTranspose, results_sdev

There are, perhaps, faster implementations with matrixop, but if you decide you want yet another statistic in the future, that statistic might already be accessible with this approach.

The approach outlined above is indeed very elegant.  It is however not clear to me what the OP meant by:

(a) "Is there a way to obtain it across layers of a 3D wave for each element of each matrix?"

and

(b) "subject each element in each matrix to an expression like SQRT(Variance)?"

It is important to specify which variance the OP needs to calculate.  Since a variance calculation requires the subtraction of a mean, it is important to specify which mean is being calculated (e.g., mean of a column, mean of a layer or of a beam).  Note that in the special case of zero mean you can factor out the (1/(n-1)) from the variance and simply add the contributions from various columns, layers, etc.

Igor wrote:

The approach outlined above is indeed very elegant.

Indeed, I don't need speed in this case and I thank for the solution. I just thought there exists an equivalent of "sumbeams" parameter to obtain standard deviation.

Igor wrote:

It is however not clear to me what the OP meant by:

(a) "Is there a way to obtain it across layers of a 3D wave for each element of each matrix?"

I presume it should be across beams. If I understand the idea of a beam correctly, it's a higher dimension, column-like structure going across the wave layers. I need stdev of beams.

Igor wrote:

and

(b) "subject each element in each matrix to an expression like SQRT(Variance)?"

It is important to specify which variance the OP needs to calculate.  Since a variance calculation requires the subtraction of a mean, it is important to specify which mean is being calculated (e.g., mean of a column, mean of a layer or of a beam).  Note that in the special case of zero mean you can factor out the (1/(n-1)) from the variance and simply add the contributions from various columns, layers, etc.

Same as above. I need standard deviation, or the square root of the variance, which is the same thing, isn't it?

@Jakub: We released Igor 8 more than 2 years ago (May 22, 2018). Your IP8 license won't work with IP9, but we often provide free upgrades to users that purchased a new license or upgrade within some period before a new major version is released. As far as I know we have not yet made a decision on whether we will do that for IP9 and if so what the cutoff date will be. The IP9 beta is taking longer to put together than we had expected and the pandemic isn't helping.