Get the mean value for a row of a 2D wave

Hei,

with the following function I am able to get the mean value of a defined region in a column (vertical dimension):

wave1(0)=mean(2Dwave,10,1)

Can anybody tell me how to get the mean value of a defined region in a row (horizontal dimension) of a 2D wave?

cheers,

Finn
I imagine that you could use a little function like this

Function MeanRow (wave2D, rn, x1, x2)

Wave wave2D
Variable rn         //row number
Variable x1,x2

Duplicate /O wave2D Rwave  //row wave
Redimension /N=(1,-1) Rwave //redimension to a single row
Rwave = wave2D[rn][q] //assign the r column
MatrixOp /O Rwave = Rwave^t //transpose row into a column

return mean(Rwave, x1,x2)

end


Here is an example that shows how to sum each of the rows of a 2D wave:
Function Demo()
    Make/O/N=(5,3) mat = p + 10*q
    Edit mat
    MatrixOp rowSums = SumRows(mat)
    AppendToTable rowSums
End

iherrera wrote:


Function MeanRow (wave2D, rn, x1, x2)

Wave wave2D
Variable rn         //row number
Variable x1,x2

Duplicate /O wave2D Rwave  //row wave
Redimension /N=(1,-1) Rwave //redimension to a single row
Rwave = wave2D[rn][q] //assign the r column
MatrixOp /O Rwave = Rwave^t //transpose row into a column

return mean(Rwave, x1,x2)

end


I prefer a slightly simpler version:

Function MeanRow (wave2D, rn, x1, x2)
Wave wave2D
Variable rn         //row number
Variable x1,x2
    MatrixOP/O/Free w=row(wave2D,rn)^t
    return mean(w, x1,x2)
End


A.G.
WaveMetrics, Inc.
Hei,

thanks very much! With your help it is working now.

cheers,

Finn
I've written a few functions that make things like this a little quicker. First I made functions that can return a row or column from a 2D wave. This result can only be passed into another function as input but these are still super useful for me (they mimic the row/col functions you can use in matrixop):

function/wave row(w,n)
  wave w;
  variable n;

  make/n=0/free wc;
  if(n < dimsize(w,0))
    matrixop/free wc = row(w,n);
  endif
  return wc;
end
function/wave col(w,n)
  wave w;
  variable n;

  make/n=0/free wc;
  if(n < dimsize(w,1))
    matrixop/free wc = col(w,n);
  endif
  return wc;
end


These functions are cool because you can pass them right into a another function. So if I wanted to find the mean of values 3 to 20 in row 15 of some 2D wave, w, I can run this:

print mean(row(w,15),3,20);


I keep loads of utility functions like these in Ipfs that load automatically with Igor at startup so they are always there for me to use.
A lot of good advice so far but I'll add my two cents.

Often times I want to do something like this but for all cols or rows:

Function MeanRows_sr(wave0, x1, x2)
Wave wave0
Variable x1
Variable x2

Make/D/O/N = (Dimsize(wave0,1)) ones = 0
ones[x1, x2] = 1
MatrixOp/O mean_rows =  (wave0 x ones)/ (x2-x1+1)

End


if you do not want subranges it is even easier:
Function MeanRowsandcols(wave0)
Wave wave0

Make/D/O/N = (Dimsize(wave0,1)) ones = 1
MatrixOp/O mean_rows =  (wave0 x ones)/ numcols(wave0)

Make/D/O/N = (Dimsize(wave0,0)) ones = 1
MatrixOp/O mean_cols = (wave0^t x ones)/numrows(wave0)

Killwaves ones

End


Just be careful - in this simple example it does not account for Nans or Infs