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