How to speed up GUI
10 次查看(过去 30 天)
显示 更早的评论
Hi people,
I have another question:
My gui has 4 axes elements, and an uitable. Now I am basically able to get the row index number and to use it in such a way I can put a marker (colored line) on the four plots contemporarily. The problem is now the speed. It takes very long to redraw all the four figures and the four lines eveytime i choose another element. how could I menage this?
I have a launch button, which during its own callback is reading an excel file, processing the data someway and generating the four vectors to plot. After that a refresh function is called, which plots the data in the right format, and puts the marker into a starting position. After that I call the refresh function evey time I choose a new value from the table, and this redraws the whole 4 graphics and the markers.
Which could be a better way to obtain this behaviour in less time?
0 个评论
采纳的回答
Walter Roberson
2011-9-7
When practical, use set() to update existing graphics rather than creating new graphics.
If you are updating several graphic items, it is often faster to set() the figure or axes visibility to off, do the updates, and then set it to be visible again.
Avoid using figure() or axes() to make a particular figure or axes the "current" one. Instead, explicitly parent operations. For example, instead of
axes(handles.axes1);
plot(x, y)
use
plot(handles.axes1, x, y);
or
plot(x, y, 'Parent', handles.axes1);
and instead of
figure(handles.guifig)
you can use
set(0, 'CurrentFigure', handles.guifig);
The figure() and axes() calls raise the object and make it visible, triggering a graphics update: you are trying to delay all graphics updates until you everything is in its place.
If you do need to call axes(), triggering a graphics update you do not want yet, then immediately (e.g., next statement) set() the visibility of the axes to be off. If you get the set() in early enough, then at least on Linux the window will not even "flash".
0 个评论
更多回答(1 个)
Titus Edelhofer
2011-9-7
Usually you can speed up significantly by avoiding to redraw everything. When you plot the first time, save the handle:
handles.plot1 = plot(handles.axes1, ...);
guidata(hObject, handles);
When your callback wants to redraw, don't redraw everything but do something like
newX = ...;
newY = ...;
set(handles.plot1, 'xdata', newX, 'ydata', newY);
Titus
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!