Hi,
You can do the following to automate a for loop instead of writing manual code for each year:
a=1;
b=1;
sigma_white_noise= a;
sigma_flicker_noise= b;
T=1;
% Initialize an empty cell array to store your results
results = cell(1, 20);
% Loop over the years
for year = 2:20
t = 0:0.00273785: year;
% Initialize an empty cell array for the current year
A = cell(1, round(year * 365.25));
% Loop over the days in the current year
for i = 1:length(t)
A{i} = [ 1 t(i) (cos((2*pi()*t(i))/T)) (sin((2*pi()*t(i))/T))];
end
A = cell2mat(A');
N = length(t);
I = eye(N);
Cee = sigma_white_noise^2 * I;
Cx = inv(A' * inv(Cee) * A);
[sd, q] = cov2corr(Cx);
% Store the results for the current year
results{year} = struct('A', A, 'N', N, 'I', I, 'Cee', Cee, 'Cx', Cx, 'sd', sd, 'q', q);
end
This code will calculate the results for each year from 2 to 20 and store them in the results cell array. Each element of results is a structure containing the matrices A, N, I, Cee, Cx, and the vectors sd, q for the corresponding year. You can access the results for a specific year using results{year}. For example:
results{3}.A % gives matrix A for 3rd year
Please note that the round function is used to convert the number of days in a year to an integer, as the number of days in a year is not always a whole number due to leap years. This might cause slight discrepancies in the results, but they should be negligible for most purposes. For more precise results, you might need to take leap years into account in your calculations.
Hope this helps!