How to draw a complicated graph

4 views (last 30 days)
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor on 10 Jun 2022
Commented: Kevin Holly on 10 Jun 2022
Hello
This is the simplest form of the graph that I want to plot. At first, I am going to draw the x-Z-Y graph when K=0. Imagine that I draw the second graph when K=2. Then, I want to connect the two curves and obtain the surface ABCD. The output surface is of graphical importance to me. How should I draw such a thing and obtain surface ABCD in MATLAB?
Bests
Pooneh

Answers (1)

Kevin Holly
Kevin Holly on 10 Jun 2022
Edited: Kevin Holly on 10 Jun 2022
Z=1:100;
Y=Z.^2;
K=2;
figure
plot3(zeros(size(Z)),Z,Y,'k')
hold on
plot3(K*(ones(size(Z))),Z,Y,'r')
line([0 K],[Z(1) Z(1)],[Y(1) Y(1)],'Color','g')
line([0 K],[Z(end) Z(end)],[Y(end) Y(end)],'Color','g')
view(90,30)
text(0,Z(1),Y(1)+500,'A','Color','b')
text(0,Z(end),Y(end)+500,'B','Color','b')
text(K,Z(1),Y(1)+500,'D','Color','b')
text(K,Z(end),Y(end)+500,'C','Color','b')
xlabel('x')
ylabel('Z')
zlabel('Y')
figure
V = meshgrid(Y,[0 K]);
surf(V)
xlabel('Z')
ylabel('x')
zlabel('Y')
  2 Comments
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor on 10 Jun 2022
thanks for your response. This is the code I have written with respect to my specific problem. Now how can I mesh grid the resulting figure?
T = readtable('table.xlsx');
T(1:9,1:4)
TS = table2array(T);
k=[0.3 0.4];
kk = length(k) ;
t = TS(:,1) ;
data = TS(:,3:4) ;
figure
hold on
for i = 1:kk
plot3(k(i)*ones(size(t)),t,data(:,i))
end
view(3)
line(k,[t(1) t(1)],[data(1) data(1)],'Color','g')
line(k,[t(end) t(end)],[data(end) data(end)],'Color','g')
view(90,30)
Kevin Holly
Kevin Holly on 10 Jun 2022
x=-15:15;
data(:,1) = x.^2;
data(:,2) = x.^3;
k=[0.3 0.4];
figure
plot3(0.4*ones(size(x)),x,data(:,1))
hold on
plot3(0.3*ones(size(x)),x,data(:,2))
You could just use surf(x,y,z) format
figure
surf(data',[x;x],[0.3*ones(size(x));0.4*ones(size(x))])
xlabel('Z')
ylabel('x')
zlabel('Y')

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!