필터 지우기
필터 지우기

MATLAB GUI Updating plot

조회 수: 7 (최근 30일)
Louis
Louis 2015년 5월 16일
댓글: Louis 2015년 5월 18일
I have a MATLAB gui that demonstrates the plotting of real-time incoming data signal and a horizontal threshold line:
axes(handles.axes1);
plot([1 windowLength].*1/sampleFreq, [-data1Threshold -data1Threshold],'k','linewidth',2);
% Plotting the threshold line
xlim([1 windowLength].*1/sampleFreq);
ylim([-300 300]);
xlabel('Time (s)')
ylabel('Filtered signal (uV)')
hold on;
plot([1:10:length(data1)].*1/sampleFreq, data1(1:10:end),'b','linewidth',2);
% Plotting the signal over the threshold line
hold off;
drawnow;
This part of the code is inside a while loop so that different parts of the signal (incoming signal) is plotted while the threshold line is identical. The issue is that the gui runs really slow. Is there anyway I can fix the threshold line and the axis information, so that I can only update the incoming signal in order to improve the speed?
I have tried the following to fix the handles to the plot, however, this still requires me to plot the threshold line and the signal at every iteration... (also not sure how to use set function with multiple data lines to plot, the threshold line and signal)
handles.plot1 = plot([1 windowLength].*1/sampleFreq, [-data1Threshold -data1Threshold],'k',[1:1:length(data1)].*1/sampleFreq, data1,'b','linewidth',2);
set(handles.plot1,'xdata',[1:10:length(data1)].*1/sampleFreq, 'ydata',data1(1:10:end));
any help will be greatly appreciated

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 16일
thisax = handles.axes1;
plot2handle = get(thisax, 'UserData');
if isempty(plot2handle) || ~isgraphics(plot2handle) || ~strcmp(get(plot2handle,'type'),'line')
plot([1 windowLength].*1/sampleFreq, [-data1Threshold -data1Threshold],'k','linewidth',2, 'Parent', thisax);
% Plotting the threshold line
xlim(thisax, [1 windowLength].*1/sampleFreq);
ylim(thisax, [-300 300]);
xlabel(thisax, 'Time (s)')
ylabel(thisax, 'Filtered signal (uV)')
hold(thisax, 'on');
plot2handle = plot([1:10:length(data1)].*1/sampleFreq, data1(1:10:end),'b','linewidth',2, 'Parent', thisax);
% Plotting the signal over the threshold line
hold(thisax, 'off');
set(thisax, 'UserData', plot2handle);
else
%if it was a valid line handle, just update it
set(plot2handle, 'XData', [1:10:length(data1)].*1/sampleFreq, 'YData', data1(1:10:end));
end
  댓글 수: 1
Louis
Louis 2015년 5월 18일
Thank you Walter! I have a follow up question... What if I want to update multiple lines (same x values, multiple y values) in the same plot window at each loop?
I have found this:
set(graph, {'XData'}, num2cell(x,2), {'YData'}, num2cell(y,2))
from here (www.mathworks.com/matlabcentral/newsreader/view_thread/293082).. However, when I have the same x-values for different y-values, it seems inefficient to create a cell just to have the repeating x-value arrays. Are there any other ways to accomplish this? Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by