Call matlab from STATA
23 次查看(过去 30 天)
显示 更早的评论
Hello,
I basically want to call MATLAB from STATA to create a file, then returning the control to STATA. I have this piece of code:
cd "${REGCON_read_path}"
shell matlab -noFigureWindows -r "try; run 'regcon_cnae_map.m'; catch; end; quit" -wait
So MATLAB opens a session in the correct folder, but it seems that it just opens the script and closes it without 'clicking on run'. I would appreciate if somebody could tell me what I am doing wrong.
I guess this is the correct forum since I could well call matlab from the windows prompt instead.
KR
0 个评论
采纳的回答
the cyclist
2021-4-3
I haven't run MATLAB from the command line in probably 20 years, but I think I would try putting the whole try-catch structure into its own *.m file, and call that. (I am not able to test that idea right now.)
2 个评论
the cyclist
2021-4-5
For debugging purposes, I would try to simplify what you are doing. So, I'd recommend the following.
First, try not calling from Stata. Just call MATLAB from the command line directly, to see if that works. That would look like
matlab -noFigureWindows -r "try; run 'regcon_cnae_map.m'; catch; end; quit" -wait
I think I would also remove the quit statement, so that the MATLAB window stays open when it is done. Maybe you'll get a clue from the open MATLAB window. That simplifies the command to
matlab -noFigureWindows -r "try; run 'regcon_cnae_map.m'; catch; end" -wait
I think I would also remove the try-catch block. The way you have written this, MATLAB is told, "Try to run regcon_cnae_map.m, but if there is an error, do nothing." ("Do nothing", because there is no command after the "catch".) That simplifies the command to
matlab -noFigureWindows -r "run 'regcon_cnae_map.m'" -wait
or, even simpler
matlab -noFigureWindows -r "regcon_cnae_map" -wait
That is a more barebones version, that simply opens MATLAB and runs the file regcon_cnae_map.m. (Notice that this last version of the command does not have the ".m" at the end.)
My guess is that your file is going to throw some error, which is why the try-catch structure opened it and then shut it down.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!