接下来,我感觉需要一个简洁的GUI,以摘要形式显示信息。
我最近才开始深入挖掘和阅读Matlab内置的GUI工具GUIDE。我跟随了几个教程,成功地能够在GUI上显示我的图形,在按下按钮后实现功能。
然而,我希望GUI能够实时更新。我的数据向量不断更新(从COMM端口读取数据),我希望GUI随着新数据的到来保持更新图形,而不是依靠按钮按下更新。请问有人可以指导我如何实现后台更新吗?
以下是GUI相关代码:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global data
global time
% Time domain plot
axes(handles.timeDomainPlot);
cla;
plot (time, data);
编辑后的代码:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Setting it to display something when it ends
% t = timer('TimerFcn', 'timerOn=false; disp(''Updating GUI!'')',...
t = timer(...
'TasksToExecute', 10, ... % Number of times to run the timer object
'Period', 3, ...
'TimerFcn', GUIUpdate());
%Starting the timer
start(t)
function GUIUpdate()
global data
global time
%Parameters below axes
global min
global max
% Time domain plot
axes(handles.timeDomainPlot);
cla;
plot (time, data);
%Other parameters:
set(handles.mean, 'String', mean);
set(handles.max, 'String', max);
The error that I get is:
??? Error using ==> GUI_Learning>GUIUpdate
Too many output arguments.
Error in ==>
@(hObject,eventdata)GUI_Learning('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
GUIUpdate(obj,event)
。 'obj'将是计时器对象的句柄,而'event'将包含有关如何调用它的一些详细信息。默认情况下,计时器函数回调将传递至少这两个参数。我不确定这是否是您错误的确切原因,但您的示例看起来不正确。如果我今天晚些时候有机会,我将尝试发布一个计时器示例。 - Aero Engy