Changing Marker Types in a Plot for a Movie - Also General Movie Troubleshooting?

2 vues (au cours des 30 derniers jours)
Valielza O'Keefe
Valielza O'Keefe le 9 Avr 2020
Hello! I'm taking a one-credit MATLAB class at university, and I could really use the community's help for my current assignment.
The primary objective of this assignment is to create a movie from the given file, and learning how to use the "movie" and "getframe" commands. That's all fine and dandy. I think I've done that much, although when it's run, the movie's first run is always very slow. Then, the second run of the movie is much faster. Also, if I click any other figure windows, the movie will appear and start playing on that figure window, too.
The secondary objective is to change the marker type for each segment of the rocket's launch in the movie. For example, a diamond marker on the plot during segment 1, when the rocket engine is on; a cross marker for segment 2, when the engine is stopped and the parachute is still closed; and a circle marker for segment 3, when the parachute opens. It can be any marker type, but it needs to change depending on what segment is being plotted.
clear all; clc;
%This program models the flight of a small rocket
m=0.05; g=9.81; tEngine=0.15; Force=16; vChute=-20; Dt=.01;
clear t v h
n=1;
t(n)=0; v(n)=0; h(n)=0;
%Segment 1: The rocket engine is on during the first .15 seconds
a1=(Force-m*g)/m;
while t(n)<tEngine && n<50000
n=n+1;
t(n)=t(n-1)+Dt;
v(n)=a1*t(n);
h(n)=0.5*a1*t(n)^2;
end
n;
v1=v(n); h1=h(n); t1=t(n);
%Segment 2: The rocket engine has stopped but the parachute hasn't opened
%yet
while v(n)>= vChute && n<50000
n=n+1;
t(n)=t(n-1)+Dt;
v(n)=v1-g*(t(n)-t1);
h(n)=h1+v1*(t(n)-t1)-0.5*g*(t(n)-t1)^2;
end
n;
v2=v(n); h2=h(n); t2=t(n);
%Segment 3: The parachute opens and the rocket floats to the ground
while h(n)>0 && n<50000
n=n+1;
t(n)=t(n-1)+Dt;
v(n)=vChute;
h(n)=h2+vChute*(t(n)-t2);
end
n;
subplot(1,2,1)
plot(t,h)
xlabel('Time (s)')
ylabel('Height (m)')
title('Rocket Height')
subplot(1,2,2)
plot(t,v)
xlabel('Time (s)')
ylabel('Velocity (m/s)')
title('Rocket Velocity')
%% Position-Time Graph Movie
fig2 = figure(2);
numframes=1000;
N=2;
FPS=100;
for i = 1:n
plot(t(1:i),h(1:i),'-k',t(i),h(i),'o','markeredgecolor','c');
xlabel('Time (s)')
ylabel('Height (m)')
title('Rocket Height')
axis ([0 12 1 120])
M(i) = getframe(fig2);
end
movie(fig2,M,N,FPS)
%% Velocity-Time Graph Movie
fig3 = figure(3);
numframes2=1000;
N2=2;
FPS2=100;
for i = 1:n
plot(t(1:i),v(1:i),'-k',t(i),v(i),'d','markeredgecolor','r');
xlabel('Time (s)')
ylabel('Velocity (m/s)')
title('Rocket Velocity')
axis ([0 12 -30 50])
M2(i) = getframe(fig3);
end
movie(fig3,M2,N2,FPS2)
The %%Movie sections are what I coded, everything above it was a part of the given file.
Any ideas? I tried putting each segment's "while" statements inside the "for" loops, but the figure would open and the movie would never start.
Thanks so much!

Réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by