Matrix addition hour values to day values
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello guys it is my first question in here so you can imagine I'm not that good at matlab.
I got a table with 8760 lines (beta). Every value is an hour value and I wanted to sum every 24 lines to one day if you know what i mean.
So i need a loop or a possibility without "sum" command which can count 24 lines together and go to the next 24.
The results have to be a new matrix with 365 lines (so one year).
My code doesnt work but maybe you can help.
Its my first semester informatics and I've been trying to solve it for days.
n = 1;
N = 24;
for i = b:c;
for v = 1:8760
Beta(1,v) = beta(n,N);
n = n + 24
N = N + 24
end
end
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 1월 4일
편집: Cris LaPierre
2021년 1월 4일
If I were going to do this, I would create a vector of datetimes incremented by 1 hour. I would then create a table with the datetimes and beta. I would then use groupsummary to calculate the sum of each day.
Here's a rough example.
beta = rand(8760,1);
d = datetime(2020,1,1,0,0,0)+hours(0:length(beta)-1)';
data = table(d,beta)
dailySum = groupsummary(data,'d','dayofyear','sum')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!