MATLAB Answers

Array size mismatch cellfun

4 views (last 30 days)
RoboKid
RoboKid on 11 Nov 2013
Commented: RoboKid on 11 Nov 2013
Help me.
D = {[1 2],[1 1] ;[1 6 ],[5 2]}
L=[1 0 0 0; 0 1 0 0 ];
out=cellfun(@(x) x*L,D,'un',0)
In result:
size(D)=(2,2) ,size(L)=(2,4) , size(out)=(2,2) Why the size(out) is not equal to (2,4),as by matrix multiplication

Accepted Answer

Matt J
Matt J on 11 Nov 2013
Edited: Matt J on 11 Nov 2013
The output of cellfun must always satisfy size(out)=size(D). Cellfun always operates on D element by element.
  1 Comment
RoboKid
RoboKid on 11 Nov 2013
Thank you Matt ..

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 11 Nov 2013
out is going to be a cell array. Each of its locations is going to have a 2 x 4 array. The 2 x 2 corresponds to the shape of the cell array D, 2 x 2, not to the size of the contents of D.
  2 Comments
RoboKid
RoboKid on 11 Nov 2013
Thank you Walter.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!