从Matlab启动应用程序 [英] Start application from Matlab

查看:490
本文介绍了从Matlab启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从Matlab中启动应用程序的方法.事实是,我的Matlab脚本将一些结果保存到文件中,然后应在关联的应用程序(在这种情况下为Blender)中打开该文件.

I'm looking for a way to start an application from within Matlab. The thing is, my Matlab script saves some results to a file, which should then be opened in the associated application (Blender in this case).

我熟悉

system('program_name')

!program_name

和其他一些方法,但实际上,该应用程序是从Matlab PATH启动的,因此它在Matlab目录中查找所需的各种库.例如:

and some other ways, but the thing is, the application is started with the Matlab PATH, so it looks inside the Matlab directory for all kinds of libraries it needs. For instance:

>> !blender
blender: /usr/local/MATLAB/R2011a/sys/os/glnx86/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by blender)

是否有某种方法可以启动使用全局(系统)PATH的应用程序?

Is there some way to start an application, which uses the global (system) PATH?

不久前,我以为我发现了一个调整,即从Matlab内部启动一个带有一些参数(Blender filename.blend)的终端.

A moment ago I thought I found a tweak, namely starting a terminal from within Matlab, with some arguments (Blender filename.blend).

system('terminal -x blender /home/pieter/Red.blend')

这确实工作了几次,但是现在执行此命令大约20次后我出现了错误...

This did work a couple of times, but now I'm getting errors after executing this command 20 times or so...

>> system('terminal -x blender /home/pieter/Red.blend')
(terminal:10982): GLib-CRITICAL **: PCRE library is compiled without UTF8 support
(terminal:10982): Terminal-CRITICAL **: Failed to parse regular expression pattern 0: PCRE library is compiled without UTF8 support

顺便说一下,我正在使用Arch Linx.

I'm using Arch Linx, by the way.

修改:

好吧,我只是想到了一个比较肮脏的解决方案. Matlab使用环境变量

Well, I just thought of a rather dirty solution. Matlab uses the environment variable

LD_LIBRARY_PATH

获取必要库的路径:

getenv('LD_LIBRARY_PATH')
/usr/local/MATLAB/R2011a/sys/os/glnx86:/usr/local/MATLAB/R2011a/bin/glnx86:/usr/local/MATLAB/R2011a/extern/lib/glnx86:/usr/local/MATLAB/R2011a/runtime/glnx86:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386/native_threads:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386/client:/usr/local/MATLAB/R2011a/sys/java/jre/glnx86/jre/lib/i386

因此我可以将此信息保存到变量(例如 MatlabPath ):

So I could save this information to a variable (e.g. MatlabPath):

MatlabPath = getenv('LD_LIBRARY_PATH')

然后在我打电话给Blender之前先做以下事情:

and then before I call blender do this:

setenv('LD_LIBRARY_PATH',getenv('PATH'))

这使Matlab使用我的系统库.然后,在程序启动后,将旧值重新分配给LD_LIBRARY_PATH:

Which makes Matlab use my system libraries. Then after the program has started, re-assign the old value to LD_LIBRARY_PATH:

setenv('LD_LIBRARY_PATH',MatlabPath)

所以...这是一个解决方案,但是如果有人知道解决问题的更简洁的方法,请告诉我.

So... it is a solution, but if anybody knows a cleaner way of solving the problem, let me know.

推荐答案

正如我在上面的编辑"中指出的那样,这可能是一个解决方案:

As I indicated in my Edit above, this could be a solution:

% Save library paths
MatlabPath = getenv('LD_LIBRARY_PATH');
% Make Matlab use system libraries
setenv('LD_LIBRARY_PATH',getenv('PATH'))
disp('Starting Blender...')
system( ['blender ', Directory, FileName, '.blend'] )
% Reassign old library paths
setenv('LD_LIBRARY_PATH',MatlabPath)

但是,通过另一种方式启动应用程序,您可以在启动后立即返回Matlab:

However, with the other way to start an application, you can immediately return to Matlab after starting it:

% Start Blender and immediately return to Matlab
!blender Geometry.blend &

&符(& )是启动应用程序后立即返回到Matlab的关键,但是以这种方式启动Blender时,我无法像使用 system( ...).

The ampersand (&) is the key to immediately return to Matlab after starting the application , but starting Blender this way I cannot provide a variable FileName like I can do with system(...).

所以,任何人都知道如何做

So, anybody got a clue on how to

  • 使用!program_name 和可变的文件名

使用 system(program_name)和一个选项,使Matlab仅启动应用程序(并且不等待返回,直到应用程序关闭)

use system(program_name) with an option such that Matlab just starts the application (and doesn't wait with returning until the application has been closed)

这篇关于从Matlab启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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