Invalid Subscript for Y, the table variable must be numeric array
조회 수: 113 (최근 30일)
이전 댓글 표시
I am trying to plot the first 1000 data from the imported txt. file and I keep getting the error message and no idea how to slove it.
Does it mean the data from the second column are not the intergers?

댓글 수: 0
채택된 답변
Voss
2022년 5월 8일
First and Second are tables. Use curly braces {} rather than parentheses () to get the data out of a table:
A = table([1;2;3;4;5],[10;20;30;40;50]);
% first, reproducing the error
First = A(:,1) % tables
Second = A(:,2)
try
plot(First,Second)
catch ME
disp(ME.message)
end
% now, the solution
First = A{:,1} % numeric arrays
Second = A{:,2}
plot(First,Second)
댓글 수: 3
추가 답변 (1개)
Image Analyst
2022년 5월 8일
Use braces
A = table(rand(1300, 1), rand(1300, 1))
x = A{1 : 1000, 1}
y = A{1:1000, 2}
plot(x, y, 'b-')
Or like this:
A = table(rand(1300, 1), rand(1300, 1), 'VariableNames', {'X', 'Y'});
plot(A.X(1:1000), A.Y(1:1000), 'b-')
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
