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

1 回表示 (過去 30 日間)
Student Israeli
Student Israeli 2021 年 4 月 25 日
コメント済み: Student Israeli 2021 年 4 月 28 日
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.

採用された回答

Jonas
Jonas 2021 年 4 月 25 日
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'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by