How to create a table from a string array as header and a numerical matrix as data?

28 次查看(过去 30 天)
Hello everyone,
So I have a string array as my header like this :
header = ['time' 'femur_r_X' 'femur_r_Y' 'femur_r_Z' 'femur_r_Ox' 'femur_r_Oy' ...
'femur_r_Oz' 'tibia_r_X' 'tibia_r_Y' 'tibia_r_Z' 'tibia_r_Ox' 'tibia_r_Oy' ...
'tibia_r_Oz' 'calcn_r_X' 'calcn_r_Y' 'calcn_r_Z' 'calcn_r_Ox' 'calcn_r_Oy' ...
'calcn_r_Oz' 'femur_l_X' 'femur_l_Y' 'femur_l_Z' 'femur_l_Ox' 'femur_l_Oy' ...
'femur_l_Oz' 'tibia_l_X' 'tibia_l_Y' 'tibia_l_Z' 'tibia_l_Ox' 'tibia_l_Oy' ...
'tibia_l_Oz' 'calcn_l_X' 'calcn_l_Y' 'calcn_l_Z' 'calcn_l_Ox' 'calcn_l_Oy' ...
'calcn_l_Oz'];
and I have a numerical matrix ( 101,37) that corresponds to this header. How can I create a table with this header and matrix as data and write it to excel with writetable?
Thanks
  1 个评论
Stephen23
Stephen23 2021-3-5
"So I have a string array..."
No, you have one character vector:
A = ['time' 'femur_r_X' 'femur_r_Y' 'femur_r_Z' 'femur_r_Ox' 'femur_r_Oy' ...
'femur_r_Oz' 'tibia_r_X' 'tibia_r_Y' 'tibia_r_Z' 'tibia_r_Ox' 'tibia_r_Oy' ...
'tibia_r_Oz' 'calcn_r_X' 'calcn_r_Y' 'calcn_r_Z' 'calcn_r_Ox' 'calcn_r_Oy' ...
'calcn_r_Oz' 'femur_l_X' 'femur_l_Y' 'femur_l_Z' 'femur_l_Ox' 'femur_l_Oy' ...
'femur_l_Oz' 'tibia_l_X' 'tibia_l_Y' 'tibia_l_Z' 'tibia_l_Ox' 'tibia_l_Oy' ...
'tibia_l_Oz' 'calcn_l_X' 'calcn_l_Y' 'calcn_l_Z' 'calcn_l_Ox' 'calcn_l_Oy' ...
'calcn_l_Oz']
A = 'timefemur_r_Xfemur_r_Yfemur_r_Zfemur_r_Oxfemur_r_Oyfemur_r_Oztibia_r_Xtibia_r_Ytibia_r_Ztibia_r_Oxtibia_r_Oytibia_r_Ozcalcn_r_Xcalcn_r_Ycalcn_r_Zcalcn_r_Oxcalcn_r_Oycalcn_r_Ozfemur_l_Xfemur_l_Yfemur_l_Zfemur_l_Oxfemur_l_Oyfemur_l_Oztibia_l_Xtibia_l_Ytibia_l_Ztibia_l_Oxtibia_l_Oytibia_l_Ozcalcn_l_Xcalcn_l_Ycalcn_l_Zcalcn_l_Oxcalcn_l_Oycalcn_l_Oz'
is exactly equivalent to:
B = 'timefemur_r_Xfemur_r_Yfemur_r_Zfemur_r_Oxfemur_r_Oyfemur_r_Oztibia_r_Xtibia_r_Ytibia_r_Ztibia_r_Oxtibia_r_Oytibia_r_Ozcalcn_r_Xcalcn_r_Ycalcn_r_Zcalcn_r_Oxcalcn_r_Oycalcn_r_Ozfemur_l_Xfemur_l_Yfemur_l_Zfemur_l_Oxfemur_l_Oyfemur_l_Oztibia_l_Xtibia_l_Ytibia_l_Ztibia_l_Oxtibia_l_Oytibia_l_Ozcalcn_l_Xcalcn_l_Ycalcn_l_Zcalcn_l_Oxcalcn_l_Oycalcn_l_Oz';
isequal(A,B)
ans = logical
1

请先登录,再进行评论。

采纳的回答

Stephen23
Stephen23 2021-3-5
编辑:Stephen23 2021-3-5
"How can I create a table with this header and matrix as data and write it to excel with writetable?"
M = rand(101,37); % fake data
H = ["time","femur_r_X","femur_r_Y","femur_r_Z","femur_r_Ox","femur_r_Oy","femur_r_Oz","tibia_r_X","tibia_r_Y","tibia_r_Z","tibia_r_Ox","tibia_r_Oy","tibia_r_Oz","calcn_r_X","calcn_r_Y","calcn_r_Z","calcn_r_Ox","calcn_r_Oy","calcn_r_Oz","femur_l_X","femur_l_Y","femur_l_Z","femur_l_Ox","femur_l_Oy","femur_l_Oz","tibia_l_X","tibia_l_Y","tibia_l_Z","tibia_l_Ox","tibia_l_Oy","tibia_l_Oz","calcn_l_X","calcn_l_Y","calcn_l_Z","calcn_l_Ox","calcn_l_Oy","calcn_l_Oz"];
T = array2table(M,'VariableNames',H);
writetable(T,'myfile.csv')

更多回答(0 个)

类别

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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by