image thumbnail
from GUIPlotTool by Nitin Skandan
This simple tool gives you better way to present the results of model simulation.

ResultsViewer(varargin)
% /***********************************************************************
% * Company:TATA ELXSI
% * File Name: 
% * Author :Nitin Skandan
% * Version :1.0
% * Description: Results Viewer
% * List of functions used :
% * Revisers Name :
% * Date :19-Oct-2006
% * Customer Bug No./ CMF No. :
% * Brief description of the fix/enhancement:
% Included holding between points to see sampling time effects
% ***********************************************************************/
function varargout = ResultsViewer(varargin)
% RESULTSVIEWER M-file for ResultsViewer.fig
%      RESULTSVIEWER, by itself, creates a new RESULTSVIEWER or raises the existing
%      singleton*.
%
%      H = RESULTSVIEWER returns the handle to a new RESULTSVIEWER or the handle to
%      the existing singleton*.
%
%      RESULTSVIEWER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RESULTSVIEWER.M with the given input arguments.
%
%      RESULTSVIEWER('Property','Value',...) creates a new RESULTSVIEWER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ResultsViewer_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ResultsViewer_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help ResultsViewer

% Last Modified by GUIDE v2.5 19-Aug-2006 06:49:33

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ResultsViewer_OpeningFcn, ...
                   'gui_OutputFcn',  @ResultsViewer_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(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 ResultsViewer is made visible.
function ResultsViewer_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 ResultsViewer (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes ResultsViewer wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = ResultsViewer_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 on selection change in defsignalmenu.
function defsignalmenu_Callback(hObject, eventdata, handles)
% hObject    handle to defsignalmenu (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 defsignalmenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from defsignalmenu


% --- Executes during object creation, after setting all properties.
function defsignalmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to defsignalmenu (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in secysignalmenu.
function secysignalmenu_Callback(hObject, eventdata, handles)
% hObject    handle to secysignalmenu (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 secysignalmenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from secysignalmenu


% --- Executes during object creation, after setting all properties.
function secysignalmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to secysignalmenu (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in modemenu.
function modemenu_Callback(hObject, eventdata, handles)
% hObject    handle to modemenu (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 modemenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from modemenu


% --- Executes during object creation, after setting all properties.
function modemenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to modemenu (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in plotbutton.
function plotbutton_Callback(hObject, eventdata, handles)
% hObject    handle to plotbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


%Get user data stored 
matobj = get(handles.open_mf,'UserData') ;
% Any plot instruction given here will make a plot ex:
%  Check is mat file is loaded or not
if (~isempty(matobj))
    % Mode select options
    fldname = fieldnames(matobj);
    ptrdef = get(handles.defsignalmenu, 'Value');
    ptrsecy = get(handles.secysignalmenu, 'Value');
    timemat = eval(['matobj.' fldname{ptrdef} '.time']);
    sigval1 = eval(['matobj.' fldname{ptrdef} '.signals.values']);
    sigval2 = eval(['matobj.' fldname{ptrsecy} '.signals.values']);   
    
    tsmode = 0 ; % time select mode flag
    % Time select mode action
    if(get(handles.timeselectmenu,'Value') > 1)
        tsmode = 1 ;
        sttim = str2num(cell2mat(get(handles.starttime,'String') ));
        endtim = str2num(cell2mat(get(handles.endtime,'String')) );
        if(sttim & endtim) %Error check
            stindx = find(timemat>=sttim,1,'first') ;
            endindx = find(timemat>=endtim,1, 'first') ;        
        else
            error('Enter start and end time correctly') ;
        end
        if(isempty(stindx)|isempty(endindx)) %Error check
            error('Enter start and end time correctly') ;
        else
            timemat = timemat(stindx:endindx) ;
            sigval1 = sigval1(stindx:endindx) ;
            sigval2 = sigval2(stindx:endindx) ;
        end
    end
    % Check hold status
    hldst = get(handles.holdcheck,'Value') ;
    % Loaded so plot
    switch(get(handles.modemenu, 'Value'))
        case 1, % Normal    
            if (hldst)
                [timemat, sigval1] = addholdelements(timemat, sigval1);
            end
            plot(timemat, sigval1) ;         
            xlabel('Time in seconds') ;
            ylabel(eval(['matobj.' fldname{ptrdef} '.signals.label']));
        case 2, % Combined
            if (hldst)
                [timematn, sigval1] = addholdelements(timemat, sigval1);
                [timematn, sigval2] = addholdelements(timemat, sigval2);
            else
                timematn = timemat ;
            end            
            plot(timematn, sigval1,timematn, sigval2) ;
            xlabel('Time in seconds') ;
            ylabel([eval(['matobj.' fldname{ptrdef} '.signals.label']) ' & ' ...
                eval(['matobj.' fldname{ptrsecy} '.signals.label'])]);            
        case 3, % Difference
            if (hldst)
                [timemat, sigdiff] = addholdelements(timemat, abs(sigval1-sigval2));
            else
                sigdiff = abs(sigval1-sigval2) ;
            end            
            plot(timemat,sigdiff ) ;
            xlabel('Time in seconds') ;
            ylabel([eval(['matobj.' fldname{ptrdef} '.signals.label']) ' - ' ...
                eval(['matobj.' fldname{ptrsecy} '.signals.label'])]);                                    
    end
    
else
    error('No mat file loaded') ;
end



% --- Executes on selection change in timeselectmenu.
function timeselectmenu_Callback(hObject, eventdata, handles)
% hObject    handle to timeselectmenu (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 timeselectmenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from timeselectmenu


% --- Executes during object creation, after setting all properties.
function timeselectmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to timeselectmenu (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function starttime_Callback(hObject, eventdata, handles)
% hObject    handle to starttime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of starttime as text
%        str2double(get(hObject,'String')) returns contents of starttime as a double


% --- Executes during object creation, after setting all properties.
function starttime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to starttime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function endtime_Callback(hObject, eventdata, handles)
% hObject    handle to endtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of endtime as text
%        str2double(get(hObject,'String')) returns contents of endtime as a double


% --- Executes during object creation, after setting all properties.
function endtime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to endtime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function open_mf_Callback(hObject, eventdata, handles)
% hObject    handle to open_mf (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Load mat file
[fname,path] = uigetfile({'*.mat','MAT-files (*.mat)'},'Pick the mat data file please');
matobj = load([path fname]) ;
%Store mat file data to GUI data structure
set(handles.open_mf,'UserData', matobj);
%Get signal names
fldname = fieldnames(matobj);
numsig = length(fldname);

for i=1:numsig
    if(isstruct(eval(['matobj.' fldname{i}])))
        signame{i} = eval(['matobj.' fldname{i} '.signals.label']);
    else
        error('Signals is not in structure with time format') ;
    end
end
% Set pop up menus
set(handles.defsignalmenu,'String', signame) ;
set(handles.secysignalmenu,'String', signame) ;
















% --------------------------------------------------------------------
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 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)




% --- Executes on button press in holdcheck.
function holdcheck_Callback(hObject, eventdata, handles)
% hObject    handle to holdcheck (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of holdcheck

% User defined function
function [timenew, signalnew] = addholdelements(timmat, sigmat)
j = 1 ;
for i=1:length(timmat)
    if(i ~= 1 )
        t1 = signalnew(1:j);
        t2 = timenew(1:j) ;
        signalnew = [t1 signalnew(j) sigmat(i)] ;
        timenew = [t2 timmat(i) timmat(i)] ;
        j = j+ 2 ;
    else        
        signalnew(j) = sigmat(i) ;
        timenew(j) = timmat(i) ;
    end
    
end

Contact us at files@mathworks.com