Comparing first n digits
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
wesso Dadoyan
am 25 Okt. 2017
Kommentiert: Rik
am 25 Okt. 2017
Hi ,
I have two columns of numbers A and B. A is 9 digits and B is 8 digits. How can I find the row in B that matches A(i) in a loop (i=1:length(A))
3 Kommentare
Rik
am 25 Okt. 2017
I would recommend not using a loop. If you have stored the number in a number format, just divide the A by 10 and floor it to convert to 8 digits. If you have it as a string, just remove the last character.
Then you can use ismember to do the work. ismember can be slow, so looking for alternative methods can be worthwhile if that is the bottleneck in your code.
Akzeptierte Antwort
Walter Roberson
am 25 Okt. 2017
[tf, Bidx] = ismember(fix(A/10), B);
Now, tf(K) tells you whether A(K) had a match in B or not, and if tf(K) is true then Bidx(K) tells you which entry in B matched.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification 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!