How to speed up searching for all items in cell array within another cell array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Titus Edelhofer
el 25 de Jun. de 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 comentarios
Titus Edelhofer
el 11 de Jul. de 2013
Please try to use the second output of ismember for the location (or find(rows))...
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!