Try, Catch not working with system command.
显示 更早的评论
In my program I have the following block of code,
try
!"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" -r "foo"
catch
warning('Directory was not found. Please locate the MATLAB R2016b installation.');
[f2016, d2016] = uigetfile('*.exe','Locate MATLAB R2016b Executable');
cmd = strcat('!"',d2016,f2016,'" -r "foo"');
eval(cmd);
end
When I run it normally, everything works fine. But when I alter the path in try to create an error, the catch is never executed. Instead the program terminates and I'm left with "The system cannot find the path specified". This text isn't displayed as an error which is probably the issue, but is there any way to make my try, catch work? Or at least a workaround?
采纳的回答
更多回答(1 个)
Fangjun Jiang
2017-11-14
编辑:per isakson
2017-11-14
use system() to replace the "!" to call your program.
[status,result] = system('command')
Use the returned "status" to determine your next step.
类别
在 帮助中心 和 File Exchange 中查找有关 Manage Products 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!