I'm trying to create an animated GIF of a 3D plot by rotating the plot around, using a method similar to the Animated GIF example in the MATLAB File Exchange ( link ).
I was able to animate the figure on the screen using the view function and pause, but I'm having trouble turning this into a GIF. On the first i loop, on the second iteration (that is, k=2), when it gets to the line "im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');" it returns the following error:
Subscripted assignment dimension mismatch. Error in test_rotate (line 40) im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
Any ideas? Thanks!
CODE:
plot3(xA,yA,zA,'-b',xB,yB,zB,'-r');
title('Plot Title')
xlabel('X data')
ylabel('Y data')
zlabel('Z data')
legend('Data A','Data B')
grid on
az = 0;
el = 90;
view([az,el])
degStep = 5;
detlaT = 0.1;
fCount = 71;
f = getframe;
[im,map] = rgb2ind(f.cdata,256,'nodither');
im(1,1,1,fCount) = 0;
k = 1;
% spin 45°
for i = 0:-degStep:-45
az = i;
([az,el])
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
k = k + 1;
end
% tilt down
for i = 90:-degStep:15
el = i;
view([az,el])
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
k = k + 1;
end
% spin left
for i = az:-degStep:-90
az = i;
view([az,el])
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
k = k + 1;
end
% spin right
for i = az:degStep:0
az = i;
view([az,el])
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
k = k + 1;
end
% tilt up to original
for i = el:degStep:90
el = i;
view([az,el])
f = getframe;
im(:,:,1,k) = rgb2ind(f.cdata,map,'nodither');
k = k + 1;
end
imwrite(im,map,'Animation.gif','DelayTime',detlaT,'LoopCount',inf)

 採用された回答

Adam Filion
Adam Filion 2013 年 9 月 11 日

3 投票

Hi Nick, you need to use
f = getframe(gcf)
instead of just 'getframe' to make sure it grabs the right figure window. I quickly tried it on my machine and that fixed it.

1 件のコメント

Nick
Nick 2013 年 9 月 11 日
That did the trick, thanks so much!

サインインしてコメントする。

その他の回答 (2 件)

Carlos Ramos
Carlos Ramos 2017 年 3 月 18 日

0 投票

Excelente aporte.. mil gracias!!
John Navarro
John Navarro 2021 年 5 月 11 日

0 投票

Great answer, but...
Does someone know if it is an updated solution or a easier command for this problem? The accepted solution is from 2013

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

製品

質問済み:

2013 年 9 月 11 日

回答済み:

2021 年 5 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by