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

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 5 de Ag. de 2017
lengthboundaries = cellfun(@length,boundaries);

2 comentarios

Jan
Jan el 5 de Ag. de 2017
Editada: Jan el 5 de Ag. de 2017
+1. Or even faster:
lengthboundaries = cellfun('length', boundaries);
Ilida Suleymanova
Ilida Suleymanova el 5 de Ag. de 2017
Wow. thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by