1

Thank you in advance for any help you can give. I am relatively new to Matlab and am stuck with the use of the batch command for passing arguments to the function. I have tried to simplify the example as much as possible.

Following the documentation, I can get it to work with a built-in function:

>> 
>> j = batch(@zeros,1,{10,1});
>> a=fetchOutputs(j)

a =

  1×1 cell array

    {10×1 double}

>> a{1}

ans =

     0
     0
     0
     0
     0
     0
     0
     0
     0
     0

I then created a simple stand-along function runTest.m:

function result = runTest(n1,n2) 
result = zeros(n1,n2);
end

It works with a direct call:

>> a=runTest(5,1)

a =

     0
     0
     0
     0
     0

But, it doesn't work using batch:

>> j = batch(runTest,1,{5,1});
Not enough input arguments.

Error in runTest (line 2)
result = zeros(n1,n2);
 

Any suggestions? Thank you.

1 Answer 1

2

When you do

j = batch(runTest,1,{5,1});

then the part of that statement that reads runTest tries to call the function runTest with no input arguments. This is where the error happens. It never gets to call batch.

Like in just about every other programming language, the arguments to a function call are evaluated before the function is called, evaluating runTest is the same as evaluating runTest(), MATLAB makes no distinction between the two.

What you intended to write was

j = batch(@runTest,1,{5,1});
Sign up to request clarification or add additional context in comments.

Comments

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.