find values from a matrix according to a criterion

1 Ansicht (letzte 30 Tage)
Richard
Richard am 17 Sep. 2012
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]];

Akzeptierte Antwort

José-Luis
José-Luis am 17 Sep. 2012
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);

Weitere Antworten (1)

Thomas
Thomas am 17 Sep. 2012
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

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by