0

I am plotting live data: for the plotting, I am using the line function, which improved the plotting performance a lot compared when using the plot function. Still, the plot gets slower with time. I realized that the sample points that I am creating are plotted, but even when they are not visible later the still remain in the plot. Could this cause any performance degradation?

I just want to see the sample points of the current three seconds, if use clf or cla function, just see very small part of the signal, which is not helpful for me. Do you have any suggestions?

%% opening function:

handles.figureHandle=figure;
guidata(hObject, handles);
t=1/200; %sample rate 5ms

%% button function:

if 40< newSamples
figure(handles.figureHandle)
              t = max(t) + (1:size(sample,1)) * 1/200;
              for x=1:8
                  subplot(8,8,x);
                  hold on
                  line('XDATA',t,'YDATA',sample(:,x),'MarkerSize', 1,'Color','r');
                  ylim([0 1024]);
                  xlim([max(t)-1 max(t)+2]);
                  hold off
              end


drawnow ;
      end

Update

%% opening function
sample=[];
t=[];
handles.figureHandle
for i=1:8
    subplot(2,2,i);
    hold on
    h=line(t,sample,'MarkerSize', 1,'Color','r');
    %          ylim([0 1024]);
    %          xlim([max(t)-1 max(t)+2]);
    hold off
end

t=1/200;
%% button function
figure(handles.figureHandle)
t = get(gca, 'XData');
sample = get(gca, 'YData');

t = max(t) + (1:size(sample,1)) * 1/200;
for x=1:8
    set(h,'XData',t,'YData',sample(:,x));
end
xava
  • 293
  • 1
  • 2
  • 16
  • 3
    Rather than creating new plot objects every time, simply update the `XData` and `YData` properties of the existing plot object. – Suever Jan 17 '17 at 15:48
  • So basically I create the subplots in the opening function of the GUI and then in the button function I update the data? – xava Jan 17 '17 at 15:54
  • Precisely. Create the plots once, and then update them. This will improve the performance significantly. – Suever Jan 17 '17 at 15:55
  • I have changed the code (see updated post)but i get the error that XDATA property on the x-axes is not found – xava Jan 17 '17 at 18:55
  • 1
    Please edit your question rather than trying to post code in a comment – Suever Jan 17 '17 at 18:56
  • I have added the code to the original post – xava Jan 17 '17 at 19:10
  • You want `h` to point to the `line` object *not* the `subplot` objects – Suever Jan 17 '17 at 19:24
  • thank you! is there anything else that can be changed because the error is still occurring – xava Jan 17 '17 at 20:04
  • What's the actual error message? – Suever Jan 17 '17 at 20:09
  • error: 'There is no XData property on the Axes class.' for get(gcf, 'XData'); There is no XData property on the Figure class.' – xava Jan 17 '17 at 20:15
  • Can you update your post with the modification that I recommended in my last comment? – Suever Jan 17 '17 at 20:17

0 Answers0