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

📄 timeseriesviewer.m

📁 这个是时间序列分析的可视化工具
💻 M
📖 第 1 页 / 共 4 页
字号:
            value = str2num(get(handles.Value,'String'));
            
            t = mainhandles.data.(parm).time;
            v = mainhandles.data.(parm).values;
            
            a = feval(operator,v,value);
            
            %Time and Value for which the condition is met.
            tfind = t;  tfind(~a) = NaN;
            vfind = v;  vfind(~a) = NaN;
            
            mainhandles.data.(parm).conditional.time = tfind;
            mainhandles.data.(parm).conditional.values = vfind;
            mainhandles.data.(parm).conditional.equation = [parm ' ' operator ' ' num2str(value)];
            
            % Update guidata for main application
            guidata(mainhandles.figure1,mainhandles);
            
            % Change the tag.  This indicates to the caller that something has
            % happened (it ends a waitfor condition)
            set(get(handles.Parm,'Parent'),'Tag',num2str(rand));
            
            
        case 'close'
            %         localCreateFindValueGUI(hObject,eventdata,'apply');
            delete(get(hObject,'Parent'));
            
    end;
    
    function localUpdateLegend(hAx)
    % Update the legend on axes hAx
    % Use the parameter list as the legend strings
    
    parms = getappdata(hAx,'Parameters');
    if ~isempty(parms)
        hLeg = legend(hAx,parms);
    else
        legend(hAx,'off');      %Turn off if plot is empty
    end;    
    
            % --- Executes during object creation, after setting all properties.    function DerivedParametersListBox_CreateFcn(hObject, eventdata, handles)    % hObject    handle to DerivedParametersListBox (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 DerivedParametersListBox.    function DerivedParametersListBox_Callback(hObject, eventdata, handles)    % hObject    handle to DerivedParametersListBox (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 DerivedParametersListBox contents as cell array    %        contents{get(hObject,'Value')} returns selected item from DerivedParametersListBox            % --- Executes on button press in CreateDerivedButton.    function CreateDerivedButton_Callback(hObject, eventdata, handles)    % hObject    handle to CreateDerivedButton (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    structure with handles and user data (see GUIDATA)        % Open a generic edit box to let user type in equation
    
    eqn  = inputdlg('Enter equation, using names from parameter list (ALL CAPS)', ...
        'Create Derived Parameter');
    if isempty(eqn), return, end;
    eqn = eqn{1};       %Break out of cell
    
    % To just evaluate eqn, we need to define individual variables for each parameter.
    % The problem is that each parameter is on a unique time basis.  To get
    % around this, we have stored a field interpvalues in each parameter.  This
    % field contains the data interpolated to a common time basis.  This is
    % done by readsparsecsv.
    parmlist = fieldnames(handles.data);
    
    for ii=1:length(parmlist);
        name = parmlist{ii};
        assignhere(name,handles.data.(name).interpvalues);
    end;
    
    answer = eval(eqn);
    
    % Store results in a cell array within handles
    derivedparameters = handles.derivedparameters;
    new.equation = eqn;
    new.values = answer;
    % Don't need to store time - use handles.commontime    
    % Add to derived parameter list
    str = get(handles.DerivedParametersListBox,'String');
    str{end+1} = eqn;
    set(handles.DerivedParametersListBox,'String',str);
    
    % Update handles structure
    if isempty(derivedparameters)   %First time only
        handles.derivedparameters = {new};
    else
        handles.derivedparameters = {derivedparameters; new};
    end;
    
    % Alternate approach:
    % Just add derived parameters to bottom of regular parameter list.  One
    % problem, though - the parameter display is not a valid MATLAB variable
    % (or field name).
    
    guidata(hObject, handles);
    
    
    
    
    
        function localParameterContextMenuCallback(hObject,eventdata);
    % Callback function for ContextMenu on lines
    fn = get(hObject,'Tag');
    handles = guidata(hObject);
    
    % Get selected parameters
    vals = get(gco,'Value');
    parmlist = get(gco,'String');
    parms = parmlist(vals);
    
    hLine = gco;        %Selected line
    xd = get(hLine,'XData');
    yd = get(hLine,'YData');
    parm = get(hLine,'Tag');
    hAx = get(hLine,'Parent');   %Axes handle
    
    % switch fn
            % --------------------------------------------------------------------    function Untitled_2_Callback(hObject, eventdata, handles)    % hObject    handle to Untitled_2 (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    structure with handles and user data (see GUIDATA)            function color = localLighten(color)
    % Create a lighter version of a color
    chsv = rgb2hsv(color);
    chsv(2) = .25;     %Reduce luminescence value
    color = hsv2rgb(chsv);
            % --------------------------------------------------------------------    % --------------------------------------------------------------------    function HelpMain_Callback(hObject, eventdata, handles)    % hObject    handle to HelpMain (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    structure with handles and user data (see GUIDATA)            % --------------------------------------------------------------------    function HelpMenu_Callback(hObject, eventdata, handles)    % hObject    handle to HelpMenu (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    structure with handles and user data (see GUIDATA)    
    thisdir = which(mfilename);
    thisdir = fileparts(thisdir);    web([thisdir filesep 'private' filesep 'timeseriesviewer_help.html'])            % --- Executes during object creation, after setting all properties.    function TimeSelectPopup_CreateFcn(hObject, eventdata, handles)    % hObject    handle to TimeSelectPopup (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    empty - handles not created until after all CreateFcns called        % Hint: popupmenu 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 TimeSelectPopup.    function TimeSelectPopup_Callback(hObject, eventdata, handles)    % Update the axes limits to reflect new time
    
    % time = localGetCurrentTime(handles);
    % set(handles.axes,'XLim',[time(1) time(end)]);
    % set(handles.axes,'XTick',[time(1) mean(time([1 end])) time(end)]);
            function localUpdateParmlist(varargin)
    if nargin==1
        handles = varargin{1};
    else
        handles = guidata(varargin{1});
    end;
    
    % Updates the listbox to match the current workspace
    vars = evalin('base','who');
    
    % Find candidate variables
    series = localFindSeries;
    
    if isempty(series)      % No valid candidates.  Demo mode
        disp('You have no valid time series in your workspace.  Running in demo mode');
        time1 = 0:.001:1;
        parm1a = sin(4*pi*time1);
        parm1b = rand(size(time1));
        time2 = 0:.035:1.25;
        parm2a = cos(pi*time2);
        parm2b = rand(size(time2));
        
        assignin('base','time1',time1);
        assignin('base','time2',time2);
        assignin('base','parm1a',parm1a);
        assignin('base','parm1b',parm1b);
        assignin('base','parm2a',parm2a);
        assignin('base','parm2b',parm2b);
        
        series = localFindSeries;
    end;
    
    
    % Exclude defined time parameters
    times = get(handles.TimeSelectPopup,'String');
    keepers = ~ismember(series,times);
    series = series(keepers);
    
    
    set(handles.listbox1,'String',series)
    
    
    function series = localFindSeries
    % Find potential series (eligible variables for this application)
    
    vars = evalin('base','whos');
    
    % Keep only 2D numeric real arrays with one singleton dimension (row or
    % column vectors; no matrices)
    series={};
    nkeep = 0;
    foundmatrices = 0;
    for ii=1:length(vars)
        
        % Must be numeric
        if isnumeric(evalin('base',[vars(ii).name]))
            if prod(vars(ii).size)>1    % Not a scalar. Keep going
                % If there is no singleton dimension, make a note and move
                % on.
                if ( vars(ii).size(1)~=1 & vars(ii).size(2)~=1)
                    foundmatrices = 1;
                else
                    nkeep = nkeep + 1;
                    %                     series{nkeep} = vars(ii).name;
                    series{nkeep,1} = [vars(ii).name '  (' num2str(max(vars(ii).size)) ')'];
                end;
            end;
        end;
    end;    
    if foundmatrices
        warndlg([upper(mfilename) ' only supports row and column vectors. ' ...
                'Please split matrices into multiple variables.']);
    end;
            % --- Executes on button press in UpdateParametersButton.    function UpdateParametersButton_Callback(hObject, eventdata, handles)    % hObject    handle to UpdateParametersButton (see GCBO)    % eventdata  reserved - to be defined in a future version of MATLAB    % handles    structure with handles and user data (see GUIDATA)    localUpdateParmlist(handles)
            function time = localGetCurrentTime(handles);
    % Return vector of currently selected time
    timeslist = get(handles.TimeSelectPopup,'String');
    timeslist = localRemoveLengthFromParms(timeslist);
    timesind = get(handles.TimeSelectPopup,'Value');
    timestr = timeslist{timesind};
    time = evalin('base',timestr);
    
    function P = no_icon;
    % Create icon for mouse pointer indicating target isn't valid
    P=[ 2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
        2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
        2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
        2     2     2     2     2     2     2     1     1     2     2     2     1     2     2     2
        2     2     2     2     2     1     1     2     2     1     1     1     2     2     2     2
        2     2     2     2     1     2     2     2     2     2     1     1     2     2     2     2
        2     2     2     2     1     2     2     2     2     1     2     1     2     2     2     2
        2     2     2     1     2     2     2     2     1     2     2     2     1     2     2     2
        2     2     2     1     2     2     2     1     2     2     2     2     1     2     2     2
        2     2     2     2     1     2     1     2     2     2     2     1     2     2     2     2
        2     2     2     2     1     1     2     2     2     2     2     1     2     2     2     2
        2     2     2     2     1     1     1     2     2     1     1     2     2     2     2     2
        2     2     2     1     2     2     2     1     1     2     2     2     2     2     2     2
        2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
        2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2
        2     2     2     2     2     2     2     2     2     2     2     2     2     2     2     2];
    
    function tlim = localGetAxesLimits(handles);
    % Compute x axis limits
    timeslist = get(handles.TimeSelectPopup,'String');
    timeslist = localRemoveLengthFromParms(timeslist);
    tmin = inf;
    tmax = -inf;
    for ii=1:length(timeslist)
        time = evalin('base',timeslist{ii});
        if min(time) < tmin
            tmin = min(time);
        end;
        if max(time) > tmax
            tmax = max(time);
        end;
    end;
    
    tlim = [tmin tmax];
    
    function parms = localRemoveLengthFromParms(parms);
    % Remove the lengths from the parameter strings.
    for ii=1:length(parms);
        % Find the first blank.
        blank = strfind(parms{ii},' ');
        parms{ii} = parms{ii}(1:blank(1)-1);
    end;
    
    function parms = localAddLengthToParms(parms);
    % Remove the lengths from the parameter strings.
    for ii=1:length(parms);
        L = evalin('base',['length(' parms{ii} ');']);
        parms{ii} = [parms{ii} '  (' num2str(L) ')'];
    end;
    
%     function localClearParameter(hObject,event);
%     % Clear a parameter from the workspace
%     val = get(gco,'Value');
%     parms = get(gco,'String'); 
%     
%     % Strip lengths off of parms
%     parms = localRemoveLengthFromParms(parms);
%     
%     % Clear the parameter
%     evalin('base',['clear ' parms{val}]);
%     
%     % Update the Parameter List
%     localUpdateParmlist(guidata(hObject));
function localTurnOffZoom(handles)
tlim = localGetAxesLimits(handles);
set(handles.axes,'XLim',tlim);

% 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) tlim(2)]);
set(handles.axes(1:NoAx-1),'XTick',[]);

⌨️ 快捷键说明

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