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

6 ビュー (過去 30 日間)
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!

採用された回答

Adam Danz
Adam Danz 2023 年 9 月 20 日
編集済み: Adam Danz 2023 年 9 月 21 日
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 件のコメント
Adam Danz
Adam Danz 2023 年 9 月 21 日
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 2023 年 9 月 21 日
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.

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2023 年 9 月 20 日
編集済み: dpb 2023 年 9 月 20 日
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 件のコメント
Mohd Aaquib Khan
Mohd Aaquib Khan 2023 年 9 月 20 日
Yea but the bigger problem is that it is not identifying UIFigure2
Unrecognized property 'UIFigure2' for class 'MyApp_16Sep'.
dpb
dpb 2023 年 9 月 20 日
>> 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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDevelop uifigure-Based Apps についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by