从终端/JAVA 更改 MATLAB 中的目录

发布于 2024-08-17 12:23:24 字数 200 浏览 2 评论 0原文

我需要能够更改 MATLAB 中的工作目录,而无需与命令窗口交互。我正在从 Java 应用程序启动 MATLAB。现在我想出的唯一解决方案是关闭 MATLAB,从 JAVA 更改目录并重新启动。有没有一些简化的方法可以从 JAVA 向 MATLAB 发送“cd”命令?从命令行执行此操作也可以,因为我可以使用 getRuntime().exec(command)

谢谢!

I need to be able to change the working directory in MATLAB without interacting with the command window. I'm launching MATLAB from a Java application. Right now the only solution I've come up with is closing MATLAB, changing directory from JAVA and relaunching. Is there some streamlined way to send MATLAB the 'cd' command from JAVA? Doing so from the command-line would also work, since I could use getRuntime().exec(command)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追我者格杀勿论 2024-08-24 12:23:24

如果您使用与 Matlab 相同的 JVM,则可以使用 JMI 来完成此操作(如果不是,那么我不知道)。关于此的在线信息并不多(WAY未记录/不受支持)。谷歌搜索或阅读以下内容:http://www.cs.virginia.edu /~whitehouse/matlab/JavaMatlab.html。简而言之,您需要包含Matlab的相关JAR文件,然后使用com.mathworks.jmi.Matlab的功能。例如:

Matlab.evalConsoleOutput("cd('C:\Program Files\')");

Yair Altman
http://UndocumentedMatlab.com

You can do this using JMI if you're using the same JVM as Matlab (if not then I have no idea). There is not much online info about this (it's WAY undocumented/unsupported). Google it or read this: http://www.cs.virginia.edu/~whitehouse/matlab/JavaMatlab.html. In short, you need to include Matlab's relevant JAR file and then use com.mathworks.jmi.Matlab's functionality. For example:

Matlab.evalConsoleOutput("cd('C:\Program Files\')");

Yair Altman
http://UndocumentedMatlab.com

樱娆 2024-08-24 12:23:24

我正在与斯蒂芬·波莱托(Stephen Poletto)合作,他发布了最初的问题。没有任何现有解决方案可以满足我们的需求,因此我们根据 Yair 提到的 Kamin Whitehouse 的工作编写了自己的解决方案。所有人都可以在 matlabcontrol.googlecode.com 上使用它。

它允许从 MATLAB 外部启动的 Java 程序控制 MATLAB。

I am working with Stephen Poletto who posted the original question. There wasn't any existing solution that met our needs so we wrote our own solution based off of Kamin Whitehouse's work mentioned by Yair. It is available for all to use at matlabcontrol.googlecode.com

It allows for controlling MATLAB from a Java program launched outside of MATLAB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文