Subplot titiles in one command

4 ビュー (過去 30 日間)
Virginia
Virginia 2013 年 6 月 6 日
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

採用された回答

Jonathan Epperl
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

その他の回答 (2 件)

Andrew Newell
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)]).

Virginia
Virginia 2013 年 6 月 10 日
Thanks! Didi it with the title array, it was very simple but I did not think about it. Thanks!

カテゴリ

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