Executing a function based on user input

30 views (last 30 days)
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

Accepted Answer

Aaron Staszewski
Aaron Staszewski on 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.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!