【发布时间】:2015-12-07 02:38:48
【问题描述】:
我在matlab中有一个函数,开头如下:
function [W,Y] = myfun(L,nit)
W = cell(L,1);
x = cell(L+1,1);
...
所以W 和x 被初始化为长度为L 的元胞数组,然后我继续在函数体中对它们进行实际操作。但是matlab的编辑器在cell的第一次用法下有红色的波浪线,并带有消息:
variable 'cell' is used but might be unset
如果我尝试在我的主脚本中调用该函数,我会收到错误:
"cell" previously appeared to be used as a function or command, conflicting
with its use here as the name of a variable.
A possible cause of this error is that you forgot to initialize the
variable, or you have initialized it implicitly using load or eval.
我不明白为什么 matlab 认为我将 cell 称为变量名。我可以执行任一行
W = cell(L,1);
x = cell(L+1,1);
在此特定功能之外,它们按预期工作。我在其他函数中创建了单元格数组而没有出现任何错误。如果我使用命令
exist cell
我得到的答案是 5,表明cell 仍然是一个内置函数。所以我很困惑。
【问题讨论】:
-
这很奇怪!你用的是什么版本的matlab?同时,您可以使用
W{L,1}=[]和x{L+1,1}=[]来创建您的元胞数组。 -
所以在你的主脚本中,如果你在调用
myfun之前的行中使用cell会抛出错误,没有错误? -
你有没有去工具 -> 代码分析器看看它给了你什么?
-
@David 确实有效,感谢您的解决方法。
-
@zeeMonkeez:正确
标签: matlab