subplot two different images in two different for loop

조회 수: 2 (최근 30일)
Pravita Lekshmanan
Pravita Lekshmanan 2019년 6월 29일
댓글: Pravita Lekshmanan 2019년 6월 29일
I need to display two images suppose as in my case it is patch 1 (P1) and patch2 (P1*) as simultaneous subplots like using for loop
again after incrementing the for loop the upcoming two images should come as the next subplots
But iam getting all P1 to P20 first then P*1 is coming as P*21 which is not what i ought to do as shown below:
I need first P1 and P*1
Here is the code:
% Plotting the patches
figure;
k=1;
for i = 1 : 40 : rowsI-40
for j = 1 : 40 : columnsI-40
im_subL=I(i:i+39,j:j+39);
im_subR=imr(i:i+39,j:j+39);
subplot(round(rowsI/40),round(columnsI/40),k),imshow(im_subL);
title(['P',num2str(k)])
subplot(round(rowsR/40),round(columnsR/40),k+1),imshow(im_subR);
title(['P*',num2str(k+1)])
k=k+1;
end
end
I need to correct it could anybody please suggest me what to do?

채택된 답변

Rik
Rik 2019년 6월 29일
편집: Rik 2019년 6월 29일
You are overwriting your plots. If you step through your code you will see that you first make an k+1 subplot, then increment k by one and on the next iteration you overwrite the k+1 plot.
If you change k=k+1 to k=k+2 the result should be closer to what you expect.
Edit:
Something like the code below should make it a lot clearer and should be easier to edit to what you want.
% Plotting the patches
figure;
sub=struct;
sub.rows=round(rowsI/40);sub.cols=round(columnsI/40);
sub.k=1;k=1;
for i = 1 : 40 : rowsI-40
for j = 1 : 40 : columnsI-40
im_subL=I(i:i+39,j:j+39);
im_subR=imr(i:i+39,j:j+39);
subplot(sub.rows,sub.cols,sub.k);sub.k=sub.k+1
imshow(im_subL);title(['P',num2str(k)])
subplot(sub.rows,sub.cols,sub.k);sub.k=sub.k+1
imshow(im_subR);title(['P*',num2str(k)])
k=k+1;
end
end
  댓글 수: 4
Rik
Rik 2019년 6월 29일
Then you need to make sure you edit the code that determines the number of rows and column of subplots so that you allocate enough space for all your images.
Pravita Lekshmanan
Pravita Lekshmanan 2019년 6월 29일
Could you please tell me how can i accomodate all images
by not increasing the size of patches from 40x40 to some higher patch dimension

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

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 29일
P*1 is coming as P*21 which is not what i ought to do?
As the title is displayed based on k value, as it reflects the number of iteration, as you have defined k=1
and within the loop
k=k+1;
When the code has to be displayed P*1 again, you may look for another variable, say l, as similar as k, for lower parts plots. (* displayed, I am supposing it exucated the lower title)

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by