Borrar filtros
Borrar filtros

Executing a function based on user input

7 visualizaciones (últimos 30 días)
Aaron Staszewski
Aaron Staszewski el 4 de Ag. de 2020
Respondida: Aaron Staszewski el 4 de Ag. de 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

Respuesta aceptada

Aaron Staszewski
Aaron Staszewski el 4 de Ag. de 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.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by