Indexing with parentheses '()' must appear as the last operation of a valid indexing expression

22 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 31 May 2021
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 Comments
Walter Roberson
Walter Roberson on 2 Jun 2021
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!