Slower program due to an additional figure window

2 visualizzazioni (ultimi 30 giorni)
TheEm
TheEm il 27 Dic 2022
Risposto: J. Alex Lee il 3 Gen 2023
Hello!
I'm writting a simulation in app designer, where one of the key elements is an animation/movie of graph changes (more precisly it's a double pendulum motion simulation). When running the gui i noticed an extra figure window opening. Search for the answer led me to this formula to stop that from happening:
fig1 = figure('visible','off');
but now my gui is running much slower than before. Deleting the formula did not bring back the additional window. Do i have to turn the visibility on or is there something else wrong?
Here is part of the code that utilises the plots:
g = app.PrzyspieszeniegEditField.Value;
%figure('visible','on');
if app.Masakulki2kgSpinner.Visible == "on"
m1 = app.Masakulki1kgSpinner.Value;
m2 = app.Masakulki2kgSpinner.Value;
l1 = app.Dlugoscwahadla1mSpinner.Value;
l2 = app.Dlugoscwahadla2mSpinner.Value;
u1 = app.Katwychylenia1radSpinner.Value;
u1_pr = 0;
u2 = app.Katwychylenia2radSpinner.Value;
u2_pr = 0;
else
m1 = app.Masakulki1kgSpinner.Value;
m2 = 0;
l1 = app.Dlugoscwahadla1mSpinner.Value;
l2 = 0;
u1 = app.Katwychylenia1radSpinner.Value;
u1_pr = 0;
u2 = 0;
u2_pr = 0;
end
tspan = app.CzassSpinner.Value;
y0 = [u1 u1_pr u2 u2_pr];
options = odeset('RelTol', 1.0e-6);
[t, y] = ode45(@pendfunc, [0, tspan], y0, options);
x1 = l1*sin(y(:,1));
y1 = -l1*cos(y(:,1));
x2 = x1 + l2*sin(y(:,3));
y2 = y1 - l2*cos(y(:,3));
V = -(m1+m2)*g*l1*cos(y(:,1)) - m2*g*l2*cos(y(:,3));
T = 0.5*m1*(l1^2)*(y(:,2).^2) + 0.5*m2*((l1^2)*(y(:,2).^2) + (l2^2)*(y(:,4).^2) + 2*l1*l2*y(:,2).*y(:,4).*cos(y(:,1) - y(:,3)));
E = T + V;
framenum = 0;
app.StoperEditField.Value = 0;
for i = 1:length(y)
plot(app.UIAxes, 0, 0, '.', 'MarkerSize', 10, 'Color', 'black');
hold(app.UIAxes,'on')
plot(app.UIAxes, x1(i), y1(i), '.', 'MarkerSize', 20, 'Color', 'red');
plot(app.UIAxes, x2(i), y2(i), '.', 'MarkerSize', 20, 'Color', 'blue');
hold(app.UIAxes,'off')
line(app.UIAxes, [0 x1(i)], [0 y1(i)], 'LineWidth', 1, 'Color', 'black');
line(app.UIAxes, [x1(i) x2(i)], [y1(i) y2(i)], 'LineWidth', 1, 'Color', 'black');
axis(app.UIAxes, [-(l1+l2+1) l1+l2+1 -(l1+l2+1) l1+l2+1]);
integ1 = floor(t(i));
if i+1 <= length(y)
integ2 = floor(t(i+1));
else
integ2 = floor(t(i));
end
if integ1 ~= integ2
app.StoperEditField.Value = app.StoperEditField.Value + 1;
end
framenum = framenum + 1;
M = getframe;
if stoppush
break
end
end
close
return
  1 Commento
Jan
Jan il 27 Dic 2022
It is not clear, why "fig1 = figure('visible','off');" should disable the creation of an additional window. It is also not clear, where this window came from. Now you have commented the line for creating the invisible window, and this does not restore the previous behaviour.
This shows, that something is going on, which is not clear to you. Therefore the described effects look "magic". In consequence I cannot understand, what really happens in your code.
Try to post some code, which really reproduces the problem.

Accedi per commentare.

Risposte (1)

J. Alex Lee
J. Alex Lee il 3 Gen 2023
I think your issue is that call to getframe() needs app.UIAxes to be supplied, that is,
getframe(app.UIAxes)
otherwise it will assume gca, which sadly doesn't grab uiaxes and will create a new axes() for you.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by