Subplot titiles in one command

3 visualizaciones (últimos 30 días)
Virginia
Virginia el 6 de Jun. de 2013
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

Respuesta aceptada

Jonathan Epperl
Jonathan Epperl el 6 de Jun. de 2013
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

Más respuestas (2)

Andrew Newell
Andrew Newell el 6 de Jun. de 2013
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 el 10 de Jun. de 2013
Thanks! Didi it with the title array, it was very simple but I did not think about it. Thanks!

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by