How to compare two rows in a cell {n x 1}

Is there any way to compare two rows in a cell with {nx1} dimensions. Help me!

1 件のコメント

Patrik Ek
Patrik Ek 2014 年 1 月 15 日
what is the data type of the content in the cell?

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

回答 (4 件)

dpb
dpb 2014 年 1 月 15 日

0 投票

For what definition of compare?
all(x{n,:}==x{m,:})
maybe for n~=m, <N=length(x)?
David Sanchez
David Sanchez 2014 年 1 月 15 日

0 投票

M = rand(10,1);
C = mat2cell(M,ones(10,1),1); % 10x1 cell
a = C{1}; % content of first cell, a is not a cell, it is a double
b = C{2};
if a == b
disp('they are equal');
else
disp('not equal');
end
% You can do it with no intermediate variables too
if C{3} == C{4}
disp('they are equal');
else
disp('not equal');
end

1 件のコメント

Jos (10584)
Jos (10584) 2014 年 1 月 15 日
This will error when C{3} and C{4} are of different classes, lengths, etc ..

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

Jos (10584)
Jos (10584) 2014 年 1 月 15 日

0 投票

To see if the elements of a cell are identical, use isequal
C = {1:4 ; 1:2, 1:4}
isequal(C{1},C{2})
isequal(C{1},C{3})
Note that the expression
C{1}==C{2}
will throw an error.
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 15 日
編集済み: Azzi Abdelmalek 2014 年 1 月 15 日

0 投票

a={11 2 0 5 2 8 8 1}'
b={1 25 3 6 0 3 12 2}'
s=sign([a{:}]-[b{:}])% if s=-1, a<b, if s=1, a>b, if s=0, a=b

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2014 年 1 月 15 日

編集済み:

2014 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by