I have a non-uniformly spaced x,y,z data (Eastings, Nothings and thickness) which I have gridded and plotted as a surface using meshgrid
, griddata
and surf
.
I would like to calculate the volume under this surface but I'm struggling to apply other answers to this question to my dataset and code in question (I am a complete Matlab beginner).
Any ideas how to do this (on Matlab version 2011b)? Thanks in advance.
load E.txt, load N.txt, load Z.txt;
[xi, yi] = meshgrid(25.351639:0.00025:25.426483, 36.363799:0.0005:36.458845);
zi = griddata(E,N,Z, xi,yi, 'linear');
surf(xi,yi,zi)
griddata
interpolates the data so that it's uniformly spaced on the xi
,yi
,zi
grid. So you could sum up all zi
values and multiply the result by the base area, which is dx*dy
:
dx = 0.00025;
dy = 0.0005;
vol = dx*dy*sum(zi(:));
If some of the zi
values are NaN, do this instead:
vol = dx*dy*sum(zi(~isnan(zi)));