[英]How to run a .m file from a tcl script (mac)
有谁知道我如何在Mac上的tcl脚本中运行matlab .m文件。 我想做一些与此相关的事情:
.tcl脚本中一些变量的定义:
# run_matlab.tcl: set a 1; set b 2; set c 3;
打开matlab test.m并使用预定义变量(在tcl中预定义)执行一些计算,例如:
% test.m D = [abc]; E = [cba]'; 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来简单地打印两个值(在单独的行上或在一行上以空格分隔)。 然后,在Tcl中:
set output [exec matlab ...]
lassign [split $output] c d
# do stuff with $c and $d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.