Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
You just call the function directly, j = myscript(someinput) –  Oleg Komarov Jun 14 '13 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. –  C.Colden Jun 14 '13 at 10:45
    
Then, check How do I call MATLAB from the DOS prompt? –  Oleg Komarov Jun 14 '13 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... –  C.Colden Jun 14 '13 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. –  Andrew Janke Jun 15 '13 at 4:59
show 2 more comments

1 Answer

up vote 1 down vote accepted

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?

share|improve this answer
    
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. –  C.Colden Jun 14 '13 at 11:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.