subplot two different images in two different for loop
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
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.
추가 답변 (1개)
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)
댓글 수: 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!