Executing a function based on user input

7 次查看(过去 30 天)
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

采纳的回答

Aaron Staszewski
Aaron Staszewski 2020-8-4
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by