How to compare two different cell arrays ?
399 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
vish
el 8 de Feb. de 2011
Comentada: Walter Roberson
el 24 de Mayo de 2019
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 comentario
Respuesta aceptada
Kenneth Eaton
el 8 de Feb. de 2011
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 comentarios
Elvira Cordova
el 24 de Mayo de 2019
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
?
Más respuestas (2)
Oleg Komarov
el 8 de Feb. de 2011
a = {'the', 'he', 'hate'};
b = {'he', 'hate'};
ismember(a,b)
Oleg
0 comentarios
Remus
el 11 de Ag. de 2011
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
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!