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

📄 spectview.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 5 页
字号:
        checks = {'off' 'off' 'on'};
    end
    old = findcstr(get(ud.hand.freqrangeMenu,'checked'),'on');
    new = findcstr(checks,'on');
    if ~isequal(old,new)
        scale = findcstr(get(ud.hand.freqscaleMenu,'checked'),'on');
        if new == 3 & scale == 2 
            % can't display negative values in logscale mode!
            % so don't change range!
            msgbox({'Sorry, you can''t set the range to include negative' ...
                    'frequencies when the Frequency Axis Scaling is logarithmic.'},...
                    'Logarithmic Scaling Conflict','warn','modal')
            return
        end
        set(ud.hand.freqrangeMenu,{'checked'},checks')
        % Zoom out both X and Y;  updates the rulers (default)
        spzoomout(ud,1)
        if setprefFlag
            p = sptool('getprefs','spectview');
            p.freqrange = new;
            sptool('setprefs','spectview',p)
        end
    end


%------------------------------------------------------------------------
% spectview('linedown',ind,mouseFlag,fig,forceFlag)
%  buttondownfcn callback of line in spectrum viewer
%  Inputs:
%     ind - integer; index of the line which was clicked or selected
%     mouseFlag - binary; == 1 ==> this is a mouse click (default)
%                         == 0 ==> this was from the legend line
%     fig - handle to figure (defaults to gcf)
%     forceFlag - binary; == 1 ==> update even if ud.focusline hasn't changed
%                       defaults to 0
case 'linedown'
    ind = varargin{2};  % which line was clicked
    
    if nargin < 3
        mouseFlag = 1;
    else
        mouseFlag = varargin{3};
    end
    if nargin < 4
        fig = gcf;
    else
        fig = varargin{4};
    end
    if nargin < 5
        forceFlag = 0;
    else
        forceFlag = varargin{5};
    end
    ud = get(fig,'userdata');
    
    if mouseFlag
       % cursor is custom
       if ud.prefs.tool.ruler & strcmp(get(fig,'pointer'),'custom') & ...
             (ud.pointer==0)
           % means that cursor is on top of one of the ruler lines
           ruldown(0)
           return
       end
   
       if justzoom(fig), return, end
   
       invis = [];
       if ud.prefs.tool.ruler
           invis = [ud.ruler.lines ud.ruler.markers ud.ruler.hand.buttons ...
                [ud.patches{:}] ]';
       end
       if strcmp(get(ud.hand.magscaleMenu(1),'checked'),'on')
           xform = inline('10*log10(x)');
       else
           xform = 'real';
       end
       if panfcn('Ax',ud.mainaxes,...
              'Bounds',ud.limits,...
              'BorderAxes',ud.mainaxes_border,...
              'Data',ud.lines,...
              'Immediate',0,...
              'Transform',xform,...
              'InterimPointer','fleur',...
              'Invisible',invis)
           if ud.prefs.tool.ruler
               ruler('newlimits')
           end
       end
    end     
       
    disableList = [ud.hand.methodPopup
                   ud.hand.methodLabel
                   ud.hand.uicontrol(:)
                   ud.hand.label(:)
                   ud.hand.confidenceCheckbox
                   ud.hand.confidenceEdit
                   ud.hand.inheritPopup];

    ud.focusIndex = ind;
    if ~isempty(ind)
        
       the_line = ud.lines(ind).h;
   
       if isequal(the_line, ud.focusline) & ~forceFlag
           return
       end
       
       ud.focusline = the_line;
   
       % make sure ruler lines are on top of stacking order, and that
       % patches are immediately behind their respective lines

       children = [ud.focusline; ud.patches{ind}];
       for i=[1:ind-1 ind+1:length(ud.lines)]
          children = [children; ud.lines(i).h; ud.patches{i}];
       end
       bringToFront(fig,children)
    
       % Force an initial choice of spectrum method
       choice = 'welch';  % (see spinit.m)
       
       % Select choice if it is available:
       defMethNum = find(strcmp(choice,(lower({ud.methods.methodName}))));
       if isempty(defMethNum)
           defMethNum = 1;  % Use first method listed in popupmenu
       end
       
       applyFlag = 0;
       importFlag = 0;  % need to poke this spectrum back into SPTool?
       % Why are we doing this?  Because it is possible to import 
       % a spectrum object into SPTool without any knowledge of
       % what its 'specs' are... only when the spectview is open
       % and initialized is it possible to know what the .specs
       % field of an imported spectrum is.
       if isempty(ud.spect(ind).specs)  % assign default specs
           %ud.spect(ind).specs.methodNum = defMethNum;
           ud.spect(ind).specs.valueArrays = {ud.methods(defMethNum).default};
           ud.spect(ind).specs.methodName = {ud.methods(defMethNum).methodName};
           ud.spect(ind).specs.methodNum = ...
               length(ud.spect(ind).specs.methodName);

           importFlag = 1;
       elseif isempty(findcstr({ud.methods.methodName},...
                ud.spect(ind).specs.methodName{ud.spect(ind).specs.methodNum}))
           % this spectrum is currently focused on a method
           % which is not available in spectview.
           %  SO, we need to find an entry we know or create one:
           methodNum = findcstr(ud.spect(ind).specs.methodName,...
                                ud.methods(defMethNum).methodName);
           if isempty(methodNum)  % add entry to list of specs for this spect
               ud.spect(ind).specs.methodName{end+1} = ud.methods(defMethNum).methodName;
               ud.spect(ind).specs.valueArrays{end+1} = ud.methods(defMethNum).default;
               ud.spect(ind).specs.methodNum = ...
                          length(ud.spect(ind).specs.methodName);
           else
               ud.spect(ind).specs.methodNum = methodNum;
           end
           applyFlag = 1;
           importFlag = 1;
       end
       if isempty(ud.spect(ind).confid) % assign default confidence specs
           ud.spect(ind).confid.enable = 0;
           ud.spect(ind).confid.level = '.95';
           ud.spect(ind).confid.Pc = [];
           importFlag = 1;          
       end
       if importFlag
           sptool('import',ud.spect(ind))
       end
       
       set(ud.hand.propLabel,...
           'string',['Selection: ' ud.spect(ind).label])
           %'backgroundcolor',get(ud.mainaxes,'color'),...
           %'foregroundcolor',ud.spect(ind).lineinfo.color,...
       if isstr(ud.spect(ind).signal)
           updateSignalInfo(ud,'',ud.spect(ind).signal,ud.spect(ind).Fs)
           set(disableList,'enable','off')
           set(ud.hand.applyButton,'enable','off')
       else
           updateSignalInfo(ud,ud.spect(ind).signalLabel,ud.spect(ind).signal,...
                               ud.spect(ind).Fs)
           set(disableList,'enable','on')
           if isempty(ud.spect(ind).P) | applyFlag
               set(ud.hand.applyButton,'enable','on')
           else
               set(ud.hand.applyButton,'enable','off')
           end
       end
       set(fig,'userdata',ud); 
       spectview('fillParams',fig,...
                ud.spect(ind).specs.methodName{ud.spect(ind).specs.methodNum},... 
                ud.spect(ind).specs.valueArrays{ud.spect(ind).specs.methodNum},... 
                ud.spect(ind).confid)
       set(ud.hand.revertButton,'enable','off')
    else
       ud.focusline = [];
       set(fig,'userdata',ud);
       updateSignalInfo(ud,'',[],[])
       set(ud.hand.propLabel,...
           'string','<no selection>')
        %   'backgroundcolor',get(0,'defaultuicontrolbackgroundcolor'),...
        %   'foregroundcolor',get(0,'defaultuicontrolforegroundcolor'),...
       set(disableList,'enable','off')
       set(ud.hand.applyButton,'enable','off')
       set(ud.hand.revertButton,'enable','off')
    end
            
   sptlegend('setvalue',ud.focusline,ud.focusIndex,1,fig)

   if ud.prefs.tool.ruler        
       ruler('showlines',fig)
       ruler('newlimits',fig)
       ruler('newsig',fig)
   end
    
%------------------------------------------------------------------------
% spectview('changefocus')
%  callback of sptlegend
case 'changefocus'
    i = sptlegend('value');
    spectview('linedown',i,0)
    
%------------------------------------------------------------------------
% spectview('newColor',lineColor,lineStyle)
%  newColorCallback of sptlegend
%  color and linestyle of ud.focusline have already been updated
case 'newColor'
    lineColor = varargin{2};
    lineStyle = varargin{3};
    
    fig = gcf;
    ud = get(fig,'userdata');
    
    ind = ud.focusIndex;
    ud.spect(ind).lineinfo.color = lineColor;
    ud.spect(ind).lineinfo.linestyle = lineStyle;
    %set(ud.hand.propLabel,'foregroundcolor',ud.spect(ind).lineinfo.color)

    if ~isempty(ud.patches{ind})
        set(ud.patches{ind},'facecolor',confidPatchColor(lineColor))
    end

    set(fig,'userdata',ud)

    % poke back into SPTool
    sptool('import',ud.spect(ind))
    
%------------------------------------------------------------------------
% enable = spectview('selection',action,msg,SPTfig)
%  respond to selection change in SPTool
% possible actions are
%    'view', 'create', 'update'
%  view Button is enabled when there is at least one spectrum selected
%  create button is enabled when there is exactly one signal selected
%  update button is enabled when there is exactly one signal & spectrum
%  msg - either 'value', 'label', 'Fs', 'dup', or 'clear'
%         'value' - only the listbox value has changed
%         'label' - one of the selected objects has changed it's name
%         'Fs' - one of the selected objects's .Fs field has changed
%         'dup' - a selected object was duplicated
%         'clear' - a selected object was cleared
case 'selection'
    msg = varargin{3};
    SPTfig = varargin{4};
    switch varargin{2}
    case 'view'
        [spect,ind] = sptool('Spectra',1,SPTfig); % get selected spectra
        % resolve any links at this time:
        spect = resolveLinks(spect,ind,SPTfig);
        
        if ~isempty(ind)
            enable = 'on';
        else
            enable = 'off';
        end
        fig = findobj('type','figure','tag','spectview');
        if ~isempty(fig)
            ud = get(fig,'userdata');
            switch msg
            case {'new','value','dup'}
                if ~isequal(spect(ind),ud.spect)
                    spectview('update',fig,spect,ind,SPTfig,msg)
                end
                changedStruc = sptool('changedStruc',SPTfig);
                if isempty(changedStruc) | ...
                   strcmp(changedStruc.SPTIdentifier.type,'Signal')
                    spectview('hotlink',changedStruc,msg,fig,SPTfig)
                end
                ud = get(fig,'userdata');
                ud.inheritList = newInheritString(ud.hand.inheritPopup,...
                             {spect.label},ud.maxPopupEntries);
                set(fig,'userdata',ud)
            case 'label'
                changedStruc = sptool('changedStruc',SPTfig);
                switch changedStruc.SPTIdentifier.type
                case 'Spectrum'
                    for i=1:length(ind)
                        if ~isequal(ud.spect(i).label,spect(ind(i)).label)
                            % change label of ud.spect(i)
                            ud.spect(i).label = spect(ind(i)).label;
                            if i==ud.focusIndex
                                set(ud.hand.propLabel,'string',...
                                     ['Selection: ' ud.spect(i).label])
                            end
                            ud.inheritList = newInheritString(ud.hand.inheritPopup,...
                                     {spect.label},ud.maxPopupEntries);
                            set(fig,'userdata',ud)
                            sptlegend('setstring',{ud.spect.label},...
                                              {ud.lines.columns},fig,1)
                            break
                        end
                    end
                case 'Signal'
                    spectview('hotlink',changedStruc,msg,fig,SPTfig)
                end
            case 'Fs'
                changedStruc = sptool('changedStruc',SPTfig);
                switch changedStruc.SPTIdentifier.type
                case 'Spectrum'
                    for i=1:length(ind)
                        if ~isequal(ud.spect(i).Fs,spect(ind(i)).Fs)
                            if isstr(ud.spect(i).signal)
                                break
                            end
                            % change Fs of ud.spect(i)
                            newFs = spect(ind(i)).Fs;
                            oldFs = ud.spect(i).Fs;
                            ud.spect(i).f = spect(ind(i)).f;
                            ud.spect(i).Fs = newFs;
                            ud.lines(i).Fs = 1./(ud.spect(i).f(2) - ud.spect(i).f(1));
                            set(ud.lines(i).h,'xdata',ud.spect(i).f)
                            siginfo2Str = sprintf('Fs = %.9g',ud.spect(i).Fs);
                            set(ud.hand.siginfo2Label,'string',siginfo2Str)
                            spzoomout(ud,0,1)
                            break
                        end
                    end
                case 'Signal'
                    spectview('hotlink',changedStruc,msg,fig,SPTfig)
                end
            case 'clear'
                changedStruc = sptool('changedStruc',SPTfig);
                switch changedStruc.SPTIdentifier.type
                case 'Spectrum'  % a spectrum was cleared
                    if isempty(ind)
                        spectview('update',fig,spect,ind,SPTfig,msg)
                    else
                        % first find out which one was deleted
                        rmInd = length(ud.spect);
                        for i = 1:length(ind)
                            if ~strcmp(spect(ind(i)).label,ud.spect(i).label)
                                rmInd = i;

⌨️ 快捷键说明

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