wangzhkk 发表于 2015-10-29 21:37

我自己写的函数为什么是错的?

function =yzfun(x)
a = randn(2,1);
if a(1)*a(2)>=0
    y = a(1)*x;
else
    z = a(2)*x;
endError in yzfun (line 2)
a = randn(2,1);
Output argument "z" (and maybe others) not assigned during call to "E:\Matlab\yzfun.m>yzfun".

happy 发表于 2015-10-30 18:50

输出变量数量不对,比如修改为
function =yzfun(x)
a = randn(2,1);
if a(1)*a(2)>=0
    y = a(1)*x;
    z = 0;
else
    y = 0;
    z = a(2)*x;
end
页: [1]
查看完整版本: 我自己写的函数为什么是错的?