필터 지우기
필터 지우기

warnings and erros in matlab

조회 수: 6 (최근 30일)
Tomas Iesmantas
Tomas Iesmantas 2011년 7월 18일
Hi, Is there any way to write all warnings and errors ocurred in simulation\calculation to some text file?
I generate simulink model automatically and the simulating it through COM. I need to have all errors and warnings occured during simulation in one file.
Thanks in advance,
Tomas

답변 (2개)

Jan
Jan 2011년 7월 18일
I use a dedicated function for logging warnings and errors: The functions is used instead of WARNING and ERROR and writes all messages in a file, which is opened once at the beginning. Unexpected errors have to be caught by TRY/CATCH then.
function myLog(Command, Caller, Msg)
persistent FID
switch Command
case 'open'
FID = fopen(Caller, 'w');
case 'close'
fclose(FID);
FID = -1;
case 'warning'
fprintf(FID, 'warning: %s: ', Caller);
if iscellstr(Msg)
Msg = sprintf(FID, '%s\n', Msg{:});
Msg(end) = [];
end
fprintf(FID, '%s\n', Msg);
% Perhapse: warning([Caller, ': ', Msg])
% or: fprintf(2, '%s\n', Msg);
case 'error'
fprintf(FID, 'error: %s: ', Caller);
if iscellstr(Msg)
Msg = sprintf('%s\n', Msg{:});
Msg(end) = []; % Remove trailing line break
end
fprintf(FID, '%s\n', Msg);
% Perhaps: error([Caller, ': ', Msg])
% or: fprintf(2, '%s\n', Msg);
end
Now this creates the messages:
myLog('open', fullfile(tempdir, 'logfile.txt'));
myLog('warning', 'Project 1', 'totally nonsense');
myLog('error', 'Project 1', {'Completely', 'wrong'});
myLog('close');

Friedrich
Friedrich 2011년 7월 18일
Hi,
I think the diary command can help you here:
  댓글 수: 1
Tomas Iesmantas
Tomas Iesmantas 2011년 7월 18일
But it creates file with whole commands used in matlab window. But I need to have just errors\warnings and whithout other commands.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by