i have cell whoes 1st column has names of countries and 2nd have population
i want to arrage it alphabetical oder in such a way so that population of counteries donot misplaced
for example
burundi 11890781 donot change means row wise data donot alter

4 件のコメント

Stephen23
Stephen23 2021 年 6 月 1 日
編集済み: Stephen23 2021 年 6 月 1 日
Note that SORT uses the character code order, which is not the same as alphabetic order.
In your example, "Réunion" would sort after "Rwanda", because "é" has a higher character code than "w":
S = ["Angola","Réunion","Rwanda","Zambia"];
T = sort(S) % wrong order!
T = 1×4 string array
"Angola" "Rwanda" "Réunion" "Zambia"
But in English and also in standard French, the letter "é" comes before "w" because the diacritic is considered as a modifier of the "e" character. Note however that in some other languages letters with diacritics are considered to be separate letters, and that the same characters can be positioned in different locations by different countries and languages. Some languages even count digraphs (two graphemes) as one letter, with "its" own position in the alphabet.
In short, sorting "alphabetically" is nowhere near as trivial as people think:
Muhammad
Muhammad 2021 年 6 月 1 日
it should sort in English alphatical oder
Stephen23
Stephen23 2021 年 6 月 1 日
@Muhammad SULAMAN: then you will need to handle the diacritics yourself (e.g. remove them before sorting and then use the sort index to sort the original data).
Stephen23
Stephen23 2023 年 8 月 14 日
編集済み: Stephen23 2023 年 8 月 14 日
Addendum: an easy way to sort Réunion into the expected position is to use ARBSORT:
For example:
S = ["Réunion","Zambia","Rwanda","Angola"];
sort(S) % for comparison
ans = 1×4 string array
"Angola" "Rwanda" "Réunion" "Zambia"
arbsort(S)
ans = 1×4 string array
"Angola" "Réunion" "Rwanda" "Zambia"

サインインしてコメントする。

 採用された回答

Rik
Rik 2021 年 6 月 1 日

0 投票

You can use sortrows directly, or use code like this:
[~,order]=sort(population(:,1));
population=population(order);

4 件のコメント

Muhammad
Muhammad 2021 年 6 月 1 日
but it doesnot have population in 2 column
Rik
Rik 2021 年 6 月 1 日
Small typo:
[~,order]=sort(population(:,1));
population=population(order,:);
Muhammad
Muhammad 2021 年 6 月 1 日
output of your code
it doesnot have populatioin
Stephen23
Stephen23 2021 年 6 月 1 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2021 年 6 月 1 日

編集済み:

2023 年 8 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by