How can i make a 3d conical helix plot itself slowly?

13 views (last 30 days)
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?

Accepted Answer

Geoff Hayes
Geoff Hayes on 25 Nov 2014
Fredrik - you can iterate over each element in x, y, and z and either plot the new points, or just update that which has already been plotted with "a little more" data. So we start off as you have done already with
% close any open figures
close all;
% create the helix data to plot
varv=10;
a = 0.05;
c = 5.0;
t = 0:0.01:varv*2*pi;
x = (a*t/2*pi*c).*sin(t);
y = (a*t/2*pi*c).*cos(t);
z = t/(2*pi*c);
% create a figure
figure(3);
Now, we just create the graphics object that will be used to draw the 3D data, and add labels and a title to the axes.
% create the graphics object
h = plot3(NaN,NaN,NaN);
% label the axes
xlabel('x');
ylabel('y');
zlabel('z');
title('Conical helix');
The call to plot3 with NaN inputs does not plot anything, it just creates the graphics handle whose data we will update. We now set limits on the axes so that when we do draw, the axes limits remain fixed.
% set limits
xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
Now we iterate over each point in our data, and update the graphics handle h with the new data, pausing for 1 millisecond to allow the new data to be drawn on the axes.
% plot the data
for k=1:length(x)
set(h,'XData',x(1:k),'YData',y(1:k),'ZData',z(1:k));
pause(0.001);
end
As you can see in the above code, on each iteration of the for loop we update the XData, YData and ZData with a new point.
Try running the above and see what happens!
  5 Comments
Pasindu Gunamuthu
Pasindu Gunamuthu on 10 Jun 2020
I am trying to see the 3D radiation pattern of a Conical spiral antenna. This shape is not available in the antenna toolbox, any idea how can I achieve this ?
Thanks
Geoff Hayes
Geoff Hayes on 11 Jun 2020
Pasindu - please post your comment as a new question as it is not necessarily related to this question.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!