代码之家  ›  专栏  ›  技术社区  ›  Oshio

Scilab语法错误:意外的endfunction,应为end

  •  0
  • Oshio  · 技术社区  · 5 年前

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

    syntax error: unexpected endfunction, expecting end
    

    有人能指出错误,我觉得一切都很好。

    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
    
    1 回复  |  直到 5 年前
        1
  •  1
  •   Stéphane Mottelet    5 年前

    这个 end 在事故发生后失踪 if then else