0
0
MATLABdata~10 mins

Animation basics in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple plot animation using a loop.

MATLAB
for k = 1:10
    plot(k, k^2, 'o');
    [1];
end
Drag options to blanks, or click blank then click option'
Agrid on
Bhold off
Cclf
Dpause(0.5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using hold off inside the loop clears the plot.
Using clf clears the figure and removes previous points.
2fill in blank
medium

Complete the code to keep all points visible during the animation.

MATLAB
figure;
hold [1];
for k = 1:10
    plot(k, k^2, 'o');
    pause(0.3);
end
Drag options to blanks, or click blank then click option'
Aon
Btoggle
Coff
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using hold off erases previous points each iteration.
3fill in blank
hard

Fix the error in the code to update the plot correctly inside the loop.

MATLAB
x = 0:0.1:2*pi;
y = sin(x);
for k = 1:length(x)
    plot(x(1:k), y(1:k));
    [1];
end
Drag options to blanks, or click blank then click option'
Ahold off
Bclf
Cdrawnow
Dpause(0.1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using pause alone may slow animation but not force immediate redraw.
Using clf clears the figure and removes the plot.
4fill in blank
hard

Fill both blanks to create an animated plot that updates y-values in a loop.

MATLAB
x = linspace(0, 2*pi, 100);
fig = figure;
for k = 1:50
    y = sin(x + [1]);
    plot(x, y);
    [2];
end
Drag options to blanks, or click blank then click option'
Ak*0.1
Bpause(0.05)
Cdrawnow
Dk+1
Attempts:
3 left
💡 Hint
Common Mistakes
Using pause without drawnow may delay but not update plot immediately.
Using k+1 in the first blank does not create a smooth phase shift.
5fill in blank
hard

Fill all three blanks to create a smooth animation of a moving point.

MATLAB
t = linspace(0, 4*pi, 200);
fig = figure;
for i = 1:length(t)
    x = cos(t(i));
    y = sin(t(i));
    plot(x, y, 'ro', 'MarkerSize', [1]);
    axis([-1.5 1.5 -1.5 1.5]);
    [2];
    [3];
end
Drag options to blanks, or click blank then click option'
A10
Bdrawnow
Cpause(0.02)
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using too large marker size makes the point hard to see clearly.
Omitting drawnow causes the plot not to update smoothly.
Omitting pause makes animation too fast to see.