Error: In an assignment A(:) = B, the number of elements in A and B must be the same.

1 回表示 (過去 30 日間)
Monserrat Olvera
Monserrat Olvera 2023 年 6 月 22 日
回答済み: Torsten 2023 年 6 月 22 日
I have been trying to get all the code to run but it keeps giving me the same error "In an assignment A(:) = B, the number of elements in A and B must be the same".
I managed to calculate w but the operations below are not performed automatically even though I already have the variables I need.
Please, help me!
A=[-1 -2 1 2;-2 3 0 -2;1 0 2 1;2 -2 1 4];
n=4;
v=eye(n,n);
HAH=A;
for k=1:n-2
x=A(:,n-k+1);
a2=x.^2;
alpha2=sum(a2(1:n-k));
sg=-sign(x(n-k));
alpha=sg*sqrt(alpha2);
w=zeros(n-k+1,1);
for i=1:n-k-1
w(n-k)=sqrt((1/2)*(1-(x(n-k)/alpha)));
wnk=w(n-k);
W(i)=-((1/2)*(x(i)/alpha*wnk));
end
w(i)=w;
end
Unable to perform assignment because the left and right sides have a different number of elements.
u=HAH*w;
h=w.'*u;
q=u-(h*w);
HAH=HAH-2*w*q.'-2*q*w.';
H=eye(length(w*w.'))-2*w*w.';
v=v*H;
  1 件のコメント
Matt J
Matt J 2023 年 6 月 22 日
In an assignment A(:) = B, the number of elements in A and B must be the same
Did you check if they are the same?

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

回答 (1 件)

Torsten
Torsten 2023 年 6 月 22 日
w(i)=w;
This line of code makes no sense. You want to assign a vector w to a scalar w(i).

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by