MATLAB: How to assign matrix value to a symbolic variable inside a matrix

cell arraysmatrixmatrix array

The error is in the line in %…I got that the error is coming because of the unmatched dimension of left hand side and right hand side of that line. I want to assign the first element of the matrix A, a matrix value again . How can I possibly do that?
c = input('c ');
g = input('g ');
st = input('st ');
syms Lambda_n C_nrt a_r
M = cell(c+1,1);
a_t = min([1:c+1;repmat(c-g+1,1,c+1)]);
for i = 1:c+1
if i <= c-g
MCell = repmat({zeros(c+2-i)}, 1, a_t(i));
else
ACell = zeros(c+2-i,c+2-i, 'sym');
if st==1
A(1,1) = Lambda_n;
else
A(1,1) = kron(C_nrt,eye(st)); %error line
end
MCell = repmat({A}, 1, a_t(i))
end
M{i} = blkdiag(MCell{:});
end
B=blkdiag(M{:})

Best Answer

A numeric array in MATLAB can only hold a single element. You need to use a cell array. Change the line to
A{1,1} = kron(C_nrt,eye(st));
You will need to adapt the code accordingly.