Animation using multiple frames/figures in for loop

23 ビュー (過去 30 日間)
Jamie Al
Jamie Al 2022 年 1 月 20 日
コメント済み: Jamie Al 2022 年 1 月 20 日
I have the for loop that plots different frames of data, but I am trying to update all my frames in one figure to create an animation. All I get is 20 separate figures (which is how many frames I have).
frame = 20;
% Load density data
n = load([Dir '/ne' num2str(frame) '.txt']); %this is my total denisty
% Load X and Y data
XX = load([Dir 'X.txt']);
YY = load([Dir 'Y.txt']);
for i=1:1:frame
figure
n = load([Dir '/ne' num2str(i) '.txt']);
%plot
pcolor(XX,YY,n);
shading flat;
colormap inferno;
colorbar;
hold on;
end

採用された回答

KSSV
KSSV 2022 年 1 月 20 日
編集済み: KSSV 2022 年 1 月 20 日
frame = 20;
% Load density data
n = load([Dir '/ne' num2str(frame) '.txt']); %this is my total denisty
% Load X and Y data
XX = load([Dir 'X.txt']);
YY = load([Dir 'Y.txt']);
figure
for i=1:1:frame
n = load([Dir '/ne' num2str(i) '.txt']);
%plot
pcolor(XX,YY,n);
shading flat;
colormap inferno;
colorbar;
drawnow
end
The best option would be to follow as discussed in the given link:
  1 件のコメント
Jamie Al
Jamie Al 2022 年 1 月 20 日
Thanks! This works!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by