How do I sort values into quarters?

1 Ansicht (letzte 30 Tage)
matla6123
matla6123 am 24 Apr. 2017
Bearbeitet: Andrew Newell am 24 Apr. 2017
I have a matrix that lists dates and values as below. It goes through days with each value, then repeats for the next person. It is thousands of values long (length=n).
731521 1
731522 1
731523 1
731524 2
731525 2
I have date values that correspond to the starting dates of 27 quarters... 733408
733499
733590
733682
733774
733864
733955
I want to create a matrix that is n x 27 where (1,1) will be the value for the first person at date 733499 (Q1), (2,1) will be the second quarter value of the first person. (1,2) will be the first quarter value for the second person.... and so on.
I have some code that I used previously to do a similar command, summing the values for each person within each period. But this time I just want the value on the first day of each quarter. That code was...
for j=1:1:length(quarter_start_days)-1
quarter_initialvalue(l,j) = quarter_initialvalue(l,j) + ...
new_data(logical((new_data(:,1)>=...
quarter_start_days(j))...
.*(new_data(:,1)<...
quarter_start_days(j+1))),2);
format short g
end
Where 'new_data' was the matrix consisting of each day a value was held for. All the new_data values make up the matrix that is n x 2 listing all days and values for each person.

Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by