Table Indexing and trained model prediction
3 ビュー (過去 30 日間)
古いコメントを表示
Last year I wrote some code which worked well with 2017a. I ran this with 2017b it gives the following error.
Error using test (line 14) You cannot subscript a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts). Use a row subscript and a variable subscript.
height = 107;
gender = "M";
ethnicity = 2;
age = 7;
weightModel = AEGH;
table = table(age,ethnicity,gender,height);
weight = weightModel.predictFcn(table);
disp(weight);
My only thought is a change between versions. However, no one else seems to be reporting this occurring so perhaps I have done something odd.
Help appreciated.
5 件のコメント
Guillaume
2018 年 2 月 20 日
編集済み: Guillaume
2018 年 2 月 20 日
@Suraj,
Since you identify the problem correctly, you should move your comment to an answer, so you can get reputation points for it.
@Sally,
Yes, do not use table as a variable name since it then prevents you from using the table function. Other function names that are commonly shadowed by mistakes are: sum, mean, cell, struct, image and even i and j although the latter two are rarely a problem.
Suraj Mankulangara
2018 年 2 月 20 日
@Guillaume
Thanks for the heads up! :) I thought I HAD posted an answer instead of a comment!
回答 (1 件)
Suraj Mankulangara
2018 年 2 月 20 日
Hi Sally,
It looks like the issue is with the following line:
table = table(age,ethnicity,gender,height);
This issue occurs since the variable name 'table' on the left-hand side is the same as the built-in MATLAB function 'table' on the right-hand side.
The first time this code is run, it works fine. The function 'table()' is invoked, and the result is stored in the variable 'table'.
If the workspace is not cleared after the execution of this code, subsequent invocations of the 'table()' function will be treated as indexing. This occurs since the variable 'table' still exists in the workspace. MATLAB gives variables higher precedence over functions of the same name.
In order to resolve this issue, you could try giving a different name to the result variable. For example:
resultTable = table(age, ethnicity, gender, height);
Sincerely,
Suraj Mankulangara
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!