Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Adam Danz
Adam Danz el 20 de Sept. de 2023
Editada: Adam Danz el 21 de Sept. de 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 comentarios
Adam Danz
Adam Danz el 21 de Sept. de 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 el 21 de Sept. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 20 de Sept. de 2023
Editada: dpb el 20 de Sept. de 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 comentarios
Mohd Aaquib Khan
Mohd Aaquib Khan el 20 de Sept. de 2023
Yea but the bigger problem is that it is not identifying UIFigure2
Unrecognized property 'UIFigure2' for class 'MyApp_16Sep'.
dpb
dpb el 20 de Sept. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by