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

조회 수: 4 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by