is there a way to put a timestep in matlab's movie plot?

17 Ansichten (letzte 30 Tage)
Hard-code a time increment value of dt=0.01s (unless the user is allowed to selected it). Regardless of the time increment value, your code should calculate the temperature at each node in the bar for an overall time duration of 100 seconds. Plot the temperature profile along the bar at time intervals of 10s (i.e., only plot after 1000 update calculations have been performed), and produce a movie that shows the transient development of the temperature profile in the bar.
Those are the instructions for the last step of my assignment, and this is the code I have. I have to use the Matlab movie commands. Please help if you can.
for i=1:dt:10 % loop for continuous iteration
T2=Ke*T+z*Tsur;
T=T2;
plot(0:dx:l,T,'MarkerFaceColor','b','MarkerSize',8)
xlabel('# Of Nodes Present')
ylabel('Temperature (C)')
hold on
getframe;
if k < 100 %counter to keep track of loop
k = k+1;
else
end
hold off
end
pause
movie(M,1,1000)%set movie to play once, high frame rate
  2 Kommentare
dpb
dpb am 5 Dez. 2021
What's wrong with the optional argument(s) to the movie function?
cherokee portman
cherokee portman am 6 Dez. 2021
It's plotting fine, basically I need the graph to plot for the interval I set, but every 10 seconds it stops, then begins again from the spot it stops at but displays each successive 10 second stopping point, if that makes sense.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Dez. 2021
Your instructions are to calculate at intervals of dt, but to plot (and record) every 10 simulated seconds. You should not be plotting unless the current time just become (or rolled over) a multiple of 10 seconds. You should plot at 10 seconds, 20 seconds, 30 seconds, up to 100 seconds, for a total of 10 frames.
T2=Ke*T+z*Tsur;
T=T2;
In cases where you are not plotting, that might be all that you do -- though I would have expected that the calculation should involve dt somehow. In cases that you are plotting (because you just hit 10 second multiple), then plot as well.
User might have deliberately chosen an interval such as 0.07381 seconds, so you cannot rely on the update being at a multiple of 10 iterations, and you cannot rely on the idea that the time increments will give you an exact multiple of 10 seconds.
Hint:
steptimes = 0:dt:10;
numsteps = length(steptimes);
updates_at = interp1(steptimes, 1:numsteps, 10:10:100, 'next');
for K = 1 : numsteps
t = steptimes(K);
stuff
if ismember(K, updates_at)
plot stuff
end
end
  3 Kommentare
dpb
dpb am 6 Dez. 2021
Bearbeitet: dpb am 6 Dez. 2021
Who's guidelines do you think you might be violating? Your school's or the forum's?
Generally we're happy to help w/ homework when we do see the student has made a sincere effort and asks specific MATLAB-related questions. Seeing the student code is about the only way we have to judge that level of effort.
As for the timing and movie, what is the value of the hardcoded timestep? If it isn't an integral fraction of 10, then a comparison won't have a chance of matching a computed time; even if it is, floating point well may not reproduce the time to exact integer values. If this is so, then ismembertol may solve some of your problems.
Otherwise, if you don't have a solution at precisely the desired output times (or within acceptable tolerance you set), then you would need to test for reaching the target time and either accept however close the timestep turns out to be as good enough, or interpolate to produce a result from the timesteps bracketing the output time at the specific time wanted.
cherokee portman
cherokee portman am 6 Dez. 2021
the timestep is 0.01, and I'm not sure on my school's policy but I dont want to risk it, you know?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu View and Analyze Simulation Results finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by