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
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!