Optimise for loop in using cell array

Is it possible to do same without for loop?
lengthboundaries=zeros(length(boundaries),1);
for i=1:length(boundaries)
lengthboundaries(i)=length(boundaries{i});
end

 Accepted Answer

lengthboundaries = cellfun(@length,boundaries);

2 Comments

+1. Or even faster:
lengthboundaries = cellfun('length', boundaries);

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!