'+' packaging or modular programming in matlab: analog of python's import?

∥☆過路亽.° 提交于 2019-12-06 07:04:01

问题


I come with the background in languages like Java or Python where modular programming is enabled by packaging system and import directive (aka namespace aliasing). Historically MATLAB's approach to resolve problems like naming conflicts boils down to setting/playing with MATLABPATH, renaming/extending identifiers with prefixes, etc. So far I have been successfully playing with native MATLAB packaging by prepending plus sign "+" before the folder name (MATLAB notation for package also see here). Obviously they are very long to type ;-) Basically I am back to the similar problem as discussed here with no solution. So let me paraphrased for my particular angle:

Assume I have folder +mypackage defined containing file myfun.m with the function code of the same name.

How to achieve aliasing for MATLAB function inside the user (non-java) package as illustrated by the following python code:

from mypackage import myfun

?

[EDIT] Please note that AFAIK import keyword works only for java classes (with jvm attached to MATLAB process). No, import is working perfectly fine for both functions and aliases for objects and function of both Java and MATLAB origin.

Possibly related but not the same.

[EDIT2]

python's

from mypackage import myfun as anotherfun

is equivalent to MATLAB's

anotherfun = @mypackage.myfun

回答1:


Doesn't

import mypackage.myfun

work?

link to documentation



来源:https://stackoverflow.com/questions/13459284/packaging-or-modular-programming-in-matlab-analog-of-pythons-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!