good morning, I have acell array and i want to compare cell's length. Till now I used just t compare the equality of the cells using:
isequal(A{1,:})
A is the cell array.
I tried to run
isequal(length(A{1,:}))
but that's not correct.
What is the easiest way to achieve that, without using a or cycle???
Thanks

6 件のコメント

Andrew Newell
Andrew Newell 2015 年 3 月 12 日
Could you give an example of A?
Adam
Adam 2015 年 3 月 12 日
Do you really mean cell length or cell size? length is just whichever of the size dimensions is the larger, size is the full measure incorporating all dimensions.
ludvikjahn
ludvikjahn 2015 年 3 月 12 日
編集済み: ludvikjahn 2015 年 3 月 12 日
A= [1x218 cell
1x211 cell
1x209 cell
1x116 cell
1x215 cell
1x215 cell
1x215 cell
1x202 cell]
so in this case isequal(if you imagine the cellS as "cut" from a larger, equal cell) would be = 0,
but if
A=[1x215 cell
1x215 cell
1x215 cell]
it would also give me 0, and I want 1 as an answer in this case!!
That's why I don't have any problems using length! (but how??) Thanks
per isakson
per isakson 2015 年 3 月 12 日
Do you really mean
A=[1x215 cell
1x215 cell
1x215 cell]
and not
A={1x215 cell
1x215 cell
1x215 cell}
?
ludvikjahn
ludvikjahn 2015 年 3 月 13 日
yes of course, I have just mistaken the brackets.
Adam
Adam 2015 年 3 月 13 日

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

 採用された回答

Stephen23
Stephen23 2015 年 3 月 13 日
編集済み: Stephen23 2015 年 3 月 13 日

0 投票

This is easy to do in one line using cellfun , diff and any:
>> A = {cell(1,3),cell(1,3),cell(1,3)};
>> B = {cell(1,5),cell(1,2),cell(1,9)};
>> any(~diff(cellfun(@numel,A)))
ans =
1
>> any(~diff(cellfun(@numel,B)))
ans =
0

その他の回答 (1 件)

per isakson
per isakson 2015 年 3 月 12 日
編集済み: per isakson 2015 年 3 月 12 日

0 投票

A hint based on some guessing
cac = {'abc','def', 'ghi'};
tmp = cellfun( @length, cac, 'uni', false );
isequal( tmp{:} )
returns
ans =
1
I failed to make a one-liner
&nbsp
Addendum
A variant more in line with the comments to the question
cac = {'abc','def', 'ghi'};
cac = { cac, cac, cac };
tmp = cellfun( @length, cac, 'uni', false );
isequal( tmp{:} )
returns
ans =
1

2 件のコメント

ludvikjahn
ludvikjahn 2015 年 3 月 12 日
編集済み: ludvikjahn 2015 年 3 月 12 日
sorry, what stands 'uni' for? just as an example of length?
per isakson
per isakson 2015 年 3 月 12 日
編集済み: per isakson 2015 年 3 月 12 日
It's short for 'UniformOutput'. See cellfun, Apply function to each cell in cell array

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

カテゴリ

ヘルプ センター および File Exchange で Cell Arrays についてさらに検索

質問済み:

2015 年 3 月 12 日

コメント済み:

2015 年 3 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by