I want to open figure only when user dialog of mask is open

I have a mask with a user dialog. I have a few issues with a figure at this dialog:
1) If the dialogue is open then the function "opening_diagram_callback" should be open and if the user changes anything, this figure should be updatet.
2) If the user closes the user dialog the figure should be also closed automatically.
3) If the simulation is started the figure shouldn't appear.
At first I tried it to put the "opening_diagram_callback" function in the init function. But then the second point isn't possible and it also appears during simulation because there it also runs through the init function.
Can someone please help me with this problem??

3 Comments

Could you please share your Simulink model for reproducing the issue?
ok it is really a lot but i hope this helps you: this is the init function
function init_function()
%% add the paths of the subfolders
block_path = fileparts(gcs);
addpath(fullfile(block_path, 'block_functions'));
addpath(fullfile(block_path, 'callbacks'));
addpath(fullfile(block_path, 'draw_image'));
addpath(fullfile(block_path, 'error_functions'));
addpath(fullfile(block_path, 'init_functions'));
addpath(fullfile(block_path, 'saved_data'));
opening_diagram_callback();
end
This is the opening_diagram_callback() function:
function opening_diagram_callback()
persistent fig
[~,~,~,~,~,max_ports,~] = general_params();
load("saved_data/act_orifice_opening.mat")
pos_boundaries = str2num(get_param(gcb, "pos_boundaries"));
n = max_ports*(max_ports - 1)/2;
% initialize window
if isempty(fig) || ~isvalid(fig)
% Neues Fenster erstellen
fig = figure('Name', 'Orifice Openings');
set(fig, 'Position', [150, 200, 650, 400]);
else
% Existierendes Fenster verwenden
figure(fig);
clf(fig);
end
%% plotting commands .....
end
Maybe i can ask for the status of the user dialogue window:
If it is open, then it should show the figure, otherwise it should be closed.
But I don't know how to do that. I already tried with "set_param(gcb, 'UserData', 'closed');" in the CloseFcn Callback and with "set_param(gcb, 'UserData', 'open');" in the InitFcn Callback. But it doesn't change my status, the status is empty if I ask for that.

Sign in to comment.

Answers (1)

To address your issues with the dialog and figure management in Simulink, consider the following two resources that might help you find a solution:
  1. Initialize Mask – Simulink (https://www.mathworks.com/help/simulink/ug/initialize-mask.html): This documentation provides detailed information on how to initialize masks in Simulink. It explains how to use initialization commands to manage callbacks like “opening_diagram_callback”, ensuring that figures are correctly updated and managed based on user interactions.
  2. Author Mask Init Callback – Simulink (https://www.mathworks.com/help/simulink/ug/author-mask-init-callback.html): This guide offers insights into authoring mask initialization callbacks in Simulink. It includes instructions on implementing callbacks that can help manage the opening and closing of figures in response to dialog events, without interfering with simulations.
To prevent the image from displaying during simulation, utilize the “SimulationStatus” property of “bdroot”.
Kindly refer following code snippet for understanding.
isSimulating = strcmp(get_param(bdroot, 'SimulationStatus'), 'running');
I hope this will be helpful.

Categories

Find more on Graphics Objects in Help Center and File Exchange

Products

Release

R2023a

Asked:

on 4 Dec 2024

Commented:

on 4 Dec 2024

Community Treasure Hunt

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

Start Hunting!