Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

function which calls M-File and set their variables

3 vues (au cours des 30 derniers jours)
Ajira
Ajira le 18 Déc 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi guys,
Is it possible to write a function which first take 1 input from user and based on that open one of two M-Files and after that ask user again now to enter the variables in that already called M-File??
thx,
  1 commentaire
Guillaume
Guillaume le 18 Déc 2019
It may be just a matter of semantic but opening an m file is typically done in order to edit the file. On the other hand, code typically run m file, which is a different operation.
It is trivial to decide which m code to run based on user input.
It's not very clear what you want to do with the second part of your question. If you're asking that the code then change actual values that are hardcoded in the m file, then you need to rethink your design and use functions with inputs.

Réponses (1)

Adam Danz
Adam Danz le 18 Déc 2019
Modifié(e) : Adam Danz le 19 Déc 2019
"Is it possible to write a function which first take 1 input from user and based on that open one of two M-Files ..."
Yes. There are lots of ways to get input from a user. If you're asking the user to open a file, you could used
function output = myFunction(input)
[file,path] = uigetfile(filter, title); % See link above
end
"... and after that ask user again now to enter the variables in that already called M-File?"
Here are ways to get that input from the user
lots more....
If you get stuck, share your updated code and describe what's wrong; I'd be glad to help out.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by