MATLAB: How to calculate fzero from values of matrices in cell array

cell arrayMATLABmatrixOptimization Toolbox

Dear All, I have three cell arrays: cv_o, std_m and mean_m. Both cells contains 359 2D matrices. The size of matrices is same. I would like to calculate the root of an equation using the values of these matrices. I tried to calculate fzero by the following way:
for jj=1:359;
for i=1:464;
for j=1:201;
mat(i,j)=cv_o{jj};
mstd(i,j)=std_m{jj};
mmean(i,j)=mean_m{jj};
if mat(i,j) == 0;
b(i,j) = 0;
else
b(i,j)=fzero(@(x)mat(i,j)-(mstd(i,j)./mmean(i,j)).^x,(0));
end
end
end
end
But I got the following error message: Subscripted assignment dimension mismatch. Could someone write me how I should solve calculate the root?

Best Answer

Dear Beáta,
Check this line (same holds for the next two lines):
mat(i,j)=cv_o{jj};
As you said, cv_o{jj} will return a matrix; but mat(i,j) is one scalar value and this mismatch is causing the error. Given that varname(i,j) returns a scalar, you'll see that also your equation can be solved analytically: x=log(mat(i,j))/log(mstd(i,j)/mmean(i,j)) I guess you want to have matrix operations here, but right now it's all scalar. Possibly you just need to remove all those (i,j), but I cannot say that for sure. Also, you'll not get b(i,j) but rather b(jj).