Calling Matlab from command line gives Caught unexpected exception of unknown type, why?

21 ビュー (過去 30 日間)
Javier Cuadros
Javier Cuadros 2021 年 4 月 9 日
コメント済み: Javier Cuadros 2021 年 4 月 9 日
I am trying to run my Matlab from the command line and I am getting a weird error when doing so. I call a script called test.m which looks like this
%% Housekeeping
clear all;
clc;
%% Update paths
addpath(genpath(pwd));
disp('INFO: OK');
I am calling it from command line in Windows via
C:\LocalData\Projects>matlab -nosplash -sd 'C:\LocalData\Projects\' -batch "run('test.m')"
and as response I get this
Caught unexpected exception of unknown type.
INFO: OK
So the script runs because it reaches the command to display INFO: OK but I am wondering, what is the error Caught unexpected exception of unknown type. referring to?
Running it with
C:\LocalData\Projects>matlab -nosplash -sd 'C:\LocalData\Projects\' -r "run('test.m')"
produces the same error within Matlab prompt
UPDATE:
Playing around with the pahts I have noticed that if I am in the path where test.m is and I provide the path to matlab with sd then I get the error
C:\LocalData\Projects>matlab -nosplash -sd 'C:\LocalData\Projects\' -batch "run('test.m')"
Caught unexpected exception of unknown type.
INFO: OK
However, if I omit the path with sd there is no error
C:\LocalData\Projects\>matlab -nosplash -batch "run('test.m')"
INFO: OK
In case I go to root and try to provide the path, I get the error plus test.m ìsn't found
C:\>matlab -nosplash -sd 'C:\LocalData\Projects\' -batch "run('test.m')"
Caught unexpected exception of unknown type.
Error using run (line 66)
test.m not found.
ERROR: MATLAB error Exit Status: 0x00000001
  6 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 9 日
could you remind us which version you are using?
Javier Cuadros
Javier Cuadros 2021 年 4 月 9 日
>> version
ans =
'9.9.0.1467703 (R2020b)'

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 9 日
clear all;
clear all asks MATLAB to destroy as much state as possible, leaving little more than what is stored in the current graphics objects. The state that is destroyed includes the variables that are used to tell run which directory to return to after the script is executed.
Do not call clear all from inside any program: save it for your one script that you use when you want to do the equivalent of "quit" followed by "restart"
  2 件のコメント
Javier Cuadros
Javier Cuadros 2021 年 4 月 9 日
Hi @Walter Roberson, I have removed
clear all
from the test, but still I running into the same issue
Caught unexpected exception of unknown type.
INFO: OK
What about clearvars , would it have same effect?
Walter Roberson
Walter Roberson 2021 年 4 月 9 日
clearvars would be a problem too in the context of run()

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by