MATLAB: Conversion to cell from double is not possible.

conversion cell doubleMATLAB

g = {};
for k=1:4
g(k) = {fspecial('gaussian',[2 2],k)};
end
dx = {}; dy = {}; h1=[-1 0 1];h2=[1 0 -1];
for k=1:4
dx(k) = imfilter(g{k},h1);
dy(k) = imfilter(g{k},h2);
end
It gives me the error : Conversion to cell from double is not possible.

Best Answer

  • dx{k} = imfilter(g{k},h1);
    dy{k} = imfilter(g{k},h2);
    % ^ ^ Use curley brackets
    or
    dx(k) = {imfilter(g{k},h1)};
    dy(k) = {imfilter(g{k},h2)};
    % ^ wrap in a cell ^