Detect if Simulink Project Shortcuts fail when working without GUI

2 Ansichten (letzte 30 Tage)
Andrew Chambers
Andrew Chambers am 13 Nov. 2015
Beantwortet: Snehal am 16 Jun. 2025
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?

Antworten (1)

Snehal
Snehal am 16 Jun. 2025
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!

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by