3D animation of imported data

조회 수: 1 (최근 30일)
Peter Fraser
Peter Fraser 2016년 6월 15일
댓글: Peter Fraser 2016년 6월 16일
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