How this code works and why for? What action does this code take?

A = [11 9 2 47 13 8 9 12];
for i=1:length(A)-1
for j = 2:length(A)
if (A(j-1)> A(j))
temp = A(j-1);
A(j-1) = A(j);
A(j) = temp;
end
end
end
Like given, it is an A vector. And temp is a variable name. It used to calculate sth but it does not tell us what.
I could not get what this code is using for. Can anyone explain it?

回答 (1 件)

James Tursa
James Tursa 2020 年 6 月 17 日

1 投票

3 件のコメント

Alex McQueen
Alex McQueen 2020 年 6 月 17 日
Hmm i do not think that code is about swapping. But thanks for the link, they really are familiar with each other.
madhan ravi
madhan ravi 2020 年 6 月 17 日
xD it is.
Alex McQueen
Alex McQueen 2020 年 6 月 17 日
Oh dang.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeArduino Hardware についてさらに検索

製品

リリース

R2020a

タグ

質問済み:

2020 年 6 月 17 日

コメント済み:

2020 年 10 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by