I'm new to MATLAB and I'm having problem with a for loop in a cell array. I have a 52x52 cell array B
. In every cell, there is a 51x51 matrix. For every cell of the first row of B, I want to calculate the trace and I want the trace-elements in a vector (and smooth them with a spline). The variables dbmus
and cs
may be overwritten every time, SQED
and ddbmus
not. I have the following line of code, but I keep getting this error: In an assignment A(I) = B, the number of elements in B and I must be the same.
X = 1:51;
xx = linspace(1,51,250);
SQED = zeros(1,52);
dbmus = zeros(1,52);
ddbmus = zeros(1,52);
for i = 1:52
SQED(i) = sum(diag(B{1,i}));
dbmus = transpose(diag(B{1,i}));
cs = spline(X,[dbmus(1),dbmus,dbmus(end)]);
ddbmus(i) = ppval(cs,xx);
end
How can I fix this?