필터 지우기
필터 지우기

Sort vector using loops

조회 수: 2 (최근 30일)
Amjad Green
Amjad Green 2018년 4월 8일
이동: Voss 2022년 8월 22일
Im asked to write a code using loops(if,for while..)that will sort an input vector
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 4월 8일

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

답변 (1개)

Swaroopa
Swaroopa 2022년 8월 22일
이동: Voss 2022년 8월 22일
You can sort a vector using for loops in the following way in MATLAB.
function res=vectorsort(ar, n)
for i=1:n
for j=1:n-i
if ar(j) > ar(j+1)
t=ar(j);
ar(j)=ar(j+1);
ar(j+1)=ar(j);
end
end
end
res=ar;
end
Refer to the below documentation for more information:
Hope it helps.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by