MATLAB - MATLAB 32 位和 64 位之间的交互

MATLAB - interaction between MATLAB 32bit and 64bit

问题

我有两个用MATLAB写的工具(我不是作者):

  1. 第一个允许我从SQL数据库中检索一些数据,但它只适用于MATLAB 64位(我有 MATLAB 2016b 64 位)。
  2. 第二个使用从第一个工具检索到的数据,并通过 一个在 32 位系统上编译的 DLL,它会得到一些输出。如前所述, 此工具仅适用于 MATLAB 32 位(我有 MATLAB 2013a 32 位)。

我想做的是:

  1. 在 MATLAB 64 位
  2. 中从 SQL 获取数据
  3. "send them" 以某种方式升级到 MATLAB 32 位
  4. 运行 MATLAB 32bit 上的工具
  5. "return" 从 MATLAB 32 位到 MATLAB 64 位的输出

我知道可以使用 IPC 机制找到解决方案,但我不确定如何找到它们或如何在 MATLAB 中使用它们。有人用过这种东西吗?

查看 MATLAB 文档,我看到可以创建 COM 对象,但我不确定如何将它用于 运行 中的一些函数MATLAB 32 位.

解决方案

正如下面@nekomatic 所建议的,如果我按照建议的方式 运行 代码,但从下面的系统命令中排除 -automatic,那么一切都对我有用。 最终的系统命令形式为

system('"C:\path\to\R2013a\matlab.exe" -wait -r "mycommand; exit"')

mycommand 是一个加载输入文件的 MATLAB 脚本,它执行某些操作然后保存输出文件。

如果你不需要这个操作很快,最简单的方法可能是:

  • 将 64 位 MATLAB 中的数据保存为 .mat 文件
  • 使用system命令启动32位MATLAB实例
  • 运行 32 位 MATLAB 中的脚本,用于从文件中读取数据、处理数据并保存数据
  • 将结果读回您的 64 位程序。

例如 64 位代码(不包括错误处理、当前文件夹设置等)可能如下所示:

delete result.mat % Delete any result from the previous run
save(data.mat, '-v7.3') % usually best to specify the .mat format to use
system('"C:\path\to\R2013a\matlab.exe" -automation -wait -r "mycommand; exit"')
processedData = load('result.mat')

其中 mycommand 是您的 MATLAB R2013a 脚本,它从 data.mat 读取数据,对其进行处理,并将结果保存在 result.mat 中。

有关 R2013a 启动选项的更多数据 here (assuming Windows) and on the system command for R2016b here。您可能需要使用 Mathworks 帐户登录才能查看旧版本的文档,但如果这是一个问题,请查看各自 MATLAB 安装中的帮助。