Indexing with parentheses '()' must appear as the last operation of a valid indexing expression
21 次查看(过去 30 天)
显示 更早的评论
des=[0.1 0.5 0.5];
L = length(des);
x = zeros(1,L)
etaa= 0.04;
w=zeros(1,L);
% w2=zeros(1,1);
e=zeros(1,1);
for k = 1:1500
x = [randi(50)/50, x(1:end-1)]
x = transpose(x);
y_fix = des * x;
y_adapt = w*x;
%%%%% error update%%%%
e(k)=y_fix-y_adapt;
%%%%% weights update%%%
for j= 1:L
w(j)(k+1)=w(j)(k)+etaa * x(j)* e(k); %MARKED
end
end
0 个评论
采纳的回答
Walter Roberson
2021-5-31
You declared
w=zeros(1,L);
Indexing that with a single subscript would lead you to a single double precision location.
What is your expectation, then, of what
w(j)(k)
might mean? The k'th location inside the single double precision number?
If you are creating two dimensional arrays, then you should initialize w as two dimensional rather than as a vector, and you would use two subscripts, such as w(j,k)
7 个评论
Walter Roberson
2021-6-2
x = zeros(1,L)
x starts out as a row vector.
x = [randi(50)/50, x(1:end-1)]
in MATLAB, when you use a single vector to index into a vector, then the result of the indexing does not depend upon the shape of the vector you indexed with, and instead depends upon the shape of the vector being indexed. So because x is a row vector, the result of x(1:end-1) is a row vector. [] between a scalar (which has one row) and a row vector (which has one row) works fine, giving you a row vector.
x = transpose(x);
You make the row vector into a column vector.
Next iteration, you encounter
x = [randi(50)/50, x(1:end-1)]
in MATLAB, when you use a single vector to index into a vector, then the result of the indexing does not depend upon the shape of the vector you indexed with, and instead depends upon the shape of the vector being indexed. So because x is now a column vector, the result of x(1:end-1) is a column vector. [] between a scalar (which has one row) and a column vector (which has multiple rows) fails.
You need to decide whether x is a row vector or a column vector, and make the code consistent for it. Do not keep changing its orientation.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!