how to arrange vectors in descending order?

조회 수: 11 (최근 30일)
Sadiq Akbar
Sadiq Akbar 2020년 10월 12일
댓글: Sadiq Akbar 2020년 10월 12일
I have 100 vectors of size 100x8 each as is given in the attachment. I want to arrange them in descending order row-wise only.i.e. the elements of each vector should not be changed but they must be arranged in descending order only. say for example if I have two vectors as given below:
v1=[1 2 3 4 5 6 7 8]
v2=[2 3 4 5 6 7 8 9]
Then they must be arranged in descending order like
v2=[2 3 4 5 6 7 8 9] % bigger vector 1st
v1=[1 2 3 4 5 6 7 8] % smallerr vector next
In my excel file given in attachement, assume that all these vectors are stored in a matrix called ErrorVectors.
  댓글 수: 1
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 12일
First you should have a criteria for comparing two vectors like sum of errors or sum of square of errors.

댓글을 달려면 로그인하십시오.

답변 (2개)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 12일
% read matrix into A then
%
sumError = sum(A.^2,2);
% sort the total error
[~, ind] = sort(sumError,'descend')
Asorted = A(ind,:)
  댓글 수: 1
Sadiq Akbar
Sadiq Akbar 2020년 10월 12일
Thank you very much dear KSSV and Asad (Mehrzad) Khoddam. I ran the programs of both of you, but they changes the contents of the vector also.
Then I found solution on below URL and it worked.
URL:https://www.mathworks.com/matlabcentral/answers/96995-how-can-i-sort-the-rows-of-a-matrix-in-descending-order-in-matlab-7-0-1-r14sp1#:~:text=Accepted%20Answer,-MathWorks%20Support%20Team&text=The%20SORTROWS%20function%20offers%20the,second%20argument%20to%20the%20function.
Thank you once again to both of you.
Regards

댓글을 달려면 로그인하십시오.


KSSV
KSSV 2020년 10월 12일
A = rand(10,5) ;
[m,n] = size(A) ;
B = A ;
for i = 1:n
B(:,i) = sort(A(:,i),'descend') ;
end

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by