MATLAB functions and subfunctions
Show older comments
I have a matlab function file which contains the main function which calls on many subfunctions. I would like to look at the output of the subfunctions in my program. How do I do this?
As it is now I have been making separate scripts to see what the output is of each of the individual subfunctions, I do not want to have to do it this way anymore.
Accepted Answer
More Answers (2)
John D'Errico
on 19 Aug 2014
0 votes
From your main function, return function handles for each subfunction. Then you can use them as independent functions.
Image Analyst
on 19 Aug 2014
You can make one m-file for them all. For example in test.m, you can have test(), sub1() and sub2() all in one single file:
function test()
out1 = sub1(10)
out2 = sub2(20)
function out = sub1(in)
fprintf('in = %f', in); % Or whatever you want to do.
function out = sub2(in)
fprintf('in = %f', in); % Or whatever you want to do.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!