S=[70 110 65 30 25 40 60] K=[4 2 3 1 5 7 6]; [~,idx]=sort(K); out=S(idx) Answer from Azzi Abdelmalek on mathworks.com
🌐
MathWorks
mathworks.com › matlab › data import and analysis › data preprocessing
sort - Sort array elements - MATLAB
Sort index, returned as a vector, matrix, or multidimensional array. I is the same size as A. The index vectors are oriented along the same dimension that sort operates on. For example, if A is a 2-by-3 matrix, then [B,I] = sort(A,2) sorts the elements in each row of A.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 217577-how-to-get-sorted-index-order-for-an-array
How to get sorted index order for an array? - MATLAB Answers - MATLAB Central
May 19, 2015 - For example, if I use the sort function on the array [14 8 91 19], I will get [8 14 19 91]. But instead I want [2 1 4 3] which gives me the indices of elements in the original array. Is there a...
🌐
MathWorks
mathworks.com › matlab › data import and analysis › data preprocessing
sortrows - Sort rows of matrix or table - MATLAB
For example, if A = [1 1; 2 2; 1 2; 2 2], then [Ba,Ia] = sortrows(A,'ascend') returns the sort index Ia = [1; 3; 2; 4] and [Bd,Id] = sortrows(A,'descend') returns the sort index Id = [2; 4; 3; 1]. ... Sorting by row names is not supported. For more information, see Tall Arrays. ... Cell or string input array is not supported. If A is complex with all zero imaginary parts, then MATLAB® might convert A to real(A) before calling sortrows(A).
🌐
MathWorks
mathworks.com › matlabcentral › answers › 477515-how-to-sort-a-matrix-s-columns-by-using-indexes
How to sort a matrix's columns by using indexes - MATLAB Answers - MATLAB Central
August 25, 2019 - I'll be very greatfull to have your opinions how to sort a matrix's columns by using an array of indexes. ... https://www.mathworks.com/matlabcentral/answers/477515-how-to-sort-a-matrix-s-columns-by-using-indexes#comment_738833
Find elsewhere
🌐
MathWorks
mathworks.com › matlabcentral › answers › 2054579-how-can-i-use-the-returned-sort-index-from-the-sort-function-on-a-multidimensional-array
How can I use the returned sort index from the sort() function on a multidimensional array? - MATLAB Answers - MATLAB Central
November 30, 2023 - [B,I] = sort(___) also returns a collection of index vectors for any of the previous syntaxes. I is the same size as A and describes the arrangement of the elements of A into B along the sorted dimension.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 2146689-how-does-indexing-work-when-sorting-a-matrix
How does indexing work when sorting a matrix? - MATLAB Answers - MATLAB Central
August 20, 2024 - For matrices, ‘sort’ orders the elements within columns. Sign in to comment. ... https://www.mathworks.com/matlabcentral/answers/2146689-how-does-indexing-work-when-sorting-a-matrix#answer_1502004
🌐
MathWorks
mathworks.com › matlabcentral › answers › 167027-how-to-index-a-sorted-array-with-the-actual-array
How to index a sorted array with the actual array? - MATLAB Answers - MATLAB Central
December 18, 2014 - I have an array, I want to sort that array and find index (location of the each element) of the sorted array elements in the actual array ... https://www.mathworks.com/matlabcentral/answers/167027-how-to-index-a-sorted-array-with-the-actual-array#comment_256410
🌐
MathWorks
mathworks.com › matlabcentral › answers › 463448-sort-an-array-while-keeping-the-right-index
Sort an array while keeping the right index - MATLAB Answers - MATLAB Central
May 22, 2019 - Look at the second output from the sort function. That can be used to generate the first output of sort from the input array, but it is not limited to being used only on that input array. Sign in to comment. Sign in to answer this question. MATLAB Language Fundamentals Matrices and Arrays Matrix Indexing
🌐
Johns Hopkins University
math.jhu.edu › ~shiffman › 370 › help › techdoc › ref › sort.html
sort (MATLAB Function Reference)
INDEX is an array of size(A), each ... value, indices are returned that preserve the original relative ordering. B = sort(A,dim) sorts the elements along the dimension of A specified by scalar dim....
🌐
MathWorks
mathworks.com › matlabcentral › answers › 368162-sort-a-matrix-according-to-the-index-of-a-vector
Sort a matrix according to the index of a vector - MATLAB Answers - MATLAB Central
November 21, 2017 - I have following labels for the rows and columns of a square matrix: labels = {'dog', 'car', 'fish'}' The corresponding matrix that expresses the semantic similarity between the terms is ...