How does getframe work?

19 vues (au cours des 30 derniers jours)
Weia Reinboud
Weia Reinboud le 7 Jan 2019
Commenté : Weia Reinboud le 7 Jan 2019
New project, new things to learn in Matlab, new problems. My previous (and first) project in Matlab led to an article which is in the peer review process now. Thanks to just 9 questions of me in this forum. Much appreciated, very much!
See attached picture made with plot3. Hold is on. It shows a highjump bar and something going over it. Hold leads to all 'frames' shown. With hold of the bar disappears and grid is invisible and axes are not fixed.
In fact I want this as a movie, with the bar, grid and axis shown and the thing moving over it. I've read and reread the documentation of getframe but seem to miss the point.
After calculation of x,y,z I do
plot3
and immediately after it
film=getframe.
But nothing happens and movie(film) does not know 'film'.
[EDITED, Jan, moved from section for answers]
Code:
while (t<2.4*ta)
.......calculation of poitns (xp,yp,zp)......
end
plot3(xp, yp, zp, 'o');
film=getframe;
t=t+dt;
end
movie(film,5)
Plot3 gives the correct picture, as attached to my previous question. But then nothing happens. Documentation says: "movie(M,N) plays the movie N times." How?
  1 commentaire
Jan
Jan le 7 Jan 2019
What does "movie(film) does not know 'film'" mean? What is "nothing happens"? What do you expect to happen? What exactly is "I do plot3"? Which point do you miss? Please post some code, which reproduces your problem.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 7 Jan 2019
Modifié(e) : Jan le 7 Jan 2019
You create a movie with 1 frame only, because film is overwritten in each iteration. Then showing 1 frame 5 times looks like nothing is happening. Try this:
k = 0;
while (t<2.4*ta)
.......calculation of poitns (xp,yp,zp)......
end
plot3(xp, yp, zp, 'o');
k = k + 1;
drawnow; % Let Matlab update the window
% Sometimes this helps also: pause(0.02)
film(k) = getframe;
t = t+dt;
end
movie(film, 5)
By the way: This is equivalent to the example in the documentation: doc getframe -> Record Frames and Play Movie (link). Reading the documentation is recommended.
  3 commentaires
Walter Roberson
Walter Roberson le 7 Jan 2019
Use
h = plot3(xp, yp, zp, 'o');
and then after the getframe,
delete(h)
Weia Reinboud
Weia Reinboud le 7 Jan 2019
Wonderful! It works and I have the movie I want. Thanks all.
Now studying the videwriter...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by