MATLAB: I am getting an error while executing a short code to update a matrix, In an assignment A(I) = B, the number of elements in B and I must be the same. Er

??? in an assignment a(i) = bthe number of elements in b and i must be the same. error

A = [0 1 1 1 ;0 0 0 1 ;0 1 0 1 ;0 0 0 0];
N=4; C=2;
rho=0.1;
B= zeros(N,C);
a=[1 0;0 1;1 1;0 1]
for k=1:N-1
B(k+1) = B(k) + (0.5 * rho* a);
end

Best Answer

Not sure if this is what you are trying to do, but I am taking Torsten's approach.
A=[0 1 1 1 ;0 0 0 1 ;0 1 0 1 ;0 0 0 0];
N=4;
C=2;
rho=0.1;
B=zeros(N,C,N);
a=[1 0;0 1;1 1;0 1];
for k=1:N-1
B(:,:,k+1) = B(:,:,k) + (0.5 * rho* a);
end