How to integrate a surf plot

조회 수: 74 (최근 30일)
Lukas Süßmilch
Lukas Süßmilch 2020년 8월 3일
답변: Raunak Gupta 2020년 8월 8일
Hello, everyone,
i would like to integrate the values over a very specific square area of my surf plot to determine the volume of this area.
Does anyone have any idea how I can do that? I have scanned and obtained a matrix with 256x256 Z-values. Using surf, Matlab automatically creates the 3D plot from the z-values and assigns X and Y to the values 1-256 . Afterwards I subtracted the surfaces from each other. Now I would like to determine the volume of the surface in the middle (look at the top view picture).
I have tried it with intergal2:
Code:
I = integral2(Subtraction(85:185, 85:185), 'all')
Subtraction is the matrix of the subtracted areas, 85:185 is to indicate the X or Y area in which the integral is to be formed and with "all" I tried to tell Matlab to form the integral over the whole area.
I get the following error message:
Error using integral2 (line 67)
Not enough input arguments.
Error in program (line 39)
Integral = integral2(subtraction)
I also used trapz, but if I do this I get a vector 1x101 and not a single value
I = trapz(Subtraction(85:185, 85:185))

답변 (1개)

Raunak Gupta
Raunak Gupta 2020년 8월 8일
Hi,
From the question I think this example clearly explain the steps of doing surface integral. You need to define the ranges in x and y coordinates also with the spacing between each value (I think the ranges are already figured out and spacing is 1 unit). Below example code might be helpful.
x = 85:185;
y = 85:185;
I = trapz(y,trapz(x,Subtraction(85:185, 85:185),2));
Also integral2 is used for numerical integration of a function which is defined analytically. In this case since you have surface values and it's not analytical (like there is no equation from which it is derived) so only trapz will provide the correct answer.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by