How do I get a user to choose an option by button?
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm getting very confused with AppDesigner. I just have a snippet-sized function I am writing, string = function(i), that converts a number selected, 1-7, into a corresponding string: eg. if i == 1, function output = "Apples" etc.
If a user runs the function by passing 1~7 into it, it will just return that string. However, if they pass in 0 I want the program to prompt the user for the input, and show them a list of the options (eg. fruit), and once they've chosen, change the value of i to 1~7. What do I have to do in AppDesigner to make buttons work like that?
1 Commento
Rik
il 12 Ago 2021
Why does it have to be 1 function? Just write a function that returns the list of options. Then you can use two other functions: one to select a fruit, the other to show the list to the user.
A function should do 1 Thing. If it does multiple Things you should probably split it.
Risposte (1)
Thomas Fournier
il 11 Ago 2021
Not sure of what you want to do but you can try to play with callbcak and "Visible" parameter of some component.
For exemple you create an edit field, the user will input a number between 0 and 7 in it.
you create a callback for this input (right clic, callback, add value changed fcn), this piece of code will be executed every time the input value change.
function EditField_2ValueChanged(app, event)
value = app.EditField_2.Value;
end
you can then create a new option list that is visible only if the input value is zero, for exemple if you created a Radio group button:
function EditField_2ValueChanged(app, event)
value = app.EditField_2.Value;
if value==0
app.ButtonGroup.Visible='on'
else
app.ButtonGroup.Visible='off'
end
end
1 Commento
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!