error in using array2table

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

x = [0, 7.2e-9]
x = 1×2
1.0e-08 * 0 0.7200
y = ["hello","world"]
y = 1×2 string array
"hello" "world"
t = array2table(x, 'VariableNames',y)
t = 1×2 table
hello world _____ _______ 0 7.2e-09
Dyuman Joshi
Dyuman Joshi 2023년 8월 23일
Is it a 1x2 string or 1x2 char?
Stephen23
Stephen23 2023년 9월 6일
편집: Stephen23 2023년 9월 6일
@Riya: Are you using AI to generate those very nicely-worded answers?
Dyuman Joshi
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
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
Maksym Tymchenko 2023년 11월 2일

0 개 추천

Hi @MAWE,
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)
ans = 1×2 table
var1 var2 ____ _______ 0 7.2e-09
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)
Error using array2table
The VariableNames property must contain one name for each variable in the table.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2019b

태그

질문:

2023년 8월 22일

답변:

2023년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by