Converting two matrix to a single table

25 ビュー (過去 30 日間)
Ville Koivunen
Ville Koivunen 2019 年 9 月 12 日
回答済み: Siddharth Bhutiya 2019 年 10 月 1 日
Hello
How could I easily construct a single table from two matrix so that the corresponding values of these matrices are represented in
table columns which have written headings.
Here is an example needed
M1 =
3 3
8 NaN
M2 =
6 1
5 4
Outcome Table =
M1value M2 value
3 6
3 1
8 5
NaN 4

回答 (1 件)

Siddharth Bhutiya
Siddharth Bhutiya 2019 年 10 月 1 日
You can flatten your matrices into column vectors (M1(:)) and then create a table from that. I see that you want the data in row major form, so you would have to transpose your matrix before flattening it.
M1 = M1';
M2 = M2';
t = table(M1(:),M2(:),'VariableNames',["M1 Value","M2 Value"])
t =
4×2 table
M1 Value M2 Value
________ ________
3 6
3 1
8 5
NaN 4

カテゴリ

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

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by