How to vectorize this operation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu Database Toolbox 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!