【发布时间】:2013-02-22 07:18:14
【问题描述】:
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;),表明单元格内容分配给了非单元格数组对象。有解决此类错误的解决方案吗?
【问题讨论】:
-
在第 17 行和第 18 行,用普通括号替换最后一个大括号:` m{a,b}{h,ch}(c,d)=1;` 和
p{a,b}{h,ch}(c,d)=1;。 -
@H.Muster 我们对
p了解多少?你确定它也是一个 4x4 数组而不是元胞数组吗? -
@Shai 是的,你是对的,我只是在没有考虑的情况下替换了那里的括号。但尽管如此,我敢打赌
p看起来就像m。 -
抱歉输入错误,感谢您的帮助!!
-
@TonyYEe - 请考虑使用
deal和cell命令来构造m。此外,当您为a==b设置m{}{}() = 1时,为什么要同时遍历a和b?使用for循环:for a=1:6, b = a; for h=1:5 ...等不是更简单吗???
标签: matlab if-statement for-loop cell