Has anybody an idea how I'm able to run a matlab .m file out of my tcl script on my mac. I want to do something linke this:
definition of some variables in my .tcl script:
# run_matlab.tcl: set a 1; set b 2; set c 3;open matlab test.m and perform some calulations with the predefined variables (predefined in tcl), e.g.:
% test.m D = [a b c]; E = [c b a]'; F = D*Eback in tcl set new variables based on F (calculated in matlab) and perform some more calulations with F, e.g.:
# run_matlab.tcl: set m $F; set n [expr 3*$m]; puts $n
I'm an absolut newbie and have no clue how to handle this problem. Can anybody help me??
first solution
I've done something, but I'm not 100% satisfied with this. My solution looks like the following:
# 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
And the Matlab .m file does look like this:
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
So someone can see, that I'e to load my calculated data with 'source output.tcl'.
BUT: Is there a way to get my variables directly into tcl variables? And whats about lists? If I've calculated a vector in matlab, how can I directly save this vector in to a list?