MATLAB: 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,:)
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?

Best Answer

  • for t = 1:20
    a = y(t,:);
    fprintf('y value #%t was %g\n', t, a); %example of using the data