필터 지우기
필터 지우기

Variable size changes on every iteration

조회 수: 1 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by