find values from a matrix according to a criterion

1 次查看(过去 30 天)
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 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by