how to make function that sometimes return output and how to call
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
besbesmany besbesmany
le 22 Oct 2017
Commenté : besbesmany besbesmany
le 22 Oct 2017
- 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)
0 commentaires
Réponse acceptée
Stephen23
le 22 Oct 2017
Simplest solution: set a default output value:
function [a,b] = myfn(x,y)
a = 1;
b = [];
if(x=y)
b = 2;
end
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!