【发布时间】:2012-11-21 09:49:14
【问题描述】:
有人知道我如何在我的 mac 上运行我的 tcl 脚本中的 matlab .m 文件。我想做一些链接这个:
-
在我的 .tcl 脚本中定义一些变量:
# run_matlab.tcl: set a 1; set b 2; set c 3; -
打开 matlab test.m 并使用预定义变量(在 tcl 中预定义)执行一些计算,例如:
% test.m D = [a b c]; E = [c b a]'; F = D*E -
回到 tcl 中基于 F 设置新变量(在 matlab 中计算)并使用 F 执行更多计算,例如:
# run_matlab.tcl: set m $F; set n [expr 3*$m]; puts $n
我是一个绝对的新手,不知道如何处理这个问题。有人可以帮帮我吗?
第一个解决方案
我已经做了一些事情,但我对此并不是 100% 满意。我的解决方案如下所示:
# test.tcl
# parameter definition
set a 7;
set b 5;
# calculation of 'e' in matlab
exec /Applications/MATLAB_R2012a.app/bin/matlab -nosplash -nodesktop -r test_matlab($a,$b);
# input calculated variables
# c = a+b = 2
# d = a-b = 12
source output.tcl
# do further calculations
set e [expr $c+$d];
puts $e
Matlab .m 文件看起来像这样:
function test_matlab(a,b)
% calculate a and b
c = a+b;
d = a-b;
% output
fprintf(fopen(['output.tcl'],'a+'),'set c %f;\n',c);
fprintf(fopen(['output.tcl'],'a+'),'set d %f;\n',d);
% quit matlab
quit
end
所以有人可以看到,我将使用 'source output.tcl' 加载我的计算数据。
但是:有没有办法让我的变量直接进入 tcl 变量?那么列表呢?如果我在matlab中计算了一个向量,如何直接将这个向量保存到一个列表中?
【问题讨论】:
-
有趣而清晰的问题。希望我能提供帮助,但我真的对如何与 Matlab 集成知之甚少……好吧,从任何东西都可以。 :-)
-
我相信你已经看到了,但以防万一:wiki.tcl.tk/4135。
-
我不知道,但这不是只适用于 mircosoft windows 吗? :S