![]() |
为什么我得到“未定义的函数或变量此MATLAB代码中的错误?
load X_Q2.data load T_Q2.data x = X_Q2(:,1); y = X_Q2(:,2); learningrate = 0.2; max_iteration = 50; % initialize parameters count = length(x); weights = rand(1,3); % creates a 1-by-3 array with random weights globalerror = 0; iter = 0; while globalerror ~= 0 && iter = 0 result = 1; else result = -1; end 什么都没出来。我在命令窗口中输出了代码,然后按Enter...。我如何获得输出?
[B]回答:[/B] 您不能在while循环的条件检查中使用变量globalerror ,因为您直到[I]在[/I]循环[I]内[/I]才将变量定义为任何变量。这就是为什么出现错误“未定义的函数或变量'globalerror'”的原因。您必须将globalerror初始化为某个值, [I]然后[/I]再尝试在任何语句中使用它。 另外,正如我在[URL="https://stackoverflow.com/questions/3445484/matlab-syntax-errors-in-single-layer-neural-network/3445610#3445610"]回答上一个问题时[/URL]提到[URL="https://stackoverflow.com/questions/3445484/matlab-syntax-errors-in-single-layer-neural-network/3445610#3445610"]的那样[/URL] ,您不能在脚本中声明函数。尝试从上面的脚本中剪切出函数calculateOutput ,并将其放置在名为自己的文件calculateOutput.m ,然后将其保存在[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/br7ppws-1.html"]MATLAB路径[/URL]中的某个位置。 还有一些其他问题: [LIST][*] MATLAB使用基于1的索引,而不使用基于0的索引。换句话说,向量的第一个元素或矩阵维度的索引值为1,而不是0。[*]我不知道您要使用此行做什么: localerror = output(p) - output 由于变量output是代码中的[I]标量[/I] ,而不是可以由p索引的[I]向量[/I] 。 [/LIST] [url=https://stackoverflow.com/questions/3452611]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 01:04。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.