9.19 The plot function plots a line and returns a handle to that line. This han-
ID: 2250047 • Letter: 9
Question
9.19 The plot function plots a line and returns a handle to that line. This han- dle 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 (2m-0) (9.4) between the limits-1.0 sIs1.0, and saves the handle of the resulting line. The angle is initially 0 radians. Then, re-plot the line over and over with = / 10 rad, = 2m/ 10 rad, = 3 /10 rad, and so forth up to = 2 rad. To re-plot the line, use a for loop to calculate the new values of x and t, and update the line's XData and YData properties using MATLAB object syntax. Pause 0.5 seconds between each update, using MATLAB's pause command.Explanation / Answer
MATLAB CODE:
clc; clear all; close all;
t=-1:0.001:1; % time duration
theta=[0 pi/10 2*pi/10 3*pi/10 2*pi]; %Phase angle
g=['--r','--b','--m','--k','--g']; % Plot or graphs colors
figure;
for i=1:1:length(theta)
x=cos(2*pi.*t-theta(i)); % x(t) calculation
plot(t,x,g(i),'LineWidth',2); %Plot
xlabel('it t ightarrow');
ylabel('it x(t) ightarrow');
pause(5);
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.