如何将命令行参数传递给在Linux/Unix上运行的独立MATLAB可执行文件? [英] How can I pass command line arguments to a standalone MATLAB executable running on Linux/Unix?

查看:185
本文介绍了如何将命令行参数传递给在Linux/Unix上运行的独立MATLAB可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将命令行参数传递给独立的MATLAB可执行文件 在Linux/UNIX上运行?

How can I pass command line arguments to a standalone MATLAB executable running on Linux/UNIX?

我需要将我的MATLAB脚本编译为一个独立文件,可以在没有MATLAB的计算机上运行.它需要能够以类似于C的argv[]的方式工作,在其中您可以执行以下操作:

I need to compile my MATLAB script as a standalone file that can be run on a machine without MATLAB present. It needs to be able to work in a way similar to C's argv[], where you do the following:

命令行:

myfile argument1.txt argument2.txt

其中参数1和2是输入和输出文件.

where argument 1 and 2 are the input and output files.

确切的语法无关紧要,但是它应该像argv[]一样工作.有什么功能可以做到这一点?

The exact syntax doesn't matter, but it should work like argv[]. What is a function that could do this?

我的意思是我的计算机上有MATLAB,但是我需要制作一个独立的可执行文件,该文件可以在Unix系统上运行,而这些计算机上没有MATLAB(这是一个集群,在一个节点上只有MATLAB).我需要找到一种方法来制作varargin函数,而无需在运行该程序的计算机上安装MATLAB.如果我可以告诉MATLAB将MATLAB库放入每个可执行文件中,那么就可以了,只要它是一个完整的独立程序包即可.

What I mean is that I have MATLAB on my computer, but I need to make an standalone executable that can run on Unix systems WITHOUT MATLAB on those computers (it's a cluster, that only has MATLAB on one node). I need to find a way to make the varargin function without having MATLAB installed on the computer that's running the program. If I can tell MATLAB to put the MATLAB library in each executable, that's OK, as long as it's a complete standalone package.

推荐答案

MATLAB网站上有一个 完整示例,其中包含有关如何编译简单应用程序以及如何将其部署到另一台计算机上的说明.本质上,您需要安装 MATLAB Compiler Runtime与您的应用程序一起使用;安装程序 在您的MATLAB编译器中应该已经存在运行时 安装.

The MATLAB website has a worked-through example with instructions on how to compile a simple application and how to deploy it on another computer. In essence, you need to install the MATLAB Compiler Runtime together with your application; the installer for the runtime should already be present in your MATLAB compiler installation.

要将命令行参数传递给MATLAB可执行文件,请定义一个 可执行文件中的单个MATLAB函数: 函数是从命令行参数获取的(第一个命令行参数是第一个参数,依此类推).

To pass command-line arguments to a MATLAB executable, you define a single MATLAB function in the executable: the arguments to the function are taken from the command line parameters (the first command-line parameter is the first argument, and so on).

例如,使用以下命令创建文件echo.m 内容:

For example, create a file echo.m with the following contents:

function exitcode = echo(a, b)

display(a);
display(b);

exitcode = 0;

然后您可以编译该文件并使用echo 1 2 3运行它,然后 将打印a=1 b=2.

You can then compile this file and run it with echo 1 2 3, and it will print a=1 b=2.

请注意,从命令行获取参数时,它们是 作为 strings 传递给函数,因此您需要将它们转换为 使用str2num功能编号.例如:

Note that, when arguments are taken from the command line, they are passed to the function as strings, so you need to convert them to numbers using the str2num function. For instance:

function rc = display_product(a, b)

a = str2num(a);
b = str2num(b);

display(a*b);

rc = 0;

这篇关于如何将命令行参数传递给在Linux/Unix上运行的独立MATLAB可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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