How to Sort Matrix Rows from Highest to Lowest
Simplied my problem so it’s easier to solve. Let’s pretend I have MatrixA that has 2 columns, and I want to sort the rows from highest to lowest depending on the value of the cell in the second column. How would I do this?
I also have a VectorB that starts at 10 and would like to add the value of each row in column 2 of the sorted MatrixA. How would I do this? Note this needs to come after MatrixA is sorted from highest to lowest.
Any suggestions matlab wizards out there? Really want to avoid using loops to make the code inefficient.
%Just creating example of the matrix I want to sort you can ignore this
MatrixA = cell(3,2);
MatrixA{1,1} = "D1";
MatrixA{2,1} = "D2";
MatrixA{3,1} = "D3";
MatrixA{1,2} = 5;
MatrixA{2,2} = 15;
MatrixA{3,2} = 10;
% Creating Vector B based on the already defined values for MatrixA which aren’t in order
VectorA = [10 10+MatrixA{1,2} 10+MatrixA{2,2} 10+MatrixA{3,2}];
% How would I sort MatrixA from highest to lowest here and the values of VectorB to be based on the sorted MatrixA?Simplied my problem so it’s easier to solve. Let’s pretend I have MatrixA that has 2 columns, and I want to sort the rows from highest to lowest depending on the value of the cell in the second column. How would I do this?
I also have a VectorB that starts at 10 and would like to add the value of each row in column 2 of the sorted MatrixA. How would I do this? Note this needs to come after MatrixA is sorted from highest to lowest.
Any suggestions matlab wizards out there? Really want to avoid using loops to make the code inefficient.
%Just creating example of the matrix I want to sort you can ignore this
MatrixA = cell(3,2);
MatrixA{1,1} = "D1";
MatrixA{2,1} = "D2";
MatrixA{3,1} = "D3";
MatrixA{1,2} = 5;
MatrixA{2,2} = 15;
MatrixA{3,2} = 10;
% Creating Vector B based on the already defined values for MatrixA which aren’t in order
VectorA = [10 10+MatrixA{1,2} 10+MatrixA{2,2} 10+MatrixA{3,2}];
% How would I sort MatrixA from highest to lowest here and the values of VectorB to be based on the sorted MatrixA? Simplied my problem so it’s easier to solve. Let’s pretend I have MatrixA that has 2 columns, and I want to sort the rows from highest to lowest depending on the value of the cell in the second column. How would I do this?
I also have a VectorB that starts at 10 and would like to add the value of each row in column 2 of the sorted MatrixA. How would I do this? Note this needs to come after MatrixA is sorted from highest to lowest.
Any suggestions matlab wizards out there? Really want to avoid using loops to make the code inefficient.
%Just creating example of the matrix I want to sort you can ignore this
MatrixA = cell(3,2);
MatrixA{1,1} = "D1";
MatrixA{2,1} = "D2";
MatrixA{3,1} = "D3";
MatrixA{1,2} = 5;
MatrixA{2,2} = 15;
MatrixA{3,2} = 10;
% Creating Vector B based on the already defined values for MatrixA which aren’t in order
VectorA = [10 10+MatrixA{1,2} 10+MatrixA{2,2} 10+MatrixA{3,2}];
% How would I sort MatrixA from highest to lowest here and the values of VectorB to be based on the sorted MatrixA? matlab, matlab code, mathematics, matrix array, matrix, matrix manipulation, matrices, array, arrays, cell array, cell arrays, vector, vectors, vectorization, cell, excel, importing excel data, matlab function, matlab coder, struct, script, speed, solve, sort, filter, fsolve MATLAB Answers — New Questions