Detect if Simulink Project Shortcuts fail when working without GUI

2 visualizaciones (últimos 30 días)
Andrew Chambers
Andrew Chambers el 13 de Nov. de 2015
Respondida: Snehal el 16 de Jun. de 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?

Respuestas (1)

Snehal
Snehal el 16 de Jun. de 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!

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by