Borrar filtros
Borrar filtros

how can i make a growing time vector, that fits my data vector?

2 visualizaciones (últimos 30 días)
Adam Klingest
Adam Klingest el 26 de Mzo. de 2015
Comentada: Star Strider el 26 de Mzo. de 2015
I have a for loop that loads in a sample of data and stores it in array for each iteration of the loop. I also want to plot the data together with time, one time for each iteration, but to do that need a growing time vector that has same length as my data array, which is updated every iteration. It look something like this.
t = 0;
for i = 1:20
pause(1)
Data(i) = LoadData()
t(i) = t(i)+1;
plot(t,Data)
end
but the problem is that as i initialize my timevector 't' it is allready bigger than my datavector 'Data', by one. But I need to initialize it, because i want it to start from zero. I thought this would be simple to solve, but maybe I am tired. I have tried different things, but I just can't figure it out.
If anybody know how to this, please help.
  1 comentario
Adam Klingest
Adam Klingest el 26 de Mzo. de 2015
It is solved
t = 0;
for i = 1:20
pause(1)
if i==1
t(i)=0
else
t(i)=t(i-1)+1
end
Data(i) = LoadData()
t(i) = t(i)+1;
plot(t,Data)
end

Iniciar sesión para comentar.

Respuestas (1)

Adam
Adam el 26 de Mzo. de 2015
Can't you just
plot( (0:(i-1), Data )
instead?
  1 comentario
Star Strider
Star Strider el 26 de Mzo. de 2015
Apparently not.
I deleted my Answer that did essentially the same thing (using the length of ‘Data’ to create ‘t’ after the loop).

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by