How to move a (x,y) line plot to the z axis?

3 views (last 30 days)
Cio on 22 Oct 2014
Edited: Matt Tearle on 22 Oct 2014
Hi everyone
I have recently got matlab and have been trying to use it to plot some functions. So far, i have been using plot(x,[y0,y1,y2....]) to plot several functions in one 2D plot, how can i move the y lines along the z axis to give a 3d view instead of them overlapping, with spacing long z, (0:7.5:60). So y0 would be at z=0, y1 at z=7.5, y2 at z=15. If the spacing can be filled in aswell to look like a smooth plain. If that makes any sense any help would be welcome. Thank you.
  1 Comment
José-Luis on 22 Oct 2014
I don't get it. Can't you just stack your lines in a 2D plot (add an offset to the y values)?

Sign in to comment.

Answers (1)

Matt Tearle
Matt Tearle on 22 Oct 2014
Edited: Matt Tearle on 22 Oct 2014
Something like this, perhaps?
x = linspace(0,1)';
y1 = cos(2*pi*x);
y2 = x.^2;
y3 = y1.*y2;
The "z" values (actually x in MATLAB's world!) are 1, 2, 3,... instead of 0, 7.5, 15,... but that can be faked, if you really need:
ax = gca;
n = (1:3)'; % change the 3 to however many y variables there are
ax.XTick = n;
ax.XTickLabel = num2str(7.5*(n-1));

Community Treasure Hunt

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

Start Hunting!