Friday, 15 March 2013

Organizing datevec in Matlab -



Organizing datevec in Matlab -

i'm trying vectorize matlab code, i'm running problem trying organize datevec array show same day every year.

for instance, have datevec array june:

1900 6 1 0 0 0 1900 6 2 0 0 0 1900 6 3 0 0 0 ... 2013 6 30 0 0 0

which contains every single day in june 1900-2013. there anyway organize datevec array year, while maintaining right dates? end result below:

1900 6 1 0 0 0 1901 6 1 0 0 0 1902 6 1 0 0 0 ... 2013 6 30 0 0 0

i tried using

june(sort(june(:,3)),:)

which returns dates in right organized fashion, year columns incorrect.

thank in advance!

i'm still working out how without loop, (i think) answers question:

[~,idx] = sort(june(:,3)); sorted_table = zeros(size(june)); ii = 1:length(idx) sorted_table(ii,:) = june(idx(ii),:); end

edit: discovered built-in sortrows:

sorted_table = sortrows(june,[3 1])

sorts column 3 , column 1

matlab

No comments:

Post a Comment