I have coded several scripts and I now want to program a MATLAB script that sets the execution order of the scripts. For example, my first script only includes the input variables that the second script requires for calculating certain outputs which are then transferred to a third function and these results are then plotted with the help of the fourth script. Now, my question is: How can I code a script to set the execution order so that I do not have to call each script beforehand?
You should create a fourth script. This script will call all of the scripts in the order you put them there. Matlab interprets a script in the order they are programmed...
script2;
script1;
script3;
Related
My code runs ok if all parfor code is in the same script file, but since the code is huge and I want to select parallel or serial mode execution, I separated it in a different script file, as fallow:
if (useParFor)
myParforCode.m
else
serialCode.m
end
The problem is that Matlab gives me this error:
"Using exist to check for a variable in the transparent workspace is
not supported."
But if I copy all the code in myParforCode.m and put it after the if statement instead of calling the script, the code runs. I thought I could divide my code in scripts without problems, but it seams it not like that.
What are the limitations here, what I'm doing wrong?
My code is huge but I'll try to create a running code sample and add it here.
How would I run a Lua script with user specified parameters from inside another Lua script?
Would the below code work? Where "content_image" is my specified input image (either saved to an image file, or still in the script) into the "deepdream.lua" script, and "output_image" is the output from the "deepdream.lua" script that I want to use in my Lua script.
dofile("deepdream.lua -content_image content_image -output_image output_image")
The script I am seeking to run within another Lua script can be found here: https://github.com/bamos/dream-art/blob/master/deepdream.lua
If you want to load and execute a script by passing it a number of parameters, you have to do this by... loading the script and executing it by passing it a number of parameters:
local chunk = loadfile("deepdream.lua")
chunk("-content_image", "content_image", "-output_image", "output_image")
Note that this will not fill in args for the arguments the way lua.exe does. It will pass the parameters as variadic parameters, just like any other Lua function. So it can mess with your globals and so forth. Also, unlike executing lua.exe, this will be executed in the current process, so if it errors out, the error will have to be handled by you.
If you want, it wouldn't be difficult at all to write a function that takes the string you provided, uses Lua patterns to parse parameters and so forth, and then loads the script with those parameters.
If you want to execute a script exactly as if you had used lua.exe on it, then you would just use os.execute:
os.execute("lua.exe deepdream.lua -content_image content_image -output_image output_image")
you can use loadfile with parameters in arg:
loadfile("deepdream.lua")({content_image="content_image",output_image="output_image"})
in deepdream.lua:
local arg={...}
local content_image = arg[1].content_image
local output_image = arg[1].output_image
I have some init commands in a m-file on disk. Depending on where the user is executing from, the contents of that init file will will change.
I'm wondering if there is a way to have Matlab automatically call this init script every time a script begins execution (either via the Run key or by requesting a call to a function in the interpreter).
I've looked at the startup.m script and that won't work as it is only executed when Matlab is first started but I want something that runs each time a script begins execution.
I've also thought about placing some boilerplate code at the top of the script file, but, that doesn't work in cell mode as the script may start execution part way through the script which would skip the boilerplate code.
Assume that you start running the script. What happens when you change that file when it is being executed? It seems that MATLAB takes a copy of the file and then starts executing it. I want to make sure that I am right. That said, I want to run a MATLAB script with different parameters on a clusters. Does it work correctly if I do the changes on that one file. Or do I need to create multiple copies of the file myself?
Changing the contents of a script / function while it is running will not affect the operation of the script as MATLAB is running a (generically speaking) "cached" and "preprocessed" version of the file. As for running a script with multiple parameters in a cluster, I assume you are using the Parallel Computing Toolbox?
One option might be to have the script load its parameters from a MAT file, allowing you to run the same script on all workers, but operate on different parameters.
Basically you will be fine if you only have one Matlab m-file for all of your computation.
But if if the file you edit get called multiple times during your computation then you will run the risk of calling multiple versions of the file by editing while running. See more in here: http://www.mathworks.com.au/matlabcentral/newsreader/view_thread/261376
I have 'inherited' Matlab code (A) that uses another compiled Matlab code (B). I do not have the source of B. B requires user intervention ('Hit return to continue'), and I need to use A in a loop. I need to do something so I would not need to hit Return each and every time until the loop is done.
The command I use in the loop is:
str='!start "Code_B" /low "c:\Code_B\bin\Code.exe" r';
eval(str)
Are there any other switches that I can use to suppress the call to 'Hit return' ?
Thanks
Katto
One way you could do this is to create a batch file that:
Starts the compiled Matlab program
Waits for the program to run (fixed delay?)
Uses a utility to send the program an Enter key
There are many (free) utilities that let you send keystrokes to a program.
Instead of calling Program B, you would call this batch file.
You can create a text file, let's say autoreturn.txt, with many empty lines (just end of line characters), over the number of loops you expect. Then add redirection of input from this at the end of your string:
str='!start "Code_B" /low "c:\Code_B\bin\Code.exe" r < autoreturn.txt';