Various inputs and outputs in functions
Afficher commentaires plus anciens
Hi. I have several techniques to find spots on an image and rather than have say 5 different functions I want to create one and pass in a "method" flag. My question is that each different method has a different number of inputs and outputs. Im not sure how to handles these, and help is greatly appreciated.
function[p1,p2,p3,p4,p5]=objectDetections(handles,image,x,y,par1,par2,method)
if method==1
//perform method 1 - requires inputs handles,image,x,y
// returns p1,p2
elseif method==2
//perform method 2 - handles,image,x,y, par1
//returns p1,p3
elseif method==3
//perform method 3 - handles,image,x,y, par1, par2
//returns p1,p2,p3,p4,p5
end
1 commentaire
Stephen23
le 9 Sep 2017
The simplest, clearest, neatest solution: use a structure. This is what MATLAB uses for many advanced functions that support multiple options, (e.g. optimization, ODE's, etc), and is simple to implement.
Réponse acceptée
Plus de réponses (1)
You could pass a structure to your function. The structure could contain whatever flags and arguments you need. Same goes for the output.
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!