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

조회 수: 3 (최근 30일)
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
the cyclist
the cyclist 2017년 1월 25일
편집: the cyclist 2017년 1월 25일
It would be much easier to help if you posted code that actually creates a small example of a, rather than pseudocode that illustrates what you mean.
Is
AGA
AGA
meant to represent a 2x3 character array? So, is it correct that
a{1,1} = ['AGA';'AGA'];
would be an example of one element? It seems like that's what you mean, but wanted to be sure.

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2017년 1월 25일
편집: the cyclist 2017년 1월 25일
Does this give what you want?
s = cellfun(@(x)size(x,1),a);

추가 답변 (1개)

Jan
Jan 2017년 1월 26일
편집: Jan 2017년 1월 26일
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.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by