# How to Cut a 3D plane with a line?

51 views (last 30 days)
Mahmoud Shakouri on 20 Apr 2016
Answered: Arnab Sen on 27 Apr 2016
I am plotting a joint pdf of some random variables and need to cut this surface with a plane extruded from a line on the XY space. The final figure should be something similar to the attached photo. I was able to plot everything except for the cutting part. Can anyone help me?
% code
clear all
mu = [0 0];
Sigma = [.4 .4; .4 1.5];
x1 = -2.5:.2:2.5;
x2 = -2.5:.2:2.5;
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],mu,Sigma);
F=F+0.1;
F = reshape(F,length(x2),length(x1));
surf(x1,x2,F);
caxis([min(F(:))-.5*range(F(:)),max(F(:))]);
axis([-3 3 -3 3 0 .4])
xlabel('x1'); ylabel('x2'); zlabel('Joint Probability Density');
hold on
contour(x1,x2,F,[.03:.05:3]);
colormap(hsv);
hold on
z = zeros(26);
y = exp(x1);
plot3(x1,y,z)
end
My result
I want it to be like this

Arnab Sen on 27 Apr 2016
Hi Mahmoud,
You can set the value of the F matrix to 0 for the specific region before plotting. You may consider the following code snippet for illustrative purpose:
y = exp(x1);
for i=1:numel(F(1,:))
for j=1:numel(F(:,1))
if i<y(j)
F(i,j)=0;
end
end
end
So, for that specific region the height is zero that should be reflected in plot. If you have follow up questions related to this you may consider contacting MathWorks Tech support of your region and one of the engineer will assist you.