필터 지우기
필터 지우기

How to fix slow GUI plotting using axes(handles...)

조회 수: 10 (최근 30일)
Louis
Louis 2015년 5월 16일
답변: Walter Roberson 2015년 5월 17일
I have a gui with multiple plots updating through while loop once user presses 'Start' button. The issue I have is that gui is running really slow.. I ran a profiler, and it turns out that calling axes function (in order to access a specific figure within the gui panel) takes up the majority of time. Below is the sample code:
Any suggestions to not use axes inside the while loop to plot, or general suggestions to improve the speed of the gui will be really appreciated. Thanks in advance.
function Start_Callback(hObject, eventdata, handles)
load('data.mat')
dataSegment = 1;
maxSegment = 1000;
%other set ups....
time calls line while (~stop && ~dataEnd)
0.01 34 328 if ~isempty(detectedSpikes1_1)
3.05 34 329 axes(handles.axes6);
0.27 34 330 plot([1:spikeLength], detectedSpikes1_1,'r','linewidth',1);
3.14 34 331 axes(handles.axes29);
0.29 34 332 scatter(detectedSpikes1PC_1(1:length(detectedSpikes1_1(:,1)),1),detectedSpikes1PC_1(1:length(detectedSpikes1_1(:,1)),2),'r');
34 333 end
34 334 if ~isempty(detectedSpikes1_2)
3.13 34 335 axes(handles.axes27);
0.07 34 336 plot([1:spikeLength], detectedSpikes1_2,'g','linewidth',1);
3.19 34 337 axes(handles.axes29);
0.29 34 338 scatter(detectedSpikes1PC_2(1:length(detectedSpikes1_2(:,1)),1),detectedSpikes1PC_2(1:length(detectedSpikes1_2(:,1)),2),'g');
34 339 end
34 340 if ~isempty(detectedSpikes1_3)
3.15 34 341 axes(handles.axes28);
0.09 34 342 plot([1:spikeLength], detectedSpikes1_3,'b','linewidth',1);
3.23 34 343 axes(handles.axes29);
0.28 34 344 scatter(detectedSpikes1PC_3(1:length(detectedSpikes1_3(:,1)),1),detectedSpikes1PC_3(1:length(detectedSpikes1_3(:,1)),2),'b');
34 345 end
end

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 17일
As we discussed in your previous question, keep the handles of the graphics objects and update them using set()
A scatterplot does not return a line object in any modern version: it returns a scatterplot object. However, the update method is very much the same, set() the XData and YData properties; see http://www.mathworks.com/help/matlab/ref/scatterseries-properties.html

카테고리

Help CenterFile 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!

Translated by