MATLAB Answers


How to use one pushbutton to open different images

Asked by janepear on 10 Mar 2013
Hi, I have a list box and one pushbutton and I want to use this push button to plot images ( it depends on what i choose from listbox). I have absolutely no idea...
Thanks Jane


Sign in to comment.

2 Answers

Answer by Image Analyst
on 10 Mar 2013
 Accepted Answer

Why not have the callback of the listbox display the image? Why have a two step process where the user has to click a button to see your image right after they clicked in the listbox to indicate the image? In the listbox callback you can have something like this:
% Get the number of the item that was selected in the listbox.
Selected = get(handles.lstImageList, 'value');
% If more than one is selected, bail out.
if length(Selected) > 1
return; % Two or more selected.
% If only one is selected, we'll display it.
% Get list of all filenames in the listbox.
ListOfImageNames = get(handles.lstImageList, 'string');
% Get the name of the one that is selected.
baseImageFileName = cell2mat(ListOfImageNames(Selected));
% Prepend folder.
fullImageFileName = fullfile(yourFolder, baseImageFileName];
% Read the image into an array.
originalImage = imread(fullFileName);
% Display the image.


Ihave this now: axes(handles.axes2) ; h=imshow('800px-Apical2.jpg'); set(h,'ButtonDownFcn',@openwindow1);
but openwindow1 is new mfile (fig)and i dont know how to set to figure just only h.
I don't understand this. So somehow, by clicking a push button I presume, you display the image in an axes (axes2), and then you want to set it up so that if the user then clicks on the displayed image, it will run a separate GUI called openwindow1, which does who-knows-what. Is that correct?
Next question: Can you explain better exactly what "to set to figure just only h" means? Does that mean that if the user clicks on the image that it brings up that image in a new, separate, full-screen window that shows only the image and nothing else? Or does it mean something else?
Yes it means that if user clicks on the image , it brings up that image in a new separate window

Sign in to comment.

Answer by Azzi Abdelmalek
on 10 Mar 2013

In your pushbutton callback add this code

  1 Comment

I doesn't work..I think it's because I dont call only image by listbox, I call .txt and 5or6 images so matlab don't know what to figure...

Sign in to comment.