Why does MATLAB terminate with no error message when using the UNIX redirection operator (<) to pass an input MATLAB file with a syntax error?

2 次查看(过去 30 天)
When a MATLAB file contains a control structure that does not terminate with an 'end' statement before the end of file is reached, no syntax error message is displayed when passing the file to MATLAB via the UNIX redirection operator (<).
if 1 disp('if!\n');
else disp('else!\n');
Calling the above script 'testif.m' using the syntax below will cause MATLAB to exit without displaying either the script output or an error message.
matlab -nodisplay < testif.m

回答(1 个)

Siddharth
Siddharth 2011-1-18
This issue is due to the way in which MATLAB interprets files that are passed to it via the redirection operator. MATLAB executes the file by reading each line as if it were typed at the MATLAB prompt. When it reaches the end of file, it continues to wait at the command prompt for the user to enter an ‘end’ statement; however, MATLAB exits once the end of the file is reached and before an 'end' is entered. It is the equivalent of entering each line of the M-file individually at the command line, then exiting MATLAB before typing the final ‘end’ statement. No error message is displayed in this case either. To work around this issue, call MATLAB using the following syntax:
matlab -nodisplay -r testif

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by