So i have these following lines of code and now all it does is give me the product of the plot right away. However i want to see it being drawn before my eyes! How can this be done? Using drawnow? And if drawnow how do i implemnt it?
MATLAB: How can i make a 3d conical helix plot itself slowly
drawnowhelixMATLABplotrealtime
Related Solutions
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.
Aradhya - everytime you call plot3 you are creating a new plot (graphics) object and the previous one is deleted. Perhaps that is why you are not seeing all of the data being plotted (if I understand your question correctly). Rather than using a loop to plot the data, just do it all at once
plot3( x_accel(1:999), y_accel(1:999), z_accel(1:999))
Else if you want to plot each point (with perhaps a pause between each one), then you will want to create one plot object and update that on each iteration of your loop
hPlot = plot3(x_accel(1), y_accel(1), z_accel(1));for k = 2:1000-1 pause(0.5); xdata = [get(hPlot, 'XData') ; x_accel(k)]; ydata = [get(hPlot, 'YData') ; y_accel(k)]; zdata = [get(hPlot, 'ZData') ; z_accel(k)]; set(hPlot, 'XData', xdata, 'YData', ydata, 'ZData', zdata);end
I haven't tested the above, but it should work something like that.
Best Answer