MATLAB: How to sort an array in descending order without using the sort function arrayssort A = [2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19] Best Answer You can use bubble sort:swapped = 1; while swapped swapped = 0; for i=1:numel(A)-1 if A(i+1) > A(i) temp = A(i); A(i) = A(i+1); A(i+1) = temp; swapped = 1; end endend Related SolutionsMATLAB: How to sort a matrix in a random order E.g.,>> x = reshape(1:24,4,6)x = 1 5 9 13 17 21 2 6 10 14 18 22 3 7 11 15 19 23 4 8 12 16 20 24>> x(:) = x(randperm(numel(x)))x = 7 12 3 19 16 23 20 24 10 11 1 17 21 14 8 5 13 18 6 22 15 4 2 9 MATLAB: How do you remove duplicates without using unique One approach:A = [1;2;3;3;4;5;6;7;7;8;9];Ac = zeros(size(A));for k1 = 1:length(A)-1 Ac(k1) = sum(A(k1) == A(k1+1:end));endOut = A(Ac == 0)Out = 1 2 3 4 5 6 7 8 9 Related QuestionSortingEliminate duplicate values in a row!Sort entire rowSorting
Best Answer