Simple Loop

2 visualizaciones (últimos 30 días)
Thomas
Thomas el 3 de Dic. de 2011
Hi, I'm OK with Matlab usually but this has me stumped. When running the following simple script I get the error
Attempted to access a_b(15); index must be a positive integer or logical.
Error in test (line 10) a_b(i) = a_a;
Here is the code:
ts = 0.01; % Timestep (s)
a_b = zeros(1,6001);
for t_a=0:ts:60
a_a = t_a*7;
i = t_a*(1/ts)+1; % Step
a_b(i) = a_a;
end
This is just the essentials of the loop that is causing the problem. Many thanks for any help in advance, Tom

Respuesta aceptada

Paulo Silva
Paulo Silva el 3 de Dic. de 2011
ts = 0.01; % Timestep (s)
a_b = zeros(1,6001);
i=1;
for t_a=0:ts:60
a_a = t_a*7;
%i = t_a*(1/ts)+1; % Step
a_b(i) = a_a;
i=i+1;
end
plot(0:ts:60,a_b)
  1 comentario
Thomas
Thomas el 3 de Dic. de 2011
oh yer, of course! Thanks very much

Iniciar sesión para comentar.

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