MATLAB: For Loop

for loop

Hi everybody!!
I´m trying to do a simple loop that looks like this:
for t = 1 : 1 : 5
[k_hat, b_T, values] = E_Test(y(t:1800+t-1), n_0);
a(:)=k_hat(t);
end
I just want that for every t, the variable "a" stores the variable k_hat but it is not working. I get the following error: Attempted to access k_hat(2); index out of bounds because numel(k_hat)=1.
If instead I try a(t)=k_hat; it just gives me one value of k_hat instead of 5 values. Could you please give me a hint on what am I doing wrong here?
Thank you so much!

Best Answer

Apparently your k_hat is a scalar. It is probably changing in each iteration because the t you passed into E_Test is different. You can try the following in the loop
[k_hat(t), b_T, values] = E_Test(y(t:1800+t-1), n_0);
Related Question