Code covered by the BSD License  

Highlights from
Biodata toolbox

image thumbnail
from Biodata toolbox by Kris De Gussem
Database system coupled to chemometric algorithms that consequently stores spectra and related data

graphtools(varargin)
%This software package is dual licensed. You can use it according to the terms
%of either the GPLv3 or the BSD license.
%
%The Biodata toolbox for MATLAB: a spectral database system for storing and
%processing spectra
%C 2004-2008, Kris De Gussem, Raman Spectroscopy Research Group, Department
%of analytical chemistry, Ghent University
%C 2009 Kris De Gussem
%
%This file is part of Biodata.
%
%Biodata is free software: you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or
%(at your option) any later version.
%
%Biodata is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with Biodata.  If not, see <http://www.gnu.org/licenses/>.

%Copyright (c) 2004-2009, Kris De Gussem
%All rights reserved.
%
%Redistribution and use in source and binary forms, with or without 
%modification, are permitted provided that the following conditions are 
%met:
%
%    * Redistributions of source code must retain the above copyright 
%      notice, this list of conditions and the following disclaimer.
%    * Redistributions in binary form must reproduce the above copyright 
%      notice, this list of conditions and the following disclaimer in 
%      the documentation and/or other materials provided with the distribution
%    * Neither the name of Raman Spectroscopy Research Group, Department of
%	  analytical chemistry, Ghent University nor the names 
%      of its contributors may be used to endorse or promote products derived 
%      from this software without specific prior written permission.
%      
%THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
%AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
%IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
%ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
%LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
%CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
%SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
%INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
%CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
%ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
%POSSIBILITY OF SUCH DAMAGE.

function varargout = graphtools(varargin)
% GRAPHTOOLS M-file for graphtools.fig
%      GRAPHTOOLS, by itself, creates a new GRAPHTOOLS or raises the existing
%      singleton*.
%
%      H = GRAPHTOOLS returns the handle to a new GRAPHTOOLS or the handle to
%      the existing singleton*.
%
%      GRAPHTOOLS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GRAPHTOOLS.M with the given input arguments.
%
%      GRAPHTOOLS('Property','Value',...) creates a new GRAPHTOOLS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before graphtools_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to graphtools_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

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

% Last Modified by GUIDE v2.5 12-Nov-2004 15:23:58

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @graphtools_OpeningFcn, ...
                   'gui_OutputFcn',  @graphtools_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 graphtools is made visible.
function graphtools_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 graphtools (see VARARGIN)

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

%just in case the user prefers to select with a certain Biodata object, so he
%has entered it in the calling command ('graphsel (Biodata_name)')
if length (varargin) == 1
    handles.standard_bd = varargin {1};
else
    handles.standard_bd = [];
end
% Update handles structure
guidata (hObject, handles);

if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end

setappdata (hObject, 'InitializeFunction', @initialize_gui);%(fig_handle, handles)

global GraphToolsHandle
GraphToolsHandle = hObject;
clear GraphToolsHandle
global GraphToolsHandle

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


% --- Outputs from this function are returned to the command line.
function varargout = graphtools_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;


function ReloadHistory (handles, varname)
History = evalin ('base', sprintf ('%s.history', varname));
set (handles.ListHistory, 'String', History);


function SetAllNOK (handles)
%button PushJoin en JoinVariableList are handled elsewhere
set (handles.ListHistory, 'String', ' ');
set (handles.EditSavgolWidth, 'String', '');
set (handles.EditSavgolOrder, 'String', '');
set (handles.EditSavgolDeriv, 'String', '');
set (handles.EditSubstractFirst, 'String', '');
set (handles.EditSubstractSecond, 'String', '');
set (handles.EditPC, 'String', '');

set (handles.PushPlot, 'Enable', 'off');
set (handles.PushPCA, 'Enable', 'off');
set (handles.PushSNV, 'Enable', 'off');
set (handles.PushNormaliz, 'Enable', 'off');
set (handles.PushClean, 'Enable', 'off');
set (handles.PushViselim, 'Enable', 'off');
set (handles.PushSavgol, 'Enable', 'off');
set (handles.PushIntegrate, 'Enable', 'off');
set (handles.PushPreprocess, 'Enable', 'off');
set (handles.PushSubstract, 'Enable', 'off');
set (handles.PushSelect, 'Enable', 'off');
set (handles.ListHistory, 'Enable', 'off');
set (handles.EditSavgolWidth, 'Enable', 'off');
set (handles.EditSavgolOrder, 'Enable', 'off');
set (handles.EditSavgolDeriv, 'Enable', 'off');
set (handles.EditSubstractFirst, 'Enable', 'off');
set (handles.EditSubstractSecond, 'Enable', 'off');
set (handles.EditPC, 'Enable', 'off');


function SetAllOK (handles, varname)
%button PushJoin en JoinVariableList are handled elsewhere
ReloadHistory (handles, varname);
set (handles.EditSavgolWidth, 'String', '9');
set (handles.EditSavgolOrder, 'String', '3');
set (handles.EditSavgolDeriv, 'String', '1');
set (handles.EditSubstractFirst, 'String', '');
set (handles.EditSubstractSecond, 'String', '');

nr = evalin ('base', sprintf ('GetLv(%s)', varname));
set (handles.EditPC, 'String', nr);

set (handles.PushPlot, 'Enable', 'on');
set (handles.PushClean, 'Enable', 'on');
set (handles.PushSubstract, 'Enable', 'on');
set (handles.PushSelect, 'Enable', 'on');
set (handles.ListHistory, 'Enable', 'on');
set (handles.EditSubstractFirst, 'Enable', 'on');
set (handles.EditSubstractSecond, 'Enable', 'on');
set (handles.EditPC, 'Enable', 'on');
AdaptToReducedState (handles, varname);


function AdaptToReducedState (handles, varname)
reduced = evalin ('base', sprintf ('%s.reduceddata', varname));
if reduced == true
    set (handles.PushPCA, 'Enable', 'off');
    set (handles.PushSNV, 'Enable', 'off');
    set (handles.PushNormaliz, 'Enable', 'off');
    set (handles.PushViselim, 'Enable', 'off');
    set (handles.PushSavgol, 'Enable', 'off');
    set (handles.PushIntegrate, 'Enable', 'off');
    set (handles.PushPreprocess, 'Enable', 'off');
    set (handles.EditSavgolWidth, 'Enable', 'off');
    set (handles.EditSavgolOrder, 'Enable', 'off');
    set (handles.EditSavgolDeriv, 'Enable', 'off');
else
    set (handles.PushPCA, 'Enable', 'on');
    set (handles.PushSNV, 'Enable', 'on');
    set (handles.PushNormaliz, 'Enable', 'on');
    set (handles.PushViselim, 'Enable', 'on');
    set (handles.PushSavgol, 'Enable', 'on');
    set (handles.PushIntegrate, 'Enable', 'on');
    set (handles.PushPreprocess, 'Enable', 'on');
    set (handles.EditSavgolWidth, 'Enable', 'on');
    set (handles.EditSavgolOrder, 'Enable', 'on');
    set (handles.EditSavgolDeriv, 'Enable', 'on');
end


function SetJoinVariableList (handles)
bdvariables = GetBdVar;
isOK = (isempty (bdvariables) == false)&&(length (bdvariables) > 1);

if isOK
    set (handles.JoinVariableList, 'Enable', 'on');
    set (handles.JoinVariableList, 'String', bdvariables(1:length (bdvariables)));
    set (handles.PushJoin, 'Enable', 'on');
else
    set (handles.JoinVariableList, 'Enable', 'off');
    set (handles.JoinVariableList, 'String', ' ');
    set (handles.PushJoin, 'Enable', 'off');
end
set (handles.JoinVariableList, 'Value', 1); %zet automatische gelijk aan de eerste waarde


function initialize_gui(fig_handle, handles)
[bdvariables, handles] = LoadBdVar (handles);
if isempty (handles.standard_bd) == false
    for i = 1:length (bdvariables)
        if strcmp (bdvariables{i}, handles.standard_bd)
            set (handles.VariableList, 'Value', i);
        end
    end
    handles.standard_bd = [];
    guidata (fig_handle, handles);
end

VariableList_Callback(handles.VariableList, [], handles) %mogelijks problemen n toekomst: eventdata??


% --- Executes during object creation, after setting all properties.
function VariableList_CreateFcn(hObject, eventdata, handles)
% hObject    handle to VariableList (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


function c = RedrawRedInfo (handles, varname)
tmp = evalin ('base', sprintf ('%s.reduceddata', varname));
[n,m] = evalin ('base', sprintf ('size(%s.data)', varname));
if tmp == 1
    set (handles.RedInfo, 'String', sprintf ('contains reduced data, %i samples and %i variables', n , m));
else
    set (handles.RedInfo, 'String', sprintf ('contains full spectra, %i samples and %i colums', n , m));
end
c = evalin ('base', sprintf ('Count (%s)', varname));
if c == 0
    set (handles.RedInfo, 'String', 'contains no data');
end


% --- Executes on selection change in VariableList.
function VariableList_Callback(hObject, eventdata, handles)
% hObject    handle to VariableList (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 VariableList contents as cell array
%        contents{get(hObject,'Value')} returns selected item from VariableList
varname = GetSelectedBd (handles);
if strcmp (varname, ' ') ~= 1
    if isempty(evalin('base', sprintf('who(''%s'')', varname)))
        uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
        initialize_gui(gcbf, handles);
        return;
    end
    type = evalin ('base', sprintf ('class (%s)', varname));
else
    type = '';
end
if strcmpi (type, 'Biodata')
    %varname kan ook nog spatie zijn: ten teke van dat er geen Biodata
    %objecten zijn
    c = RedrawRedInfo (handles, varname);
    if c == 0
        SetAllNOK (handles);
    else
        SetAllOK (handles, varname);
    end
else
    SetAllNOK (handles);
    set (handles.RedInfo, 'String', ' ');
end
SetJoinVariableList (handles);


% --- Executes during object creation, after setting all properties.
function ListHistory_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ListHistory (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 ListHistory.
function ListHistory_Callback(hObject, eventdata, handles)
% hObject    handle to ListHistory (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 ListHistory contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ListHistory

% --- Executes on button press in PushPCA.
function PushPCA_Callback(hObject, eventdata, handles)
% hObject    handle to PushPCA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmpstr = sprintf ('%s = pca(%s);', bdname, bdname);
evalin ('base', tmpstr);
c = RedrawRedInfo (handles, bdname);
AdaptToReducedState (handles, bdname);
ReloadHistory (handles, bdname);


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



function EditPC_Callback(hObject, eventdata, handles)
% hObject    handle to EditPC (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 EditPC as text
%        str2double(get(hObject,'String')) returns contents of EditPC as a double
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmp = get (handles.EditPC, 'String');
succes = [];
try
    lv = str2num (tmp);
    if isnumeric (lv)
        %nog een controle op de dimensies voor toekennen van het aantal
        %PC's
        data = evalin ('base', sprintf ('%s.data', bdname)); 
        [m,n] = size (data);
        if (lv > 0) && (lv <= min (m,n))
            evalin ('base', sprintf ('%s.options.defaultlv = %i;', bdname, lv));
            succes = 1;
        end
    end
            
catch
end
if isempty (succes)
    nr = evalin ('base', sprintf ('GetLv(%s)', bdname));
    set (handles.EditPC, 'String', num2str(nr));
end


% --- Executes on button press in PushSNV.
function PushSNV_Callback(hObject, eventdata, handles)
% hObject    handle to PushSNV (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmpstr = sprintf ('%s = snv(%s);', bdname, bdname);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


% --- Executes on button press in PushNormaliz.
function PushNormaliz_Callback(hObject, eventdata, handles)
% hObject    handle to PushNormaliz (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmpstr = sprintf ('%s = normaliz(%s);', bdname, bdname);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


% --- Executes on button press in PushClean.
function PushClean_Callback(hObject, eventdata, handles)
% hObject    handle to PushClean (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

retval = questdlg (sprintf ('Are you sure to erase all data of Biodata object %s?', bdname), 'Biodata tools', 'Yes','No','No');
if strcmp (retval, 'Yes') == 1
    tmpstr = sprintf ('%s = Clean(%s);', bdname, bdname);
    evalin ('base', tmpstr);
end
ReloadHistory (handles, bdname);


% --- Executes on button press in PushViselim.
function PushViselim_Callback(hObject, eventdata, handles)
% hObject    handle to PushViselim (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmpstr = sprintf ('%s = viselim(%s);', bdname, bdname);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


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

bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

%get the different parameters for the savitsky-golay algortithm
wi = get (handles.EditSavgolWidth, 'String');
or = get (handles.EditSavgolOrder, 'String');
de = get (handles.EditSavgolDeriv, 'String');
wi = str2double(wi);
or = str2double(or);
de = str2double(de);

%do the actual derivatisation
tmpstr = sprintf ('%s = savgol (%s, %i, %i,%i)', bdname, bdname, wi, or, de);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


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



function EditSavgolWidth_Callback(hObject, eventdata, handles)
% hObject    handle to EditSavgolWidth (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 EditSavgolWidth as text
%        str2double(get(hObject,'String')) returns contents of EditSavgolWidth as a double
nr = [];
try
    nr = str2double(get (hObject, 'String'));
catch
    nr = [];
end
if (isnumeric (nr) == false) || isempty (nr) || isnan (nr) 
    set (hObject, 'String', '9');
end

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



function EditSavgolOrder_Callback(hObject, eventdata, handles)
% hObject    handle to EditSavgolOrder (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 EditSavgolOrder as text
%        str2double(get(hObject,'String')) returns contents of EditSavgolOrder as a double
nr = [];
try
    nr = str2double(get (hObject, 'String'));
catch
    nr = [];
end
if (isnumeric (nr) == false) || isempty (nr) || isnan (nr) 
    set (hObject, 'String', '3');
end


% --- Executes on button press in PushIntegrate.
function PushIntegrate_Callback(hObject, eventdata, handles)
% hObject    handle to PushIntegrate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmpstr = sprintf ('%s = Cumtrapz(%s);', bdname, bdname);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


% --- Executes on button press in PushPreprocess.
function PushPreprocess_Callback(hObject, eventdata, handles)
% hObject    handle to PushPreprocess (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

tmpstr = sprintf ('%s = preprocess(%s);', bdname, bdname);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


% --- Executes on button press in PushJoin.
function PushJoin_Callback(hObject, eventdata, handles)
% hObject    handle to PushJoin (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

contents = get(handles.JoinVariableList,'String');
if isempty (contents)
    return;
end
bdjoinname = contents{get(handles.JoinVariableList,'Value')};
clear contents;
if isempty (bdjoinname)
    return;
end
tmpstr = sprintf ('%s = join(%s, %s);', bdname, bdname, bdjoinname);
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);


% --- Executes during object creation, after setting all properties.
function JoinVariableList_CreateFcn(hObject, eventdata, handles)
% hObject    handle to JoinVariableList (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 JoinVariableList.
function JoinVariableList_Callback(hObject, eventdata, handles)
% hObject    handle to JoinVariableList (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 JoinVariableList contents as cell array
%        contents{get(hObject,'Value')} returns selected item from JoinVariableList


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

%check input
Value = get(handles.EditSubstractFirst, 'String');
xfirst = ControlSampleNr (Value);
if isempty (xfirst)
    warndlg('No sample numbers or incorrect input given for sample numbers. No Substraction executed.','Graphtools')
    return;
end
Value = get(handles.EditSubstractSecond, 'String');
xsecond = ControlSampleNr (Value);
if isempty (xsecond)
    warndlg('No sample numbers or incorrect input given for sample numbers. No Substraction executed.','Graphtools')
    return;
end

%execute substraction
bdname = GetSelectedBd (handles);%krijg de naam van het te bewerken object
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

dest = inputdlg ('Enter name for destination Biodata object:', 'Graphtools');
dest = dest{1};
tmpstr = sprintf ('%s = diff(%s, [%s], [%s]);', dest, bdname, num2str(xfirst), num2str(xsecond));
evalin ('base', tmpstr);
ReloadHistory (handles, bdname);

%reinitialize all windows
InitializeGraphplot;
InitializeGraphsel;
[bdvariables, handles] = LoadBdVar (handles);
SetAsSelectedBd(handles, bdname);
SetJoinVariableList (handles);


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



function EditSavgolDeriv_Callback(hObject, eventdata, handles)
% hObject    handle to EditSavgolDeriv (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 EditSavgolDeriv as text
%        str2double(get(hObject,'String')) returns contents of EditSavgolDeriv as a double
nr = [];
try
    nr = str2double(get (hObject, 'String'));
catch
    nr = [];
end
if (isnumeric (nr) == false) || isempty (nr) || isnan (nr) 
    set (hObject, 'String', '1');
end


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



function EditSubstractFirst_Callback(hObject, eventdata, handles)
% hObject    handle to EditSubstractFirst (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 EditSubstractFirst as text
%        str2double(get(hObject,'String')) returns contents of EditSubstractFirst as a double

%check input
Value = get(handles.EditSubstractFirst, 'String');
xfirst = ControlSampleNr (Value);
if isempty (xfirst)
    warndlg('No sample numbers or incorrect input given for sample numbers.','Graphtools')
    set(handles.EditSubstractFirst, 'String', ' ');
end


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



function EditSubstractSecond_Callback(hObject, eventdata, handles)
% hObject    handle to EditSubstractSecond (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 EditSubstractSecond as text
%        str2double(get(hObject,'String')) returns contents of EditSubstractSecond as a double
Value = get(handles.EditSubstractSecond, 'String');
xsecond = ControlSampleNr (Value);
if isempty (xsecond)
    warndlg('No sample numbers or incorrect input given for sample numbers.','Graphtools')
    set(handles.EditSubstractSecond, 'String', ' ');
end


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

bdname = GetSelectedBd (handles);
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

graphplot(bdname);


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


% --- Executes on button press in PushSelect.
function PushSelect_Callback(hObject, eventdata, handles)
% hObject    handle to PushSelect (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
bdname = GetSelectedBd (handles);
if isempty(evalin('base', sprintf('who(''%s'')', bdname)))
    uiwait(warndlg ('This Biodata variable does not exist anyore. Will reload graphtools...'));
    initialize_gui(gcbf, handles);
    return;
end

Graphsel(bdname);


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

Contact us at files@mathworks.com