Problem with animated a 'surf' plot

I have a 3D-data structure which is effectively a series of 2D matrices which are used to built a 3d-surface plot. I'm trying to stitch them together into an animation, but all that seems to be grabbed is white space...
The code I'm using is below and I would be so grateful to anyone who could tell me what I'm doing wrong.
Zlim = max(max(max(Psi)));
NFrames = Nz;
%Window = gca;
Frames = moviein(NFrames);
%colormap('jet')
%map=jet;
for i = 1:NFrames
surf(Psi(:,:,i));
h= get(gcf,'CurrentAxes');
zlim([0 Zlim]);
Frames(i) = getframe(h);
%Frames(i) = getframe;
end
%clf
movie2avi(Frames,'Output.avi','compression','Cinepak','fps',3);
%close(Window);

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 4일

0 개 추천

Well, I don't have your data. But I tried and it did show the animation. Maybe check your data Psi?
I used this and then run your code. The output.avi is correct too.
Psi=rand(100,100,10);
Nz=10;
Charles
Charles 2011년 8월 4일

0 개 추천

Many thanks! I'm fairly certain the data's ok, as I see the graphs being plotted as the script runs (the data is generated by some C++ code). So I've tried to simplify:
Zlim = max(max(max(Psi))); Fig = newplot; FigHandle = get(Fig,'Parent'); Frames = moviein(Nz,FigHandle);
colormap('jet')
for i = 1:Nz surf(Psi(:,:,i)); zlim([0 Zlim]); Frames(:,i) = getframe(FigHandle); end
movie2avi(Frames,'OutputXY.avi','compression','Cinepak','fps',5);
When I run this, the surf plots are made, but the movie grabs only some empty, 2D axes.

댓글 수: 1

Fangjun Jiang
Fangjun Jiang 2011년 8월 4일
Again, I don't have your data. Did you try my example using the random data? Did it show correctly and did you check whether Output.avi plays outside of MATLAB?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Animation에 대해 자세히 알아보기

태그

질문:

2011년 8월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by