我在Matlab 2010b下使用GUIDE創建了一些GUI。將Matlab升級到2015b後,我發現一些小部件現在有不同的設計,而我的舊GUI具有不匹配的外觀。有沒有一些方法可以升級GUI以與2015b兼容?以下是顯示不匹配小部件的屏幕截圖。 將GUIDE GUI小部件升級到最新的Matlab版本
我已經看到了一些升級腳本的參考,這些升級腳本會爲你做這件事,但是在官方的matlab文檔中沒有看到任何參考。
我在Matlab 2010b下使用GUIDE創建了一些GUI。將Matlab升級到2015b後,我發現一些小部件現在有不同的設計,而我的舊GUI具有不匹配的外觀。有沒有一些方法可以升級GUI以與2015b兼容?以下是顯示不匹配小部件的屏幕截圖。 將GUIDE GUI小部件升級到最新的Matlab版本
我已經看到了一些升級腳本的參考,這些升級腳本會爲你做這件事,但是在官方的matlab文檔中沒有看到任何參考。
MATLAB沒有任何官方的做法。您看到的這種差異是由於版本之間的缺省uicontrol
和uipanel
BackgroundColor
屬性的差異。我在下面有一個腳本,可以實際加載.fig
文件(使用GUIDE或其他方式創建),並用當前默認背景色替換BackgroundColors
的uicontrol
或uipanel
對象。然後在保留原件的備份的同時重新保存.fig
文件。
function varargout = updatebgcolor(figfile)
% updatebgcolor - Updates the uicontrol background colors
%
% USAGE:
% updatebgcolor(figfile)
data = load(figfile, '-mat');
% Types of controls to update
types = {'uicontrol', 'uipanel'};
% Get the current default background color
bgcolor = get(0, 'DefaultUIControlBackgroundColor');
% Switch out all of the background colors
data2 = updateBackgroundColor(data, types, bgcolor);
% Resave the .fig file at the original location
movefile(figfile, [figfile, '.bkup']);
save(figfile, '-struct', 'data2')
if nargout; varargout = {data2}; end
end
function S = updateBackgroundColor(S, types, bgcolor)
% If this is not a struct, ignore it
if ~isstruct(S); return; end
% Handle when we have an array of structures
% (call this function on each one)
if numel(S) > 1
S = arrayfun(@(s)updateBackgroundColor(s, types, bgcolor), S);
return
end
% If this is a type we want to check and it has a backgroundcolor
% specified, then update the stored value
if isfield(S, 'type') && isfield(S, 'BackgroundColor') && ...
ismember(S.type, types)
S.BackgroundColor = bgcolor;
end
% Process all other fields of the structure recursively
fields = fieldnames(S);
for k = 1:numel(fields)
S.(fields{k}) = updateBackgroundColor(S.(fields{k}), types, bgcolor);
end
end
你說的是uicontrols的背景顏色嗎? – Suever