How do I sort a cell of data according to it's label?

2 ビュー (過去 30 日間)
tinkiewinkie
tinkiewinkie 2020 年 3 月 14 日
回答済み: Aghamarsh Varanasi 2020 年 3 月 17 日
Hi suppose I have the following data,
how do i sort the following data in the order of stridor first followed by wheeze then by crackle.
Thank you.
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 3 月 14 日
It will be helpful if you attach a small sample dataset.
dpb
dpb 2020 年 3 月 14 日
  1. Turn into categorical variable and set the output order as desired, or
  2. Create auxiliary variable of 1:3-->names in order wanted and sort by it.

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

採用された回答

Aghamarsh Varanasi
Aghamarsh Varanasi 2020 年 3 月 17 日
Hi,
As suggested by dpb, you can convert the ‘label’ column of the table to be categorical and specify the order in which you want to sort the data. The following code snippet reflects the same, considering the data to be in a table named ‘dataset’.
% dataset.Var6 is the sixth column of the table
dataset.Var6 = categorical(dataset.Var6, {'stridor', 'wheeze', 'cracle'});
% The order of sort will be the order in which the categories are specified in creating the categorical array
dataset = sortrows(dataset,6);
Hope this helps.

その他の回答 (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