create cell array of individual years from a long time series
1 次查看(过去 30 天)
显示 更早的评论
I have a matrix which is composed of a mixture of datevec and time series of measurements, e.g.
time = datevec(datenum('1966-01-01'):datenum('2009-12-03'));
data = rand(size(time,1),1);
Final = [time,data];
a = cell(length(unique(time(:,1))),1);
I would like to place all individual years in separate cells, I have created an empty cell array to house the values but am unsure about the most efficient way of moving the values from 'Final' to 'a'.
So far I have:
b = unique(Final(:,1));
for i = 1:length(a);
a{i} = Final(find(Final(:,1)==b(i)),:);
end
This works fine but I was wondering if anyone had an alternative method?
0 个评论
采纳的回答
Andrei Bobrov
2012-9-6
编辑:Andrei Bobrov
2012-9-6
try this is code (corrected)
time = datevec(datenum('1966-01-01'):datenum('2009-12-03'));
data = rand(size(time,1),1);
Final = [time,data];
[c c c] = unique(Final(:,1));
a2 = accumarray(c,Final(:,end),[],@(x){x});
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!