Subplotting many images in one figure

Hi there,
I am pretty ignorant about matlab but starting to learn.
Here I am trying to subplot a group of images located in a folder. The names of the pictures are like "Point01Pic1_140127","Point01Pic1_140128".... "Point02Pic1_140127", "Point02Pic2_140128"...
being the date the final part of the name. the idea is to plot all of them in the same figure with the purpose of comparison.
I am trying something like this:
clear all
clc
a = uigetdir;
A = dir( fullfile(a, '*.jpg') );
fileNames = { A.name };
for iFile = 1 : numel( A )
newName = fullfile(a, sprintf( '%03d.jpg', iFile ) );
movefile( fullfile(a, fileNames{ iFile }), newName );
end
subplottight(2,4,1), imshow('008.jpg', 'border', 'tight');
subplottight(2,4,2), imshow('006.jpg', 'border', 'tight');
subplottight(2,4,3), imshow('004.jpg', 'border', 'tight');
subplottight(2,4,4), imshow('002.jpg', 'border', 'tight');
subplottight(2,4,5), imshow('007.jpg', 'border', 'tight');
subplottight(2,4,6), imshow('005.jpg', 'border', 'tight')
subplottight(2,4,7), imshow('003.jpg', 'border', 'tight');
subplottight(2,4,8), imshow('001.jpg', 'border', 'tight');
Doing this way I am renaming the files like "001", "002" (I dont know how to handle the orig. names) etc getting a 2x4 subplot with the right arragement but I would like to use the original names (ie "Point02Pic2_140128" for example)and have all the pictures of "Point 1" in one row in cronological order, all the pictures of "Point2" in the next row etc.
I hope I explained myseld clear enough.
Thanks for the patience and any help will be appreciated.

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 12 Feb. 2014
Bearbeitet: Mischa Kim am 12 Feb. 2014

1 Stimme

Edu, this should do:
for ii = 1:8
file_name = strcat('Point0',num2str(ceil(ii/4)),'Pic',num2str(ii-4*(ii>4)),'_140128.jpg')
subplottight(2,4,ii), imshow(file_name, 'border', 'tight');
end
assuming your image files end with _140128 (not quite sure I understand the file name sequence). If they do not, I am sure with the above code snippet you can figure out how to adjust the code.

5 Kommentare

Edu PL
Edu PL am 12 Feb. 2014
Bearbeitet: Edu PL am 12 Feb. 2014
First of all, big thanks. I was not expecting an answer that fast...or even an answer :-) Very appreciated Mischa.
That is more or less what I meant but I would like to have in the rows all the pics corresponding to one point in dif dates, this is:
Point01Pic1_140127 Point01Pic1_140128 Point01Pic1_140129 etc...
Point01Pic2_140127 Point01Pic2_140128 Point01Pic2_140129 etc
Point02Pic1_140127 Point02Pic1_140128 Point02Pic1_140129 etc
Point02Pic2_140127 Point02Pic2_140128 Point02Pic2_140129 etc
your code is giving me all the pics of a point in the same row but I would like to have same pic of same point for differents dates. Probably it is just easy to implement but I am pretty bad with this damned thing.
Any ideas? thanks again and sorry to bother you.
Edu PL
Edu PL am 12 Feb. 2014
Bearbeitet: Edu PL am 12 Feb. 2014
it is as I stated. To clarify, this is a set of photos taken from different points.But there are more than one photo taken from some of the points, so they are named
Point01Pic1_140127 Point01Pic1_140128 Point01Pic1_140129 etc
and this I want to be in rows in the final subplot for being able to compare same photo same place but dif date. Second row will be
Point01Pic2_140127 Point01Pic2_140128 Point01Pic2_140129
if there is another photo shot from point1 or
Point02Pic1_140127 Point02Pic1_140128 Point02Pic1_140129
if there is not.
Buff It looks like difficult to explain but it is not really. thanks
Mischa Kim
Mischa Kim am 12 Feb. 2014
Bearbeitet: Mischa Kim am 12 Feb. 2014
Got it.
figure
for ii = 1:2
for jj = 1:2
for kk = 1:4
file_name = strcat('Point0',num2str(ii),'Pic',num2str(jj),'_1401',num2str(kk+26),'.jpg')
subplottight(4,4,8*(ii-1)+4*(jj-1)+kk), imshow(file_name, 'border', 'tight');
end
end
end
which works for a total of 16 images dated 140127 through 140130. If you have more images simply adapt the code accordingly.
Does that answer your question? If it does, please formally accept the answer.
Edu PL
Edu PL am 12 Feb. 2014
Amazing! yes it does, smoothly!! thanks Mischa, you are a crack! :-)
Edu PL
Edu PL am 26 Feb. 2014
hummm could you look down please? it looks like I responded to myself...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Edu PL
Edu PL am 26 Feb. 2014

0 Stimmen

Hello Mischa,
Edu again here trying to solve something in matlab. Now I want to put a title or text in every picture of the set. I am arranging them putting together the same images but at a different time to check the changes. For example 8 images in two rows but each of them of the same place but at a different date. Next 2 rows are showing 8 more images of another site during the same different 8 dates.
How can I put the date in every image? in the example below it should be 4 differents dates in the two rows.
I hope I made this clear.
Thanks!

1 Kommentar

Khan Bahadar Khan
Khan Bahadar Khan am 11 Mai 2019
Untitled.png
How can we add images in MATLAB like the displayed one.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by