Matlab中的'+'封装或模块化编程:python的导入模拟吗? [英] '+' packaging or modular programming in matlab: analog of python's import?

查看:279
本文介绍了Matlab中的'+'封装或模块化编程:python的导入模拟吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以Java或Python等语言为背景,其中通过打包系统和import指令(即名称空间别名)来启用模块化编程.从历史上讲,MATLAB解决诸如命名冲突之类的问题的方法归结为使用MATLABPATH进行设置/播放,使用前缀重命名/扩展标识符等.到目前为止,我已经通过在文件夹名称前加加号"+"成功地使用了本机MATLAB打包.包的MATLAB表示法也请参见此处) .显然,它们的键入时间很长;-)基本上,我会回到讨论的类似问题

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:

假设我定义了文件夹 + mypackage ,其中包含文件 myfun.m ,且功能代码相同.

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

如何在用户(非Java)包中为MATLAB函数实现别名,如以下python代码所示:

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 ] 请注意,AFAIK导入关键字仅对 java类(将jvm附加到MATLAB进程). 不,对于Java和MATLAB起源的对象和函数,对于函数和别名,导入都可以很好地工作.

[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.

可能相关,但与相同无关.

[ EDIT2 ]

python的

from mypackage import myfun as anotherfun

等同于MATLAB的

anotherfun = @mypackage.myfun

推荐答案

不是

import mypackage.myfun

工作吗?

链接到文档

这篇关于Matlab中的'+'封装或模块化编程:python的导入模拟吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆