Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hold a plot when using plot3 in matlab?

This works as I expected:

    for i=1:100
      hold on;
      plot(i,i^2);
      drawnow;
    end

Ploting the points as they come in the same figure.

This on the other hand, doesn't:

    for i=1:100
      hold on;
      plot3(i,i^2,sqrt(i));
      drawnow;
    end;

Since it does not show a 3d plot of the points, it only shows the projection of them in the xy plane. Somehow the hold onstatement messes up with plot3.

How can I obtain results that are analogous to the 2d case when using plot, in the 3d case, when I have points in several 3d locations?

I've tried to make this question concise, if you believe I haven't explained it well enough for a satisfactory answer please say so in the comments.

like image 755
JLagana Avatar asked Apr 30 '13 01:04

JLagana


1 Answers

Your code correctly plots a 3-D curve. All you need to do to see it is add

view(3);

anywhere in your code.

Additionally, one hold on command is sufficient (i.e. you don't need to repeat it in every loop iteration).

like image 151
Ansari Avatar answered Oct 04 '22 21:10

Ansari