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]];
0 个评论
采纳的回答
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);
0 个评论
更多回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!