I want to create a file for some utility functions, ie: utils.m, where utils would export a list of functions. But so far as I know, matlab can only export one function per .m file that takes on the name of the file? How do I get around this?
You don't really "get around" this - but it sounds like for this use case, packages would be an idea:
http://www.mathworks.de/de/help/matlab/matlab_oop/scoping-classes-with-packages.html
In your case, put all utility functions into a directory called +utils:
+utils
foo.m
bar.m
Then you can call foo and bar via
utils.foo(...)
If you really want all functions in one m-file, you could make utils a class with only static functions, something like:
classdef utils
methods (Static)
function foo(..)
end
function bar(..)
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With