MATLAB Answers

0

Converting two matrix to a single table

Asked by Ville Koivunen on 12 Sep 2019
Latest activity Answered by Siddharth Bhutiya on 1 Oct 2019 at 21:19
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

  0 Comments

Sign in to comment.

Products


Release

R2018b

1 Answer

Answer by Siddharth Bhutiya on 1 Oct 2019 at 21:19

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

  0 Comments

Sign in to comment.