Decompose a matrix into smaller matrices by the date
Afficher commentaires plus anciens
Dear all,
I have a matrix with the dimension 946836x3 and it is a cell. The first column is the date (dd.mm.yyyy 'HH:MM:SS), followed by two exchange rates. The rows look like this: '01.01.2004 00:00:00.000', 1.2587, 1.2698. The span of time goes from '01.01.2004 00:00:00.000' to '31.12.2012 23:55:00.000'. I have for every day intra-day data points(every 5 minutes, but they are not equal for every month, some have 288 and others 287 or 286). Now I want for every day a matrix filtered by the date. As an example in one matrix should be all datapoints of january 2004 and in the next for february and so. As a result I should have 12*9 matrices. How can I do that? Thank you in advance!
Réponse acceptée
Plus de réponses (2)
DateV = datevec(C(:, 1), 'dd.mm.yyyy HH:MM:SS');
Year = DateV(:, 1);
Month = DateV(:, 2);
Result = cell(12, 9);
for iYear = 1:9
yearMatch = (Year == iYear + 2003);
for iMonth = 1:12
Result{iMonth, iYear} = C(Month == ii & yearMatch, :);
end
end
Now you have a {12 x9} cell, which contains cell with the monthly data. If the elements should be double matrices:
D = C(Month == ii & yearMatch, :);
Result{iMonth, iYear} = reshape(cat(1, D{:}), [], 2);
[This is not tested or debugged, but written in the web interface only]
Andrei Bobrov
le 19 Août 2013
DD = datevec(C(:,1),'dd.mm.yyyy HH:MM:SS')
[a1,i1,i1] = unique(DD(:,1));
[a2,i2,i2] = unique(DD(:,2));
T = accumarray([i1,i2],(1:size(DD,1))',[12 9],@(x){x});
D2 = cell2mat(C(:,2:3));
out = cellfun(@(x)D2(x,:),T,'un',0);
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!