Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
volume calculation from surface difference

Subject: volume calculation from surface difference

From: nman2084

Date: 13 Apr, 2012 17:32:30

Message: 1 of 2

I have pre and post xyz data, the coordinates are in same plane. How do i go about in calculating the volume difference between the two surfaces in matlab.

Is this the way to do this?

spX = linspace(preTest.minX, preTest.maxX);
spY = linspace(preTest.minY, preTest.maxY);
[xC,yC] = meshgrid(spX,spY);

zC = bin2mat(preTest.x,preTest.y,preTest.z,xC,yC);

spX1 = linspace(postTest.minX, postTest.maxX);
spY1 = linspace(postTest.minY, postTest.maxY);
[xC1,yC1] = meshgrid(spX1,spY1);

zC1 = bin2mat(postTest.x,postTest.y,postTest.z,xC,yC);


dZ = zC - zC1;


Subject: volume calculation from surface difference

From: Roger Stafford

Date: 13 Apr, 2012 18:41:25

Message: 2 of 2

"nman2084" wrote in message <jm9nve$6fn$>...
> .......
> V=dx*dy*sum(dZ);
- - - - - - - - -
  You are apparently assuming that the regions in the x-y plane to be covered by the two surfaces are the same right rectangular area aligned with the two axes. Otherwise the computation would be way off and would instead require delaunay triangulation or the like.

  Even so, there is a small error in your formula. You have extended the x-y rectangle all around its edge by 1/2*dx and 1/2*dy in the line "V=dx*dy*sum(dZ);". Look up the "trapezoidal rule" as exemplified by 'trapz'.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us