필터 지우기
필터 지우기

For loop

조회 수: 1 (최근 30일)
Ayda
Ayda 2012년 4월 21일
Good evening\morning i want to get the same result of the ascending method from the for loop.
I have to use the for loop because i want to calculate the time for each job.
numOfJobs=5;
for i=1:numOfJobs
job(i)=i;
end
arrivalTime=[2 4 1 5 3];
[sortedArrivalTimes, job] = sort(arrivalTime);
%*****************************************
numOfJobs=5;
for i=1:numOfJobs
job(i)=i;
end
arrivalTime=[2 4 1 5 3];
for i=1:numOfJobs
y=i+1;
for j=1:numOfJobs-1
if(arrivalTime(j)<arrivalTime(i))
firstcome=job(j);
job(j)=job(i);
job(i)=firstcome;
end
end
end
job
  댓글 수: 1
Image Analyst
Image Analyst 2012년 4월 21일
Here's another way to sort: http://blogs.mathworks.com/steve/2012/04/11/and-now-for-something-completely-different/

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2012년 4월 21일
Looks like you're failing to swap arrival times in your loop.
  댓글 수: 1
Ayda
Ayda 2012년 4월 21일
is it wrong if i swap !

댓글을 달려면 로그인하십시오.

카테고리

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