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

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by