How to use one pushbutton to open different images

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

 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.
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

  1. step is :open a topic using list box
  2. step is: open a new image in selected section
Sure, new topic is opened without a button and this part of code i have.
thanks
The second link doesn't work, and the first link is no reason why you should have a two step non-intuitive more difficult GUI when a simple intuitive and easy to use one will give your users a much better experience. For example, look at the intuitive step by step process laid out by this framework: http://www.mathworks.com/matlabcentral/fileexchange/24224. You click on an image, and it displays it. Click on a button and it analyzes the selected image(s). What could be simpler and more intuitive than that?
I need two steps becouse i don´t want to open it every time..only if i choose it...
Alright, whatever. The code will still work if you put it in the callback of a pushbutton. It will display the highlighted image, as long as only one image is highlighted.
And Isn't possible to use buttondownfcn to open a new window..so i wouldn't use pushbutton?
button down on which control? Of course you don't use a buttondown on a button, you use the regular normal callback like I suggested, so which control are you thinking of?
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.

More Answers (1)

In your pushbutton callback add this code
s=get(handles.listbox1,'string')
idx=get(handles.listbox1,'value')
im=imread(s{idx})
imshow(im)

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.

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!