Mapping a function over each cell in a cell array using arrayfun

C=cell(2,2);
C(1,1)={[1,1,1]};
C(1,2)={[2,2,3]};
C(2,1)={[3,3]};
C(2,2)={[4,4]};

myresult = arrayfun(@(c) norm(c{1}), C);

Or more compactly,

myresult = cellfun(@norm,C);

 

 


https://www.mathworks.com/matlabcentral/answers/7174-mapping-a-function-over-each-cell-in-a-cell-array-using-arrayfun#answer_9831

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s