필터 지우기
필터 지우기

Creating a gif from a matrix of double.

조회 수: 19 (최근 30일)
andrea
andrea 2020년 4월 19일
편집: Ameer Hamza 2020년 4월 20일
My problem is that I have a set of matrices , each matrix contain only 1 and -1.
What I'm trying to do is to make a gif of this matrices in succesion, so that the gif frames are the rapresenation of the the matrices with colors, black for -1 and white for 1 (somthing like imagesc) . But from my code somenthind do not work.
In my code x is a cell array which contains my matrices .

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 20일
편집: Ameer Hamza 2020년 4월 20일
See this example to create a gif using black and white imagesec() plots.
% 100 matrices of size 4x4 stored in cell array filled with random data
M = squeeze(mat2cell((rand(20,20,100) > 0.5)*2-1, 20, 20, ones(1,100)));
outFilename = 'myGifFile.gif';
fig = figure();
ax = axes();
colormap([0 0 0; 1 1 1]);
for i=1:100
imagesc(ax, M{i});
img = getframe(ax);
img = rgb2gray(img.cdata);
if i==1
imwrite(img, outFilename, 'gif', 'LoopCount', inf, 'DelayTime', 0.05)
else
imwrite(img, outFilename, 'gif', 'WriteMode', 'append', 'DelayTime', 0.05);
end
end

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 4월 19일
If you want a non-animated one, just use imwrite().
  댓글 수: 1
andrea
andrea 2020년 4월 19일
Not really of any help. I just wanna an animated gif of a sequence matrices which entries are -1 and 1 , I don't know if helps but i'm trying to make an animated gif of an Ising Model simulation.

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by