Reputation: 190
i build a gui displaying multiple images with subplot , but with lot of images you have to make more axes with subplot and therefor the images became more smaller , so i want to link the slider to my axes generated by subplot , so i can keep the size of the images and scroll down between them there is my code for now :
function pushbutton1_Callback(hObject, eventdata, handles)
[filename pathname] = uigetfile({'*.*'},'File Selector','MultiSelect', 'on')
iscellstr(filename) celldata1 = cellstr(pathname) celldata2 =
cellstr(filename) celldata3 = strcat(celldata1,celldata2)
subplot(3,3,1),imshow(celldata3{1})
subplot(3,3,2),imshow(celldata3{2})
subplot(3,3,3),imshow(celldata3{3})
subplot(3,3,4),imshow(celldata3{4})
subplot(3,3,5),imshow(celldata3{5})
and the gui looks like this : http://img.prntscr.com/img?url=http://i.imgur.com/Vt56E6Y.jpg
PS : i want to use subplot with slider so i can see all the images while i'm scrolling down not being replaced everytime with static axes.
Upvotes: 2
Views: 420
Reputation: 536
you should really format your code correctly instead of using blockquotes, it makes it very hard to read and understand the code quickly.
To make a gui using a slider to change multiple images at once you need to have set up the gui which you seem to have done based on your uploaded image.
The first thing to do is change some of the slider properties. the easiest way to do this is to double click the slider in your guide figure and change the following values:
the basic idea behind the following code is when you move the slider a number is produced based on position and then that number is used to search through the images and display the correct ones.
the push button calls the uigetfile function to allow multiple files to be selected in the same way you did it in your question. it produces two variable filename and pathname. file name is a cell with the names of all the files you selected. you will use the number based on the slider position to decide which images to display.
the following code is for the push button.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
%global variables allow sharing of variables between functions
global filename pathname k1 SliderMax SliderMin
%multi-file selection
[filename, pathname, ~] = uigetfile({ '*.jpg'}, 'Pick files',...
'MultiSelect', 'on');
%determine the maximum value the slider can be. this value is based on the
%number of files selected
%the min value will be set to 1
SliderMax = length(filename)
SliderMin = 1;
set(handles.slider1,'Max',SliderMax);
set(handles.slider1,'Min',SliderMin);
%initialise k1 (slider position) since 4 images will be shown k1 needs to
%be incremented so you show
%4 different images
k1 = 1;
k2 = k1 + 1;
k3 = k1 + 2;
k4 = k1 + 3;
%generating of strings containing the full path to the that will be
%displayed.
img1 = strcat(pathname, filename{k1});
img2 = strcat(pathname, filename{k2});
img3 = strcat(pathname, filename{k3});
img4 = strcat(pathname, filename{k4});
%assign an axes handle to precede imshow and use imshow to display the
%images
% in individual axes.
axes(handles.axes1);
imshow(img1);
axes(handles.axes6);
imshow(img2);
axes(handles.axes7);
imshow(img3);
axes(handles.axes8);
imshow(img4);
the following code is for the slider
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
global filename pathname SliderMax SliderMin
%put slider postion value into variable k1
k1 = get(handles.slider1,'Value');
%initialise k4 so that it can be used in the if statement for the check.
k4 = k1 + 3;
%the if statement below is a check to make sure the value of k4 is never
%larger than the total number of images, without some sort of check then
%k4 will exceed the matrix dimensions and give an error.
if k4 > SliderMax
k1 = SliderMax - 3;
k2 = SliderMax - 2;
k3 = SliderMax - 1;
k4 = SliderMax;
else
k1 = floor(k1);
k2 = k1 + 1;
k3 = k1 + 2;
k4 = k1 + 3;
end
%generating of strings containing the full path to the that will be
%displayed.
img1 = strcat(pathname, filename{k1});
img2 = strcat(pathname, filename{k2});
img3 = strcat(pathname, filename{k3});
img4 = strcat(pathname, filename{k4});
%assign an axes handle to precede imshow and use imshow to display the
%images in individual axes.
axes(handles.axes1);
imshow(img1);
axes(handles.axes6);
imshow(img2);
axes(handles.axes7);
imshow(img3);
axes(handles.axes8);
imshow(img4);
Upvotes: 3