Handle graphics and animation HELLLP!

조회 수: 3 (최근 30일)
Mike
Mike 2013년 11월 21일
댓글: Walter Roberson 2013년 11월 21일
The plot function plots a line and returns a handle to that line. This handle can be used to get or set the line’s properties after it has been created. Two of a line’s properties are XData and YData, which contain the x- and y-values currently plotted. Write a program that plots the function
x(t) = cos(2*pi*t – θ)
between the limits -1.0 ≤ t ≤ 1.0 and saves the handle of the resulting line. Remember, the smaller the increment, the smoother the plot. The angle θ is initially 0 radians.
Then, re-plot the line over and over with θ=p/10 rad, up to θ=2p rad. Again, the smaller the increment, the smoother the transition. To re-plot the lines, use a for loop to calculate new values for x and update the line’s XData property with the set command.
I have this so far
t = -1:0.1:1;
theta=0;
a = cos(2*pi*t-theta);
So I realize that during the for loop theta is going to increase by pi/10
theta=0;
n=0;
for theta<=2pi;
n=(n-1)+1
theta=n*(pi/10)
a = cos(2*pi*t-theta);
hndl=plot(t,a)
and thats all I have
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 11월 21일
n=(n-1)+1 is the same as n=n except if n is 0 and n is an unsigned integer (in which case n-1 is 0-1 which is clipped to 0 in unsigned calculations, and then the +1 would make it 1 instead of leaving n at 0.)
for theta<=2pi; is not valid syntax. "for" is used when you know how many times you are going to loop; to loop until a condition is satisfied use "while"

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2013년 11월 21일
편집: Image Analyst 2013년 11월 21일
Not too bad. Here, x is y (controlled by YData), and t ix x (controlled by XData). Try
% First do a plot to get hPlot.
for number_of_t_steps = 10 : 10 : 100
t = linspace(-1, 1, number_of_t_steps)
theta = 0; % or pi/10 or 2*pi
xt = cos(2*pi*t - theta);
set(hPlot, 'XDATA', t); % Adjust horizontal axis
drawnow; % Force it to draw immediately.
pause(1); % Wait a second for you to see it.
end
Realize that this only updates the horizontal axis, not the vertical.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by