how to arrange vectors in descending order?
26 views (last 30 days)
Show older comments
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 Comment
Asad (Mehrzad) Khoddam
on 12 Oct 2020
First you should have a criteria for comparing two vectors like sum of errors or sum of square of errors.
Answers (2)
KSSV
on 12 Oct 2020
A = rand(10,5) ;
[m,n] = size(A) ;
B = A ;
for i = 1:n
B(:,i) = sort(A(:,i),'descend') ;
end
0 Comments
Asad (Mehrzad) Khoddam
on 12 Oct 2020
% read matrix into A then
%
sumError = sum(A.^2,2);
% sort the total error
[~, ind] = sort(sumError,'descend')
Asorted = A(ind,:)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!