How to Name Columns in a Table?

76 次查看(过去 30 天)
I would like to change my array (y) to a table. y is 1a 3 x 133 double. I would also like to name the columns of this table with the names listed. I have checked to see if these names work within matlab with the isvarname function and they work fine. I have also counted these variables and there are 133 . I have also tried this with commas inbetween the variables but I get the same error message. I am not sure why this error message is popping up and any help is much appreciated!
Code:
B = array2table(y, 'VariableNames',{'L_palmPosX' 'L_palmPosY' 'L_palmPosZ' 'L_thumb_basePosX' 'L_thumb_basePosY' 'L_thumb_basePosZ' 'L_thumb_knuckle1PosX' 'L_thumb_knuckle1PosY' 'L_thumb_knuckle1PosZ' 'L_thumb_knuckle2PosX' 'L_thumb_knuckle2PosY' 'L_thumb_knuckle2PosZ' 'L_thumb_tipPosX' 'L_thumb_tipPosY' 'L_thumb_tipPosZ' 'L_index_basePosX' 'L_index_basePosY' 'L_index_basePosZ' 'L_index_knuckle1PosX' 'L_index_knuckle1PosY' 'L_index_knuckle1PosZ' 'L_index_knuckle2PosX' 'L_index_knuckle2PosY' 'L_index_knuckle2PosZ' 'L_index_tipPosX' 'L_index_tipPosY' 'L_index_tipPosZ' 'L_middle_basePosX' 'L_middle_basePosY' 'L_middle_basePosZ' 'L_middle_knuckle1PosX' 'L_middle_knuckle1PosY' 'L_middle_knuckle1PosZ' 'L_middle_knuckle2PosX' 'L_middle_knuckle2PosY' 'L_middle_knuckle2PosZ' 'L_middle_tipPosX' 'L_middle_tipPosY' 'L_middle_tipPosZ' 'L_ring_basePosX' 'L_ring_basePosY' 'L_ring_basePosZ' 'L_ring_knuckle1PosX' 'L_ring_knuckle1PosY' 'L_ring_knuckle1PosZ' 'L_ring_knuckle2PosX' 'L_ring_tipPosX' 'L_ring_tipPosY' 'L_ring_tipPosZ' ' L_pinky_basePosX' 'L_pinky_basePosY' 'L_pinky_basePosZ' 'L_pinky_knuckle1PosX' 'L_pinky_knuckle1PosY' 'L_pinky_knuckle1PosZ' 'L_pinky_knuckle2PosX' 'L_pinky_knuckle2PosY' 'L_pinky_knuckle2PosZ' 'L_pinky_tipPosX' 'L_pinky_tipPosY' 'L_pinky_tipPosZ' 'R_elbowPosX' 'R_elbowPosY' 'R_elbowPosZ' 'R_wristPosX' 'R_wristPosY' 'R_wristPosZ' 'R_palmPosX' 'R_palmPosY' 'R_palmPosZ' 'R_thumb_basePosX' 'R_thumb_basePosY' 'R_thumb_basePosZ' 'R_thumb_knuckle1PosX' 'R_thumb_knuckle1PosY' 'R_thumb_knuckle1PosZ' 'R_thumb_knuckle2PosX' 'R_thumb_knuckle2PosY' 'R_thumb_knuckle2PosZ' 'R_thumb_tipPosX' 'R_thumb_tipPosY' 'R_thumb_tipPosZ' 'R_index_basePosX' 'R_index_basePosY' 'R_index_basePosZ' 'R_index_knuckle1PosX' 'R_index_knuckle1PosY' 'R_index_knuckle1PosZ' 'R_index_knuckle2PosX' 'R_index_knuckle2PosY' 'R_index_knuckle2PosZ' 'R_index_tipPosX' 'R_index_tipPosY' 'R_index_tipPosZ' 'R_middle_basePosX' 'R_middle_basePosY' 'R_middle_basePosZ' 'R_middle_knuckle1PosX' 'R_middle_knuckle1PosY' 'R_middle_knuckle1PosZ' 'R_middle_knuckle2PosX' 'R_middle_knuckle2PosY' 'R_middle_knuckle2PosZ' 'R_middle_tipPosX' 'R_middle_tipPosY' 'R_middle_tipPosZ' 'R_ring_basePosX' 'R_ring_basePosY' 'R_ring_basePosZ' 'R_ring_knuckle1PosX' 'R_ring_knuckle1PosY' 'R_ring_knuckle1PosZ' 'R_ring_knuckle2PosX' 'R_ring_knuckle2PosY' 'R_ring_knuckle2PosZ' 'R_ring_tipPosX' 'R_ring_tipPosY' 'R_ring_tipPosZ' 'R_pinky_basePosX' 'R_pinky_basePosY' 'R_pinky_basePosZ' 'R_pinky_knuckle1PosX' 'R_pinky_knuckle1PosY' 'R_pinky_knuckle1PosZ' 'R_pinky_knuckle2PosX' 'R_pinky_knuckle2PosY' 'R_pinky_knuckle2PosZ' 'R_pinky_tipPosX' 'R_pinky_tipPosY' 'R_pinky_tipPosZ'});
Error:
The VariableNames property must contain one name for each variable in the table.

采纳的回答

Star Strider
Star Strider 2019-6-20
That looks like it should work.
Try this:
B = array2table(y)
first, to be sure that all the columns in ‘y’ are actually being assigned to columns in ‘B’. I suspect that they aren’t.
  4 个评论
Julia Williams
Julia Williams 2019-6-20
Amazing! Thank you once again for all your help! My miscount has caused me so much frustration!

请先登录,再进行评论。

更多回答(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