Is there a way to abort the running of startup scripts in Simulink Project based on a condition check ?

6 views (last 30 days)
I have a few scripts set as startup shortcuts in a Simulink Project. Whenever you open a Simulink Project all the startup scripts are run .However I need to know a way to abort the loading of the Simulink Project and close it in case a condition check fails in the startup script.

Answers (1)

Snehal
Snehal on 16 Jun 2025
I understand that you want a way to abort the loading of the Simulink Project and close it in case a condition check fails in the startup script.
Simulink Project executes all startup shortcuts after the ‘openProject’ command is executed to open a project in MATLAB. So normally the project is already opened by the time your script runs.
However, you can use the ‘if-else’ loop and ‘close’ function inside your startup script to close a project as soon as some condition fails.
Here is a sample code snippet for your reference:
% Inside your startup script:
% Perform your condition check first
if ~your_condition
% Access the currently loaded project
proj = currentProject;
% Display a message
warning('Condition failed. Closing project.');
% Close the project immediately
close(proj);
% (Optionally) you can error here if you want:
% error('Aborting due to failed condition.');
% After closing, you might want to return immediately
return;
End
% If condition passes, the script simply continues
You may refer to the following documentation links for more details:
Hope this helps!

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!