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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Matt J
Matt J am 22 Jun. 2023
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by