フィルターのクリア

How to rearrange a column by a specific order?

3 ビュー (過去 30 日間)
MKM
MKM 2021 年 10 月 11 日
コメント済み: KSSV 2021 年 10 月 11 日
Lets say i have a table:
IDname | IDnumber | version | status
x1 | 1 | v1 | backlog
x2 | 1 | v1 | Done
x3 | 1 | v1 | verify
x4 | 1 | v1 | Done
x5 | 1 | v1 | backlog
x6 | 1 | v1 | verify
x7 | 1 | v1 | verify
I want to be able to group and reorder column "Status" like this:
IDname | IDnumber | version | status
x1 | 1 | v1 | backlog
x5 | 1 | v1 | backlog
x3 | 1 | v1 | verify
x6 | 1 | v1 | verify
x7 | 1 | v1 | verify
x2 | 1 | v1 | Done
x4 | 1 | v1 | Done
I thought you would categorical the column and try sort it using some like this
datanew = categorical(data.Status, {'backlog', 'verify', 'done'}
but this doesnt seem to work..
Cheers!

回答 (1 件)

KSSV
KSSV 2021 年 10 月 11 日
How about using sort?
s = [{'Done' }
{'verify' }
{'Done' }
{'backlog' }
{'verify' }
{'verify' }] ;
s = sort(s)
You can access that column using T.status, where T is your table and status is your column.
  2 件のコメント
MKM
MKM 2021 年 10 月 11 日
編集済み: MKM 2021 年 10 月 11 日
doesnt this only sort the data by alphabetical roder? I am looking for a specific pattern, not alphabetical.

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

カテゴリ

Help Center および File ExchangeModel Compatibility についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by