Plot images with iterative names as subplots

조회 수: 1 (최근 30일)
Heidi Hirsh
Heidi Hirsh 2020년 11월 9일
댓글: Heidi Hirsh 2020년 11월 9일
I have several images that I have read in as A1 to A43. For instance,
A1= imread('False_Color/20181007.png');
A2= imread('False_Color/20181015.png');
A3= imread('False_Color/20181023.png');
Then I am trying to use a loop to print all 43 images since the names are so similar. I think I am close, but I can't figure out how to remove the quotes so that I can plot imagesc(A3) instead of imagesc('A3') which of course does not work. Please let me know if there is another function I should be using instead of sprintf. Thank you!
This is what I am doing:
for i=1:length(dates_over)
f1=figure(1)
subplot(5,9,i)
imagesc(sprintf('%s%d','A',i)) %I want to loop through so it does imagesc(A1) then imagesc(A2) then imagesc(A3) etc
title(sprintf('%s',dates_over(i)),'fontsize',12) %this works
end

채택된 답변

Matt J
Matt J 2020년 11월 9일
편집: Matt J 2020년 11월 9일
First you need to fix the way you read in the images. They should go into the elements of a cell array likse so,
A{1}= imread('False_Color/20181007.png');
A{2}= imread('False_Color/20181015.png');
A{3}= imread('False_Color/20181023.png');
...
A{43}=...
and then you would do,
for i=1:length(dates_over)
f1=figure(1)
subplot(5,9,i)
imagesc(A{i}) %I want to loop through so it does imagesc(A1) then imagesc(A2) then imagesc(A3) etc
title(sprintf('%s',dates_over(i)),'fontsize',12) %this works
end
  댓글 수: 1
Heidi Hirsh
Heidi Hirsh 2020년 11월 9일
Thank you! I knew there was a smarter way!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by