Clear Filters
Clear Filters

app.UIFigure = uifigure(); creates a new UIfigure window and the original app is not accessible through app.UIFigure

6 views (last 30 days)
This is a continuation to Adam Danz's answer to:
While I get the plot by copyobj(), my app.uifigure is changed from app main window to the new window.
I can close the new app.uifigure, close(app.UIFigure) but the old one is still lost. So I cannot use some button down functions!

Accepted Answer

Adam Danz
Adam Danz on 20 Sep 2023
Edited: Adam Danz on 21 Sep 2023
the first two lines of my answer in the thread you linked to were just to simulate app desgner. These two lines, copied below, can be removed from your implementation.
app.UIFigure = uifigure();
app.UIAxes = uiaxes(app.UIFigure);
The code in the red box in the image in your question should appear like this
  1. I've removed the first two lines
  2. I've changes app.UIAxes to app.UIaxes2 since I think this the variable that stores your axes.
% Plot cfit object externally.
a = linspace(0,10,10)';
b = linspace(0,20,10)';
[fitline,gof] = fit(a, b, 'poly1');
fig = figure('Visible','off'); % you may want to set this to "on" to see what's happening
ax = axes(fig);
h = plot(fitline,a,b);
% Copy content of temp axes to app designer
hApp = copyobj(h, app.UIAxes2);
% You'll need to recreate the legend since it isn't independently copied
lh = legend(app.UIAxes2);
% Delete temp figure
delete(fig)
  3 Comments
Adam Danz
Adam Danz on 21 Sep 2023
Ha! Sorry, I updated the tag.
If I understood your follow-up question correctly, you can add as many graphics objects you want by following this template
ax = axes(fig);
hold(ax,'on')
h1 = _____
h2 = _____
h3 = _____
% Copy content of temp axes to app designer
hApp = copyobj([h1,h2,h3] app.UIAxes2);
However, it's much better to directly plot to your app axes by specifying the parent handle as the first option input:
plot(app.UIAxes2,____)
The reason you can't do this with fitline is because it uses a different version of plot() that does not support the optional parent argument.
Mohd Aaquib Khan
Mohd Aaquib Khan on 21 Sep 2023
Dont mind the tag, I just meant it as a joke. Crazy enough, the tag you used was my brothers name so I was confused if I logged in from my brothers account!! 😂
Thanks for your solution.

Sign in to comment.

More Answers (1)

dpb
dpb on 20 Sep 2023
Edited: dpb on 20 Sep 2023
If the AppDesigner app main figure were named just UIFigure in the auto-generated startup code function createComponents(app), then when you execute
app.UIFigure = uifigure();
you've overwritten the application app struct UIFigure handle with the new one and (as you've discovered) orphaned the original. DON'T DO THAT!!! :) You must use a different struct name when you create the second figure.
app.UIFigure2 = uifigure();
would work.
It's surprising the original app uifigure would not have some additional decoration in its name based on the name you gave the app when you created/saved it, but it appears must be given the symptoms you describe.
Show us what the beginning of the auto-generated createComponents(app) function looks like...
  9 Comments
dpb
dpb on 20 Sep 2023
>> app.UIFigure=uifigure;
>> app.UIFigure2=uifigure('Name','Second','WindowStyle','modal');
>> app
app =
struct with fields:
UIFigure: [1×1 Figure]
UIFigure2: [1×1 Figure]
>> delete(app.UIFigure2)
>> delete(app.UIFigure)
>> clear app
>>
works locally so syntax isn't the problem.
Would have to see the actual MyApp_16Sep/energyCycleNumberDropDownValueChanged callback function that is where the error is...there's something amiss inside it.

Sign in to comment.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!