How to use one pushbutton to open different images
3 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Image Analyst
on 10 Mar 2013
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.
end
% 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.
imshow(imgOriginal);
9 Comments
Image Analyst
on 13 Mar 2013
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?
More Answers (1)
Azzi Abdelmalek
on 10 Mar 2013
In your pushbutton callback add this code
s=get(handles.listbox1,'string')
idx=get(handles.listbox1,'value')
im=imread(s{idx})
imshow(im)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!