MATLAB: How to calculate the volume under a 2D surface specified on a grid in MATLAB 7.1 (R14SP3)

2dMATLABsurfacevolume

I have data in a form of a matrix which specifies a 2D surface on a gird, such as
[X,Y]=meshgrid(-3:0.1:3,-3:0.1:3);
data=peaks(X,Y);
I would like to know how to calculate the volume under this surface.

Best Answer

While there is no built-in functionality to do specifically what you want, you may be able to write a function to perform such a computation.
You can use the function DBLQUAD, which evaluates double integral of a specified function of 2 variables numerically. In this case the function is specified as discretized values on a grid. To be able to find the function value at an arbitrary point (x,y), you can use the 2D MATLAB interpolation function INTERP2.
q2= dblquad(@(x,y)interp2(X,Y,data,x,y,'*cubic'),-3,3,-3,3)
For more information on the DBLQUAD and INTERP2 functions type
doc interp2
doc dblquad
in your MATLAB command line.
Related Question