How to Cut a 3D plane with a line?

10 次查看(过去 30 天)
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

回答(1 个)

Arnab Sen
Arnab Sen 2016-4-27
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.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by