2016-03-17 55 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