2016-03-17 35 views
2

我在Matlab 2010b下使用GUIDE创建了一些GUI。将Matlab升级到2015b后,我发现一些小部件现在有不同的设计,而我的旧GUI具有不匹配的外观。有没有一些方法可以升级GUI以与2015b兼容?以下是显示不匹配小部件的屏幕截图。 mismatched widgets将GUIDE GUI小部件升级到最新的Matlab版本

我已经看到了一些升级脚本的参考,这些升级脚本会为你做这件事,但是在官方的matlab文档中没有看到任何参考。

+0

你说的是uicontrols的背景颜色吗? – Suever

回答

1

MATLAB没有任何官方的做法。您看到的这种差异是由于版本之间的缺省uicontroluipanelBackgroundColor属性的差异。我在下面有一个脚本,可以实际加载.fig文件(使用GUIDE或其他方式创建),并用当前默认背景色替换BackgroundColorsuicontroluipanel对象。然后在保留原件的备份的同时重新保存.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 
+0

我很惊讶没有原生的方式来做到这一点,因为它似乎是任何人更新matlab和维护GUI将会遇到。 – Fadecomic

+1

@Fadecomic我同意。虽然,还有很多其他图形不一致实际上会导致在两者之间移植真正无法以自动方式处理的GUI时出现问题。这种颜色的变化也不是简单的,因为它会撤销任何自定义背景颜色规范。 – Suever