필터 지우기
필터 지우기

find values from a matrix according to a criterion

조회 수: 1 (최근 30일)
Richard
Richard 2012년 9월 17일
I have a time series of measurements as follows:
time = [733774,733774,733775,733775,733775,733776,733776];
data = [1,1.3,1,2.5,2.5,1,1.2];
Final = [time',data'];
I want to create a new variable that only contains the values that contain more than two measurements for individual days. So, from the example above, the result should be:
newData = [[733775;733775;733775],[1;2.5;2.5]];

채택된 답변

José-Luis
José-Luis 2012년 9월 17일
time = [733774,733774,733775,733775,733775,733776,733776];
data = [1,1.3,1,2.5,2.5,1,1.2];
unik_time = unique(time);
rep_time = arrayfun(@(x) (sum(ismember(time,x)) > 2),unik_time);
idx = ismember(time,unik_time(rep_time));
your_time = time(idx);
your_vals = data(idx);

추가 답변 (1개)

Thomas
Thomas 2012년 9월 17일
Something like this
time = [733774,733774,733775,733775,733775,733776,733776];
data = [1,1.3,1,2.5,2.5,1,1.2];
Final = [time',data'];
unique_days=unique(time);
for ii=1:length(unique_days)
count(ii)=sum(unique_days(ii)==time);
end
idx=find(count>2);
% If there is more than 1 day with 3 or more readings
for jj=1:length(idx)
idx_time(jj,:)=find(time==unique_days(idx(jj)));
newTime=time(idx_time(jj,:))
newData=data(idx_time(jj,:))
end

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by