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

📄 timeseriesviewer.m

📁 这个是时间序列分析的可视化工具
💻 M
📖 第 1 页 / 共 4 页
字号:
function varargout = timeseriesviewer(varargin)
%% TIMESERIESVIEWER    Interactive application for exploring time series data
%
% TIMESERIESVIEWER opens the timeseriesviewer application. Detailed help is available
% from the help menu.  

% Scott Hirsch
% shirsch@mathworks.com
% 12/03

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @timeseriesviewer_OpeningFcn, ...
    'gui_OutputFcn',  @timeseriesviewer_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before timeseriesviewer is made visible.
function timeseriesviewer_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to timeseriesviewer (see VARARGIN)

% Choose default command line output for timeseriesviewer
handles.output = hObject;

% Handle multiple axes configurations.
% There are 4 configurations, containing between 1 and 4 axes. 
% All possible positions are laid out in guide, but we'll only use 4 of the
% axes.  Get the positions from all axes, then delete the ones we don't
% need.  We'll hide the axes we aren't currently using

% Store axes handles a bit more conveniently
ax1 = handles.Ax11;                                             %1 Axes
ax2 = [handles.Ax21 handles.Ax22];                              %2 Axes
ax3 = [handles.Ax31 handles.Ax32 handles.Ax33];                 %3 Axes
ax4 = [handles.Ax41 handles.Ax42 handles.Ax43 handles.Ax44];    %4 Axes

handles.axes = ax4;     %These are the only four we need
handles.axpos{1} = {get(ax1,'Position')};
handles.axpos{2} = get(ax2,'Position');
handles.axpos{3} = get(ax3,'Position');
handles.axpos{4} = get(ax4,'Position');

delete([ax1 ax2 ax3]);

% Initially, show only one axes
DA = 1;            %Vector from 1:number axes
set(ax4(DA),'Visible','on','Position',handles.axpos{1}{1});
set(ax4(DA+1:end),'Visible','off');

% Make the one visible axes look inactive
inactivecolor = [.7 .7 .7];
set(ax4(DA),'Color',inactivecolor,'XColor',inactivecolor,'YColor',inactivecolor);

% Configure drag and drop interface.
% Allow parameters to be dragged from parameter list to axes
% Also allow one axes to be dragged to another - replace the contents of
% the target with the source.  This is useful for moving a plot up to the
% top axes
% Finally, allow for parameters to be dragged from parameter list to
% TimeSelectPopup.  This defines these parameters as time bases, as removes
% them from the parameter list.
dd = dragndrop(handles.figure1);

set(dd,'DragHandles',[handles.listbox1 handles.axes]);
% set(dd,'DropHandles',[handles.axes handles.TimeSelectPopup]);
set(dd,'DropHandles',[handles.axes handles.AddTimeVectorsFrame]);
set(dd,'DropCallbacks',@localDropCallback);
set(dd,'DropValidDrag','all');
% set(dd,'DropValidDrag','all');

% Make only the Time Select popup valid.  Once the user adds something 
% to the TimeSelect, we'll enable visible axes, too.  This happens in
% localDropCallback.
% set(dd,'DropHandles',handles.TimeSelectPopup);
set(dd,'DropHandles',handles.AddTimeVectorsFrame);

handles.dd = dd;

% Add a context menu to the axes
% Add a context menu to each line
cmenu = uicontextmenu('Parent',handles.figure1);
set(handles.axes,'UIContextMenu',cmenu);
item1 = uimenu(cmenu, 'Label', 'Export Axes', ...        % Export Axes
    'Callback', @localExportAxes,'Tag','ExportAxes');

item2 = uimenu(cmenu, 'Label', 'Clear Axes', ...        % Clear Axes
    'Callback', @localClearAxes,'Tag','ClearAxes', ...
    'Separator','on');

% Put icons on toolbar
load zoom_icons
set(handles.ZoomButton,'CData',zoomxCData);

load datatip_icon
set(handles.DataLabelButton,'CData',cdata);

% Initialize a storage location for derived parameters
handles.derivedparameters = {};

% Initialize application data for storage of parameter names in each axes
for ii=1:length(handles.axes)
    setappdata(handles.axes(ii),'Parameters',{})
end;

% Load data from workspace
%   - populate parameter list with all 2D variables, except time
localUpdateParmlist(handles);

% Add a context menu to the parameter list
% I can't do this, because the context menu shows up whenever you drag!!
% cmenu = uicontextmenu('Parent',handles.figure1);
% set(handles.listbox1,'UIContextMenu',cmenu);
% item1 = uimenu(cmenu, 'Label', 'Clear', ...        % Clear Parameter
%     'Callback', @localClearParameter,'Tag','ClearParameter');
% item2 = uimenu(cmenu, 'Label', 'Update Parameters', ...        % Refresh Parameter List
%     'Callback', @localUpdateParmlist,'Tag','UpdateParameters');

% Initialize the TimeSelectPopup, so it knows that no data has been dragged
% to it.
firsttime = 1;
set(handles.TimeSelectPopup,'UserData',firsttime);

% Update handles structure
guidata(hObject, handles);
%UIWAIT makes timeseriesviewer wait for user response (see UIRESUME)
% uiwait(handles.figure1);

movegui(handles.figure1,'north')

% --- Outputs from this function are returned to the command line.
function varargout = timeseriesviewer_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.function listbox1_CreateFcn(hObject, eventdata, handles)% hObject    handle to listbox1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: listbox controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc    set(hObject,'BackgroundColor','white');else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end
% --- Executes on selection change in listbox1.function listbox1_Callback(hObject, eventdata, handles)% hObject    handle to listbox1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array%        contents{get(hObject,'Value')} returns selected item from listbox1


function localDropCallback(drag,drop);
% Don't do anything if drop target is invisible (such as a hidden axes)
vis = get(drop,'Visible');
if ~strcmp(vis,'on')
    return
end;
handles = guidata(drag);        %Get handles structure

% Switch between drop target types:
% 1) Popupmenu.  Identify a parameter as a time basis.
% 2) Axes.  Drag and drop plotting

switch get(drop,'Type')
    case 'uicontrol'    % Identify a parameter as a time basis.
        
        % Special case for first time
        %  - Enable other controls
        %  - Replace string with parameters
        firsttime = get(handles.TimeSelectPopup,'UserData');
        if firsttime
            oldtimes = {};
            firsttime = 0;
            set(handles.TimeSelectPopup,'UserData',firsttime);
            
            % Enable dropping on the axes.
%             handles.dd = set(handles.dd,'DropHandles',[handles.axes(1) handles.TimeSelectPopup]);
            handles.dd = set(handles.dd,'DropHandles',[handles.axes(1) handles.AddTimeVectorsFrame]);
            
            
        else
            % Get original time list
            val = get(handles.TimeSelectPopup,'Value');
            oldtimes = get(handles.TimeSelectPopup,'String'); 
            oldtimes = localRemoveLengthFromParms(oldtimes);
            selectedtime = oldtimes{val};
        end;
        
        % Get new time vectors from parameter list
        val = get(drag,'Value');
        parms = get(drag,'String'); 
        
        % Strip lengths off of parms
        parms = localRemoveLengthFromParms(parms);
        
        newtimes = parms(val);             %Name of parameters
        
        % Build unique intersection of the lists.
        times = unique([oldtimes;newtimes]);
        
        % Remove from parameter list
        ind = 1:length(parms);
        keepind = setdiff(ind,val);
        parms = parms(keepind);
        
        % Update parameter list
        set(handles.listbox1,'Value',1);
        parms = localAddLengthToParms(parms);
        set(handles.listbox1,'String',parms);
        
        % Update list of time vectors and Select the new time vector 
        % (first if multiple added)
        val = find(strcmp(newtimes{1},times));
        times = localAddLengthToParms(times);
        set(handles.TimeSelectPopup,'String',times);
        set(handles.TimeSelectPopup,'Value',val);
        
        % Set the axis limits to the max range of all time vectors
        tlim = localGetAxesLimits(handles);
        set(handles.axes,'XLim',tlim);
        set(handles.axes,'XTick',[tlim(1) mean(tlim) tlim(2)]);
        
    case 'axes'         % Drag and drop plotting
        % Switch between valid drag sources: 1) Parameter list. 2) another axes
        switch get(drag,'Type')
            case 'uicontrol'        % Parameter List
                val = get(drag,'Value');
                strng = get(drag,'String'); 
                parms = strng(val);             %Name of parameters
                
                % Strip lengths off of parms
                parms = localRemoveLengthFromParms(parms);
                
                set(handles.figure1,'CurrentAxes',drop);
                
                % First time only:
                % * Enable some controls
                % * Turn off text directions covering the axes
                % * Change the axes color
                if strcmp(get(handles.DirectionsText,'Visible'),'on');
                    % Enable other controls
                    list = [handles.ZoomButton handles.CursorButton handles.DataLabelButton ...
                            handles.NoAxesCombo handles.NoAxesText];
                    set(list,'Enable','on');
                    
                    set(handles.DirectionsText,'Visible','off');
                    % Give axes normal colors
                    set(handles.axes,'Color','w','XColor','k','YColor','k')
                end;
                
                % Get list of parameters already plotted
                oldparms = getappdata(drop,'Parameters');
                
                % New parameters
                newparms = setdiff(parms,oldparms);
                
                % Each parameter could have multiple columns.  Need to
                % account for all of them.
                %                 nLines = 0;
                %                 for ii=1:length(newparms)
                %                     [nr,nc] = evalin('base',['size(' newparms{ii} ')']);
                %                     if nr<nc, % Force into columns
                %                         newparms{ii} = newparms{ii}'; 
                %                         [nr,nc] = size(newparms{ii});
                %                     end 
                %                     nLines = nLines = nc;
                %                 end;
                
                % Initialize array of line handles
                lh = [];
                
                % Color picking.  This is flawed, but good enough for now.
                colors = get(0,'defaultAxesColorOrder');
                cind = length(oldparms) + 1; nc = length(colors);  %Number of colors
                    cind = rem(cind,nc);    % limit to 1..nc
                    if cind==0, cind=size(colors,1); end;
                
                % Get time basis
                time = localGetCurrentTime(handles);
                
                % Store list of parameters that are actually plotted.  Any
                % parameters that aren't the same length as the time basis
                % will be removed
                newparms_keep = {};
                keepers = 0;
                for ii=1:length(newparms)
                    data = evalin('base',newparms{ii});
                    
                    % Don't plot if this variable is not defined on
                    % the current time.  Instead, display a NO
                    % cursor
                    if length(data) ~= length(time)
                        ptr = get(handles.figure1,'Pointer');
                        set(handles.figure1,'Pointer','custom');
                        set(handles.figure1,'PointerShapeCData',no_icon,'PointerShapeHotSpot',[9 9]);
                        pause(.2)
                        set(handles.figure1,'Pointer',ptr);
                        
                        continue    % Go to next iteration
                    end;
                    
                    % Handle
                    lh = [lh line(time, data, ...
                        'Parent',drop, ...
                        'Color',colors(cind,:))];
                    
                    % Add to list of parameters we actually plotted
                    keepers = keepers+1;
                    newparms_keep{keepers,1} = newparms{ii};
                    
                    %Cycle through colors
                    cind = rem(cind+1,nc);
                    if cind==0, cind=size(colors,1); end;
                end;
                
                % Build list of all parameters plotted on this axes.
                parms = unique([oldparms;newparms_keep]);
                
                % Store tags. Skip if didn't add any parameters
                if any(lh)
                    set(lh,{'Tag'},newparms_keep);                  %Store names in lines
                end;
                %     plot(handles.timeNumVec, handles.rawdata(:,val),'Parent',drop)
                setappdata(drop,'Parameters',parms);    %Store this so that we can restore legend
                localUpdateLegend(drop);
                
                
                %If datalabels are on, update them
                if get(handles.DataLabelButton,'Value')
                    datalabel('update');
                end;
                

⌨️ 快捷键说明

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