필터 지우기
필터 지우기

How to vectorize this operation

조회 수: 1 (최근 30일)
Pete sherer
Pete sherer 2018년 2월 3일
편집: Pete sherer 2018년 2월 4일
Hi,
Could you help guide how I can vectorize this operation? I have the original fullset matrix which i want to retain and populate for each of the locID (4 locID total). For each locID, it looks up the loss values from ELT when there's a match on eventid.
fullset= struct;
fullset.yearid= [1 1 2 3 4 5 6 7 7 7]';
fullset.eventid=[201 202 203 204 201 210 208 209 210 210]';
fullset.indx = [1:10]';
fullset= struct2table( fullset);
ELT= struct;
ELT.eventid= [ 201 203 209 210 210 210 201 210]';
ELT.loss = [ 100 100 100 200 1 1 5 1]';
ELT.locid = [ 1 1 1 1 2 3 4 4]';
ELT= struct2table( ELT);
This is the operation I used to come up with full matrix set [10x4]. It has the full sequence from fullset, and for each indx, it's filled in with the loss from ELT of the same eventid
uniqLocID= unique( ELT.locid);
nLoc= length( uniqLocID);
simLocFull= deal( zeros( length( fullset.eventid), nLoc) );
for runi= 1: nLoc
tloc = (ELT.locid== uniqLocID( runi)); % (JlocID== runi);
tdata= struct;
[tdata.eventid, tdata.loss]= deal( ELT.eventid(tloc), ELT.loss(tloc));
[ tlocMaster, locELT]= ismember( fullset.eventid, tdata.eventid);
simLocFull( tlocMaster, runi)= tdata.loss( locELT( tlocMaster));
end % for runi
I tried using outerjoin, but was unsuccessful.
tall=outerjoin( fullset, ELT,'Type','LEFT','MergeKeys', true, 'LeftKeys',{'eventid'},'RightKeys',{'eventid'}, 'LeftVariables',{'yearid','eventid'},'RightVariables',{'locid','loss'});
Thanks in advance.

답변 (1개)

Pete sherer
Pete sherer 2018년 2월 4일
편집: Pete sherer 2018년 2월 4일
Each locid in the ELT has a unique set of eventid by the way

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by