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

📄 spectview.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 5 页
字号:
    if m.confidenceFlag
        set(ud.hand.confidenceCheckbox,'visible','on')
        set(ud.hand.confidenceEdit,'visible','on')
        set(ud.hand.confidenceCheckbox,'value',confid.enable)
        set(ud.hand.confidenceEdit,'string',confid.level)
        if confid.enable
            set(ud.hand.confidenceEdit,'enable','on')
        else
            set(ud.hand.confidenceEdit,'enable','off')
        end
    else
        set(ud.hand.confidenceCheckbox,'visible','off')
        set(ud.hand.confidenceEdit,'visible','off')
    end
    
%------------------------------------------------------------------------
% spectview('changeMethod')
%   callback of method popup
%   assumes spectview is current figure
case 'changeMethod'
    fig = gcf;
    ud = get(fig,'userdata');
    ind = ud.focusIndex;
    toolMethodNum = get(ud.hand.methodPopup,'value');
    methodNameList = get(ud.hand.methodPopup,'string');
    name = ud.methods(toolMethodNum).methodName;
    
    methodNum = findcstr(ud.spect(ind).specs.methodName,name);
    if isempty(methodNum)
        % need to add method to spect
        ud.spect(ind).specs.methodName{end+1} = name;
        ud.spect(ind).specs.valueArrays{end+1} = ...
                            ud.methods(toolMethodNum).default;
        methodNum = length(ud.spect(ind).specs.methodName);
        set(fig,'userdata',ud)
    end
    spectview('fillParams',fig,name,ud.spect(ind).specs.valueArrays{methodNum},...
              ud.spect(ind).confid)
    set([ud.hand.applyButton ud.hand.revertButton],'enable','on')
    
%------------------------------------------------------------------------
% spectview('paramChange',paramNum)
%   callback of uicontrol for a parameter
%   assumes spectview is current figure
case 'paramChange'
    paramNum = varargin{2};
    fig = gcf;
    ud = get(fig,'userdata');
    methodNum = get(ud.hand.methodPopup,'value');

    % if this is a popup menu, it might have subordinate parameters:
    if strcmp(get(ud.hand.uicontrol(paramNum),'style'),'popupmenu')
       popupVal = get(ud.hand.uicontrol(paramNum),'value');
       subs = ud.methods(methodNum).subordinates{paramNum};
       % need to update subordinate parameters
       for i=1:length(subs)
           changeParamType(ud.methods(methodNum).type{subs(i)}{popupVal},...
                           ud.methods(methodNum).default{subs(i)}{popupVal},...
                           ud.methods(methodNum).label{subs(i)}{popupVal},...
                           ud.methods(methodNum).popupString{subs(i)}{popupVal},...
                           ud.hand.label(subs(i)),ud.hand.uicontrol(subs(i)))
       end
    end
    
    set([ud.hand.applyButton ud.hand.revertButton],'enable','on')

%------------------------------------------------------------------------
% spectview('apply')
%   callback of apply button
%   assumes spectview is current figure
case 'apply'
    fig = gcf;
    ud = get(fig,'userdata');
    setptr(fig,'watch')
    drawnow
    
    methodNum = get(ud.hand.methodPopup,'value');
    
    numParams = length(ud.methods(methodNum).default);
    valueArray = cell(numParams,1);
    for i=1:numParams
        switch get(ud.hand.uicontrol(i),'style')
        case {'checkbox','radiobutton','popupmenu'}
            valueArray{i} = get(ud.hand.uicontrol(i),'value');
        otherwise
            valueArray{i} = get(ud.hand.uicontrol(i),'string');
        end
    end
    spect = ud.spect(ud.focusIndex);
    spect.specs.methodNum = findcstr(spect.specs.methodName,...
                                      ud.methods(methodNum).methodName);
    if isempty(spect.specs.methodNum)  % spectrum doesn't have this method
        % add this method to spectrum
        spect.specs.methodNum = length(spect.specs.methodName)+1;
        spect.specs.methodName{end+1} = ud.methods(methodNum).methodName;
    end
    spect.specs.valueArrays{spect.specs.methodNum} = valueArray;
    spect.confid.enable = get(ud.hand.confidenceCheckbox,'value');
    spect.confid.level = get(ud.hand.confidenceEdit,'string');
    
    oldFs = FsFromSpect(spect);
    [errstr,spect] = computeSpectrum(ud.methods,spect);
    
    if ~isempty(errstr)
        msgbox(errstr,'Error','error','modal')
    else
        ind = ud.focusIndex;
        magscale = findcstr(get(ud.hand.magscaleMenu,'checked'),'on');
        yd = spmagfcn(spect.P,magscale);
        xd = spect.f;
        set(ud.lines(ind).h,'xdata',xd,'ydata',yd)
        
        if spect.confid.enable & ud.methods(methodNum).confidenceFlag
            Pc = spect.confid.Pc;
            if isempty(ud.patches{ind})
                ud.patches{ind} = patch(0,0,...
                   confidPatchColor(get(ud.lines(ind).h,'color')),...
                   'edgecolor','none','parent',ud.mainaxes,... 
                   'buttondownfcn',['spectview(''linedown'',' ...
                                         num2str(ind) ')']);

                % reorder children:
                bringToFront(fig,[ud.lines(ind).h ud.patches{ind}])
            end
            verts = [[xd(:); flipud(xd(:))] ...
                      spmagfcn([Pc(:,1); flipud(Pc(:,2))],magscale)];
            N = length(verts(:,1));
            numFaces = N-2;
            faces = zeros(numFaces,3);
            faces(1:2:end,1) = (1:numFaces/2)';
            faces(2:2:end,1) = (2:numFaces/2+1)';
            faces(1:2:end,2) = (2:numFaces/2+1)';
            faces(2:2:end,2) = N - (1:numFaces/2)';
            faces(1:2:end,3) = N - (0:numFaces/2-1)';
            faces(2:2:end,3) = N - (0:numFaces/2-1)';
            set(ud.patches{ind},'vertices',verts,...
                         'faces',faces,...
                         'visible','on');
        else
            spect.confid.Pc = [];
            if ~isempty(ud.patches{ind})
                set(ud.patches{ind},'visible','off')
            end
        end
        
        % set up fields for panning:
        ud.lines(ind).data = spect.P;
        ud.lines(ind).Fs = -1;  % panfcn uses -1 for unequally spaced
        ud.lines(ind).t0 = spect.f(1);% starting "time" for panfcn
        ud.lines(ind).xdata = spect.f;  

        ud.spect(ind) = spect;
        set(fig,'userdata',ud)
        
        % Zoom out both X and Y
        spzoomout(ud,~isequal(oldFs,FsFromSpect(spect)))
                
        set([ud.hand.applyButton ud.hand.revertButton],'enable','off')
    
        % poke new spectrum data into SPTool:
        sptool('import',spect)
    end
    setptr(fig,'arrow')

%------------------------------------------------------------------------
% spectview('revert')
%   callback of revert button
%   assumes spectview is current figure
case 'revert'
    fig = gcf;
    ud = get(fig,'userdata');
    spect = ud.spect(ud.focusIndex);
    methodNum = spect.specs.methodNum;
    
    spectview('fillParams',fig,spect.specs.methodName{methodNum},...
         spect.specs.valueArrays{methodNum},spect.confid)
         
    set(ud.hand.revertButton,'enable','off')
    if ~isempty(spect.P)
        set(ud.hand.applyButton,'enable','off')
    end
    
%------------------------------------------------------------------------
% spectview('confidence',flag)
%   callback of Confidence Checkbox and Edit
%   flag is either 'check' or 'edit'
%   assumes spectview is current figure
case 'confidence'
    fig = gcf;
    ud = get(fig,'userdata');
    flag = varargin{2};
    switch flag
    case 'check'
        if get(ud.hand.confidenceCheckbox,'value')
            set(ud.hand.confidenceEdit,'enable','on')
        else
            set(ud.hand.confidenceEdit,'enable','off')
        end
    case 'edit'
        % do nothing
    end
    set([ud.hand.applyButton ud.hand.revertButton],'enable','on')
    
%------------------------------------------------------------------------
% spectview('inherit')
%   callback of Inherit from popupmenu
%   assumes spectview is current figure
case 'inherit'
    fig = gcf;
    ud = get(fig,'userdata');
    v = get(ud.hand.inheritPopup,'value');
    if v == 1
        return
    else
        popupStr = get(ud.hand.inheritPopup,'string');
        popupUd = ud.inheritList;  % get(ud.hand.inheritPopup,'userdata');
        if ~isempty(popupUd) & v==length(popupStr)
           % user selected 'More...'
           [selection,ok] = listdlg('ListString',popupUd,...
             'SelectionMode','single',...
             'PromptString',...
             {'Select a Spectrum from which to inherit properties:'},...  
             'Name','Inherit Properties');
           if ~ok
               return
           end
           label = popupUd{selection};
        else
           label = popupStr{v};
        end
        
        spect = sptool('Spectra');
        ind = findcstr({spect.label},label);
        
        if isempty(spect(ind).specs) % use default method specs
            methodNum = 1;
            methodPopupStr =  get(ud.hand.methodPopup,'string');
            methodName = methodPopupStr{methodNum};
            valueArray = ud.methods(methodNum).default;
        else
            methodNum = spect(ind).specs.methodNum;
            methodName = spect(ind).specs.methodName(methodNum);
            valueArray = spect(ind).specs.valueArrays{methodNum};
        end
        if isempty(spect(ind).confid) % use default confidence specs
            confid.enable = 0;
            confid.level = '.95';
            confid.Pc = [];
        else       
            confid = spect(ind).confid;
        end

        spectview('fillParams',fig,methodName,valueArray,confid)
        
        set([ud.hand.applyButton ud.hand.revertButton],'enable','on')
        
        set(ud.hand.inheritPopup,'value',1);
    end
%------------------------------------------------------------------------
% errstr = spectview('setprefs',panelName,p)
% Set preferences for the panel with name panelName
% Inputs:
%   panelName - string; must be either 'ruler','color', or 'spectview'
%              (see sptprefreg for definitions)
%   p - preference structure for this panel
case 'setprefs'
    errstr = '';
    panelName = varargin{2};
    p = varargin{3};
    switch panelName
    case 'ruler'
        rc = evalin('base',p.rulerColor,'-1');
        if rc == -1
            errstr = 'The Ruler Color you entered cannot be evaluated.';
        elseif ~iscolor(rc)
            errstr = 'The Ruler Color you entered is not a valid color.';
        end
        if isempty(errstr)
            ms = evalin('base',p.markerSize,'-1');
            if ms == -1
                errstr = 'The Marker Size you entered cannot be evaluated.';
            elseif all(size(ms)~=1) | ms<=0 
                errstr = 'The Marker Size you entered must be a real scalar.';     
            end
        end
    case 'color'
        co = evalin('base',p.colorOrder,'-1');
        if co == -1
            errstr = 'The Color Order that you entered cannot be evaluated.';
        else
            if ~iscell(co)
                co = num2cell(co,[3 2]);  % convert to cell array
            end
            for i = 1:length(co)
                if ~iscolor(co{i})
                    errstr = 'The Color Order that you entered is invalid.';
                    break
                end
            end
        end
    
        if isempty(errstr)
            lso = evalin('base',p.linestyleOrder,'-1');
            if lso == -1
                errstr = 'The Line Style Order that you entered cannot be evaluated.';
            else
                if ~iscell(lso)
                    lso = num2cell(lso,[3 2]);  % convert to cell array
                end
                for i = 1:length(lso)
                    if isempty(findcstr({'-' '--' ':' '-.'},lso{i}))
                        errstr = 'The Line Style Order that you entered is invalid.';
                        break
                    end
                end
            end
        end
        
    case 'spectview'
    end
    varargout{1} = errstr;
    if ~isempty(errstr)
        return
    end
    
    fig = findobj('type','figure','tag','spectview');
    if ~isempty(fig)
        ud = get(fig,'userdata');
        newprefs = ud.prefs;
        switch panelName
        case 'ruler'
            markerStr = { '+' 'o' '*' '.' 'x' ...
               'square' 'diamond' 'v' '^' '>' '<' 'pentagram' 'hexagram'}';
            newprefs.ruler.color = p.rulerColor;
            newprefs.ruler.marker = markerStr{p.rulerMarker};
            newprefs.ruler.markersize = p.markerSize;
            
            if ud.prefs.tool.ruler
                rc = evalin('base',newprefs.ruler.color);
                set(ud.ruler.lines,'color',rc);
                set(ud.ruler.markers,'color',rc,'marker',newprefs.ruler.marker,...
                   'markersize',evalin('base',newprefs.ruler.markersize))
            end
        case 'color'
            newprefs.colororder = p.colorOrder;
            newprefs.linestyleorder = p.linestyleOrder;
            ud.colororder = num2cell(evalin('base',newprefs.colororder),2);
            ud.linestyleorder = num2cell(evalin('base',newprefs.linestyleorder),2);
        case 'spectview'
            newprefs.tool.ruler = p.rulerEnable;
            newprefs.tool.zoompersist = p.zoomFlag;

⌨️ 快捷键说明

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