Effacer les filtres
Effacer les filtres

Variable size changes on every iteration

1 vue (au cours des 30 derniers jours)
Aftab Ahmed Khan
Aftab Ahmed Khan le 5 Juin 2014
Commenté : José-Luis le 5 Juin 2014
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.

Réponse acceptée

José-Luis
José-Luis le 5 Juin 2014
Modifié(e) : José-Luis le 5 Juin 2014
Pre-allocate. Before departure(1) = 250, place:
departure_time = NaN .* ones(30,1);
  4 commentaires
Aftab Ahmed Khan
Aftab Ahmed Khan le 5 Juin 2014
Thanks for the explanation, Accepted.
Cheers.
José-Luis
José-Luis le 5 Juin 2014
My pleasure, thank you.

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