matlab里如何写子函数

function result = MathSat(S)
if fabs(S) <= 0.15
{
result=S/0.15;
}
elseif S>0.15
{
result=1;
}
else
{
result=-1;
}
end

编写这样简单的一个子程序,可是报错
错误: 文件:MathSat.m 行:4 列:11
等号左侧的表达式不是用于赋值的有效目标。

1、matlab的循环体不用花括号围起来,所以把上面嗲嘛中所有花括号{}去掉即可

2、matlab中取绝对值函数为abs

function result = MathSat(S)
if abs(S) <= 0.15 
    result=S/0.15;
elseif S>0.15 
    result=1;
else
    result=-1;
end

温馨提示:答案为网友推荐,仅供参考
相似回答