from Find and Replace Tool by Shanmugam Kannappan
Find & Replace the signal names in Simulink & Stateflow

FndRep_GUI(action)
function FndRep_GUI(action)
% **********************************************************************
%    File Name : FndRep_GUI
%    Author : Shanmugam Kannappan
%    Description : This is the function called when the 
%    " Find and Replace " option is selected in SIMULINK edit menu.
%***********************************************************************
global h
if nargin==0 % Initialize the GUI with objects when called from SIMULINK
    action = 'Initialize';
end

switch action
    case 'Initialize'
        % Main figure
       h.fig=figure('NumberTitle','Off','Name','Find & Replace','Menubar','None','Toolbar','None', ...
           'Units','Normalized', 'Position',[.2 .6 .45 .2]);
      % Create a button Group object to group the options
       h.hbtngrp = uibuttongroup(h.fig,'visible','on','Position',[0 0 .25 1],'Units','Normalized');
        
       % Created the Check box 1 & set it to be selected by default & 
       % associated the callback to make the objects visible for the string option &
       % invisible for Excel file option     
       h.cbh1 = uicontrol(h.hbtngrp,'Style','checkbox','String','String',...
            'Value',1,'Position',[20 110 70 20]);
       set(h.cbh1,'Callback','FndRep_GUI(''Cb1CompVisible'')');
       % Static Text for check box 1
        uicontrol(h.fig,'style','text','Position',[120 120 75 15],'String','Find what:', ...
            'HorizontalAlignment','Left','Tag','cbh11','BackgroundColor',[0.8 0.8 0.8]);
        uicontrol(h.fig,'style','text','Position',[120 60 75 15],'String','Replace with:',...
            'HorizontalAlignment','Left','Tag','cbh12','BackgroundColor',[0.8 0.8 0.8]);
        % Edit box for check box 1
        h.fndstr = uicontrol(h.fig,'style','edit','Position',[220 120 220 20],...
            'HorizontalAlignment','Left','Tag','cbh13','BackgroundColor',[1 1 1]);
        h.repstr = uicontrol(h.fig,'style','edit','Position',[220 60 220 20],...
            'HorizontalAlignment','Left','Tag','cbh14','BackgroundColor',[1 1 1]);
        
        % Push buttons for Check box 1 with associated callback to pass the 
        % strings to the function " FindandReplace"  
        uicontrol(h.fig,'Style', 'pushbutton', 'String', 'O.K','Position',[260 35 50 20],...
            'Callback','FndRep_GUI(''Getstr_edits'')','Tag','cbh15')
        uicontrol(h.fig,'Style', 'pushbutton', 'String', 'Close','Position',[360 35 50 20],...
            'Callback','close all','Tag','cbh16') % callback associated close the figure


        % Created Check box 2 & associated a callback to make the objects
        % visible correspond to this option.Sets the objects invisible
        % which correspond to String option
         
        h.cbh2 = uicontrol(h.hbtngrp,'Style','checkbox','String','Excel File',...
                        'Value',0,'Position',[20 55 70 20]);
        set(h.cbh2,'Callback','FndRep_GUI(''Cb2CompVisible'')'); 
        
        % Static Text for check box 2 to display the Excel file name
        h.xlfile = uicontrol(h.fig,'style','edit','Position',[120 90 290 20],...
            'HorizontalAlignment','Left','Tag','cbh21','BackgroundColor',[1 1 1],'Visible','off');
        % Browse button for option2 to select the excel file associated
        % with the callback to get the Excel file
        uicontrol(h.fig,'Style', 'pushbutton', 'String', 'Browse','Position',[410 90 50 20],...
            'Tag','cbh22','Visible','off','Callback','FndRep_GUI(''getexcelfile'')')
        % O.K button associated with the callback to pass the Excel file to
        % the function Find & Replace
        uicontrol(h.fig,'Style', 'pushbutton', 'String', 'O.K','Position',[250 50 50 20],...
            'Callback','FndRep_GUI(''Getfile_edits'')','Tag','cbh23','Visible','off')       
    
    % Component visibility control for check box2(Excel file option)               
    case 'Cb2CompVisible'
        set(h.cbh1,'Value',0)
        h11 = get(gcf,'Children');
        Chilh = get(h11,'Tag');
        for i=1:length(Chilh)
             if ~isempty(regexp(Chilh{i},'cbh2','once')) % make the components visible which belongs to checkbox 2 
                set(h11(i),'visible','On')
            elseif isempty(regexp(Chilh{i},'cbh1','once'))
                continue
            else                
                set(h11(i),'visible','Off') % make the components invisible which belongs to checkbox 1 
            end
        end
    % Component visibility control for check box1(String option)      
    case 'Cb1CompVisible'
        set(h.cbh2,'Value',0)
        h11 = get(gcf,'Children'); % all the components of the Find & Replace figure
        Chilh = get(h11,'Tag');
        for i=1:length(Chilh)
            if ~isempty(regexp(Chilh{i},'cbh1','once')) % make the components visible which belongs to checkbox 1 
                set(h11(i),'visible','On')
            elseif isempty(regexp(Chilh{i},'cbh2','once'))
                continue
            else                
                set(h11(i),'visible','Off') % make the components invisible which belongs to checkbox 2
            end
        end

    % Get the strings & pass it to the function "FindandReplace"
    case 'Getstr_edits'
        strns= cell(1,2);
        if ~isempty(get(h.fndstr,'String'))&& ~isempty(get(h.repstr,'String'))
            strns{1,1} = get(h.fndstr,'String');
            strns{1,2} = get(h.repstr,'String');
            FindandReplace(strns)
        end
    % Browse for the Excel files set the editbox with fullname(path & file name) 
    case 'getexcelfile'
        [XlFile XlPath] = uigetfile('.xls','Select the Excel file contains signals to be replaced ');
        set(h.xlfile,'String',[XlPath XlFile])
    % Get the excel file & pass it to the function "FindandReplace"     
    case 'Getfile_edits'
        if ~isempty(get(h.xlfile,'String'))
            file = get(h.xlfile,'String');
            FindandReplace(file)
        end
end
end

Contact us at files@mathworks.com