⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sptool.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 5 页
字号:
function varargout = sptool(varargin)
%SPTOOL  Signal Processing Tool - Graphical User Interface.
%   SPTOOL opens the SPTool window which allows you to import,
%   analyze, and manipulate signals, filters, and spectra.
%   
%   Exporting Component Structures from SPTool via the Command Line
%   ---------------------------------------------------------------
%   The following commands export component structures from the
%   currently open SPTool.
%
%   s = sptool('Signals') returns a structure array of all the signals.
%   f = sptool('Filters') returns a structure array of all the filters.
%   s = sptool('Spectra') returns a structure array of all the spectra.
%
%   [s,ind] = sptool(...) returns an index vector indicating which
%   of the elements of s are currently selected in SPTool.
%
%   s = sptool(...,0) returns only the currently selected objects.
%
%   Creating and Loading Component Structures via the Command Line
%   --------------------------------------------------------------
%   struc = sptool('create',PARAMLIST) creates a component
%   structure, struc, (defined by PARAMLIST) in the workspace.
%
%   sptool('load',struc) loads struc into SPTool; opens SPTool if
%   necessary.
%
%   struc = sptool('load',PARAMLIST) loads the component structure
%   defined by PARAMLIST into SPTool; if an optional output argument is
%   specified, a component structure, struc, is created in the workspace.
%
%   COMPONENT           PARAMLIST
%   ~~~~~~~~~           ~~~~~~~~~
%   SIGNALS:   COMPONENT_NAME,DATA,FS,LABEL
%   FILTERS:   COMPONENT_NAME,NUM,DEN,FS,LABEL
%   SPECTRA:   COMPONENT_NAME,DATA,F,LABEL
%
%   PARAMETER DEFINITIONS
%   ~~~~~~~~~~~~~~~~~~~~~
%   COMPONENT_NAME - 'Signal', 'Filter', or 'Spectrum'; if omitted
%             COMPONENT_NAME defaults to 'Signal'.
%   DATA    - a vector of doubles representing a signal or a spectrum.
%   NUM,DEN - numerator and denominator coefficients of the filter's
%             response in transfer function form.
%   FS      - sampling frequency (OPTIONAL), defaults to 1.
%   F       - frequency vector; applies to spectrum components only.
%   LABEL   - a string specifying the variable name of the component
%             as it will appear in SPTool (OPTIONAL); defaults to one
%             of the following: 'sig', 'filt', or 'spec'.

%  API for calling other tools - 
%     Components and clients are defined by 'components' data
%     structure in the file signal/private/sptcompp.m.  See this
%     file for details.
%     Verb Button Pressed - calls 
%         feval(verb.owningClient,'action',verb.action)
%     Selection has changed - calls for ALL verbs
%         enable = feval(verb.owningClient,'selection',verb.action,msg)
%         and sets verb's enable to result
%     Closing SPTool - calls
%         feval(defaultClient,'SPTclose')

%   Copyright (c) 1988-98 by The MathWorks, Inc.
% $Revision: 1.33 $

% Authors: T. Krauss and B. Jones

if nargin == 0
    action = 'init';
    shh = get(0,'ShowHiddenHandles');
    set(0,'ShowHiddenHandles','on')
    spfig = findobj(0,'Tag','sptool');
    set(0,'ShowHiddenHandles',shh);
    if ~isempty(spfig)
        figure(spfig)
        return
    end
else
    action = varargin{1};
end

switch action

case 'init'
    % initialization
    ud.prefs = sptprefp;  % calls sptprefp in signal/private
    for i=1:length(ud.prefs)
        p = getsigpref(ud.prefs(i).panelName);
        if ~isempty(p)
            ud.prefs(i).currentValue = struct2cell(p);
            % check to make sure currentValue has the correct number of
            % elements.  If it doesn't then the preferences must be out
            % of date, so set the current value to the factory setting.
            if length(ud.prefs(i).currentValue) ~= length(ud.prefs(i).controls(:,1))
                ud.prefs(i).currentValue = ud.prefs(i).controls(:,7);
                warning(...
                    sprintf(['Preferences for "%s" not correct size and are\n'...
                        'assumed to be out-of-date;' ... 
                        ' using factory settings.'],ud.prefs(i).panelDescription))
          end
      end
    end
    allPanels = {ud.prefs.panelName};
    plugInd = findcstr(allPanels,'plugins');
    plugPrefs = cell2struct(ud.prefs(plugInd).currentValue,ud.prefs(plugInd).controls(:,1));
    if plugPrefs.plugFlag   
        % add any additional preferences
	ud.prefs = sptool('callall','sptpref',ud.prefs);
    end

    ud.panelInd = 1;
    ud.components = [];
    ud.components = sptcompp(ud.components); % calls one in signal/private
    if plugPrefs.plugFlag
        % now call each one found on path:
        ud.components = sptool('callall','sptcomp',ud.components);
    end
    
    numComponents = length(ud.components);
    maxVerbs = 1;
    for i=1:numComponents
        maxVerbs = max(maxVerbs,length(ud.components(i).verbs));
    end
    ud.maxVerbs = maxVerbs;
    screenRect = get(0,'screensize');
    figHeight = ud.maxVerbs*20+240;
    fp = [18 screenRect(4)-figHeight-50 120*numComponents figHeight];
    ud.sessionName = 'untitled.spt';
    ud.wd = pwd;  % working directory for Opening, Saving, etc.
    ud.importwd = pwd;  % working directory for importing file data
    ud.exportwd = pwd;  % working directory for exporting data to disk
    ud.savedFlag = 0;  % flag indicating if session has ever been saved
    ud.unchangedFlag = 1;  % indicates if sess. is unchanged since last save
    figname = prepender(['SPTool: ' ud.sessionName]);
    
    uibgcolor = get(0,'defaultuicontrolbackgroundcolor');
    uifgcolor = get(0,'defaultuicontrolforegroundcolor');
 
    % CREATE FIGURE
    fig = figure('createfcn','',...
            'closerequestfcn','sptool(''close'')',...
            'tag','sptool',...
            'numbertitle','off',...
            'integerhandle','off',...
            'units','pixels',...
            'position',fp,...
            'menubar','none',...
            'color',uibgcolor,...
            'inverthardcopy','off',...
            'paperpositionmode','auto',...
            'visible','off',...
            'name',figname);


    fontsize = get(0,'defaultuicontrolfontsize');
    for i=1:numComponents
        maxVerbs = max(maxVerbs,length(ud.components(i).verbs));
        ud.list(i) = uicontrol('style','listbox','backgroundcolor','w',...
                      'units','pixels',...
                      'callback',['sptool(''list'',' num2str(i) ')'],...
                      'value',[],'Tag',['list' num2str(i)]);
        if ud.components(i).multipleSelection
            set(ud.list(i),'max',2)
        end
        ud.label(i) = uicontrol('style','text','string',ud.components(i).name,...
                      'Tag',['list' num2str(i)],...
                      'units','pixels',...
                      'fontweight','bold');
        for j=1:length(ud.components(i).verbs)
            ud.buttonHandles(i).h(j) = uicontrol('string',...
                 ud.components(i).verbs(j).buttonLabel,...
                 'units','pixels',...
                 'callback',['sptool(''verb'',' num2str(i) ',' num2str(j) ')'],...
                 'tag',[ud.components(i).verbs(j).owningClient ':' ...
                        ud.components(i).verbs(j).action]);
        end
    end

    % ====================================================================
    % MENUs
    %  create cell array with {menu label, callback, tag}

 %  MENU LABEL                     CALLBACK                      TAG
fm={ 
 'File'                              ' '                        'filemenu'
 '>&Open Session...^o'               'sptool(''open'')'         'loadmenu'
 '>------'                           ' '                        ' '
 '>&Import...^i'                     'sptool(''import'')'       'importmenu'
 '>&Export...^e'                     'sptool(''export'')'       'exportmenu'
 '>------'                           ' '                        ' '
 '>&Save Session^s'                  'sptool(''save'');'        'savemenu'
 '>Save Session As...'               'sptool(''saveas'');'       'saveasmenu'
 '>------'                           ' '                        ' '
 '>Preferences...'                   'sptool(''pref'') '        'prefmenu'
 '>&Close^w'                         'sptool(''close'')'        'closemenu'};
 
    ud.filemenu_handles = makemenu(gcf, char(fm(:,1)),char(fm(:,2)), char(fm(:,3)));
    for idx = 4:6
      set(ud.filemenu_handles(idx),'Enable','off');
    end
 
 
 %  MENU LABEL                     CALLBACK                      TAG
em={ 
 'Edit'                             'sptool(''edit'')'           'editmenu'
 '>Duplicate'                       'sptool(''edit'')'           'dupmenu'
 '>Clear'                           'sptool(''edit'')'           'clearmenu'
 '>------'                          ' '                          ' '
 '>Name...'                         'sptool(''edit'')'           'newnamemenu'  
 '>Sampling Frequency...'           'sptool(''edit'')'           'freqmenu'};

    ud.editmenu_handles = makemenu(gcf, char(em(:,1)),char(em(:,2)), char(em(:,3)));
    ud.dupsub(1) = uimenu(ud.editmenu_handles(2),'Label',' ',...
           'tag','dupmenu','Callback',['sptool(''duplicate'',',int2str(1),')']);
    ud.clearsub(1) = uimenu(ud.editmenu_handles(3),'Label',' ',...
           'tag','clearmenu','Callback',['sptool(''clear'',',int2str(1),')']);
    ud.namesub(1) = uimenu(ud.editmenu_handles(4),'Label',' ',...
           'tag','newnamemenu','Callback',['sptool(''newname'',',int2str(1),')']);
    ud.freqsub(1) = uimenu(ud.editmenu_handles(5),'Label',' ',...
           'tag','freqmenu','Callback',['sptool(''freq'',',int2str(1),')']);
    for idx = 2:5
       set(ud.editmenu_handles(idx),'Enable','off');
    end


hm={'Help'                          ' '                          'helpmenu'
    '>Overview...'                  'sptool(''help'',''overview'')'  'helpoverview'
    '>Context Sensitive...^h'       'sptool(''help'',''mouse'')'  'helpmouse'
    };

    ud.helpmenu_handles = makemenu(gcf, char(hm(:,1)),char(hm(:,2)), char(hm(:,3)));
    
    
wm={'Window'                        'winmenu(gcf);'              'winmenu'};


   ud.winmenu_handles = makemenu(gcf, char(wm(:,1)),char(wm(:,2)), char(wm(:,3)));
   winmenu(gcf);

    ud.session = cell(numComponents,1);
    for i=1:numComponents
        ud.session{i} = [];
    end
    % the 'changeStruc' field will contain the structure which has been
    % altered by the most recent operation, as it was before the operation.
    %  operations include: clear, name change, import over (such as 
    %   applying a filter), sampling frequency change
    ud.changedStruc = [];
    ud.importSettings = [];
    ud.sessionPath = [];
    ud.pointer = 1;
    set(fig,'userdata',ud,'resizefcn','sptool(''resize'')')

    sptool('resize')
    selectionChanged(fig,'new')
    set(fig,'HandleVisibility','callback','visible','on')
        
%------------------------------------------------------------------------
% structArray = sptool('callall',fname,structArray)
% searches for all fname.m on path
% and calls all found with structArray = feval(fname,structArray)
case 'callall'
    fname = varargin{2};
    structArray = varargin{3};
    
    w = which('-all',fname);
    % make sure each entry is unique
    for i=length(w):-1:1
        ind = findcstr(w(1:i-1),w{i});
        if ~isempty(ind)
            w(i) = [];
        end
    end
    if length(w)>0
        origPath=pwd;
    end
    for i=1:length(w)
        thispath=char(w(i));
        pathsp=find(thispath==filesep);
        if isvms
            pathsp=find(thispath==']');
        end
        pathname=thispath(1:pathsp(end));
        cd(pathname)
        structArray = feval(fname,structArray);
    end
    if length(w)>0
        cd(origPath)
    end
    varargout{1} = structArray;
    
%------------------------------------------------------------------------
% p = sptool('getprefs',panelName)
% p = sptool('getprefs',panelName,fig)
%   Return preference structure for panel with panelName
%   Inputs:
%     panelName - string
%     fig (optional) - figure of SPTool; uses findobj if not given
%   Outputs:
%     p - value structure for this panel
%     p_defaults - default values structure for this panel
case 'getprefs'
    % set showhiddenhandles since this might be called from the command line:
    shh = get(0,'showhiddenhandles');
    set(0,'showhiddenhandles','on');
    panelName = varargin{2};
    if nargin > 2
        fig = varargin{3};
    else
        fig = findobj(0,'Tag','sptool');
    end
    ud = get(fig,'userdata');
    allPanels = {ud.prefs.panelName};
    i = findcstr(allPanels,panelName);
    if isempty(i)
        error(sprintf('Sorry, no panel with name ''%s''; available: %s',...
                     panelName, sprintf('\n   ''%s'' ',allPanels{:})))
    end
    %p = prefstruct(ud.prefs(i));
    p = cell2struct(ud.prefs(i).currentValue,ud.prefs(i).controls(:,1));
    varargout{1} = p;
    if nargout > 1
        varargout{2} = cell2struct(ud.prefs(i).controls(:,7),...
	                           ud.prefs(i).controls(:,1));
    end
    set(0,'showhiddenhandles',shh);

        
%------------------------------------------------------------------------
% sptool('setprefs',panelName,p)
% sptool('setprefs',panelName,p,fig)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -