Indexing with parentheses '()' must appear as the last operation of a valid indexing expression
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
採用された回答
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 件のコメント
no .. not two dimesional array
for j= 1:L
w(j)(k+1)=w(j)(k)+etaa * x(j)* e(k); %MARKED
end
j is the location of elememts which go till "L" . K is the iteration on which code is running . in above term i just want to update elements of "w" array for next term (K+1)
If you need to keep a record of what all of the values were, whether for plotting or later calculations, then you need to use one of:
- a 2D array (most efficient, especially if pre-allocated w = zeros(L, 1500)
- a cell array (less efficient)
- a non-scalar struct (I am not sure how this would compare in efficiency to a cell array)
- a table (less efficient than any of the above)
If you do not need to keep a record, then just leave out the (k+1) and (k) indexing, like
w(j) = w(j) + etaa * x(j)* e(k); %MARKED
In some situations, you will find you need to know what the value for the previous generation was, such as if the code involved
w(j,k+1) = w(j,k) + etaa * x(j) * e(k);
x(j) = sqrt(w(j,k));
here, the w(j,k) in the x(j) line is the value of w(j) before it was was updated in the w(j,k+1) line. In such a case, where you need to know the old value to complete a sequence of iterations, then you cannot just get rid of the second index:
w(j) = w(j) + etaa * x(j) * e(k);
x(j) = sqrt(w(j)); %NOT THE SAME
here the w(j) is the updated value, whereas in the original it was the value before being updated.
In order to deal with this kind of situation, you would not need to keep the full 2D array. Instead you can use something like
oldw = w;
for j = etc
w(j) = oldw(j) + etaa * x(j) * e(k);
x(j) = sqrt(oldw(j));
end
do you know about horzcat Error???
Yes. horzcat() errors occur when you try to use [] to put together values that have different numbers of rows. For example,
x = [rand(50)/50, 1:10]
would try to use [] to put together a 50 x 50 random array with a 1 x 10 array; this would be an error.
Ali Mukhtar
2021 年 6 月 2 日
編集済み: Ali Mukhtar
2021 年 6 月 2 日
how could we solve it ... ???
x = [randi(50)/50, x(1:end-1)] its giving me error in this equation ... im not getting to solve it
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.
thanks alot your tips are always life saving ...;-)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
