How do I let a user choose what variable they want to assign a value to?

15 次查看(过去 30 天)
I am making a program where I would like it to display a list of variable names (already created inside the program) and then let the user decide which one variable they want to assign a value to (either by typing the name of the variable or by typing in some pre-set command) and then input the value to be assigned to that variable.
(To give some background this is for a unit converter program where the user would, for instance, type "feet" and then e.g. "3" and it would return what 3 feet is in metres, inches, miles, yards etc; or they could type "metres" and then e.g. "5" and it would return this value in feed, inches etc).

采纳的回答

Image Analyst
Image Analyst 2018-12-27
编辑:Image Analyst 2018-12-27
I would put those variable names into a drop down list (what Mathworks calls a popup).
Then the user can select one, and in the popup callback, you can execute the proper code for that selection using a switch or if/else block.
Or perhaps less user friendly, you could use the menu() function and execute the appropriate code for whatever button number they clicked on.

更多回答(1 个)

madhan ravi
madhan ravi 2018-12-27
编辑:madhan ravi 2018-12-27
There's already one requires symbolic math toolbox :
Use input() or just use inputdlg() to input a value.

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by