Effacer les filtres
Effacer les filtres

How to run Main Function saved in mfile that has many subfunction that are saved in separate mfiles but all has to run together due to iteration within main function?

1 vue (au cours des 30 derniers jours)
I am using R2016a version. I have a function file with a following structure -
function[out1, out2,...,out5]=MAINFUNCTION(inp1, inp2,inp3)
if nargin==2
statements of iteration
end
[lout1, lout2,]=LOCALFUN1(linp1,linp2)
[lout1, lout2,]=fmicon(@(X) LOCALFUN2(linp1,linp2),inpt6,)
[lout1, lout2,]=LOCALFUN2(linp1,linp2),inpt6,)
.
.
like this many subfunctions
.
.
end for MAIN FUNCTON
How to run this MAIN FUNCTION with all the sub functions saved in separate mfiles and can't be put in the main file due to optimisation restrictions put on them?
1. if I copy the entire function in command window i get error -Function definitions are not permitted in this context.
2. if I run from the RUN command the script I get error - Not enough input arguments.
what to do ?
  19 commentaires
NS
NS le 16 Oct 2018
No sir, apologies for my inability to explain to you my issue. What I meant was that these subfunctions are FUNCTIONs saved in their own respective mfiles starting with word function and ending with end BUT in Main function mfiles these subfunctions are called by the codes
[lout1, lout2,]=SUBFUN1(linp1,linp2)
and not starting with
function SUBFUNC1
end
How to run such functions?
Stephen23
Stephen23 le 16 Oct 2018
Modifié(e) : Stephen23 le 16 Oct 2018
"...BUT in Main function mfiles these subfunctions are called by the codes"
[lout1, lout2,]=SUBFUN1(linp1,linp2)
"and not starting with"
function SUBFUNC1
end
"How to run such functions?"
Just like your code already does, like this:
[lout1, lout2,]=SUBFUN1(linp1,linp2)
You do NOT define the function where it is called. When you need to call the function you just type its name, together with any input and output arguments... exactly as your code already does. This is explained in the MATLAB documentation, e.g. in the introductory tutorials, which explain how to call functions:
Are you having specific problems calling those functions? Do you get any warnings of error messages? If so, please show us the complete message.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Software Development Tools dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by