Filter löschen
Filter löschen

Executing a function based on user input

7 Ansichten (letzte 30 Tage)
Aaron Staszewski
Aaron Staszewski am 4 Aug. 2020
Hello,
I have written several long funcitons that I am placing in a new .m file. I want a user to be able to pick from these funcitons, but not have to call them by name exaclty. For example, if the funciton name is something nasty like: da20_weightAndBallance, I would like the user to just be able to type: weight and ballance, into the command window to run the funciton.
I have tried to do this by reassigning the string as a vairable in the following basic example:
x = input('What program would you like: ','s');
if x == 'da20'
function bigNastyFunctionName
fprintf('yes');
end
end
But MATLAB doesn't like this. What am I doing wrong / how do I fix this?
I know that I can just get rid of the 'funciton' and 'end' lines inside of the if statement, but I want to keep it because it is collapsable and will make writing the program much easier to visualize.
Thanks for the help

Akzeptierte Antwort

Aaron Staszewski
Aaron Staszewski am 4 Aug. 2020
So I figured it out if anyone else was as confused as I was
x = input('What program would you like: ','s');
if x == 'da20'
bigNastyFunctionName
end
function bigNastyFunctionName
fprintf('yes');
end
Its so simple.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by