Table Indexing and trained model prediction

2 visualizaciones (últimos 30 días)
Sally Britnell
Sally Britnell el 4 de Feb. de 2018
Comentada: Suraj Mankulangara el 20 de Feb. de 2018
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 comentarios
Guillaume
Guillaume el 20 de Feb. de 2018
Editada: Guillaume el 20 de Feb. de 2018
@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
Suraj Mankulangara el 20 de Feb. de 2018
@Guillaume
Thanks for the heads up! :) I thought I HAD posted an answer instead of a comment!

Iniciar sesión para comentar.

Respuestas (1)

Suraj Mankulangara
Suraj Mankulangara el 20 de Feb. de 2018
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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by