MATLAB 代码的打包
在最近的问题“如何组织 MATLAB 代码?”Andrew Janke 在他的回答中提到使用类将 MATLAB 函数组织到包中:
...考虑使用无状态实用程序将一些代码重写为对象 以类方法和私有函数作为封装相关方式的类 一起发挥作用并提供一些封装。 ... 在 经典的 MATLAB,类是执行某种包的唯一方法。
请您提供更多相关信息吗?用于理解概念的链接、代码示例。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Loren 主持了一位客座博主讨论这个问题:
http://blogs.mathworks.com/loren/2008/08/18/when-to-create-classes-in-matlab/
我制作了一个关于此的简单视频:
http://博客。 mathworks.com/videos/2008/07/07/advanced-matlab-class-system-for-oop-in-matlab-introduction/
当然,MATLAB 文档:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_oop/brh2rgw。 html
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
不要使用类进行打包
Matlab 中的类有已知的限制(从 性能可扩展性等)。
在 MATLAB 中使用 OOP 之前,首先学习 “+”包装(即不是“@”或句柄)。
像
import foo.bar
这样的语句按预期工作(另请检查 这个)。警告:如果您确实需要 OOP,请考虑在 MATLAB 中执行此操作之前选择另一种语言。我必须将 OOP MATLAB 代码重写回函数和包,因为 Mathworks 的 OOP 实现“不成熟”。第一个麻烦是从
parfor
开始的,其中的内容必须以一定的开销进行序列化,但仍然经常中断。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.