Effacer les filtres
Effacer les filtres

uifigure() laggy with multiple axes, figure() does not support scrollable components

57 vues (au cours des 30 derniers jours)
Guillaume
Guillaume le 2 Mai 2024
Réponse apportée : Sandeep Mishra le 13 Août 2024 à 6:03
I made an interface to display data from multiple measurement channels. It's using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel...
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),...
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),...
fig_ax,'UniformOutput',false);
linkaxes(fig_ax,'x')
zoom(fig_ax(1),'xon')
pan(fig_ax(2),'xon')
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),...
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),...
uifig_ax,'UniformOutput',false);
linkaxes(uifig_ax,'x')
zoom(uifig_ax(1),'xon')
pan(uifig_ax(2),'xon')
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it's even unusable on some not-too-old computers.
  • Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
  • Is there any way to prevent uifigure() window being this laggy ?
  3 commentaires
Guillaume
Guillaume le 3 Mai 2024
The example I described, with measurement channels, is part of a large app I made with the App Designer. The problematic part is navigating data with multiple axes, each on a row of a grid layout and linked on X (linkaxes).
I actually tested the short code above on a laptop with R2024a, and a quite powerful desktop PC with R2023b. It is especialy when chaning the X range with the pan tool.
William Dean
William Dean le 3 Mai 2024
I see, it sounds like your problem might lie with linking the axes, rather than the scrolling. In my experience, linking more than a few axes with linkaxes() can cause issues, especially if it is part of a more complicated app with many components.
However, when I tested your uifigure code section, it ran just fine. Didn't seem laggy to me. But if you have more than 15 axes I can see how it could be.
You might just have to find another method that doesn't use linkaxes().

Connectez-vous pour commenter.

Réponses (1)

Sandeep Mishra
Sandeep Mishra le 13 Août 2024 à 6:03
Hello Guillaume,
I understand that you are trying to make an interface to display data from multiple measurement channels and seeking assistance regarding the following queries:
  • Is there an alternative to Grid Layout Manager or scrollable Panel for “figure” windows?
  • Is there any way to prevent “uifigure” window being this laggy?
Addressing your first query regarding the MATLAB “figure” component.
Regarding your second query, to use the “uifigurecomponent without laggy nature.
  • I ran the provided code snippet in MATLAB R2024a and observed similar laggy nature of the “uifigurecomponent.
  • As @William Dean already explained in the comments, the issue came around due to the multiple axes linked using “linkaxesfunction.
  • You can refer to the below workaround to fix the laggy nature by using “listener” and callback functions instead of thelinkaxes” function.
% Function to synchronize XLim of all axes
function syncXLim( ~, event, uifig_ax)
newXLim = event.AffectedObject.XLim;
for ax = uifig_ax
if ~all(ax.XLim == newXLim)
ax.XLim = newXLim;
end
end
end
% Add listener to each axis
for ax = uifig_ax
addlistener(ax, 'XLim', 'PostSet', @(src,evnt)syncXLim(src,evnt, uifig_ax));
end
Refer to the following documentations for more details on the functions used.
  1. addlistener”: https://www.mathworks.com/help/releases/R2024a/matlab/ref/handle.addlistener.html
  2. Listener Callback Syntax”: https://www.mathworks.com/help/releases/R2024a/matlab/matlab_oop/listener-callback-functions.html
I hope this helps.

Catégories

En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by