I want to add several functions from a single .m file. Is this possible without actually having to create an individual m file for each function?
Asked
Active
Viewed 1.2k times
5
-
1Duplicate: [Is it possible to define more than one function per file in MATLAB?](http://stackoverflow.com/questions/3569933/is-it-possible-to-define-more-than-one-function-per-file-in-matlab). – gnovice Oct 25 '10 at 20:28
1 Answers
10
For later versions of Matlab that support the classdef
keyword, I recommend adding the functions as static methods to a class and then calling them from an instance of that class. It can all be done with one .m file:
classdef roof
methods (Static)
function res = f1(...)
...
end
function res = f2(...)
...
end
end
end
and you call them by
roof.f1();
roof.f2();

John Alexiou
- 28,472
- 11
- 77
- 133