MATLAB: How to load N images in 4 axes GUI Matlab

load_imagesmatlab gui

So my question is how am I going to load N images in 4 axes..I made push button and four axes so I can load one image and put it in first axes,so when I am loading second image I need to be uploaded in first axes and the image from the first axes to be moved to second axes. While loading third image,image from second axes need to be moved to third and first image to second axes and so on. Last image is always replaced by the penultimate.
I used this code but it works only for one image
[filename, foldername] = uigetfile({'*.*'}, 'Select file');
if filename ~= 0
FileName = fullfile(foldername, filename);
end
axes (handles.axes1);
F = imread (FileName);
imshow(F, 'Parent', handles.axes1);
s=F;
axes(handles.axes2);
imshow(s)
Please can anyone help me with this?

Best Answer

delila - I think that you can just switch/swap the data from each axes before you load the newest image into axes1. For example, suppose that in your GUI's OpeningFcn you default all of the axes data to a blank image like
defaultImg = uint8(zeros(400,400));
imshow(defaultImg,'Parent',handles.axes1);
imshow(defaultImg,'Parent',handles.axes2);
imshow(defaultImg,'Parent',handles.axes3);
imshow(defaultImg,'Parent',handles.axes4);
Now each of these axes has something that we can swap amongst each other. Now in your code that gets the next image, do something like
[filename, foldername] = uigetfile({'*.*'}, 'Select file');
if filename ~= 0
FileName = fullfile(foldername, filename);
img = imread(FileName);
% swap images
cdata = get(get(handles.axes3,'Children'),'CData');
set(get(handles.axes4,'Children'),'CData',cdata);
axis(handles.axes4,'tight');
cdata = get(get(handles.axes2,'Children'),'CData');
set(get(handles.axes3,'Children'),'CData',cdata);
axis(handles.axes3,'tight');
cdata = get(get(handles.axes1,'Children'),'CData');
set(get(handles.axes2,'Children'),'CData',cdata);
axis(handles.axes2,'tight');
% add the new image to axes1
set(get(handles.axes1,'Children'),'CData',img);
axis(handles.axes1,'tight');
end
In the above, we assume that each axes has exactly one child, and that that child corresponds to an image. We then take that image data (from the property CData) and copy it into the CData of the child graphics object in the subsequent axes (so that in 2 moves to 3, that in 3 moves to 4, etc.). We use the
axis(handles.axes4,'tight');
so that the our image fits into the axes (and so the latter doesn't try to re-adjust for images with different dimensions).