Scilab语法错误:意外的endfunction,期待结束

问题描述 投票:0回答:1

我是scilab的新手,编写一个简单的函数会引发一个语法错误,这对我没有任何帮助。

syntax error: unexpected endfunction, expecting end

有人可以指出我的错误,一切似乎都很好。

我用.sci扩展名保存。

function y = bin2SignDec(bin)
    // Determines the signal of the binary number
    if part(bin, 1:1) == '0' then
        signal = 1;
    else
        signal = -1;

    // remove the signal bit from the string
    uBin = part(bin, 2:length(bin));

    // find the position of the decimal point and split the value in two variables
    pointIndex = strindex(uBin, '.');
    integerStr  = part(uBin, 1:(pointIndex-1));
    fractionStr = part(uBin, (pointIndex+1):length(uBin));

    // convert integer part to decimal
    integer = bin2dec(integerStr);

    // convert fraction part to integer
    fraction = 0;
    for i = 1:length(fractionStr)
        fraction = fraction + strtod(part(fractionStr, i:i)) * 2^(-i);
    end

    // return
    y = integer + fraction;

endfunction
scilab
1个回答
1
投票

end构造之后,if then else失踪了。

© www.soinside.com 2019 - 2024. All rights reserved.