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

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Jonas
Jonas am 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'

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by