matlab indexing and swapping
이전 댓글 표시
x = [6 5 3 5 9 10 438 4 1 4 7 0 4 8 4 2];
len = length(x);
minval = x(1);
for n = 1:len
for i = 1:len
if x(i) < minval
minval = x(i);
end
end
sortval(i) = minval;
x(n find(x==minval)) = x(find(x==minval) n);
x(n) = [];
end
disp(sortval)
I am trying to swap the position of n and my minval so I can delete that minval later and not affect the process of sorting later in the for loop.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!