Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does matlab have modules?

Tags:

matlab

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?

like image 801
xiaolingxiao Avatar asked Nov 17 '25 16:11

xiaolingxiao


1 Answers

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
like image 159
sebastian Avatar answered Nov 20 '25 13:11

sebastian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!