How do I let a user choose what variable they want to assign a value to?
조회 수: 13 (최근 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).
댓글 수: 1
Stephen23
2018년 12월 27일
Letting the user dynamically select a variable name would not be a good approach:
There are plenty of much better approaches to writing a unit converter, just search File Exchange:
채택된 답변
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.
댓글 수: 0
추가 답변 (1개)
madhan ravi
2018년 12월 27일
편집: madhan ravi
2018년 12월 27일
There's already one requires symbolic math toolbox :
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!