3D animation of imported data

1 次查看(过去 30 天)
Peter Fraser
Peter Fraser 2016-6-15
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 个评论
Peter Fraser
Peter Fraser 2016-6-16
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?

请先登录,再进行评论。

回答(1 个)

Nut
Nut 2016-6-16
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 个评论
Peter Fraser
Peter Fraser 2016-6-16
Thanks. That looks interesting and appropriate. I'll check it out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by