Is it possible to design a Matlab gui, with buttons that appear based on user input?

2 vues (au cours des 30 derniers jours)
crengr24
crengr24 le 8 Oct 2015
I am trying to design a GUI for a function that multiplies N-matrices, with each matrix containing elements that are defined by several variables unique to that matrix. I would like to prompt the user to input how many matrix elements he/she wishes to multiply, and then populate the GUI with N "Edit Text" fields so the user can input the necessary parameters to define each matrix. The difficulty is, N will be different each time, so N "Edit Text" fields must be created after N is set. Does anybody know how to do this?

Réponses (1)

Walter Roberson
Walter Roberson le 9 Oct 2015
The most difficult part of this is getting nice Position for them. Otherwise you just loop creating uicontrol().
Have you considered using inputdlg() ?
  2 commentaires
crengr24
crengr24 le 9 Oct 2015
Thanks for the advice!!
Using uicontrol() inside a for loop seems to work. I considered using inputdlg(), however I want a GUI interface that allows the user to change multiple parameters, and then view corresponding function changes on a plot; having editable text fields seemed like an easier method.
Using uicontrol() inside a for loop raises a few more questions though:
1) Each time x = uicontrol() is called inside the for loop, what exactly is stored in 'x'?
2) If I am creating multiple push buttons / text fields using the x = uicontrol() command inside a for loop, should the syntax be x = uicontrol() or x(i) = uicontrol()?
3) Once the for loop has created the ui components I want, how do assign actions to the push-buttons, and retrieve inputs to the text field?
Walter Roberson
Walter Roberson le 9 Oct 2015
The output of uicontrol() is the handle to the uicontrol graphic object. If you are using R2014a or earlier, the handle is represented as a double precision number that would internally be looked up in a table to find the data. If you are using R2014b or later, you get a handle to an Object in the Object Oriented Programming sense.
Whether you store into x or x(i) depends on whether you need to reference the individual values after the loop. Often you do, but not always.
You can assign actions at the time you create the uicontrol, by passing a 'Callback' property into the uicontrol() call. Or you can set() the properties later. Or use dot syntax if you are using R2014b or later.
To retrieve the contents of the text field, you need to get a handle to the object somehow (such as by looking in your x vector), and then you get() the String property, or you can use dot notation if you are using R2014b or later
x(5).String
I suggest that you use the command
dbtype inputdlg
and look to see how it works.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by