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

 采纳的回答

lengthboundaries = cellfun(@length,boundaries);

2 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by