필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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

답변 (1개)

Titus Edelhofer
Titus Edelhofer 2013년 6월 25일
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
Gregory
Gregory 2013년 6월 25일
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 2013년 7월 11일
Please try to use the second output of ismember for the location (or find(rows))...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by