5
votes

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.

1

1 Answers

6
votes

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