Info

此问题已关闭。 请重新打开它进行编辑或回答。

function which calls M-File and set their variables

1 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2019-12-18
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.

回答(1 个)

Adam Danz
Adam Danz 2019-12-18
编辑:Adam Danz 2019-12-19
"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.

Community Treasure Hunt

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

Start Hunting!

Translated by