2
votes

So I have a lot of cell manipulation in code I'm writing right now where it helps greatly to have cell functions of two arguments (e.g., to concatenate arrays in cells of the same size). However, MatLab is reacting confusingly to even simple uses of multiple-input cellfun calls, so I'd like to find out what I'm doing wrong (as I'm just following the MatLab function reference). For instance,

B = {[1 2;3 4] , [5 6;7 8]}
cellfun(mtimes,B,B)

returns

??? Error using ==> mtimes
Not enough input arguments.

In fact, it returns the same message if I input

cellfun(mtimes,B)

or

cellfun(mtimes,B,B,B,B)

Help?

1

1 Answers

2
votes

As per the MATLAB CELLFUN documentation the first argument to CELLFUN has to be a function handle, not just the "raw" name of a function. So, something like this...

B = {[1 2;3 4] , [5 6;7 8]}
cellfun(@mtimes,B,B)

(notice the @ sign in front of mtimes on the second line).

By putting in a "raw" mtimes, MATLAB is trying to evaluate the function MTIMES on no arguments, and use the result of that as the first argument to CELLFUN. But, as the error messages indicate, MTIMES acting on no arguments is an error.

Instead, use @mtimes to mean the function handle that "points to" the MTIMES function.