![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285937/image.gif)
Creating a gif from a matrix of double.
14 ビュー (過去 30 日間)
古いコメントを表示
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 .
0 件のコメント
採用された回答
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/285937/image.gif)
0 件のコメント
その他の回答 (1 件)
Image Analyst
2020 年 4 月 19 日
See Steve's blog on how to make animated gifs: https://blogs.mathworks.com/steve/2019/02/07/animated-png-apng-files/?s_tid=srchtitle
If you want a non-animated one, just use imwrite().
参考
カテゴリ
Help Center および File Exchange で Animation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!