Hello!
I'm having trouble creating a gif for this script! Could anyone help me? Thanks
close all
clear all
clc
pt=randi([100,200],10,3);
plot3(pt(:,1),pt(:,2),pt(:,3),'o','markerfacecolor','r','markeredgecolor','r')
grid on
box
daspect([1 1 1])
x_lim=get(gca,'xlim')
y_lim=get(gca,'ylim')
z_lim=get(gca,'zlim')
set(gca,'xtick',[x_lim(1):25:x_lim(2)])
set(gca,'ytick',[y_lim(1):25:y_lim(2)])
set(gca,'ztick',[z_lim(1):25:z_lim(2)])
set(gca,'CameraViewAngle',[15])
for i=1:5:380
view(i,33)
pause(0.15)
end

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 14일
편집: Ameer Hamza 2020년 11월 14일

1 개 추천

You can use imwrite(). See the example titled "Write Animated GIF" here: https://www.mathworks.com/help/matlab/ref/imwrite.html#btv452g-1
For example
close all
clear all
clc
pt=randi([100,200],10,3);
plot3(pt(:,1),pt(:,2),pt(:,3),'o','markerfacecolor','r','markeredgecolor','r')
grid on
box
daspect([1 1 1])
x_lim=get(gca,'xlim');
y_lim=get(gca,'ylim');
z_lim=get(gca,'zlim');
set(gca,'xtick',[x_lim(1):25:x_lim(2)])
set(gca,'ytick',[y_lim(1):25:y_lim(2)])
set(gca,'ztick',[z_lim(1):25:z_lim(2)])
set(gca,'CameraViewAngle',[15])
for i=1:5:380
view(i,33)
pause(0.15)
frame = getframe(gcf);
[im, map] = rgb2ind(frame2im(frame),256);
if i == 1
imwrite(im, map, 'myAnimation.gif', 'gif', 'LoopCount', 1, 'DelayTime', 0.1);
else
imwrite(im, map, 'myAnimation.gif', 'gif', 'WriteMode', 'append', 'DelayTime', 0.1);
end
end

댓글 수: 7

Alberto Acri
Alberto Acri 2020년 11월 14일
thank you so much !!
Alberto Acri
Alberto Acri 2020년 11월 14일
And... is it possible to hide the axes?
Ameer Hamza
Ameer Hamza 2020년 11월 14일
Which part of axes you want to hide? Do you want to hide the complete thing? Add this line before the for-loop
set(gca, 'Visible', 'off');
Alberto Acri
Alberto Acri 2020년 11월 14일
yes, perfect. Thank you so much !!
Alberto Acri
Alberto Acri 2020년 11월 14일
And another thing. Can I have a white background in the gif?
Ameer Hamza
Ameer Hamza 2020년 11월 14일
Put these two lines before for-loop
set(gcf, 'Color', [1 1 1])
set(gca, 'Visible', 'off');
Alberto Acri
Alberto Acri 2020년 11월 14일
ok, thanks

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

추가 답변 (0개)

카테고리

제품

릴리스

R2020a

태그

질문:

2020년 11월 14일

댓글:

2020년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by