【发布时间】:2019-03-01 00:49:05
【问题描述】:
在做 matlab 作业时,我遇到了一个非常奇怪的错误。这是我的代码:
function [z,times] = Divide(x,y)
persistent times;
if (y == 0)
if (isempty(times))
times = 1;
else
times = times + 1;
end
end
z = x/y;
end
运行时,这给了我错误:
Error: File: Divide.m Line: 3 Column: 16
The PERSISTENT declaration must precede any use of the variable times.
这很奇怪,因为它告诉我需要在将变量声明为持久变量之前将其声明为持久变量(!?)。我不知道我在这里做错了什么,所以如果我应该使用一些奇怪的解决方法,请告诉我。
【问题讨论】:
标签: matlab compiler-errors persistent