フィルターのクリア

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 件のコメント
Rik
Rik 2018 年 4 月 8 日
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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by