Simple Loop

2 ビュー (過去 30 日間)
Thomas
Thomas 2011 年 12 月 3 日
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

採用された回答

Paulo Silva
Paulo Silva 2011 年 12 月 3 日
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 件のコメント
Thomas
Thomas 2011 年 12 月 3 日
oh yer, of course! Thanks very much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by