How can I know the volume behind a surface?

14 views (last 30 days)
Hi! I imported some data x,y,z. z plotted against x and y creates a surface similar to a Gaussian one. I approximated my data with cftool. I obtained a surface in the space. Now I would like to know the volume behind the interpolant surface because it can approximate the spacial surface I am looking for.
Have you got any ideas? 'Cause I can only find in the guide cfit/integrate help but anything concerning sfit/integrate.
Many thanks...

Accepted Answer

Star Strider
Star Strider on 21 Jul 2014
If you have a matrix of data, I would use trapz to do the integration. You will have to use it two times — once in each dimension of the matrix — to get a scalar value for the volume.
  4 Comments
Francesca
Francesca on 22 Jul 2014
Unfortunately, using cftool for surfaces doesn't provide an equation for the interpolating surface. So I cannot use integral2.
However x,y,z are vectors of the same dimension.
Star Strider
Star Strider on 22 Jul 2014
I don’t have the Curve Fitting Toolbox (I have the Optimization and Statistics Toolboxes), so I cannot address the problems with it directly.
If you have a function that you fit that is a function of x, y, and parameters, you can substitute in it the parameters that you fit and use that (as an anonymous function or a function file) for your function argument to integral2.
If you have an anonymous function and a set of fitted parameters (here in vector b), for instance, you can use integral2 with it:
b = [b(1) ... b(n)]; % Parameter vector from fitting routine
f = @(b,x,y) b(1).*exp(-(b(2).*x).^2) + b(3).*exp(-(b(4).*y).^2);
(the function is hypothetical but is probably something close to yours), then use integral2:
vol = integral2(@(x,y) f(b,x,y), x1, x2, y1,y2);
where x1 ... y2 are the relevant integration limits. Your f function will pick up the parameter vector from your workspace. It seems like strange syntax, but it creates a function only in (x,y) from f(b,x,y) so that integral2 can use it. (I tested this code with my own set of b, x1 ... y2, and it works.)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!