how to do a subplot loop?
1 次查看(过去 30 天)
显示 更早的评论
Hi, I'm trying to subplot whithin a for loop. I'm asking matlab tu plot me three contourf called nzero_mean1, nzro_mean2, nzro_mean3 in a single subplot and each countourf has a title. But I don't know how to make those trhee contourf at one subplot in a forloop. I need help. I'm currently doing it like this:
figure
subplot(1,3,1)
contourf(nzro_frec1)
set(gca,'XTickLabel',vec)
set(gca,'YTickLabel',vec)
title('Especie 1')
colorbar('southoutside')
subplot(1,3,2)
contourf(nzro_frec2)
set(gca,'XTickLabel',vec)
set(gca,'YTickLabel',vec)
title('Especie 2')
colorbar('southoutside')
subplot (1,3,3)
contourf(nzro_frec3)
set(gca,'XTickLabel',vec)
set(gca,'YTickLabel',vec)
title('Especie 3')
colorbar('southoutside')
[ax1,h1]=suplabel('Delta m3');
[ax2,h2]=suplabel('Delta m2','y');
[ax3,h3]=suplabel('Frecuencia de sobrevivencia. Alpha = 0. p=10. Respuesta Sigmoide (s=2)' ,'t');
set(h3,'FontSize',20)
set(h1,'FontSize',14)
set(h2,'FontSize',14)
orient portrait
print('-dps','suplabel_test')
%unix('convert suplabel_test.ps suplabel_test.jpg');
0 个评论
采纳的回答
Image Analyst
2018-9-5
It wouldn't be worth it. You'd have to have if blocks in the loop to handle cases that should be different on every loop but don't depend on the loop iterator. Sure you could do
for k = 1 : 3
subplot(1, 3, k);
% code
caption = sprintf('Especie %d', k);
title(caption);
end
but the contourf, etc. are not a function of k so you'd have to say
if k == 1
contourf(nzro_frec1)
colorbar('southoutside')
elseif k == 2
contourf(nzro_frec2)
colorbar('southoutside')
etc. that essentially the looping is not gaining you anything.
更多回答(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!