从m.file运行C ++程序 [英] Running a C++ program from an m.file

查看:83
本文介绍了从m.file运行C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在从事的项目,我正在MATLAB中准备数据,然后通过名为Model v2.exe的单独外部应用程序(用C ++编写)运行数据,然后使用MATLAB中的输出执行进一步的分析.我正在尝试创建一个可以完成所有这些操作的M文件,但我正努力从我的MATLAB代码中启动C ++程序.

For a project I am working on I'm preparing data in MATLAB, then running the data through a separate external application (written in C++) named Model v2.exe, then performing further analysis with the output in MATLAB. I'm trying to create an M-file which does all of this, but I am struggling to get the C++ program to launch from my MATLAB code.

如何从我的MATLAB代码中启动外部应用程序?

How can I launch an external application from within my MATLAB code?

推荐答案

您可以使用!运算符或system()命令.

You can either make use of the ! operator, or the system() command.

首先,将应用程序重命名为名称中没有空格的名称,例如modelv2.exe.接下来,要么确保它位于系统环境变量定义的系统路径中,要么生成它的完整路径(例如:C:\Users\Phil\Desktop\modelv2.exe).

First, rename you application to something that has no spaces in the name, like modelv2.exe. Next, either make sure it is in the system path, as defined by your system environment variables, or generate a full path to it (eg: C:\Users\Phil\Desktop\modelv2.exe).

您可以使用感叹号或系统命令从命令行调用可执行程序:

You can call an executable program from the command line using the exclamation point or the system command:

!modelv2

或:

!C:\Users\Phil\Desktop\modelv2.exe

如果在当前目录或系统路径中有这样的文件,

将导致Windows执行程序hello.exe.或者:

will cause Windows to execute the program hello.exe if there is such a file in the current directory or on the system path. Alternatively:

system('modelv2');

system('C:\Users\Phil\Desktop\modelv2.exe');

会做同样的事情.

参考

  1. "MATLAB中心-在Windows下在matlab中调用和运行外部程序",已访问2014-03-19, 查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆