Borrar filtros
Borrar filtros

For Loop

1 visualización (últimos 30 días)
Lu
Lu el 30 de Mayo de 2012
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!

Respuesta aceptada

Honglei Chen
Honglei Chen el 30 de Mayo de 2012
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);

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by