How to merge two variables together in a table

1 次查看(过去 30 天)
Hi, I have a quick question : I have an initial table T and I would like to merge the variables deph1 and deph2 into a single new variable called deph as shown in the desired output (T1).
% Initial table
set_no = [1, 2, 3]';
deph1 = [123, 125, 150]';
deph2 = [124, 126, 148]';
T = table(set_no, deph1, deph2)
T = 3×3 table
set_no deph1 deph2 ______ _____ _____ 1 123 124 2 125 126 3 150 148
% Desired output
set_no = [1, 1, 2, 2, 3, 3]';
deph = [123, 124, 125, 126, 150, 148]';
T1 = table(set_no, deph)
T1 = 6×2 table
set_no deph ______ ____ 1 123 1 124 2 125 2 126 3 150 3 148
Any ideas ?
Thank you,

采纳的回答

Cris LaPierre
Cris LaPierre 2022-2-2
Use stack.
% Initial table
set_no = [1, 2, 3]';
deph1 = [123, 125, 150]';
deph2 = [124, 126, 148]';
T = table(set_no, deph1, deph2)
T = 3×3 table
set_no deph1 deph2 ______ _____ _____ 1 123 124 2 125 126 3 150 148
% Desired output
T1 = stack(T,["deph1","deph2"])
T1 = 6×3 table
set_no deph1_deph2_Indicator deph1_deph2 ______ _____________________ ___________ 1 deph1 123 1 deph2 124 2 deph1 125 2 deph2 126 3 deph1 150 3 deph2 148

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by