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.
Paolo Binetti
Paolo Binetti 2017 年 1 月 25 日
Sorry, I just uploaded a .mat file with "a"

サインインしてコメントする。

採用された回答

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by