[英]Matlab GUIDE callback does not update handles even when guidata is used
[英]MATLAB Guide handles between Callback and Function
我有一個MATLAB Guide項目。 我在同一.m
文件中混合了常規函數和回調函數。
我從回調中調用函數,並且該函數通過for
循環運行,希望更新字符串框。 這是一個例子:
從回調(顯示摘錄)中,我調用此函數:
[color] = get_color(images, handles);
set(handles.ProcessImage, 'string', 'Processing Complete');
get_color
函數位於同一.m
文件中
function [color_corrections] = get_color(images, handles)
[n, ~, ~, ~] = size(images); % Find the number of images
for imgIdx=1:n % For each image
set(handles.ProcessImage, 'String', 'Processing Image #');
end
end
問題是handles.ProcessImage
在for
循環期間沒有更新,但是當它從函數返回時被寫入'Processing Complete'
。
有什么想法嗎?
謝謝,TommyMac
在緊密循環中,計算優先,因此Matlab最終無需費心去更新GUI,直到再次有時間(即循環完成)為止。 您可以在更新字符串后通過調用drawnow
來強制進行GUI更新,如下所示:
set(handles.ProcessImage, 'String', 'Processing Image #');
drawnow; % force the new string to be rendered
請注意,如果循環中的代碼很短但有很多迭代,則可能會嚴重打擊性能。 如果迭代次數相對較少,但每次迭代都花費很長時間,則您不會注意到其中的區別。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.