comparing numbers

조회 수: 6 (최근 30일)
kash
kash 2012년 2월 7일
편집: Matt J 2013년 10월 2일
I have a80 values
K=[1 3 7 9 2 ....] till 80 which are not sorted ,now i want to take first 10 numbers compare each number and sort using for loops ,should not use sort command,for examplae if my first 10 values are
J=[1 2 7 9 2 77 65 23 34 30]
i need answer as ascending order without using sort command,
like these i need for all 80 values,taking each 10..
please help

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 2월 7일
K = randi(200,80,1);
out = reshape(K,[],8);
for i1 = 1:size(out,2)
A = out(:,i1);
i2 = 1;
while numel(A)
s = A(1);
for j1 = 2:numel(A)
if s > A(j1)
k = A(j1);
A(j1) = s;
s = k;
end
end
out(i2,i1) = s;
A = A(2:end);
i2 = i2 + 1;
end
end
out = out(:);
  댓글 수: 2
Andrei Bobrov
Andrei Bobrov 2012년 2월 7일
this is homework
kash
kash 2012년 2월 7일
Thanksandrei

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

추가 답변 (0개)

카테고리

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