Reputation: 25048
How to get the magnitude of each value in a matrix, so:
0.2964 0.8765 0.3793
0.6832 -0.4721 0.5571
-0.6674 -0.0941 0.7387
is transformed?
0.2964 0.8765 0.3793
0.6832 0.4721 0.5571
0.6674 0.0941 0.7387
to sort the in a descend way, we do sort(A,'descend'), but as I have negative values I would like to have the magnitudes and then sort, can this be done in a single instruction??(get magnitudes and sort them in descending order)
so at the end we get
0.8765
0.7387
0.6832
0.6674
0.5571
0.3793
0.4721
0.2964
0.0941
Upvotes: 1
Views: 2584
Reputation: 238259
What about this:
>> a
a =
0.2964 0.8765 0.3793
0.6832 -0.4721 0.5571
-0.6674 -0.0941 0.7387
>> temp=sort(abs(a(:)),'descend')
ans =
0.8765
0.7387
0.6832
0.6674
0.5571
0.4721
0.3793
0.2964
0.0941
Upvotes: 3