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!