find element of a cell or char array that matches a nonleading substring
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Leo Simon
am 14 Dez. 2014
Beantwortet: Star Strider
am 14 Dez. 2014
This question seems closely related to thread 50624-testing-for-the-presence-of-a-substring-in-a-cell-array-of-strings but has an extra wrinkle.
I have an array of the form x = {'010','030',...,'310'} and a string y = 'W_030_000'. I'd like to find the element of x which matches some portion of the string y. In this example, the second element of x is the one I want to find. Obviously, I could do this if I restricted to y(3:5), then I could use strmatch, but I'd rather not have to be that explicit.
Thanks for any advice!
Leo
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 14 Dez. 2014
Bearbeitet: Azzi Abdelmalek
am 14 Dez. 2014
x = {'010','030','310'}
y = 'W_030_000'
out=x( ismember(x,regexp(y,'\d+','match')))
0 Kommentare
Weitere Antworten (1)
Star Strider
am 14 Dez. 2014
An alternative:
x = {'010','030','310'};
y = 'W_030_000';
ys = strsplit(y,'_');
[Q,ia,ib] = intersect(x,ys);
0 Kommentare
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!