Counting element length in cells.

29 ビュー (過去 30 日間)
Glenn
Glenn 2014 年 11 月 18 日
コメント済み: Evan 2014 年 11 月 18 日
I have this cell array: {Piggy; gue7352892; hdufhe~jf} How can I get the length of the elements in this array and access these one at a time?
Thank you

回答 (1 件)

Evan
Evan 2014 年 11 月 18 日
編集済み: Evan 2014 年 11 月 18 日
Look into cellfun
>> A = {'Piggy'; 'gue7352892'; 'hdufhe~jf'};
>> cellfun('length',A)
ans =
5
10
9
  2 件のコメント
Glenn
Glenn 2014 年 11 月 18 日
Thanks! I have some more questions too, if I want to select a specific element, i.e. I want the length of 'Piggy' only, how would I do that? and also, how would I be able to select 'Piggy' so that I can use the isstrprop function on it? Thanks
Evan
Evan 2014 年 11 月 18 日
You can access the contents of specific elements of cell arrays like so:
element = A{1};
Note that if you try to access the element like you would a normal (non-cell) array [i.e. element = A(1)], the command will still run, but you will grab the cell "wrapper" for that element. Accessing with curly brackets like I did above grabs the content inside this "wrapper."
Once you have the content in that cell, you can send it into functions like length or isstrprop like you would any other string or numeric array.

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

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by