Sort(x) doesn't work properly.

5 views (last 30 days)
Julian Wzorek
Julian Wzorek on 12 Nov 2020
Commented: Walter Roberson on 12 Nov 2020
Why when I'm trying to sort , at the end there are numbers that are not sorted?

Accepted Answer

Ameer Hamza
Ameer Hamza on 12 Nov 2020
Edited: Ameer Hamza on 12 Nov 2020
How do you know it is not sorted. The following code shows that it is indeed sorted
daily_logreturns_sorted = sort(daily_logreturns);
tf = all(diff(daily_logreturns_sorted)>=0)
Result
>> tf
tf =
logical
1
  2 Comments
Walter Roberson
Walter Roberson on 12 Nov 2020
Or a slightly easier test,
daily_logreturns_sorted = sort(daily_logreturns);
issorted(daily_logreturns_sorted)

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!