For Loop

1 次查看(过去 30 天)
Lu
Lu 2012-5-30
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!

采纳的回答

Honglei Chen
Honglei Chen 2012-5-30
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by