Error: In an assignment A(:) = B, the number of elements in A and B must be the same.
3 次查看(过去 30 天)
显示 更早的评论
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
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
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
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).
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!