How to compare two different cell arrays ?

384 ビュー (過去 30 日間)
vish
vish 2011 年 2 月 8 日
コメント済み: Walter Roberson 2019 年 5 月 24 日
I would like to know if there is any way by which I can compare all the elements and remove the matched elements if not needed.
eg : a = the, he, hate
b = he, hate
so c should be equal to the.
PS: I have tried string comparision method but, unfortunately they eliminate the 'he' from 'the' thus giving the output as only 't'.
Thank you, vish
  1 件のコメント
Igor Fedorov
Igor Fedorov 2016 年 5 月 3 日
Have you tried the function setdiff()?

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

採用された回答

Kenneth Eaton
Kenneth Eaton 2011 年 2 月 8 日
The SETDIFF function does what you want. It will give you the values in one set (i.e. cell array) that are not present in another set:
>> a = {'the', 'he', 'hate'};
>> b = {'he', 'hate'};
>> c = setdiff(a,b)
c =
'the'
  5 件のコメント
Elvira Cordova
Elvira Cordova 2019 年 5 月 24 日
Suppose I have the following:
a = { 'the', 'he', 'hate'}
b = { 'he', 'hate', 'she' }
And I want to obtain something like the following:
c = 'the'
d = 'she'
Is it possible with
setdiff
?
Walter Roberson
Walter Roberson 2019 年 5 月 24 日
c = setdiff(a,b);
d = setdiff(b,a);

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

その他の回答 (2 件)

Oleg Komarov
Oleg Komarov 2011 年 2 月 8 日
a = {'the', 'he', 'hate'};
b = {'he', 'hate'};
ismember(a,b)
Oleg

Remus
Remus 2011 年 8 月 11 日
What if I have two cell arrays with each array element continuing some structure with a combination of real elements and strings. i.e. A = {struct1,struct2,...} B = {struct1,struct2,...} here each struct can be of the type : structX.member1= ... (string/number) structX.member2= ... (string/number) ... Is there a way to compare the two cel arrays. dismember or setdiff only looks for strings so it won't work. Thanks Remus
  10 件のコメント
chocho
chocho 2017 年 3 月 10 日
Stephen Cobeldick thanks bro,but in my case i have a cell array inside another cell array i.e cell 1 627*1 (row=627 and col=1) and inside each row (from 1 to 627 ) i have 1*3 cell! .

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by