フィルターのクリア

¿How to order 'x' numbers in ascending or descending?

1 回表示 (過去 30 日間)
Carlos Zuñiga
Carlos Zuñiga 2012 年 10 月 9 日
I did this for two numbers, but I find it difficult for an indefinite amount of numbers (as input vector).
I was thinking of a nested loop.
I have come to this point:
clear;
V=input('Ingrese el vector V= ');
n=length(V);
% Ordenamiento
for i=1:n

採用された回答

Alessandro Masullo
Alessandro Masullo 2012 年 10 月 9 日
If you don't want to use sort (may be for practicing?), here is a simple alternative:
a = round(rand(1, 10)*20)
tmp = a;
t = zeros(1, length(a));
for i = 1:length(a)
m = find(tmp == min(tmp));
t(i) = tmp(m(1));
tmp(m(1)) = [];
end
t

その他の回答 (1 件)

Julien
Julien 2012 年 10 月 9 日
Hi, this function already exists on Matlab. It is called 'sort'
Additional information here
  1 件のコメント
Carlos Zuñiga
Carlos Zuñiga 2012 年 10 月 9 日
Oh, yeah.
But I do not use that feature.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by