我在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