Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 263
Yauhen Yakimovich Avatar asked Dec 10 '25 07:12

Yauhen Yakimovich


1 Answers

Doesn't

import mypackage.myfun

work?

link to documentation

like image 160
Jonas Avatar answered Dec 13 '25 07:12

Jonas