How to sort rows in a matrix of strings according to a specific char?

1 view (last 30 days)
For example, I want to sort this matrix:
A = ['1C3489' ; '2E1919' ; '0A8721' ; '8B1821']
according to the letters (the 2nd char in each row), so the result will be:
A_sorted = ['0A8721'; '8B1821'; '1C3489'; '2E1919']
I didn't understand if the function "sort" knows how to do it.

Accepted Answer

Jonas
Jonas on 25 Apr 2021
easily possible,
A = ['1C3489' ; '2E1919' ; '0A8721' ; '8B1821']; sortrows(A,2)
the chars can dirextly be interpreted as numbers, e.g. char(97) is equal to 'a'

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!