Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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

Antworten (1)

Titus Edelhofer
Titus Edelhofer am 25 Jun. 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 Kommentare
Gregory
Gregory am 25 Jun. 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 am 11 Jul. 2013
Please try to use the second output of ismember for the location (or find(rows))...

Melden Sie sich an, um zu kommentieren.

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!

Translated by