Simple Loop

2 vues (au cours des 30 derniers jours)
Thomas
Thomas le 3 Déc 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

Réponse acceptée

Paulo Silva
Paulo Silva le 3 Déc 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 commentaire
Thomas
Thomas le 3 Déc 2011
oh yer, of course! Thanks very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by