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

📄 sptool.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 5 页
字号:
                             'tag','freqmenu', ...
                             'Callback',['sptool(''freq'',',int2str(idx1),')']);
                    end
                elseif ishandle(ud.freqsub(idx1))
                        set(ud.freqsub(idx1),'Visible','off')
                end
             end
 
         end
    else
         set(mh2,'Enable','off');
         set(mh3,'Enable','off');
         set(mh4,'Enable','off');
         set(mh5,'Enable','off');
    end
    drawnow;
    set(sptoolfig,'Userdata',ud);
    
%------------------------------------------------------------------------
% sptool('duplicate')
% callback of duplicate submenu
case 'duplicate'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    lab = get(ud.dupsub(varargin{2}),'Label');
    bracket = findstr(lab,'[');
    lab1 = [lab(1:bracket-2),'copy'];
    lab2 = lab(bracket-1:end); 
    idx = ud.compidx(varargin{2},:);
    
    % make sure new label is unique:
    labelList = {ud.session{idx(1)}.label};
    numCopies = 1;
    while ~isempty(findcstr(labelList,lab1))
        lab1 = [lab(1:bracket-2),'copy',num2str(numCopies)];
        numCopies = numCopies + 1;
    end
  
    ud.changedStruc = [];  
    ud.session{idx(1)}(end+1)=ud.session{idx(1)}(idx(2));
    ud.session{idx(1)}(end).label = lab1;
    n = length(get(ud.list(idx(1)),'String'));
    set(ud.list(idx(1)),'Value',n+1);
    ud.unchangedFlag = 0;
    set(ud.filemenu_handles(5),'Enable','on')
    set(sptoolfig,'UserData',ud);
    updateLists(sptoolfig)
    selectionChanged(sptoolfig,'dup')
    
%------------------------------------------------------------------------
% sptool('clear')
% callback of clear submenu
case 'clear'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    lab = get(ud.dupsub(varargin{2}),'Label');
    idx = ud.compidx(varargin{2},:);
    
    ud.changedStruc = ud.session{idx(1)}(idx(2));
    ud.session{idx(1)}(idx(2)) = [];
    
    if ud.components(idx(1)).multipleSelection
    % just remove item from selection
        listVal = get(ud.list(idx(1)),'value');
        listValInd = find(listVal==idx(2));
        listVal(listValInd+1:end) = listVal(listValInd+1:end)-1;
        listVal(listValInd) = [];
    else
        listVal = 1;
    end
    str = get(ud.list(idx(1)),'String');
    str(idx(2)) = [];
    set(ud.list(idx(1)),'Value',listVal,'String',str);    
    
    ud.unchangedFlag = 0;
    set(ud.filemenu_handles(5),'Enable','on')
    set(sptoolfig,'UserData',ud)
    selectionChanged(sptoolfig,'clear')
    
%------------------------------------------------------------------------
% sptool('newname')
% callback of Name... submenu
case 'newname'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    lab = get(ud.dupsub(varargin{2}),'Label');
    bracket = findstr(lab,'[');
    lab1 = lab(1:bracket-2);
    lab2 = lab(bracket-1:end);
    idx = ud.compidx(varargin{2},:);
    prompt={'Enter new variable name:'};
    def = {lab1};
    title = 'Name Change Dialog';
    lineNo = 1;
    lab1 =inputdlg(prompt,title,lineNo,def);
    if isempty(lab1)
        return
    end            
    err = ~isvalidvar(lab1{:});
    if ~err
        currentlabels = get(ud.list(idx(1)),'String');
        labelList = sptool('labelList',sptoolfig);
        if ~isempty(findcstr(labelList,deblank(lab1{:})))
               % error prompt
               errstr = {'There is already an object in the SPTool '
                         'with this name.  Please use a unique name.'};
               errordlg(errstr,'Non-unique Name','replace');
               return
         end   
    else
         errstr = {'Sorry, the name you entered is not valid.'
                   'Please use a legal MATLAB variable name.'};
         errordlg(errstr,'Bad Variable Name','replace');
         return
    end     

    if isequal(ud.session{idx(1)}(idx(2)).label,lab1{:})
        % new label is the same as the old one - do nothing!
        return
    end
    ud.changedStruc = ud.session{idx(1)}(idx(2));
    ud.session{idx(1)}(idx(2)).label = lab1{:};
    ud.unchangedFlag = 0;
    set(ud.filemenu_handles(5),'Enable','on')
    set(sptoolfig,'UserData',ud);
    listStr = get(ud.list(idx(1)),'string');
    listStr{idx(2)} = [deblank(lab1{:}) lab2];
    set(ud.list(idx(1)),'string',listStr)
    selectionChanged(sptoolfig,'label')
    
%------------------------------------------------------------------------
% sptool('freq')
% callback of Sampling Frequency... submenu
case 'freq'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    lab = get(ud.dupsub(varargin{2}),'Label');
    idx = ud.compidx(varargin{2},:);
    prompt={'Enter the sampling frequency.'};
    def = {sprintf('%.9g',ud.session{idx(1)}(idx(2)).Fs)};
    title = 'Sampling Frequency for Signal Processing';
    lineNo = 1;
    Fs=inputdlg(prompt,title,lineNo,def);
    if isempty(Fs)
        return
    end
    [Fs,err] = validarg(Fs{:},[0 Inf],[1 1],'sampling frequency (or expression)');
    if err ~= 0
         return
    end
    if ud.session{idx(1)}(idx(2)).Fs == Fs
        % new Fs is the same as the old one - do nothing!
        return
    end
    
    ud.changedStruc = ud.session{idx(1)}(idx(2));
    ud.session{idx(1)}(idx(2)) = feval(ud.components(idx(1)).importFcn,'changeFs',...
                  ud.session{idx(1)}(idx(2)),Fs);
    ud.unchangedFlag = 0;
    set(ud.filemenu_handles(5),'Enable','on')
    set(sptoolfig,'UserData',ud);
    selectionChanged(sptoolfig,'Fs')

%------------------------------------------------------------------------
% sptool('help','overview')  <-- overview help
% sptool('help') <-- context sensitive help
case 'help'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    whichHelp = varargin{2};
    titleStr = 'SPTOOL Help';
    helpFcn = 'spthelpstr';
    if strcmp(whichHelp,'overview')
       spthelp('tag',sptoolfig,titleStr,helpFcn,'overview');
       return
    end
    saveEnableControls = [];
    if ud.pointer ~= 2   % if not in help mode
        numComponents = length(ud.components);
        % enter help mode
        controlNumber = 0;
        for idx1 = 1:numComponents
            controlNumber = controlNumber + 1;
            saveEnableControls(controlNumber) = ud.list(idx1);
            for idx2 = 1:length(ud.components(idx1).verbs)
                controlNumber = controlNumber + 1;
                saveEnableControls(controlNumber) = ud.buttonHandles(idx1).h(idx2);
            end
        end
        spthelp('enter',sptoolfig,saveEnableControls,[],titleStr,helpFcn)
    else
        spthelp('exit')
    end

%------------------------------------------------------------------------
%  sptool('verb',i,j)  - i component #, j verb #
case 'verb'
    sptoolfig = findobj(0,'Tag','sptool');
    setptr(sptoolfig,'watch')
    drawnow
    ud = get(sptoolfig,'UserData');
    i = varargin{2};
    j = varargin{3};
    feval(ud.components(i).verbs(j).owningClient,'action',...
          ud.components(i).verbs(j).action);
    setptr(sptoolfig,'arrow')
    
%------------------------------------------------------------------------
%  sptool('list',i)  - i component #     LISTBOX CALLBACK
case 'list'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    idx = varargin{2};
    if 0  % short cut (double click) is disabled for now
    % if strcmp(get(sptoolfig,'SelectionType'),'open')
       dc = ud.components(idx).defaultClient;
       whichClient = 0;
       k = 0;
       while ~whichClient
           k = k + 1;
           if strcmp(dc,ud.components(idx).verbs(k).owningClient)
              whichClient = k;
           end
       end
       sptool('verb',idx,whichClient);
    else
       selectionChanged(sptoolfig,'value')
    end
    
%----------------------------------------------------------------------------
% struct = sptool('changedStruc',sptoolfig) - return recently
%  changed structure (removed, imported, name or Fs changed)
%  sptoolfig - optional, found with findobj if not present
case 'changedStruc'
    if nargin < 2
        shh = get(0,'ShowHiddenHandles');
        set(0,'ShowHiddenHandles','on')
        sptoolfig = findobj(0,'Tag','sptool');
        set(0,'ShowHiddenHandles',shh);
    else
        sptoolfig = varargin{2};
    end
    ud = get(sptoolfig,'UserData');
    varargout{1} = ud.changedStruc;
    
%----------------------------------------------------------------------------
% Fs  = sptool('commonFs)
case 'commonFs'         
   % For sampling frequency, if there are filters in the SPTool,
        % use their common sampling frequency (or the last one if
        % they don't have one).  If there no filters, do the same
        % for Signals.  If no signals either, use Fs = 1.
        ftemp = sptool('Filters');
        if ~isempty(ftemp)
            Fs = ftemp(end).Fs;
        else
            stemp = sptool('Signals');
            if ~isempty(stemp)
                Fs = stemp(end).Fs;
            else
                Fs = 1;
            end
        end
        varargout{1} = Fs;
  
%----------------------------------------------------------------------------
%  Client API
%  can ask for the currently selected objects
% [s,ind] = sptool(componentName,allFlag)
% [s,ind] = sptool(componentName,allFlag,fig)
% Returns a structure array of the current data items in the SPTool
%   Inputs:
%      componentName - string; name of component e.g. 'Filters' or 'Signals'
%      allFlag - 1 ==> return all objects of the requested type in s
%                0 ==> return only the currently selected objects in s
%                allFlag is optional; it defaults to 1
%      fig - figure handle of SPTool; optional - if omitted, will be found with findobj
%   Outputs:
%       s - structure array
%       ind - optional output; indices of s which are currently selected 
%             in SPTool
otherwise
    sptoolfig = [];
    if nargin < 3
        shh = get(0,'ShowHiddenHandles');
        set(0,'ShowHiddenHandles','on')
        sptoolfig = findobj(0,'Tag','sptool');
        set(0,'ShowHiddenHandles',shh);
    else
        if isempty(varargin{3}) | ishandle(varargin{3})
            sptoolfig = varargin{3};
        else
            error('Invalid input.  Please type ''help sptool'' for more information.')
        end
    end
    
    if isempty(sptoolfig)
        error('Sorry, SPTool is not open.')
    end
    
    ud = get(sptoolfig,'UserData');
    l = {ud.components.name};
    whichComponent = findcstr(l,action);
    if isempty(whichComponent)
        error(sprintf('Sorry, no component with name ''%s''; available: %s',...
                     action, sprintf('''%s'' ',l{:})))
    end
    if nargin > 1
        allFlag = varargin{2};
    else
        allFlag = 1;
    end
    
    varargout{1} = ud.session{whichComponent};
    ind = get(ud.list(whichComponent),'value');
    if allFlag
        varargout{2} = ind;
    else
        if isempty(varargout{1})
            varargout = { [] [] };
        else
            varargout = {varargout{1}(ind) 1:length(ind)};
        end
    end
    
end

function updateLists(fig,componentNum)
%updateLists  - creates listbox strings for all components
%   based on ud.session

⌨️ 快捷键说明

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