Guide: Load images in Listbox and Popupmenu

8 views (last 30 days)
Maria Schmidt
Maria Schmidt on 21 Feb 2020
Commented: Adam on 21 Feb 2020
Good afternoon,
I am new to Matlab and I have a question concerning GUIDE. I am supposed to be able to load pictures from Matlab Image Processing Toolbox via a Menu button so they show up in a listbox. If I click on one choice in the listbox, that one is supposed to show up in a popupmenu in my GUI. Also, if I click on one of the choices in my popupmenu, that specific image is supposed to show up in an axis.
I already have the Menu Button and an (empty) listbox (listdlg) shows up when I click on it. I am confused as to how I can load images into the listbox. Do I have to use a cell array and load all images via the command window?
How can I connect the listbox with the popupmenu? I know I can put in the string manually, but if I want the string to change depending on what is clicked in the listbox, what do I have to write?
And finally, how can I make sure that whichever choice I click in the popupmenu, the correct image will appear in the axis and the axis will not change size according to the image but the image will only be in the area of the axis?
I really don't know a lot about Matlab yet and have no idea how to put everything together. Thank you in advance for any kind of help, I would appreciate it a lot!
  1 Comment
Adam
Adam on 21 Feb 2020
Have a read of this for how to share data between various callbacks:
You have a callback for your listbox which will trigger when a selection is made. In this callback you can access your popup menu via the handles structure and populate it, or repopulate it as you wish.
Likewise you have a callback for the popup menu and from there you can access, again via handles, the handle of your axes, which you can plot your image on.
I would strongly advise plotting an image only once, keeping the handle to the plotted image (the output argument of e.g. imshow or imagesc) and thereafter simply updating XData, YData, CData as appropriate. It is faster than keep creating a new image.
You can use
doc dir
if you expect to load all images from a certain directory, but you didn't give details on where all the images will come from to populate your listbox or popup menu so I'm not quite clear what is supposed to be different between the listbox and the popupmenu. Once you have made a selection in the listbox what are you expecting to be the options in the popup menu? If you just want all images from a given directory then the listbox seems un-necessary and a
doc uigetdir
should do fine to the populate the popup menu using dir.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!