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

39 ビュー (過去 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

採用された回答

Walter Roberson
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
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.
Ali Mukhtar
Ali Mukhtar 2021 年 6 月 3 日
thanks alot your tips are always life saving ...;-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by