Azzera filtri
Azzera filtri

Executing a function based on user input

7 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Aaron Staszewski
Aaron Staszewski il 4 Ago 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.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by