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

📄 sptool.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 5 页
字号:
        set(0,'showhiddenhandles',shh)            
        error(errstr)
    end
    
    % If Fs required and no Fs was entered; use default Fs=1
    if FsFlag & (length(compCell) < numCompFields+1)  
        Fs = 1;
        compCell = {compCell{:} Fs};
    end
    
    % Complete cell array to be passed to the import function
    paramsCell = {formIndx compCell{:}};  
    [err,errstr,struc] = feval(ud.components(compIndx).importFcn,...
        'make',paramsCell);
    if err
        set(0,'showhiddenhandles',shh)        
        error(errstr)
    end
    
    if isstr(varargin{end})
        if ~isvalidvar(varargin{end})
            set(0,'showhiddenhandles',shh)
            error('Sorry, the label must be a valid MATLAB variable name.')
        else
            % Component label
            struc.label = varargin{end};
        end
    else
        struc.label = defaultLabel;
    end
    
    if nargout == 1
        varargout{1} = struc;
    end
    
case 'load'
% Importing Signals, Filters or Spectra from the command line:
% sptool('load',struc) checks for validity of struc and imports it
%   if it is valid.
% The following syntax creates new structure using 'make' facility of
% importFcn, and imports it into SPTool.

    error(nargchk(2,9,nargin))
    shh = get(0,'showhiddenhandles');
    set(0,'showhiddenhandles','on')
    sptoolfig = findobj(0,'Tag','sptool');
    if isempty(sptoolfig)           % SPTool is closed - open it!
        sptool('init')
        sptoolfig = findobj(0,'Tag','sptool');
    end

    ud = get(sptoolfig,'UserData');
    compNames = {ud.components.structName};
    
    if isstruct(varargin{2})  % Second input is a structure
        struc = varargin{2};
        if nargin > 2
            set(0,'showhiddenhandles',shh)
            error('Too many arguments for importing a structure.')
        end

        errstr = isvalidstruc(struc,ud.components,compNames);
        if ~isempty(errstr)
            set(0,'showhiddenhandles',shh)
            error(errstr)
        end
    else                      % Second input is not a structure
        if ~isstr(varargin{2}) & ~isnumeric(varargin{2})
            set(0,'showhiddenhandles',shh)
            errstr = sprintf(['Second argument must be:\n'...
                    '  a structure, \n'...
                    '  a string indicating the component name, or \n'...
                    '  a double containing data for the first component.'])...

            error(errstr)
        end
        % Create and load at the same time? - 'create' will parse the input
        struc =  sptool('create',varargin{2:end});
    end

    if nargout == 1
        varargout{1} = struc;
    end
    sptool('import',struc,1,sptoolfig)
    set(0,'showhiddenhandles',shh)

case 'import'
% sptool('import')  import structure using dialog box from sptimport
% sptool('import',struc)  import given structure
% sptool('import',struc,selectFlag)  import given structure and change
%   selection in appropriate column to the imported struc if
%     selectFlag == 1 (selectFlag defaults to 0)
% sptool('import',struc,selectFlag,sptoolfig)  
%    uses sptoolfig as figure handle of sptool; if omitted, uses findobj
% sptool('import',struc,selectFlag,sptoolfig,updateChangedStruc)
%   if updateChangedStruc == 1, changedStruc is updated in the case of
%    a replacement of struc (changedStruc is ALWAYS cleared when struc
%    is new).
%   if updateChangedStruc == 0, changedStruc is untouched (default)  

    if nargin < 4
        sptoolfig = findobj(0,'Tag','sptool');
    else
        sptoolfig = varargin{4};
    end    
    ud = get(sptoolfig,'UserData');

    if nargin < 5
        updateChangedStruc = 0;
    else
        updateChangedStruc = varargin{5};
    end

    if nargin < 3
        selectFlag = 0;
    else         
        selectFlag = varargin{3};
    end

    if isempty(sptoolfig)
        error('Sorry, SPTool is not open.')
    end
    labelList = sptool('labelList',sptoolfig);
    if nargin == 1
        [componentNum,struc,ud.importSettings,ud.importwd] = ...
              sptimport(ud.components,labelList,ud.importSettings,ud.importwd);
        figure(sptoolfig)
    
        if componentNum<1  % user cancelled - so save userdata and bail
            set(sptoolfig,'userdata',ud)
            return
        end
    else
        struc = varargin{2};
    end

    componentNum = findcstr({ud.components.structName},...
                            struc.SPTIdentifier.type);

    if ~isempty(findcstr(labelList,struc.label))
    % replace old structure with this label -----------------------------

        % first find column number of old structure:
        for i=1:length(ud.components)
            ind = findStructWithLabel(ud.session{i},struc.label);
            if ~isempty(ind)
                oldComponentNum = i;
                break
            end
        end

        if (nargin==1) | updateChangedStruc
            ud.changedStruc = ud.session{oldComponentNum}(ind);
        end
        if componentNum == oldComponentNum  % replace in same column
            oldComponent = ud.session{oldComponentNum}(ind);
            if (nargin==1) % | strcmp(oldComponent.label,struc.label)

                % The following doesn't work because filtdes.m calls
                % sptool('import') when the filter is already imported
                %if strcmp(oldComponent.label,struc.label)
                %    s1 = sprintf('Warning: Component structure %s ',struc.label);
                %    s2 = sprintf('already exists in SPTool; replacing %s.',struc.label);
                %    disp([s1 s2])
                %end

                % obtained by import dialogue so retain lineinfo field
                ud.session{oldComponentNum}(ind) = ...
                    feval(ud.components(oldComponentNum).importFcn,'merge',...
                      oldComponent,struc);

            else
                ud.session{oldComponentNum}(ind) = struc;
            end
        else  % overwrite object of different type (column)
            ud.session{oldComponentNum}(ind) = [];
            if isempty(ud.session{componentNum})
                ud.session{componentNum} = struc;
            else
                ud.session{componentNum}(end+1) = struc;
            end
        end

        set(sptoolfig,'userdata',ud)
        updateLists(sptoolfig,componentNum)
        if componentNum ~= oldComponentNum
            updateLists(sptoolfig,oldComponentNum)
            set(ud.list(componentNum),'value',length(ud.session{componentNum}))
        end
        if selectFlag | (nargin==1) | updateChangedStruc
            selectionChanged(sptoolfig,'new')
        end
    else
    % append structure to appropriate structure array -------------------
        ud.changedStruc = [];
        if isempty(ud.session{componentNum})
            ud.session{componentNum} = struc;
        else
            ud.session{componentNum}(end+1) = struc;
        end
        set(sptoolfig,'userdata',ud)
        updateLists(sptoolfig)
        set(ud.list(componentNum),'value',length(ud.session{componentNum}))
        selectionChanged(sptoolfig,'new')
    end
    for idx = 4:6
      set(ud.filemenu_handles(idx),'Enable','on');
    end
    ud = get(sptoolfig,'userdata');  % need to get this again since
                                     % selectionChanged call might have 
                                     % changed userdata
    ud.unchangedFlag = 0;
    set(ud.filemenu_handles(5),'Enable','on')
    set(sptoolfig,'UserData',ud);

% sptool('export')
%   Export objects from SPTool.
case 'export'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    [componentSelect,fname,pathname] = ...
        sptexport(ud.components,ud.session,get(ud.list,'value'),ud.exportwd);
    if ~isequal(pathname,ud.exportwd)
        ud.exportwd = pathname;
        set(sptoolfig,'UserData',ud)
    end

%------------------------------------------------------------------------
% labelList = sptool('labelList',SPTfig)
%   returns a cell array of strings containing all of the
%   object labels currently in the SPTool.
case 'labelList'
    fig = varargin{2};
    labelList = {};
    ud = get(fig,'userdata');
    for i=1:length(ud.components)
        if ~isempty(ud.session{i})
            labelList = {labelList{:} ud.session{i}.label};
        end
    end
    varargout{1} = labelList;

%------------------------------------------------------------------------
% sptool('edit')
% callback of Edit menu
case 'edit'
    sptoolfig = findobj(0,'Tag','sptool');
    ud = get(sptoolfig,'UserData');
    mh2 = ud.editmenu_handles(2);
    mh3 = ud.editmenu_handles(3);
    mh4 = ud.editmenu_handles(4);
    mh5 = ud.editmenu_handles(5);
    str = cell(0);
    for idx = 1:length(ud.components)
           tmp = get(ud.list(idx),'Value');
           if tmp == 1 & isempty(get(ud.list(idx),'String'))
              tmp = [];
           end
           if idx == 1,
              selobj = tmp(:);
              compidx = [ones(length(tmp),1)];
           else
              selobj = [selobj; tmp(:)];
              compidx = [compidx; idx*ones(length(tmp),1)];
           end
           
           ud.compidx = [compidx selobj];
           tmpstr = get(ud.list(idx),'String');
           if ~isempty(tmpstr)
              tmpstr = tmpstr(tmp);
              if idx == 1
                  str = tmpstr;
              else
                  str = cat(1,str,tmpstr);
              end
           end
    end
    
    if ~isempty(selobj)
         % first initialize FsFlag array (determines if you can edit the
         % sampling frequency of a component or not)
         for i = 1:length(ud.components)
            [popupString,fields,FsFlag(i),defaultLabel] = ...
                 feval(ud.components(i).importFcn,'fields');
         end
         
         set(mh2,'Enable','on');
         set(mh3,'Enable','on');
         set(mh4,'Enable','on');
         set(mh5,'Enable','on');
         
         % remove extra menu items:
         delete(ud.dupsub(length(selobj)+1:end))
         ud.dupsub(length(selobj)+1:end)=[];
         delete(ud.clearsub(length(selobj)+1:end))
         ud.clearsub(length(selobj)+1:end)=[];
         delete(ud.namesub(length(selobj)+1:end))
         ud.namesub(length(selobj)+1:end)=[];
         ind = length(selobj)+1:length(ud.freqsub);
         delete(ud.freqsub(ind( find(ishandle(ud.freqsub(ind))) )))
         ud.freqsub(length(selobj)+1:end)=[];
         
         for idx1 = 1:length(selobj)
             if idx1 > length(ud.dupsub)
             % create a new uimenu
                ud.dupsub(idx1) = uimenu(mh2,'Label',str{idx1},'tag','dupmenu',...
                     'Callback',['sptool(''duplicate'',',int2str(idx1),')']);
                ud.clearsub(idx1) = uimenu(mh3,'Label',str{idx1},'tag','clearmenu',...
                     'Callback',['sptool(''clear'',',int2str(idx1),')']);
                ud.namesub(idx1) = uimenu(mh4,'Label',str{idx1},...
                     'tag','newnamemenu',...
                     'Callback',['sptool(''newname'',',int2str(idx1),')']);
                if FsFlag(compidx(idx1))
                    ud.freqsub(idx1) = uimenu(mh5,'Label',str{idx1},...
                        'tag','freqmenu','Callback',['sptool(''freq'',',int2str(idx1),')']);
                else
                % just put place holder here - don't create menu item since
                % we can't edit the Sampling frequency for this component
                    ud.freqsub(idx1) = -1;
                end
             end
             if idx1 <= length(selobj) 
             % change label and ensure visibility of existing uimenu
                set(ud.dupsub(idx1),'Visible','on','Label',str{idx1});
                set(ud.clearsub(idx1),'Visible','on','Label',str{idx1});
                set(ud.namesub(idx1),'Visible','on','Label',str{idx1});
                if FsFlag(compidx(idx1))
                    if ishandle(ud.freqsub(idx1))
                        set(ud.freqsub(idx1),'Visible','on','Label',str{idx1});
                    else
                        ud.freqsub(idx1) = uimenu(mh5,'Label',str{idx1},...

⌨️ 快捷键说明

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