MATLAB Answers

How to Cut a 3D plane with a line?

51 views (last 30 days)
Mahmoud Shakouri
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 = reshape(F,length(x2),length(x1));
axis([-3 3 -3 3 0 .4])
xlabel('x1'); ylabel('x2'); zlabel('Joint Probability Density');
hold on
hold on
z = zeros(26);
y = exp(x1);
My result
I want it to be like this

Answers (1)

Arnab Sen
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)
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.

Community Treasure Hunt

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

Start Hunting!