I am trying to create a user-defined selection sort for 2-D arrays. The user will select column to sort.However, as the desired column is selected all columns are to be moved at the same time so that the values in a single row are kept together.
My attempt:
load sort_data.dat
col = input('Please enter the column you wish to sort: ');
sortorder(sort_data,col)
————————————————————————————-
function [value,loc] = sortorder(array,col) %This function uses the selection sort method to sort a column of an array
[n,m] = size(array); loc = 1; value = 1; i = n;
j = 1;
for i = 1:n
i = i - 1 ; if i >= 2 value = max(array(1:i,col));
else
array(1:n,1:m); if [value] ~= max(array(i, col)) for j = 1:m j = j + 1; temp = array(loc,j); array(loc,j) = array(i,j); array(i,j) = temp; end end endend
Any ideas?
Best Answer