Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

function which calls M-File and set their variables

조회 수: 1 (최근 30일)
Ajira
Ajira 2019년 12월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
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