Invalid Subscript for Y, the table variable must be numeric array

112 ビュー (過去 30 日間)
Eris Bolduc
Eris Bolduc 2022 年 5 月 8 日
コメント済み: Kalyani Ghuge 2023 年 3 月 29 日
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?

採用された回答

Voss
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
First = 5×1 table
Var1 ____ 1 2 3 4 5
Second = A(:,2)
Second = 5×1 table
Var2 ____ 10 20 30 40 50
try
plot(First,Second)
catch ME
disp(ME.message)
end
Invalid subscript for Y. A table variable subscript must be a numeric array containing real positive integers, a logical array, a character vector, a string array, a cell array of character vectors, or a pattern scalar matching one or more variable names.
% now, the solution
First = A{:,1} % numeric arrays
First = 5×1
1 2 3 4 5
Second = A{:,2}
Second = 5×1
10 20 30 40 50
plot(First,Second)
  3 件のコメント
Voss
Voss 2022 年 5 月 9 日
You're welcome!
Kalyani Ghuge
Kalyani Ghuge 2023 年 3 月 29 日
Great answer bro! Thank you!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
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-')
  1 件のコメント
Eris Bolduc
Eris Bolduc 2022 年 5 月 8 日
Thank you very much, now I understand what's going on.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by