find values from a matrix according to a criterion

1 visualización (últimos 30 días)
Richard
Richard el 17 de Sept. de 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]];

Respuesta aceptada

José-Luis
José-Luis el 17 de Sept. de 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);

Más respuestas (1)

Thomas
Thomas el 17 de Sept. de 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

Categorías

Más información sobre Argument Definitions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by