开发者

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.

Woul开发者_如何学JAVAd you please provide more information on it? Links, code examples to understand the concept.


Loren hosted a guest blogger to discuss this issue:

http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/

I made a simple video about this:

http://blogs.mathworks.com/videos/2008/07/07/advanced-matlab-class-system-for-oop-in-matlab-introduction/

Of course the MATLAB documentation for this:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brh2rgw.html


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜