0

I would like to run a script called 'myscript' using the batch command:

j = batch('myscript')

My script has a function in the beginning so:

function myscript(input)
...
end

Is it somehow possible to run batch files with different input parameters for my function? I know that there are matlabpool, parfor etc commands, but it is unfortunately not working for me.

6
  • You just call the function directly, j = myscript(someinput) Commented Jun 14, 2013 at 10:42
  • But then I can't submit it as a job, so that I can run more scripts in parallel on different cores. Commented Jun 14, 2013 at 10:45
  • Then, check How do I call MATLAB from the DOS prompt? Commented Jun 14, 2013 at 10:50
  • I apologize for the confusion. I would like to run the batch command (mathworks.de/de/help/distcomp/batch.html) in Matlab, so that I can use parallel computing. Unfortunately, I can't find a way how to change variables in the function... Commented Jun 14, 2013 at 10:56
  • This might clear things up a bit: technically, Matlab "functions" and "scripts" are not the same thing, and can behave differently. A script is a file with a simple sequence of commands that are run in the context where it is called. A function is a file that defines a top-level function, with input and output arguments, that runs in its own workspace when called. Because it says "function" at the top, What you've got here is a function, and not a script. Reread the doco with that in mind. Commented Jun 15, 2013 at 4:59

1 Answer 1

1

The syntax you have to use is indicated in the documentation of batch():

j = batch(fcn,N,{x1, ..., xn})

and in your case

j = batch(fcn, 1, {input})

Alternatively, you can check How do I call MATLAB from the DOS prompt?

2
  • How would it look like for my function without any output? j= batch(myscript,{input})? If I try that I get the following error: Too many output arguments. Commented Jun 14, 2013 at 11:03
  • @C.Colden Do you still get that error if you leave out the j=? Basically you are telling the computer that you want an output to fill j. Commented Aug 5, 2016 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.