单元格内容分配给非单元格数组对象

时间:2013-03-07 07:21:07

标签: matlab if-statement for-loop cell

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

错误出现在第17行(m{a,b}{h,ch}{c,d}=1;)中,它显示了单元格内容分配给非单元格数组对象。解决此类错误的任何解决方案?

1 个答案:

答案 0 :(得分:2)

这是一个可怕的代码。

对于错误,m{a,b}{h,ch}引用的变量在第5行中分配给4x4 数组而不是cellarray。因此,您应该将第17行更改为

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

注意常规括号(访问数组时)和花括号(访问cellarrays时)之间的区别。