'+' packaging or modular programming in ma

2019-04-11 15:30发布

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条回答
再贱就再见
2楼-- · 2019-04-11 16:03

Doesn't

import mypackage.myfun

work?

link to documentation

查看更多
登录 后发表回答