error in using array2table
1 次查看(过去 30 天)
显示 更早的评论
I have two numerical values in an array x and two string values in an array y. In the workspace these are shown as [0, 7.2e-9] and 1X2 string. But when I try build a tavle using array2table as
array2table(x,'VariableNames', y);
I get the error
The VariableNames property must contain one name for each variable in the table.
What does this mean?
5 个评论
Dyuman Joshi
2023-9-6
The answer has been deleted.
@Stephen23, I suspect that you have tagged the wrong profile.
This is the profile of the author in discussion - https://in.mathworks.com/matlabcentral/profile/authors/30941256
Stephen23
2023-9-6
@Dyuman Joshi: thank you for pointing out the wrong profile, now I can't figure out how to "@" the correct one :)
回答(1 个)
Maksym Tymchenko
2023-11-2
I was able to create a table successfully using the steps that you described:
x = [0, 7.2e-9];
y = ["var1", "var2"];
array2table(x,'VariableNames', y)
I suspect that you were storing either "x" or "y" as a 2x1 array instead, which would trigger the error that you mentioned:
x = [0; 7.2e-9];
y = ["var1", "var2"];
array2table(x,'VariableNames', y)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!