Why do I get the error "Unable to use a value of type '...' as an index."?

53 views (last 30 days)
Why do I get error messages such as:
Unable to use a value of type cell as an index.
Unable to use a value of type idnlarx as an index.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Apr 2021
This error can occur if you accidentally used a function name as a variable name. The solution is to rename your variable to something else.
See the following documentation to learn more about the Function Precedence Order in MATLAB:
Example:
load twotankdata;
z = iddata(y, u, 1);
sys1 = nlarx(z(1:300),[15 15 1]);
forecast = 6;
figure();
compare(z(1:800), sys1, forecast);
Y_Pred = forecast(sys1, z(1:500), 6, z.u(501:506));
The variable defined by "forecast = 6;" shadows the function "forecast" of the same name.
Solution:
Rename the variable "forecast" to "forecast1":
load twotankdata;
z = iddata(y, u, 1);
sys1 = nlarx(z(1:300),[15 15 1]);
forecast1 = 6;
figure();
compare(z(1:800), sys1, forecast1);
Y_Pred = forecast(sys1, z(1:500), 6, z.u(501:506));

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!