subplot two different images in two different for loop
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Pravita Lekshmanan
am 29 Jun. 2019
Kommentiert: Pravita Lekshmanan
am 29 Jun. 2019
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226833/image.jpeg)
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 Kommentare
Akzeptierte Antwort
Rik
am 29 Jun. 2019
Bearbeitet: Rik
am 29 Jun. 2019
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 Kommentare
Rik
am 29 Jun. 2019
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.
Weitere Antworten (1)
KALYAN ACHARJYA
am 29 Jun. 2019
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 Kommentare
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!