subplot of plots generated from a for loop

1 回表示 (過去 30 日間)
Nany
Nany 2022 年 4 月 9 日
コメント済み: Nany 2022 年 4 月 9 日
Hi everyone,
I am trying to creat one subplot that has all my 16 plots that were generated from a for loop. I want my subplot to be a 2x8 grid
This is what I am doing but it doesn't seem to work. Any help is appreciated
X= my_data
nCols=3
subplot (2,8,1)
hold on
for iCol=1:nCols:size(X,2)
figure
plot(X(:,iCol:iCol+nCols-1))
end
hold off

採用された回答

MJFcoNaN
MJFcoNaN 2022 年 4 月 9 日
If you need a subplot in for loop, maybe this is an example:
X= my_data
nCols=3
for iCol=1:nCols:size(X,2)
ax=subplot(2, 8, iCol);
plot(ax, X(:,iCol:iCol+nCols-1))
end
  3 件のコメント
MJFcoNaN
MJFcoNaN 2022 年 4 月 9 日
The object of axes is very flexible for recalling, for example:
for ii=1:16
ax(ii)=subplot(2, 8, ii);
end
plot(ax(3), x3, y3)
But your task may not be such complex, and this could be enough:
count=0;
for iCol=1:nCols:size(X,2)
count=count+1;
ax=subplot(2, 8, count);
plot(ax, X(:,iCol:iCol+nCols-1))
end
Nany
Nany 2022 年 4 月 9 日
Thank you so much! That solved the problem. I really appreciate your help

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by