0

Here's a line of code that's giving me trouble.

arrayfun(@(x)container.nodelist(x).config(@a_func_handle,0),2:6);

Container is a class with one of its properties being an object array of nodes, and that array is called nodelist.

Each node has a function called config that is used to initialize it. Config expects one input, one of which is a handle to a function. The function handle I'm passing needs a constant passed along with it, which is represented by the 0.

In this case, I want to configure the nodes at positions 2 through 6 in nodelist with a specific function, so I thought to use arrayfun instead of a for loop.

Unfortunately, Matlab barfs with "too many inputs" for function config. What am I writing wrong? Is this example clear?

2
  • Just going by arrayfun's doc, it looks like the second argument to arrayfun is supposed to be the structure/vector on which you want to apply the function @config, not the indices. Granted, this doesn't explain the "too many inputs" error that you get. But maybe try passing nodelist(2:6) as the second argument instead of just 2:6? Commented May 11, 2012 at 4:49
  • Thanks for the advice, I didn't notice that part. Commented May 11, 2012 at 13:09

2 Answers 2

2

I figured it out. What I ended up doing was using nested anonymous functions, like so:

arrayfun(@(y)y.config(@(x)(configSlave(x,0))),exp.pico_list(2:6));
Sign up to request clarification or add additional context in comments.

Comments

0

If I've understood correctly, config is a method of the objects contained within your nodelist array. In which case, in the usual MATLAB manner, the object on which you're invoking the method gets passed as the first argument. For example, you might need to write the config method like this:

function config(obj, fcnHandle, value)
    obj.FunctionHandle = fcnHandle;
    obj.Value = value;
end

1 Comment

Ah, I've cleared up my example. What I meant to write was that the function handle itself needs to have a variable passed to it, aka mathworks.com/help/techdoc/matlab_prog/brfpxhw-1.html

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.