Not same fprintf MATLAB and Linux Console

3 ビュー (過去 30 日間)
Javier Naranjo
Javier Naranjo 2017 年 10 月 10 日
編集済み: Jan 2017 年 10 月 19 日
Hello everybody,
I am trying to catch an error and I have made the following code in Matlab:
catch ME
% Some error occurred if you get here.
errorMessage1 = sprintf('Error in function %s()\n',ME.stack.name);
errorMessage2 = sprintf('Error in line %d\n',ME.stack(1).line);
errorMessage3 = sprintf('Error %s()\n',ME.message);
fprintf(2,'-----------------------------\n');
fprintf(2,'%s\n', errorMessage1);
fprintf(2,'-----------------------------\n');
fprintf(2,'%s\n', errorMessage2);
fprintf(2,'-----------------------------\n');
fprintf(2,'%s\n', errorMessage3);
The output of Matlab is the following one:
Error in hello()
Error in line 386
Error Index exceeds matrix dimensions.()
But, when I execute matlab from de Linux console:
./matlab < hello.m
I just get this output:
Index exceeds matrix dimensions
I cannot see the line or the .m I am running.
What kind of problem is this?
Thanks in advance,
Javi

採用された回答

Jan
Jan 2017 年 10 月 10 日
編集済み: Jan 2017 年 10 月 10 日
If you write the message to stderr by
fprintf(2, '%s\n', errorMessage1);
you have to catch this channel also. Try:
fprintf(1, '%s\n', errorMessage1);
Perhaps this works instead, but I cannot try it currently and hopefully someone corrects me:
matlab -r hello.m 2>&1
  12 件のコメント
Javier Naranjo
Javier Naranjo 2017 年 10 月 19 日
/folder1/getOutput.m
|
Error: Unexpected MATLAB operator.
I tried with single and doble quotes and it did not work.. When I write down double it says too many input arguments.
Thanks
Jan
Jan 2017 年 10 月 19 日
編集済み: Jan 2017 年 10 月 19 日
@Javier: Sorry, my mistake.
./matlab -r "cd('~/folder1'); getOutput" -nosplash -nodesktop
The parameter of the -r command must contain a valid Matlab command, not the path of a m-function. You can find more details in the documentation: https://www.mathworks.com/help/matlab/matlab_env/startup-options.html

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by