保存并分享具有函数依赖关系的Matlab代码。

huangapple go评论89阅读模式
英文:

save \ share matlab code with function dependencies

问题

I wrote a Matlab script that calls some functions that are exist in my path (that I wrote as well).
我编写了一个Matlab脚本,调用了一些存在于我的路径中的函数(我也编写了这些函数)。

I'd like to share this code, but often I need to look for all these function dependencies and copy these functions one by one.
我想分享这段代码,但通常需要逐个查找所有这些函数的依赖关系并复制这些函数。

Is there an easy and automatic way to share my code such as all the functional dependencies are addressed?
是否有一种简便且自动的方法可以分享我的代码,以便处理所有功能性依赖关系?

For example
例如,

a = 1;
a = 1;
b = fun1(a^2); % fun1 is in some other folder in the matlab path
b = fun1(a^2); %fun1位于Matlab路径中的其他文件夹
c = fun2(b); % fun2 is in some other folder in the matlab path
c = fun2(b); %fun2位于Matlab路径中的其他文件夹
save_fully('my_code.zip') % the function I'd like to have that
save_fully('my_code.zip') %我想要的函数,用于生成包含运行示例所需的所有m文件的zip文件

英文:

I wrote a Matlab script that calls some functions that are exist in my path (that I wrote as well).
I'd like to share this code, but often I need to look for all these function dependencies and copy these functions one by one.
Is there an easy and automatic way to share my code such as all the functional dependencies are addressed?

For example

a = 1;
b = fun1(a^2); % fun1 is in some other folder in the matlab path 
c = fun2(b);    % fun2 is in some other folder in the matlab path
save_fully('my_code.zip') % the function I'd like to have that 
                          % generates a zip file with all the m files needed to run the example

答案1

得分: 4

你可以使用 matlab.codetools.requiredFilesAndProducts 来获取运行所需的文件和产品:

[fList, pList] = matlab.codetools.requiredFilesAndProducts('myScript.m');

然后只需将 fList 中列出的文件复制到一个文件夹中(例如,使用 copyfile),然后使用 zip 进行压缩。

英文:

Assume your example is called by a script called myScript.m. You can use matlab.codetools.requiredFilesAndProducts to get the required files and products for it to run:

[fList, pList] = matlab.codetools.requiredFilesAndProducts('myScript.m');

It is then just a matter of copying the files listed in fList to a folder (e.g., using copyfile) and zipping it using zip.

huangapple
  • 本文由 发表于 2023年6月29日 08:12:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定