MATLAB: Filling area between two planes in 3d plot

meshpatchsurfwaterfall

I'm trying to more or less plot an amorphous blob on a 3d plot. I know the top, and I know the bottom. Is there an easy way to fill the space between? For example, if I have
surf(peaks)
hold on
surf(peaks + 5)
hold off
How could I connect the two planes so it's like a volume?
Thank you so much for your time

Best Answer

The isosurface approach that Tim suggested is possible. Here's an example of how you'd do that. It's a bit involved and it uses quite a bit of memory:
%%Start with 2 surfaces
nx = 25;
ny = 25;
nz = 25;
[x,y] = meshgrid(linspace(-2,2,nx),linspace(-2,2,ny));
z1 = peaks(x,y);
z2 = peaks(x,y) + 5;
surf(x,y,z1);
hold on
surf(x,y,z2)
%%Create 3D grid containing distance to closest surface
[y3,x3,z3] = ndgrid(linspace(-2,2,ny),linspace(-2,2,nx),linspace(-10,15,nz));
v = zeros(size(z3));
for r=1:ny
for c=1:nx
for s=1:nz
d1 = z3(r,c,s) - z1(r,c);
d2 = z2(r,c) - z3(r,c,s);
if d1 < 0
v3(r,c,s) = d1;
elseif d2 < 0
v3(r,c,s) = d2;
else
v3(r,c,s) = min(d1,d2);
end
end
end
end
%%Create isosurface
figure
p = [patch(isosurface(x3,y3,z3,v3,0)), ...
patch(isocaps(x3,y3,z3,v3,0))];
isonormals(x3,y3,z3,v3,p(1))
set(p,'FaceColor','yellow')
set(p,'EdgeColor','none')
set(p,'FaceLighting','gouraud')
view(3)
camlight right
You need both isosurface and isocaps there. The isosurface command creates the parts inside the volume (the same parts surf created) while isocaps creates the parts along the boundary. You can also combine isocaps from that example with your surface objects like this:
figure
surf(x,y,z1);
hold on
surf(x,y,z2)
isocaps(x3,y3,z3,v3,0);