I have two matlab script files .m (not function files) and if I want to call another script in my current script, which command should I use? Thank you.
In script test1.m put this: function test1 disp('test 1')
aaa=111;
test2( aaa );
end
In test2.m put this, then run test1.m: function test2(aaa) fprintf('test 2 aaa=%d !!!\n', aaa ) end
As you said, if your script2 is in the same folder as your script1, you can call it with its name.
script2
If it is in another folder, you can use 'run'.
run("../path/to/your/script/script2")
I found the answer.
Just name the script in the other script:
myOtherScript
You can use run('myOtherScript') if you prefer, but it will end up internally doing the same thing as naming it directly; you might, though, like the emphasize that it gives that it is a script being mentioned.
If you want to pass parameters to it, enclose them in parentheses.
angle=.78; bias=.001;
myOtherScript(angle, bias)
If you want to return parameters from it, do it like this:
adjustedAngle = myOtherScript(angle, bias);
Or multiple return values:
[status adjustedAngle] = myOtherScript(angle, bias);
If you don't want the return values immediately reflected to the command window (maybe this call is in a big loop and you're going to plot all the values later), be sure to put a semicolon after the call statement.