MATLAB: How to orbit a plot3 via mouse while updating it

figureplot3

I have a plot that I want to be able to orbit with my mouse while it's updating. But every update to the plot forces the plot to go back to it's default view point. Is there a way to do what I want?
Thanks in advance!

Best Answer

Dereck - how is your code updating the figure at each iteration? Is it re-plotting all 3D data with the addition of some new points, or are you just updating the axes with the new points?
I used the helix example from plot3 and noticed that if I plotted the data, then rotated the axes, and then plotted the data again, that the view point of the axes was restored to its original value. However, if after I rotated the axes and then called the command
hold on
for the current axes, that the subsequent call to plot the same data again, resulted in the view point of the axes remaining fixed at what I rotated it to. (For details on hold on, type doc hold - basically it retains the current graph and axes properties when adding a new graph/plot, rather than resetting/clearing the axes properties.)
So you could do the same here - call hold on just once to ensure that the axes properties (in this case View which returns the azimuth and elevation of the graph) are maintained from one call of plot3 to another. Or, just after creating the figure, you could try
set(gca,'NextPlot','add');
Which will set the current axes (its handle obtained from gca, get current axes) NextPlot property to add which will use the existing axes to draw the graph (the default is replace which resets all axes properties). See axes properties for details. This method worked well - I could rotate the figure and re-plot the graph without loss to my last view point of the axes.