Finding elements in string or cell array with common strings
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saeid
am 25 Apr. 2022
Kommentiert: Saeid
am 27 Apr. 2022
Consider two arrays A & B:
A={'blah_12_blah' 'blah_456_blah' 'blah_789_blah' 'blah_NPQZ_blah'}
B={'blah_NPQZ_blah' 'blah_135_blah' 'blah_579_blah' 'blah_12_blah' 'blah_RSTX_blah'}
The termn 'blah' basically refers to any string that comes before and after the parts of interest and each 'blah' could be a different string.
I would like to compare these two arrays and fine only the members that have the "part of interest" in common. In this case it means that after comparing A & B, only the elements 'blah_12_blah' and 'blah_NPQZ_blah' will show up as output, since these elements have the parts '12' and 'NPQZ' incommon, no matter what their respective 'blah' parts are.
0 Kommentare
Akzeptierte Antwort
Kevin Holly
am 25 Apr. 2022
A={'blah_12_blah' 'blah_456_blah' 'blah_789_blah' 'blah_NPQZ_blah'}
B={'blah_NPQZ_blah' 'blah_135_blah' 'blah_579_blah' 'blah_12_blah' 'blah_RSTX_blah'}
A_partofinterest = extractBetween(A,'_','_')
B_partofinterest = extractBetween(B,'_','_')
A_new = A(ismember(A_partofinterest,B_partofinterest))
B_new = B(ismember(B_partofinterest,A_partofinterest))
5 Kommentare
Kevin Holly
am 27 Apr. 2022
A={'123abc' '456klm' '1a2b3c'}
B={'blah123abcblah' 'blah789ijkblah' 'blah11aa22bbblah' '123abc' '456pqr' '1a2b3c'}
contains(B,A)
B(contains(B,A))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!