()-indexing must appear last in an index expression

5 visualizaciones (últimos 30 días)
Misa
Misa el 9 de En. de 2013
Comentada: Walter Roberson el 2 de Dic. de 2016
I get this error related to this line of code:
A(l,c)=A(l,c)+(b(l)(D(1,h))*b(c)(D(1,h)))
b is a vector that in each position has a function(like x^2), and D is a matrix whose all components are numbers. What i whant to do here is calculate the value of the functon b(l) on D(l,h)

Respuesta aceptada

Philip Borghesani
Philip Borghesani el 9 de En. de 2013
MATLAB does not support arrays of function handles (some earlier versions did what version are you using?). Use a cell array containing the function handles then you should be able to use the line:
A(l,c)=A(l,c)+(b{l}(D(1,h))*b{c}(D(1,h)))
Note changing ( to { for accessing b.

Más respuestas (3)

Daniel Shub
Daniel Shub el 9 de En. de 2013
What i whant to do here is calculate the value of the functon b(l) on D(l,h)
The simple answer is that despite the fact that you want to do this, you cannot. There are hacks, but the simplest way is
temp1 = b(l);
temp2 = b(c);
A(l,c)=A(l,c)+temp1(D(1,h))*temp2(D(1,h));
  2 comentarios
Misa
Misa el 9 de En. de 2013
I tried that but I get another error:
??? Attempted to access temp1(-2); index must be a positive integer or logical.
So I think 'it' isnt recognizing temp1 as a function but as an array
Walter Roberson
Walter Roberson el 9 de En. de 2013
Editada: Walter Roberson el 9 de En. de 2013
What datatype is b ? What does class(b) show ?

Iniciar sesión para comentar.


Jan
Jan el 9 de En. de 2013
Editada: Jan el 9 de En. de 2013
If you use a modern Matlab version, at least >= 2009a, you can store function handles in a cell only. Then this should work:
A(l,c) = A(l,c) + (b{l}(D(1,h)) * b{c}(D(1,h)))
Using an array for function handles has been available for a short time only, because it causes an ambiguity for e.g. "F(1)": Is (1) the argument of the function or the index of the functionhandle array?

Utaibah Mustafa
Utaibah Mustafa el 2 de Dic. de 2016
Editada: Walter Roberson el 2 de Dic. de 2016
??? Error: ()-indexing must appear last in an index expression
p=0.05;
i=0.01;
d=0;
sim('utaibah')
plot(time,PV)
hold on
p=0.1;
i=0.01;
d=0;
sim('utaibahm')
plot(time,PV,'r')
p=0.2;
i=0.01;
d=0;
sim('utaibahmus')
plot(time,PV,'k')
  2 comentarios
Utaibah Mustafa
Utaibah Mustafa el 2 de Dic. de 2016
how do i fix that
Walter Roberson
Walter Roberson el 2 de Dic. de 2016
You appear to be using sim() on three Simulink models. Do one or more of them have MATLAB Function Blocks, or arithmetic blocks, or Level 2 Functions programmed in MATLAB? The problem is probably in one of the models.
We will probably need the three models to test with.
Question: does utaibah have a To Workspace block that is creating PV, or did you define PV in something you did not show here?

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by