Subplot titiles in one command

조회 수: 3 (최근 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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by