How do I sort values into quarters?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!