It appears you are using the transpose character ('
) to
influence the results of the sort
function. Depending on
what you are trying to accomplish, this might be inefficient or ineffective.
The sort
function with no input arguments sorts the
columns of a matrix and the row of a row vector.
If you want to change the order of the input matrix, while maintaining its
original shape, do one of the following, depending on the type of array you
input to the sort
function:
Note
If a variable you pass to the sort
function could
be matrix or a vector because the variable's size varies, use the syntax
suggested for matrix input.
Matrix input
Specify the dimension of the matrix as the second input argument.
For instance, in the following example, the variables
y
and z
are identical, but
the syntax used to specify z
is more
efficient.
x = [5, 1, 3; 2, 4, 0];
y = sort(x')'
z = sort(x, 2)
Vector input
Remove the transpose character ('
). For
example, if your code looks like this,
y = [ 9; 4; 6; 2 ]
sort(y')
then replace it with this:
y = [ 9; 4; 6; 2 ]
sort(y)