English 中文(简体)
我为什么在本MATLAB代码中出现“不确定功能或变数<可变名称”错误?
原标题:Why do I get an "Undefined function or variable <variable name>" error in this MATLAB code?
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 <= max_iteration
  iter = iter + 1;
  globalerror = 0;
  for p = 1:count
    output = calculateOutput(weights,x(p),y(p));
    localerror = T_Q2(p) - output
    weights(1)= weights(1) + learningrate *localerror*x(p);
    weights(2)= weights(1) + learningrate *localerror*y(p);
    weights(3)= weights(1) + learningrate *localerror;
    globalerror = globalerror + (localerror*localerror);
  end 
end  

在其他一些档案中,我写了这本fu。

function result = calculateOutput (weights, x, y)
s = x * weights(1) + y * weights(2) + weights(3);
if s >= 0
    result = 1;
else
    result = -1;
end

没有。 我在指挥窗口和报界的守则中穿过......在窗户上没有 app。 如何获得产出?

最佳回答

您可以在休息时间进行情况检查时使用<代码>的变数代码>,因为你没有将变数定义为<>在的休息时间。 正因为如此,你正在发现“不确定功能或变异的全球变体”错误。 您必须首先将globalerror / to some Value before ,你试图在任何发言中使用。

此外,正如我在中提到的那样 回答你先前的问题,你可以在文字中宣布职能。 缩略语 从上述文字中删除,并将其放在自己的档案中:calculateOutput.m,然后在MATLAB路

我看到的另外几个问题:

  • MATLAB uses 1-based indexing, not 0-based indexing. In other words, the first element of a vector or a matrix dimension is indexed by the value 1, not 0.
  • 我对你试图与这一路线做些什么没有想法:

    localerror = output(p) - output
    

    由于变量<代码>output 是scalar,载于您的代码,而不是vector,可按<代码>p加以索引。

问题回答

暂无回答




相关问题
MATLAB Solving equations problem

I want to solve these equations using MATLAB and I am sure there is a non zero solution. The equations are: 0.7071*x + 0.7071*z = x -0.5*x + 0.7071*y + 0.5*z = y -0.5*x - 0.7071*y +...

Difference between MATLAB s matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = ...

preventing data from being freed when vector goes out of scope

Is there a way to transfer ownership of the data contained in a std::vector (pointed to by, say T*data) into another construct, preventing having "data" become a dangling pointer after the vector goes ...

Divide two polynomials using MATLAB

I want to divide p(x) by q(x) given that: p(x)=-5x^4+3x^2-6x q(x)=x^2+1 I tried: p=inline( -5*(x^4)+3*(x^2) , x ) p = Inline function: p(x) = -5*(x^4)+3*(x^2) q=inline( x^2+1 , x ) q = ...

matlab deals with Fibbonacci

The Fibonacci series is given as follows: 1, 2, 3, 5, 8, 13, 21, ... How can I write a script which calculates and prints the n-th Fibonacci term (for n>2), where n is inputed by the user. This ...

How do I plot lines between all points in a vector?

I have a vector containing some points in 2-D space. I want MATLAB to plot these points with lines drawn from every point to every other point. Basically, I want a graph with all vertices connected. ...

How do I create a string using a loop variable in MATLAB?

I have a loop like this: for i=1:no %some calculations fid = fopen( c:\out.txt , wt ); %write something to the file fclose(fid); end I want data to be written to different files like ...

热门标签