Clear Filters
Clear Filters

How to slice an outer surface plot to reveal an inner surface plot in MATLAB?

1 view (last 30 days)
I have the following sample code which creates two 3D plots on the same axes and which overlay each other:
[X,Y,Z] = peaks(75);
[Xa,Ya,Za] = peaks(50);
figure
surf(X,Y,Z)
colormap(spring)
shading(interp)
hold on
surf(Xa,Ya,Za)
colormap(winter)
shading(interp)
hold off
grid off
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Surface Plot')
I wish to remove a portion of the first outer plot [surf(X,Y,Z)] to reveal the second inner plot [surf(Xa,Ya,Za)]. The cross-section of the segment to be removed should be a quadrant of the first plot in the XY plane.
Please advise on how this can be done in MATLAB?
Thanks!

Accepted Answer

Bruno Luong
Bruno Luong on 9 Apr 2022
Use NaN to remove points you don't want to see, adapt to your need
[X,Y,Z] = peaks(75);
[Xa,Ya,Za] = peaks(50);
Z(X<0 & Y<0) = NaN;
Za = -1-0.5*Za;
%Za(Xa<0 & Ya<0) = NaN;
figure
surf(X,Y,Z,'FaceColor','b')
hold on
surf(Xa,Ya,Za,'FaceColor','y')

More Answers (0)

Community Treasure Hunt

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

Start Hunting!