manipulate structure field data to create a table

Hello All,
I am trying to restructure the data from the structure fields to get the desired table. For better understanding i illustrate with a simple example below:
1x4 struct with 3 fields
type list no
type1 a 1
type1 p 0
type2 a 7
type2 c 6
what i need is a sorted summary table like this: (alphabetically sorted & unique of 'list' with unique of 'type' associated with their respective 'no' values.)
a c p
type1 1 - 0
type2 7 6 -
Thank you all in advance.

 採用された回答

Peter Perkins
Peter Perkins 2019 年 5 月 3 日

1 投票

Tailor-made for the too-often-overlooked unstack:
>> type = categorical(["type1";"type1";"type2";"type2"]);
>> list = ["a";"p";"a";"c"];
>> no = [1;0;7;6];
>> t = table(type,list,no)
t =
4×3 table
type list no
_____ ____ __
type1 "a" 1
type1 "p" 0
type2 "a" 7
type2 "c" 6
>> t2 = unstack(t,"no","list")
t2 =
2×4 table
type a c p
_____ _ ___ ___
type1 1 NaN 0
type2 7 6 NaN

1 件のコメント

ppp
ppp 2019 年 5 月 7 日
Perfect! good to learn about 'unstack'. Thank you :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

タグ

質問済み:

ppp
2019 年 4 月 18 日

コメント済み:

ppp
2019 年 5 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by