how to make function that sometimes return output and how to call

1 次查看(过去 30 天)
  • b sometimes returned from myfn and sometimes not returned, so how to write the function that may retrun b
function [a,b] = myfn(x,y)
a
if(x=y)
b
end
  • also how to call myfn from the main file if b is not returned
[a,b]=myfn(x,y)

采纳的回答

Stephen23
Stephen23 2017-10-22
Simplest solution: set a default output value:
function [a,b] = myfn(x,y)
a = 1;
b = [];
if(x=y)
b = 2;
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by