How to implement "run" command with inputs

Hello
I've been trying to run a different script with a function header but I realized that I need to pass parameters as well. I would like the script name to be a variable so I cannot just type out the script name and put parenthesis to run that script. How would I go about doing this?
I have tried:
run(scriptVariable(parameter1, parameter2));
matlab -r scriptVariable(parameter1, parameter2);
But both don't work. I have also tried using eval but I couldn't insert object parameters.
Thank you

 채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 17일

0 개 추천

It is never possible to pass parameters with run() .
It is never possible to pass parameters to a script.
If you have the unqualified name of a function as a string, you can get a handle to the function using str2func .
If you have a path to a function (that is, including directory information) then you would have to use techniques similar to what run() does to cd into the containing directory; you could then take a handle to the function using str2func() .

댓글 수: 3

yySBU
yySBU 2018년 7월 18일
Hello
Thank you for answering my question
Instead of running a script, would I be able to make an object, call its constructor and pass parameters into it? Of course, the variable containing the string to the class name would be used to call the constructor.
yySBU
yySBU 2018년 7월 18일
I found a method that works.
https://stackoverflow.com/questions/7102828/instantiate-class-from-name-in-matlab
+mypackage/foo.m method worked for me.
Thank you for the help
Using a class is a potential solution. But I did not see any particular reason in your question why you could not just use a regular function.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 7월 17일

댓글:

2018년 7월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by