我是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
答案 0 :(得分:1)
end
构造后缺少if then else
。