2
votes

I have some GUIs I created using GUIDE under Matlab 2010b. After upgrading Matlab to 2015b, I see that some of the widgets now have a different design, and my older GUI has a mismatched appearance. Is there some way to upgrade the GUI to have a compatible appearance with 2015b? Here is a screenshot showing the mismatched widgets. mismatched widgets

I have seen references to some upgrade scripts that will do this for you, but I don't see any references in the official matlab documentation.

1
Are you talking about the background color of the uicontrols?Suever

1 Answers

1
votes

MATLAB does not have any official way of doing this. This difference that you're seeing is due to a difference in the default uicontrol and uipanel BackgroundColor property between releases. I have a script below that can actually load in a .fig file (created with GUIDE or otherwise) and swap out the BackgroundColors of uicontrol or uipanel objects with the current default background color. It then re-saves the .fig file while maintaining a backup of the original.

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