()-indexing must appear last in an index expression
3 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
Philip Borghesani
2013-1-9
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.
0 个评论
更多回答(3 个)
Daniel Shub
2013-1-9
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 个评论
Jan
2013-1-9
编辑:Jan
2013-1-9
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?
0 个评论
Utaibah Mustafa
2016-12-2
编辑:Walter Roberson
2016-12-2
??? 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 个评论
Walter Roberson
2016-12-2
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!