Octave 在倍频程中查找分析错误

Octave 在倍频程中查找分析错误,octave,parse-error,Octave,Parse Error,我用Octave编写了一个简单的代码,但它一直报告我找不到的解析错误 X = magic(3) m = size(X, 1) p = zeros(m, 1) theta = [1;2;1] hypo = 1./(1.+exp(-X*theta)); for i = 1:m if hypo(i) > 0.5 p(i) = 1; else p(i) = 0; end 和倍频程报告 parse error near line 12 of fil

我用Octave编写了一个简单的代码,但它一直报告我找不到的解析错误

X = magic(3)
m = size(X, 1)
p = zeros(m, 1)
theta = [1;2;1]
hypo = 1./(1.+exp(-X*theta));
for i = 1:m
    if hypo(i) > 0.5
        p(i) = 1;
    else
        p(i) = 0;
end
和倍频程报告

 parse error near line 12 of file F:/my document/machine learning/machine-learning-ex2/ex2/new 1.m

  syntax error



error: source: error sourcing file 'F:/my document/machine learning/machine-learning-ex2/ex2/new 1.m'
error: parse error

但是,第12行没有内容。最后一行是11。我不知道哪里错了。

if语句以八度
endif
结尾(请参见:),for语句以
endfor
结尾(请参见:)

因此正确的代码应该是:

X = magic(3)
m = size(X, 1)
p = zeros(m, 1)
theta = [1;2;1]
hypo = 1./(1.+exp(-X*theta));
for i = 1:m
    if hypo(i) > 0.5
        p(i) = 1;
    else
        p(i) = 0;
    endif
endfor

您缺少用于终止
if
语句的
end
。正确的代码应如下所示:

X=magic(3)
m=尺寸(X,1)
p=零(m,1)
θ=[1;2;1]
hypo=1./(1.+exp(-X*θ));
对于i=1:m
如果hypo(i)>0.5
p(i)=1;
其他的
p(i)=0;

非常感谢你!我很愚蠢,我把Python和Octave的语法混在一起了。请注意,在stackoverflow上,如果一个答案解决了您的问题,您应该将其标记为已接受,否则它将持续为
未回答
我非常感谢您的好意!