Generating a vector containing the sizes of all cells of a cell array, along a specific dimension

1 view (last 30 days)
Is there a way to vectorize this? (I tried with "cellfun", but did not succeed).
for i = 1:numel(a)
s(i) = size(a{i}, 1);
end
Where a sample of "a" is provided in attachment.
  2 Comments

Sign in to comment.

More Answers (1)

Jan
Jan on 26 Jan 2017
Edited: Jan on 26 Jan 2017
cellfun has some builtin-functions, which are provided as strings and much faster than using anomyous functions:
s = cellfun('size', a, 1)
Unfortunately they appear in the docs as "Backward compatibility" only, but they are jewels.

Community Treasure Hunt

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

Start Hunting!