How to extract different element between two cell array?

1 Ansicht (letzte 30 Tage)
I have two array
X1 = {'A','B','C','D'}
x2 = {'A','B','C','D','E','F','G','H'}
and I want to create a row having element not found in A i.e.
X3 ={ 'E','F','G','H'}

Akzeptierte Antwort

Dave B
Dave B am 5 Aug. 2022
Bearbeitet: Dave B am 5 Aug. 2022
How about using ismember combined with not (~)?
X1 = {'A','B','C','D'}
X1 = 1×4 cell array
{'A'} {'B'} {'C'} {'D'}
x2 = {'A','B','C','D','E','F','G','H'}
x2 = 1×8 cell array
{'A'} {'B'} {'C'} {'D'} {'E'} {'F'} {'G'} {'H'}
X3 = x2(~ismember(x2,X1))
X3 = 1×4 cell array
{'E'} {'F'} {'G'} {'H'}

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by