yuk
yuk

Reputation: 19870

Packaging of MATLAB code

In the recent question "How to organize MATLAB code?" Andrew Janke mentioned in his answer using classes to organize MATLAB functions into packages:

... consider rewriting some of the code as objects, using stateless utility classes with class methods and private functions as ways of packaging related functions together and providing some encapsulation. ... In classic MATLAB, classes are your only way of doing some sort of packages.

Would you please provide more information on it? Links, code examples to understand the concept.

Upvotes: 3

Views: 812

Answers (2)

Yauhen Yakimovich
Yauhen Yakimovich

Reputation: 14211

Don't use classes for packaging

Classes in Matlab has known limitaitons (starting with performance scalability, etc). Before going into using OOP in MATLAB, first learn "+" packaging (i.e. not "@" or handles).

Statements like import foo.bar work just as expected (also check this).

A word of caution: if you really need OOP, just consider picking another language before doing it in MATLAB. I had to rewrite my OOP MATLAB code back to functions and packages because OOP implementation by Mathworks is just "immature". First troubles start with parfor where stuff has to be serialized with an overhead and then still breaks way too often.

Upvotes: 2

Related Questions