Azzera filtri
Azzera filtri

How to speed up searching for all items in cell array within another cell array

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Titus Edelhofer
Titus Edelhofer il 25 Giu 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 Commenti
Gregory
Gregory il 25 Giu 2013
This just gives a logical yes or no as to if each name in TBOM exists in BoM, I need the actual row number.
Regards, Greg
Titus Edelhofer
Titus Edelhofer il 11 Lug 2013
Please try to use the second output of ismember for the location (or find(rows))...

Accedi per commentare.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by