0

我试图在程序忙于计算时将我的 gui 按钮的背景颜色设置为不同的颜色。如果我只是在单击按钮时将颜色设置为更改,则它会更改;但是,如果我在实际计算之后添加另一行代码以将颜色更改回默认值,则颜色永远不会第一次更改。

function FitData_button_Callback(hObject, ~, handles) %#ok<DEFNU>

set(handles.FitData_button,'BackgroundColor',[0 204 0]./255,'String','Fitting Data');

% do some computation that takes time here...

% this line causes the first instance of 'set' not to work
set(handles.FitData_button,'BackgroundColor',[237 237 237]./255,'String','Fit Data'); 

如果我第二次更改属性,我调用“设置”,它确实会从默认值更改为第二次指定的属性(并且在长时间计算完成后执行此操作)。但是,第一组属性永远不会被分配。所以看起来我只能设置一次 BackgroundColor 和 String 属性,这没有任何意义。

是什么赋予了?谢谢

4

1 回答 1

3

简短的回答是在你的计算中间放置一个“drawnow”。长答案最好由 Yair Altman 在他的博客上说明(顺便说一句,这太棒了) - http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/

于 2013-06-19T20:17:41.637 回答