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

 Risposta accettata

lengthboundaries = cellfun(@length,boundaries);

2 Commenti

Jan
Jan il 5 Ago 2017
Modificato: Jan il 5 Ago 2017
+1. Or even faster:
lengthboundaries = cellfun('length', boundaries);
Wow. thanks!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by