How can I call sub-functions in the Main function

67 vues (au cours des 30 derniers jours)
Thibedi Malotana
Thibedi Malotana le 29 Mai 2020
Commenté : Cris LaPierre le 30 Mai 2020
So I have four functions and 3 of them are sub-functions and I am told that the 1 main function must call the other 3 functions in its execution I would please like to know how to call these sub-functions in my main code when I am using MATLAB grader
  2 commentaires
Ameer Hamza
Ameer Hamza le 29 Mai 2020
How do you define "sub-functions"? Are they just normal functions defined in 3 separate files?
Thibedi Malotana
Thibedi Malotana le 29 Mai 2020
Yes they are just 3 different functions in separate files

Connectez-vous pour commenter.

Réponses (1)

Ameer Hamza
Ameer Hamza le 30 Mai 2020
Modifié(e) : Ameer Hamza le 30 Mai 2020
I haven't used MATLAB grader, but you should be able to call them like normal MATLAB functions.
function main % name of main function
y = sub_fun1(x1, x2, x3) % name of a sub-function, x1 x2 x3 are input arguments
% similar lines for sub_fun2 and sub_fun3
end
You can read following documentation to read about basics of function definition and call in MATLAB
  1 commentaire
Cris LaPierre
Cris LaPierre le 30 Mai 2020
I assume the 3 subfunction have been provided for you. They exist in the current folder. The instructor will have had to have provided you with information on what their inputs and outputs are. Call them like you would any other function: [outputs] = funcName(inputs);

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by