【问题标题】:matlab error: variable 'cell' is used but might be unset : matlab thinks function name is variable namematlab 错误:使用了变量“cell”,但可能未设置:matlab 认为函数名是变量名
【发布时间】:2015-12-07 02:38:48
【问题描述】:

我在matlab中有一个函数,开头如下:

function [W,Y] = myfun(L,nit)
W = cell(L,1);
x = cell(L+1,1);
...

所以Wx 被初始化为长度为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


【解决方案1】:

我遇到了同样的问题。结果我后来在函数中出现了一个错字(很多),我调用了单元格而不是变量:

function [conn] = myfun(nn)

conn = cell(nn,1); 

.
.
.

conn{i} = unique( cell{i} ); 

而不是:

conn{i} = unique( conn{i} );

导致错误的原因。

【讨论】:

    猜你喜欢
    • 2015-03-11
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    相关资源
    最近更新 更多