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

3 次查看(过去 30 天)
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 个评论
Bernhard
Bernhard 2024-12-4
编辑:Bernhard 2024-12-4
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
Bernhard
Bernhard 2024-12-4
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.

请先登录,再进行评论。

回答(1 个)

Jaimin
Jaimin 2024-12-4
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.

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by