How to add a vector to another vector in for loop

Hi,
I have a code calculating hourly temperatures in a system over a year in a for loop i=1:8760 (8760 is the number of hours in a year).
I would like to see how the hourly temperature level develop over ten years. I was thinking to put my already existing code into a new for loop with j=1:10, but I struggle with how wrap it up to a long vector with 87600 elements at the end. (not taking leap years into account). The code at this point is like this:
years=10;
T_tot=zeros(years,1);
for j=1:years
for i=1:8760
Tvec(i)=%code
end
T_tot(j)=Tvec;
end
I see that my code have some issues as I add several elements to my yearsx1 vector. How can this be improved so that i get my hourly values over 10 years (1x87600 or opposite)?

Answers (1)

One way is to replace T_tot(j)=Tvec; by T_tot((j-1)*8760+i)=Tvec;

Categories

Asked:

on 29 May 2020

Edited:

on 29 May 2020

Community Treasure Hunt

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

Start Hunting!