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!