Subplot titiles in one command
3 ビュー (過去 30 日間)
古いコメントを表示
So, I would like to know, if I have a code, with many subplots,for example:
p=1;
for i=1:10
for j=1:3
subplot(i,j)
plot(time,A(p,:))
p=p+1;
end
end
I have 10x3 30 subplots, so I do not want to go subplot by subplot writing subplot(10,3,1) title('whatever') and like this 30 times. I would like to know if there is a command to name them all, like with the legend command: legend([a b c],'oneplot,'twoplot','threeplot') Thank you
0 件のコメント
採用された回答
Jonathan Epperl
2013 年 6 月 6 日
Collect your titles in a cell array:
titles = {'One','two','three'; 'Eins', 'Zwei', 'Drei'; 'Ichi', 'ni', 'san'}
or whatever. Then do what Andrew said and move the title command inside the loop
for p=1:30
subplot(10,3,p)
plot(time,A(p,:))
title(titles{p})
end
0 件のコメント
その他の回答 (2 件)
Andrew Newell
2013 年 6 月 6 日
You could just have the title command inside the inner loop. Suppose you have some sort of function yourTitleHere(i,j) for creating the title string. Then you could do this:
p=1;
for i=1:10
for j=1:3
subplot(i,j)
plot(time,A(p,:))
title(yourTitleHere(i,j))
p=p+1;
end
end
Or the title line could be a command like title(['Plot number (',num2str(i),','num2str(j)]).
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!