My for loop execution is not working.

I have a time range (t) going from 1 to 20, and a random collection of data of 20 points (y). I need to have y(1,:) for t(1,:), y(2,:) for t(2,:) and so on. This is what I wrote:
for t=1:1:20.0
a = y(1,:) : y(20,:)
end
But all this executes is the just one value of y (the first or the last, I can't tell because they are the same number). What should I correct?

2 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 7 de Jun. de 2015
Your question is not clear
Hiskiel Stephanus
Hiskiel Stephanus el 9 de Jun. de 2015
Editada: Hiskiel Stephanus el 9 de Jun. de 2015
I am assuming you are trying to assign values to an "a" matrix. Try making "a" a dynamic array by saying
a(1,t) = y(1,:) : y(20,:)

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Jun. de 2015
for t = 1:20
a = y(t,:);
fprintf('y value #%t was %g\n', t, a); %example of using the data
end

1 comentario

Prakriti Sardana
Prakriti Sardana el 7 de Jun. de 2015
Editada: Prakriti Sardana el 7 de Jun. de 2015
Hm, thank you very much. This works well for me.
PS: If I happen to use a part of this code in my summer project, I would credit you. :p Hehe.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda 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