Bowler
Bowler

Reputation: 411

Expectation values in MATLAB

I have a 3D data set representing a grid of photosensors which unfortunately were not steady during use. I have estimated the pdf for the motion of the detector and I want to find the expectation value for each sensor. As I don't want to reflect my pdf (i.e. I want f(t) not f(t-tau)) I don't think I can use the matlab convolve function. Is there a function that will do what I want or should I just get on with it? I've found movavg but it seems to do something else or maybe I just haven't followed it correctly.

Also, as I'm faily new to matlab, from C, I tend to use for loops which I'm aware is not the way to use Matlab. Is there an easy way to convert my 1-D pdf to a 3D matrix that will only operate in one axis (z in this case). Something like repmat(i, j, pdf).

Thanks

Upvotes: 2

Views: 5613

Answers (1)

silvado
silvado

Reputation: 18187

The expected value of a pdf is the integral over the product of the grid values and the pdf values at the corresponding grid points.

To integrate over a 3D-Grid, use the Matlab function triplequad (doc). As an example, let us compute the expected x value:

expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)

pdfxfun in this call must be a function handle which for any (x,y,z) point it receives should return the product of the pdf value at that point and x. In your case, this could probably be achieved by interpolation over your grid data. I don't know a 3D-interpolation function in Matlab, so probably you have to work on this for yourself. Roughly, what you would do is:

function pdfvalue = pdfinterpolation(x,y,z,Xgrid,Ygrid,Zgrid,pdfdata)
% compute interpolated pdfvalue at (x,y,z) from griddata and pdfdata

Then, pdfxfun above can be defined as anonymous function in the call to triplequad:

pdfxfun = @(x,y,z) x*pdfinterpolation(x,y,z,myxgrid,myygrid,myzgrid,pdfdata)
expectedx = triplequad(pdfxfun,xmin,xmax,ymin,ymax,zmin,zmax)

Upvotes: 1

Related Questions