tiledlayout doesn't work with uifigure?

Hi, I just encountered a strange behaviour. I recently programmed a script witch uses a tiledlayout within an uifigure. It worked well so far until today, when Matlab refuses to apply the tiledlayout onto the already opened uifigure but instead opens a separate figure.
fig = uifigure;
tiledlayout(1, 2);
nexttile(1)
plot(0)
nexttile(2)
plot(0)
That's a demoscript witch provokes the described behaviour. As soon as tiledlayout gets called a new figure opens and the uifigure is ignored. I wrote my script in Matlab R2019b but also upgraded to a fresh R2020a today. Same behaviour. I can't tell why it worked well so far but suddenly started to behave strangely as of today. Any clues?

Respuestas (2)

Ameer Hamza
Ameer Hamza el 29 de Abr. de 2020
Explicitly specify the handles of graphic objects
fig = uifigure;
t = tiledlayout(fig, 1, 2);
ax = nexttile(t);
plot(ax, 0)
ax = nexttile(t);
plot(ax, 0)

9 comentarios

powl
powl el 29 de Abr. de 2020
Well I'm just trying around and I think I could succeed with that. But why did Matlab change it's whole behaviour out of a sudden? My script was working perfectly fine until today, when It just refused to reuse the already opened active uifigure.
Ameer Hamza
Ameer Hamza el 29 de Abr. de 2020
I am not sure why Mathworks suddenly changed this behavior? Have you installed the latest update released recently for R2020a?
powl
powl el 29 de Abr. de 2020
Well, the script worked fine, I went to sleep, I stood up, I restarted the script, then it changed the behaviour, haha.
Matlab doesn't perform auto updates, right? Maybe something in my whole system changed. Maybe it was just a "bug" that my old script worked so far.
Ameer Hamza
Ameer Hamza el 29 de Abr. de 2020
Yes, MATLAB does not update automatically. Maybe It was making a normal figure instead of uifigure, but you didn't notice it before.
powl
powl el 29 de Abr. de 2020
I certainly noticed that it created a uifigure ;-). A uifigure looks different as there's no toolbar in it. Also now when I call the old script, I creates a uifiure and a figure. That's why I'm wondering what's going wrong now.
powl
powl el 29 de Abr. de 2020
Editada: powl el 29 de Abr. de 2020
ok next problem:
t = nexttile(l, [5 2]);
pax = polaraxes(t);
p2 = polarplot(pax, rho, current);
the normal plots look fine now, but as soon as it reaches the polar axes I get an error
Error using polaraxes
Too many output arguments.
I couldn't work my way arount it. Any suggestions?
Ameer Hamza
Ameer Hamza el 29 de Abr. de 2020
Were you able to draw the polaraxes over a tile before without using the axes handles? What was the code?
powl
powl el 30 de Abr. de 2020
Well, I didn't need to use polaraxes in the first place. I Just called polarplot and it worked. Here is the original code that created my window in a simplified form:
fig = uifigure;
ldbtn = uibutton(fig);
ldbtn.Position = [360 30 60 22];
ldbtn.Text = 'Rnd';
svbtn = uibutton(fig);
svbtn.Position = [440 30 60 22];
svbtn.Text = 'Save';
rho = linspace(0, 2*pi, n);
axx = [1 n -0.3 0.3];
tiledlayout(5, 3);
nexttile(1)
p11 = plot(sin1);
p11.YDataSource = 'sin1';
t11 = title('');
axis(axx);
nexttile(4)
p12 = plot(sin2);
p12.YDataSource = 'sin2';
t12 = title('');
axis(axx);
nexttile(7)
p13 = plot(sin3);
p13.YDataSource = 'sin3';
t13 = title('');
axis(axx);
nexttile(10)
p14 = plot(sin4);
p14.YDataSource = 'sin4';
t14 = title('');
axis(axx);
nexttile(13)
p13 = plot(current_flip);
p13.YDataSource = 'current_flip';
title('sum');
axis(axx);
nexttile([5 2])
p2 = polarplot(rho, current);
axis([1 361 -1 1]);
p2.YDataSource = 'current';
After 'the incident' happened, literally every single ui instruction I don't give a reference to the already opened uifigure tries to open its own figure. That wasn't the case before. It used to look like this:
It is quite strange that you were able to make such a thing in uifigure yesterday. I tried to make polaraxes over the tiledlayout, and it is proving to be quite difficult. The following code shows a workaround. Maybe you can file a bug report (not sure, if it is a bug or intended behavior ?) or at least a feature request to make the process of creating polaraxes over tiledlayout in uifigure a bit easier.
fig = uifigure;
ldbtn = uibutton(fig);
ldbtn.Position = [360 30 60 22];
ldbtn.Text = 'Rnd';
svbtn = uibutton(fig);
svbtn.Position = [440 30 60 22];
svbtn.Text = 'Save';
n=100;
rho = linspace(0, 2*pi, n);
axx = [1 n -0.3 0.3];
t = tiledlayout(fig, 5, 3);
ax = nexttile(t,1);
p11 = plot(ax, 0);
p11.YDataSource = 'sin1';
t11 = title(ax,'');
axis(ax,axx);
ax = nexttile(t,4);
p12 = plot(ax, 0);
p12.YDataSource = 'sin2';
t12 = title(ax,'');
axis(ax,axx);
ax = nexttile(t,7);
p13 = plot(ax, 0);
p13.YDataSource = 'sin3';
t13 = title(ax,'');
axis(ax,axx);
ax = nexttile(t,10);
p14 = plot(ax,0);
p14.YDataSource = 'sin4';
t14 = title(ax,'');
axis(ax,axx);
ax = nexttile(t,13);
p13 = plot(ax,0);
p13.YDataSource = 'current_flip';
title(ax,'sum');
axis(ax,axx);
ax = nexttile(t,[5 2]);
ax.Visible = 'off';
pax = polaraxes(fig);
pax.Position = ax.Position;
p2 = polarplot(pax,1, 1);
axis(ax,[1 361 -1 1]);
p2.YDataSource = 'current';

Iniciar sesión para comentar.

Paul Hamacher
Paul Hamacher el 30 de Abr. de 2020
Editada: Paul Hamacher el 30 de Abr. de 2020

0 votos

Thank you for you effort! I think the problem arises from the fact, that I try to combine "old" (GUIDE, figure) and "new" (appDesigner, uifigure) GUI elements together in the first place. I think tiledlayout isn't inteded to work with uifigure. I can't tell why it worked at first and then suddenly stopped working. ?
I will try to re-implement my GUI with only new GUI elements (uigridlayout instead of tiledlayout...). Maybe this is easier. This was the first time I worked with gui elements. Compared to other programming environments, GUI programming seems a bit hard to me in Matlab.

2 comentarios

Ameer Hamza
Ameer Hamza el 30 de Abr. de 2020
Yes, making older graphical elements to work with the uifigure can be a bit of pain. You can try to use uigridlayout since it was specifically made for uifigure. The only thing I find confusing is why it was working before since you didn't even update MATLAB, so there shouldn't be any major changes. I don't think there is a physical explanation for this. Something supernatural must be going on with your system :D
Paul Hamacher
Paul Hamacher el 30 de Abr. de 2020
I couldn't give a better explanation for this behaviour! ?

Iniciar sesión para comentar.

Categorías

Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 29 de Abr. de 2020

Comentada:

el 30 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by