select data from different data sets
조회 수: 3 (최근 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!