Simple Loop

2 Ansichten (letzte 30 Tage)
Thomas
Thomas am 3 Dez. 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

Akzeptierte Antwort

Paulo Silva
Paulo Silva am 3 Dez. 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 Kommentar
Thomas
Thomas am 3 Dez. 2011
oh yer, of course! Thanks very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by