Variable size changes on every iteration

3 views (last 30 days)
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.

Accepted Answer

José-Luis
José-Luis on 5 Jun 2014
Edited: José-Luis on 5 Jun 2014
Pre-allocate. Before departure(1) = 250, place:
departure_time = NaN .* ones(30,1);
  4 Comments
Aftab Ahmed Khan
Aftab Ahmed Khan on 5 Jun 2014
Thanks for the explanation, Accepted.
Cheers.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!