How to create a GUI with changing buttons?

Good morning,
I am looking for a possibility to create a GUI (with GUIDE, if possible) with changing buttons. This means, that the GUI offers two seperate bundles of functions and I would like the user to choose at the beginning which bundle to use and the other bundle to disappear, to fold up, or something similar.
Does anybody know how to do this?
Thank you!
(P.s.: I am still working with Matlab R2007b and I don't have to possibility to upgrade)

6 Comments

Adam
Adam on 4 Sep 2019
Edited: Adam on 4 Sep 2019
What kind of choice are you offering the user? As in what will they need to see to make their choice? It may be simplest to produce two distinct GUIs (especially if you want to use GUIDE) and have a 3rd simple GUI that is launched as a front end. That 3rd GUI will simply contain the two options for the user to choose from (if these options are simple to display - e.g. just a button for each with a string or icon explaining what it is). Then when they click the relevant one that first GUI opens whichever of the other two is necessary and closes itself.
If I were to do it all in one GUI especially then I would make use of the GUI Layout toolbox:
This does contain collapsible panels as well as tabs (also available in other forms of programmatic GUI, but not GUIDE. The collapsible panels take a bit of practice to program as you have to code the function that says what happens when the collapse/expand button is pressed, but they work fine if you get it right.
Collapsible panels, this is exactly what I was looking for! Thank you very much for the hint!!
I've also thought about creating two more GUI's, but the collapsible panels seem way more elegant even if they require programmation.
Thanks a lot!
It depends if there is any synergy between what is in the two different panels really. If not then whichever GUI panel is active you just have twice as much underlying code in your file as you need for it, although it depends how you code it. If each panel is its own class or function then that needn't be the case.
A less elegant but simpler solution is to make a panel with group of buttons visible/unvisible.
@Adam
Is it possible to combine programmatic GUI parts and a GUI made with GUIDE? Or do I need to rebuild an entire GUI if I want to incorporate collapsible panels?
The toolbox is unfortunately only compatible with Matlab R2010 or later.
Thank you
You can add programmatic components to panels that you lay out as placeholders in GUIDE. You can't put GUIDE components inside programmatic ones though, only the other way round. So you can have a mostly GUIDE-based GUI in which you put an empty panel (for which you can turn off border, etc if you wish, to make it invisible).
Then in your code you can use this panel as a parent for whatever you want to do programmatically, including tabbed panels, layouts, java components, or anything you wish.

Sign in to comment.

Answers (1)

Another possibility is to use the same set of buttons for both options, but assign associated properties (String label) within the OpeningFcn. You can do this with a separate mat-file that holds a table (or cell array) of settings for each button and bundle option. (Table columns: [Option1], [Option2], ... . Table rows: button1Label, button1FcnHandle, button2Label, ...).
OpeningFcn: Load the file. Ask the user for their bundle choice. Create a "subtable" of the settings based on the bundle choice. Save the subtable to the UserData property of one of the objects (or guidata or appdata). Assign the button labels from the subtable.
When the user clicks a button, read the subtable from UserData. Look up its function handle (@MyFcnHandleName) for that button in the subtable and run it.
fhAnalysis = str2func(tblWorking(button2FcnHandle));
[output] = fhAnalysis(inputs);

Categories

Products

Release

R2007b

Asked:

on 4 Sep 2019

Answered:

CAM
on 17 Oct 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!