Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

9.19 The plot function plots a line and returns a handle to that line. This han-

ID: 2250025 • 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.0sIS1.0, and saves the handle of the resulting line The angle is initially 0 radians. Then, re-plot the line over and over with -m/ 10 rad, 2m/ 10 rad, = 3m/ 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

fs = 50;

t = -1.0:1/fs:1.0;
theta = 0;
x = cos(2*pi*t - theta);
p = plot(t,x);
grid on;
p.XDataSource = 't';
p.YDataSource = 'x';

for i = 1:20

x = cos(2*pi*t - theta);
refreshdata
pause(0.5);
theta = i*pi/10;
end