How to speed up searching for all items in cell array within another cell array
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I have some code which is taking ages to run.
I have 2 cell arrays of strings called:
"TBOM_PartNo" which is 7252 rows, and 3 columns.
"BoMExplosion_PartNo" which is 45567 rows, and 3 columns.
I need to find on what row every entry in TBOM_PartNo resides in BoMExplosion_PartNo. All 3 strings need to match.
They look like this: TBOM_PartNo(1:5,:)
ans =
'FK72' '142' 'AA'
'FK72' '142' 'BA'
'FK72' '142' 'BA'
'EX' '186' 'AA'
'UH12' '0069' 'DBA'
So i'm looking for a vector of integers equal in length to TBOM_PartNo (7353) that contains the row numbers where that entry in TBOM_PartNo can be found in BoMExplosion_PartNo.
At the moment I'm just looping through TBOM_PartNo and using ismember at each loop, which takes forever:
for i = 1 : length(TBOM_PartNo)
CurrentPartNo = TBOM_PartNo(i,:);
ThreeColumnLogic = ismember(BoMExplosion_PartNo,CurrentPartNo); %logical for each column
[A,RowNo] = max(sum(ThreeColumnLogic,2)); %find match in all three columns
AllRows = [AllRows; RowNo];
end
0 commentaires
Réponses (1)
Titus Edelhofer
le 25 Juin 2013
Hi, the fastest usually is to concatenate the strings, i.e.,
TBOM = strcat(TBOM_PartNo(:,1), TBOM_PartNo(:,2), TBOM_PartNo(:,3));
BoM = strcat(...); % do the same
rows = ismember(TBOM, BoM);
Titus
2 commentaires
Titus Edelhofer
le 11 Juil 2013
Please try to use the second output of ismember for the location (or find(rows))...
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!