Figure open on every run
Show older comments
Hello i want my figure only open once and not on very new compile. I send the code but it still opens everytime i click run. I added the if equations but it didnt changed: Can you pls help me?
if ~exist('fig', 'var') || ~isvalid(fig)
fig = uifigure('Name', 'test', 'Position', [300, 300, 800, 600]);
% UI-Komponenten erstellen
layout = uigridlayout(fig, [1, 2]);
label1 = uilabel(fig, 'Position', [20, 500, 300, 60], 'Text', ['hello'],'FontWeight', 'bold');
label2 = uilabel(fig, 'Position', [130, 500, 300, 60], 'Text', ['hello'],'FontWeight', 'bold');
layout.ColumnWidth = {'1x', '1x'};
label3 = uilabel(fig, 'Position', [20, 350, 300, 60], 'Text', ['hello']);
label4 = uilabel(fig, 'Position', [20, 320, 300, 22], 'Text', ['hello']);
end
2 Comments
Manikanta Aditya
on 25 Mar 2024
Hi,
I think the issue is mostly due to the scope of fig variable. If you’re running this code in a function, the fig variable is local to that function. This means that every time you run the function, it doesn’t know about the fig from the last run.
max muster
on 25 Mar 2024
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!