Detect if Simulink Project Shortcuts fail when working without GUI

조회 수: 2 (최근 30일)
Andrew Chambers
Andrew Chambers 2015년 11월 13일
답변: Snehal 2025년 6월 16일
I have a simulink project that uses startup shortcuts. When running Matlab and Simulink in GUI mode, I can see a dialog box open and it says "Running startup shortcuts:" and it lists all of the shortcut scripts that are run after opening the project. When they are successful there is a little green check mark and if they fail there is a red X and a "Details..." button. I can click the Details button to get a error message if a script fails to complete.
When I open matlab in text only mode (matlab -nodisplay) and open my project using simulinkproject('MyProject.prj'), I cannot tell if the startup shortcuts are successful or not. There doesn't seem to be a way to detect if a script completes successfully or fails.
How can I can if the startup scripts are successful?

답변 (1개)

Snehal
Snehal 2025년 6월 16일
I understand that you want to track the success/failure of startup shortcuts when opening MATLAB in text-only mode.
You can achieve this by implementing either or both of the following workarounds:
  1. Exception Handling (try/catch)
  2. Writing logs or files upon failure
Here is a code snippet for reference:
% Exception Handling using ‘try-catch’ and MATLAB functions like ‘warning’:
try
% Your startup operations here
% If something fails, it will throw
catch ME
% Handle failure gracefully
warning('Startup script failed: %s', ME.message);
% Write to a log file for later diagnostics
fid = fopen('startup_error.log', 'a');
fprintf(fid, '%s\n', ME.message);
fclose(fid);
% (Optionally) close the project or raise an error
proj = currentProject;
close(proj);
error('Aborting due to startup failure');
end
The corresponding error log file can then be viewed when using a non-GUI (text-only) layout by executing the following command in the command window:
cat startup_error.log
% where ‘startup_error’ is the name of the log file
You may refer to the following documentation links for further details:
Hope this helps!

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by