在matlab GUIDE中显示GUI是否正在运行

时间:2013-06-12 09:39:03

标签: matlab matlab-guide

我目前正在使用mathlab GUIDE创建GUI。由于GUI非常慢,我想添加edit_text uicontrol以显示GUI是否正在运行。

例如,我有一个push_button可以更改轴上的绘图。当用户单击此按钮时,GUI需要几秒钟才能执行新绘图。我想要做的是在按下按钮后立即使用字符串edit_text设置'running'。完成回调并绘制绘图后,我想将edit_text设置为另一个字符串:'ready'

我使用了以下代码:

function push_button_Callback(hObject, eventdata, handles)
% hObject    handle to push_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.edit_text,'String','Running...');
%a bunch of code...
set(handles.edit_text,'String','Ready.');
guidata(hObject,handles);

我希望一旦调用回调,GUI就会在'running...'上显示edit_text。显然我错了。运行GUI并按下push_button情节更改但edit_text保持不变。

然后我尝试了使用ButtonDownFcn回调的其他内容。我的想法是后一个回调将在实际回调之前执行(如上所述)。这是代码:

function push_button_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to push_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.edit_text,'String','Running...');
guidata(hObject,handles);

问题是每次都不会执行ButtonDownFcn回调。正如GUIDE所说的关于后者的回调:

% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over str22.

显然我希望启用push_button,否则它将无法按我想要的方式运行。所以我不知道还有什么可以尝试。

有人知道我怎么能做到这一点吗?

1 个答案:

答案 0 :(得分:1)

您可以尝试

set(handles.edit_text,'String','Running...');
drawnow;
%a bunch of code...

在您到达

之前,GUI可能不会更新
set(handles.edit_text,'String','Ready.');

因此强制它用drawow更新可能对你有用。