Search code examples
matlabif-statementfor-loopcell

Cell contents assignment to a non-cell array object


for ch=1:63
    for h=1:5
        for a=1:6
            for b=1:6
                m{a,b}{h,ch}=zeros(4,4);
            end
        end
    end
end


for a=1:6
    for b=1:6
        if b==a
            for h=1:5
                for ch=1:63
                    for c=1:4
                        for d=1:4
                            m{a,b}{h,ch}{c,d}=1;
                        end
                    end
                end
            end
        end
    end
end

The error was appeared in line 17 ( m{a,b}{h,ch}{c,d}=1; ),it showed that the cell contents assignment to a non-cell array object. Any solution to solve this type of error?


Solution

  • This is a horrible code.

    As for the error, the variable referenced to by m{a,b}{h,ch} was assigned in line 5 to a 4x4 array not a cellarray. Therefore, you should change line 17 to

    m{a,b}{h,ch}(c,d)=1;
    

    Note the difference between regular parentheses (when accessing arrays) and curly braces (when accessing cellarrays).