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

📄 timeseriesviewer.m

📁 这个是时间序列分析的可视化工具
💻 M
📖 第 1 页 / 共 4 页
字号:
        set(handles.ZoomButton,'Value',0)
        linkedzoom off
        
        %Turn on cursors
        eventlabel
        
    else
        eventlabel off
    end;
    
    function localContextMenuCallback(hObject,eventdata);
    % Callback function for ContextMenu on lines
    fn = get(hObject,'Tag');
    handles = guidata(hObject);
    
    hLine = gco;        %Selected line
    xd = get(hLine,'XData');
    yd = get(hLine,'YData');
    parm = get(hLine,'Tag');
    hAx = get(hLine,'Parent');   %Axes handle
    
    switch fn
        case 'MaxMin'   %Compute and display max and min values
            % Label Max and Min of selected parameter
            % Compute max&min
            [ymax,maxind] = max(yd);
            [ymin,minind] = min(yd);
            
            xmax = xd(maxind);
            xmin = xd(minind);
            
            %Add text
            th(1) = text(xmax,ymax,{parm;['x_{max} = ' num2str(xmax)];['y_{max} = ' num2str(ymax)]});
            th(2) = text(xmin,ymin,{parm;['x_{min} = ' num2str(xmin)];['y_{min} = ' num2str(ymin)]});
            set(th(1),'VerticalAlignment','top');
            set(th(2),'VerticalAlignment','bottom');
            
            %Add marker, too
            lh(1) = line(xmax,ymax,'Color','k','Marker','o','MarkerFaceColor',get(hLine,'Color'),'MarkerSize',4);
            lh(2) = line(xmin,ymin,'Color','k','Marker','o','MarkerFaceColor',get(hLine,'Color'),'MarkerSize',4);
            
            setappdata(th(1),'h',lh(1));
            setappdata(th(2),'h',lh(2));
            setappdata(lh(1),'h',th(1));
            setappdata(lh(2),'h',th(2));
            
            %Right click marker or text to delete
            cmenu = uicontextmenu('Parent',handles.figure1);
            set([lh th],'UIContextMenu',cmenu);
            
            % Define the context menu items
            item1 = uimenu(cmenu, 'Label', 'Delete', ...
                'Callback', 'h=getappdata(gco,''h'');delete(h);delete(gco)');
            set(th,'BackgroundColor',localLighten(get(hLine,'Color')),'FontSize',8);
            set(th,'ButtonDownFcn','dragtext(gco)');
            
        case 'Mean'     %Compute and display mean value
            % Label Mean value of selected parameter
            
            % Compute mean
            ymn = mean(yd);
            
            
            % Add text.  Place it just to the right of the axis.
            xl = xlim(get(hLine,'Parent'));
            x = xl(2) - .05*diff(xl);
            th = text(x,ymn,{[parm ': mean = ' num2str(ymn)]});
            set(th,'VerticalAlignment','middle');
            
            % Add a line along the mean, too
            hMeanLine = line(xd,ymn*ones(1,length(xd)), ...
                'Color',localLighten(get(hLine,'Color')), ...
                'LineStyle', '-.');
            
            setappdata(th,'h',hMeanLine);
            setappdata(hMeanLine,'h',th);        
            
            %Right click text to delete
            cmenu = uicontextmenu('Parent',handles.figure1);
            set([th hMeanLine],'UIContextMenu',cmenu);
            
            % Define the context menu items
            item1 = uimenu(cmenu, 'Label', 'Delete', ...
                'Callback', 'h=getappdata(gco,''h'');delete(h);delete(gco)');
            set(th,'BackgroundColor',localLighten(get(hLine,'Color')),'FontSize',8);
            set(th,'ButtonDownFcn','dragtext(gco)');
            
        case 'Derivative'       %Plot the normalized derivative
            d = diff(yd);
            
            ymin = min(yd);     %We'll normalize to the original data
            ymax = max(yd);
            yl = [ymin ymax];
            
            dmn = min(d);
            dmx = max(d);
            
            dn = yl(1) + (d-dmn)*(diff(yl)/(dmx-dmn));   %Normalized to same scale as y
            dt = mean(diff(xd));        %Approximate dt
            dtime = xd(1:end-1)+.5*dt;  %Approximate time
            % Compute color for new line - same color, but lighter!
            color = get(hLine,'Color');
            color = localLighten(color);
            
            lh = line(dtime, dn,'Color',color);
            %         lh = patch([dtime NaN],[dn NaN],'k', ...
            %             'FaceColor','n', ...
            %             'EdgeColor',get(hLine,'Color'), ...
            %             'EdgeAlpha',.3);
            %         %Use patch instead of line, so that we can make it faint
            set(lh,'Tag',['d' parm]);
            
            %Right click line to delete
            cmenu = uicontextmenu('Parent',handles.figure1);
            set(lh,'UIContextMenu',cmenu);
            
            % Define the context menu items
            item1 = uimenu(cmenu, 'Label', 'Delete', ...
                'Callback', @localDeleteObject);
            
            % Update legend
            parms = getappdata(hAx,'Parameters');    %Store this so that we can restore legend        
            parms{end+1} = ['d' parm];
            setappdata(hAx,'Parameters',parms);
            legend(hAx,parms)
            
        case 'FindValue'        %Find a specified value
            % Create a simple dialog
            h = localCreateFindValueGUI([],[],'init',parm,handles);
            waitfor(h,'Tag');       %We change the tag when clicking apply button
            
            % Get updated handles structure
            handles = guidata(hObject);
            
            %Overlay conditional on plot
            values = handles.data.(parm).conditional.values;
            time   = handles.data.(parm).conditional.time;
            
            % Check if anything was found
            if all(isnan(values))
                msgbox('No values found','','modal');
                return
            end;
            
            % If only a few values, plot a marker
            if length(values)<=15 
                Marker = '*';
            else
                Marker = 'none';
            end;
            
            % Use same color as existing line, just a little thicker
            c = get(hLine,'Color');
            lh = line(time, values, ...
                'Parent',hAx, ...
                'Color',c, ...
                'LineWidth',3, ...
                'Marker',Marker, ...
                'Tag',handles.data.(parm).conditional.equation);
            
            parms = getappdata(hAx,'Parameters');
            parms{end+1} = handles.data.(parm).conditional.equation;
            
            setappdata(hAx,'Parameters',parms);
            
            % Add a context menu to delete
            cmenu = uicontextmenu('Parent',handles.figure1);
            set(lh,'UIContextMenu',cmenu);
            
            % Define the context menu items
            item1 = uimenu(cmenu, 'Label', 'Delete', ...
                'Callback', @localDeleteObject);
            
            % Update the legend.
            localUpdateLegend(hAx)
            
            
            
    end;
    
    
    
            % --------------------------------------------------------------------    function Untitled_1_Callback(hObject, eventdata, handles)    % hObject    handle to Untitled_1 (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    structure with handles and user data (see GUIDATA)    
    % Unused callback for File menu (top level)
    % Do not delete        function localZoomCallback(hFigure);
    % Callback for zoom action. 
    % Keep ticks at first, center, last
    % This is called by linkedzoom after each zoom update.
    
    % Get handles
    handles = guidata(hFigure); 
    
    % Get the axis limits
    noax = str2num(get(handles.NoAxesCombo(2),'String'));
    ax = handles.axes(noax);
    tlim = xlim(ax);
    
    % Set the ticks on last axes, hide on others
    NoAx = str2num(get(handles.NoAxesCombo(2),'String'));
    set(handles.axes(NoAx),'XTick',[tlim(1) mean(tlim([1 end])) tlim(end)]);
    set(handles.axes(1:NoAx-1),'XTick',[]);
    
    function localExportAxes(hObject,eventdata);
    % Callback for axes context menu item to export the axes (to a new
    % figure)
    
    % Clone the current axes
    hgS = handle2struct(gco);
    
    figure;
    ax = axes;
    struct2handle(hgS,ax);
    
    function localClearAxes(hObject,eventdata);
    % handle 2 input cases.
    switch get(hObject,'type')
        case 'axes'         % Internal call to clear axes
            h = hObject;  
        case 'uimenu'       % Context menu select clear
            h = gco;
    end;    
    
    % Callback for axes context menu item to clear the axes
    kids = get(h,'Children');     % Handle to children
    fig = get(h,'Parent');        % Figure handle
    
    if ~isempty(kids)               % Don't bother if there's nothing to delete
        localDeleteObject(kids,[],1);   % Third argument says delete all kids
    end;
    
    
    %     for ii=1:length(kids)
    %         set(fig,'CurrentObject',kids(ii));  % Make this child current (necessary for localDeleteObject)
    %         localDeleteObject(kids(ii),[]);
    %     end;
    
    function localDeleteObject(hObject,eventdata,deleteall);
    % Callback for context menu item to delete an object
    % Third input argument is an option for internal calls which tells
    % localDeleteObject that it is deleting all of the objects on an axes.
    % This provides speed benefits.  deleteall = 1 (true) or 0 (false).
    % You must still pass the handles to all objects you want to delete
    
    if nargin<3             % Default
        deleteall = 0;  
    end;
    
    % handle 2 input cases.
    switch get(hObject(1),'type')
        case 'uimenu'       % Context menu select clear
            h = gco;        % The selected line
        otherwise 
            h = hObject;  
    end;    
    
    % Delete an object and update the legend
    hAx = get(h(1),'Parent');       %Axes handle
    %     hAx = get(gco,'Parent');       %Axes handle
    handles = guidata(hObject(1));  % All handles
    parms = getappdata(hAx,'Parameters');    %Store this so that we can restore legend
    
    if deleteall
        % Remove parameters from list
        parmsnew = {};
        setappdata(hAx,'Parameters',parmsnew);
        
        % Delete objects
        delete(h)
        
        % Update legend
        localUpdateLegend(hAx)
        return
    end;
    
    
    
    %Remove from appdata
    thisparm = get(h,'Tag');
    %     thisparm = get(gco,'Tag');
    ind = strmatch(thisparm,parms);
    
    parmsnew = cell(length(parms)-1,1);
    for ii=1:length(parms)
        if ii<ind
            parmsnew{ii} = parms{ii};
        elseif ii>ind
            parmsnew{ii-1} = parms{ii};
        end;
    end;
    
    setappdata(hAx,'Parameters',parmsnew);
    
    % Delete line
    delete(h)
    %     delete(gco)
    h = flipud(findobj(hAx,'Type','Line'));
    % Update legend
    % if length(parmsnew)>0
    localUpdateLegend(hAx)
    % end;
    
    function hFigureFV = localCreateFindValueGUI(hObject,eventdata,action,parm,mainhandles);
    
    switch action
        case 'init' %Initialize
            hFigureFV = figure('Position',[300 300 150 80], ...
                'MenuBar','none','NumberTitle','off','Name','Find Values', ...
                'Visible','off','HandleVisibility','Callback');%, ...
            %            'CloseRequestFcn',{@localCreateFindValueGUI,'close',[],mainhandles});
            %             'WindowStyle','modal');
            
            movegui(hFigureFV,'center');
            set(hFigureFV,'Visible','on');
            
            hParm = uicontrol(hFigureFV, ...            % Parameter text string
                'Position',[10 50 40 17], ...
                'Style','text', ...
                'String',parm, ...
                'BackgroundColor',get(0,'defaultFigureColor'), ...
                'Tag','Parm');
            hOperator = uicontrol(hFigureFV, ...        % Operator menu
                'Position',[55 50 40 20], ...
                'Style','Popupmenu', ...
                'String',{'==';'<';'>';'<=';'>='}, ...
                'BackgroundColor','white', ...
                'Tag','Operator');        
            hValue = uicontrol(hFigureFV, ...           % Value edit box
                'Position',[100 50 40 20], ...
                'Style','Edit', ...
                'String','', ...
                'BackgroundColor','white', ...
                'Tag','Value');   
            hApply = uicontrol(hFigureFV, ...           % Apply button
                'Position',[25 10 40 20], ...
                'Style','Pushbutton', ...
                'String','Apply', ...
                'Callback',{@localCreateFindValueGUI,'apply',[],mainhandles});   
            hClose = uicontrol(hFigureFV, ...           % Close button
                'Position',[85 10 40 20], ...
                'Style','Pushbutton', ...
                'String','Close', ...
                'Callback',{@localCreateFindValueGUI,'close',[],mainhandles});   
            
            handles = guihandles(hFigureFV);
            guidata(hFigureFV,handles)
            
            
            
        case 'apply'
            handles= guidata(hObject);
            
            parm = get(handles.Parm,'String');
            str = get(handles.Operator,'String');
            opind = get(handles.Operator,'Value');
            operator = str{opind};
            

⌨️ 快捷键说明

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