Error when creating table

3 次查看(过去 30 天)
Jake Welch
Jake Welch 2022-6-17
回答: Voss 2022-6-17
I am trying to create this table and i keep getting this error. Why? and how do I fix it?
clc;clear;
startAngle = [1,2];
middleAngle = [1,2];
endAngle = [1,2];
tableHeader = ["Start","Transition","End"];
putterNames = ["Putter1 :","Putter 2:"];
a = table(startAngle,middleAngle,endAngle,'RowNames', putterNames, 'VariableNames', tableHeader);
Error using table
The RowNames property must contain one name for each row in the table.
display(a);

采纳的回答

Voss
Voss 2022-6-17
If you try creating the table without the RowNames you'll see that your table actually has one row, and each element of the table is a 1-by-2 vector:
clc;clear;
startAngle = [1,2];
middleAngle = [1,2];
endAngle = [1,2];
tableHeader = ["Start","Transition","End"];
putterNames = ["Putter1 :","Putter 2:"];
a = table(startAngle,middleAngle,endAngle, 'VariableNames', tableHeader)
a = 1×3 table
Start Transition End ______ __________ ______ 1 2 1 2 1 2
If you make those variables into column vectors when making the table, then specifying RowNames works:
a = table(startAngle(:),middleAngle(:),endAngle(:),'RowNames', putterNames, 'VariableNames', tableHeader)
a = 2×3 table
Start Transition End _____ __________ ___ Putter1 : 1 1 1 Putter 2: 2 2 2

更多回答(0 个)

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by