Variable size changes on every iteration

4 ビュー (過去 30 日間)
Aftab Ahmed Khan
Aftab Ahmed Khan 2014 年 6 月 5 日
コメント済み: José-Luis 2014 年 6 月 5 日
Hi,
What is an efficient way of doing the following task.
departure_time(1) = 250;
file_arrival(1) = 0.0;
for i = 2:30
departure_time(i) = arrival_time(i)+transmission_time(i)+departure_time(i-1);
end
This code is working fine for me but the matlab script editor show the message that "the variable departure_time changes size on every loop iteration. I am sure that there will be another way of achieving the same task, right?
Thank you so much.

採用された回答

José-Luis
José-Luis 2014 年 6 月 5 日
編集済み: José-Luis 2014 年 6 月 5 日
Pre-allocate. Before departure(1) = 250, place:
departure_time = NaN .* ones(30,1);
  4 件のコメント
Aftab Ahmed Khan
Aftab Ahmed Khan 2014 年 6 月 5 日
Thanks for the explanation, Accepted.
Cheers.
José-Luis
José-Luis 2014 年 6 月 5 日
My pleasure, thank you.

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

その他の回答 (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