3D animation of imported data

2 vues (au cours des 30 derniers jours)
Peter Fraser
Peter Fraser le 15 Juin 2016
Commenté : Peter Fraser le 16 Juin 2016
I'm trying to animate a 16 x 16 pressure map. The pressure data are imported as num_frames * 16 by 16 array. I reshape it to a 16 by 16 by num_frames array, and use "surf" to display it. I have two problems. I want to be able to rotate the view in real time, but I can't work out how to do that. The animation runs OK without messing with the azimuth and elevation, but when I add the azimuth and elevation I get "too many output arguments" with the "[az, el] = view" line.
P = permute(reshape(out', 16, 16,[]),[2,1,3]);
clearvars out
dims = size(P)
num_frames = dims(3)
[az, el] = deal(-30, 30) % initial view direction
for frame = 1:num_frames
surf(P(:, :, frame))
view = [az, el]
axis([1 16 1 16 0 max(max(max(P)))])
[az, el] = view %update view direction
pause(0.05)
end
The other problem is that I need the "pause" command for it to animate(without the [az, el] stuff. Is it just running too fast without the pause? How to I correctly synchronize the rendering to the monitor display rate?
Thanks
  1 commentaire
Peter Fraser
Peter Fraser le 16 Juin 2016
Fixed it.
[az, el] = deal(-30, 30) % initial view direction
for frame = 1:num_frames
surf(P(:, :, frame));
view([az, el]);
axis([1 16 1 16 0 max(max(max(P)))]);
pause(0.03)
[az, el] = view %update view direction
end
There were two problems. My syntax for setting the view azimuth and elevation was wrong. Also, I need to get the az and el after the pause. If I execute
[az, el] = view
before the pause it returns the old value most of the time.
I still need to understand the synchronization issues. Why do I need a pause to get the animation to run in the first place, and how long do I need to wait before the [az, el] = view command? Is there some sort of "wait for frame to be displayed" command?

Connectez-vous pour commenter.

Réponses (1)

Nut
Nut le 16 Juin 2016
Hi,
I'm not able to answer your question, I'm writing just for a suggestion. I never used the "drawnow" function, but I know that it is often used when an animation is needed. So, I think it may be helpful for you, try to read about it:
  1 commentaire
Peter Fraser
Peter Fraser le 16 Juin 2016
Thanks. That looks interesting and appropriate. I'll check it out.

Connectez-vous pour commenter.

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