フィルターのクリア

How do I get the lengths of each entry in a cell array without using a loop

11 ビュー (過去 30 日間)
Michael
Michael 2019 年 1 月 25 日
コメント済み: Michael 2019 年 1 月 25 日
How can I generate a vector with one entry for the length of each vector in a cell array without using a loop. e.g.
>> ca={1:4,1:9,3:15}
ca =
1×3 cell array
{1×4 double} {1×9 double} {1×13 double}
I want a vector with [4 9 13]
Obviously I could do :
>> for i=1:length(ca);lca(i)=length(ca{i});end
>> lca
lca =
4 9 13
But I have an aversion to using a loop for something like this.

採用された回答

madhan ravi
madhan ravi 2019 年 1 月 25 日
cellfun(@length,ca)
  1 件のコメント
Michael
Michael 2019 年 1 月 25 日
>> cellfun(@length,ca)
ans =
4 9 13
Great!. Thanks Madhan!

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

その他の回答 (0 件)

カテゴリ

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