select data from different data sets
5 次查看(过去 30 天)
显示 更早的评论
Hi all.
I have two data sets looks like (year doy time value1 error):
dataset1:
2015 12 10.44 371 4.32
2015 12 11.45 289 3.25
.
.
.
2019 38 16.56 456 1.78
dataset2:
2015 12 10.44 385 1.35
2015 12 11.89 256 6.52
.
.
.
2019 38 16.56 587 3.74
All values of the time are not the same in the two datasets. I want to keep the data with the smallest error in the common hour in the two data sets and the other data wich are not have the same time as they are.
I want this:
2015 12 10.44 385 1.35
2015 12 11.45 289 3.25
2015 12 11.89 256 6.52
.
.
.
2019 38 16.56 456 1.78
Any ideas?
Thank you!
0 个评论
回答(1 个)
Andrei Bobrov
2019-3-29
编辑:Andrei Bobrov
2019-3-29
dat1 = [2015 12 10.44 371 4.32
2015 12 11.45 289 3.25
2019 38 16.56 456 1.78];
dat2=[2015 12 10.44 385 1.35
2015 12 11.89 256 6.52
2019 38 16.56 587 3.74];
d = [dat1;dat2];
[~,~,c] = unique(d(:,1:3),'rows');
T = sortrows( array2table([d,c]),'Var6');
ii = varfun(@(x)x == min(x),T(:,5:6),'G',2);
out = T(ii{:,end},1:end-1);
or
d = [dat1;dat2];
[~,~,c] = unique(d(:,1:3),'rows');
out = d(accumarray(c,(1:size(d,1))',[],@(x) x(d(x,5) == min(d(x,5))) ),:);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!