image thumbnail

eogui – a software to analyze electro-oculogram (EOG) recordings

by

 

10 Aug 2011 (Updated )

detects blinks and saccadic eye movements in EOG recordings

uigetdouble.m
function varargout = uigetdouble(varargin)
% $Id: uigetdouble.m 6 2004-12-13 12:28:39Z maik $
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @uigetdouble_OpeningFcn, ...
                   'gui_OutputFcn',  @uigetdouble_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 uigetdouble is made visible.
function uigetdouble_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 uigetdouble (see VARARGIN)

% prft zuerst ob wir auch eine gltige datenmatrix bekommen haben

% Parameter1 = Matrix
% Parameter2 = Index
% Parameter3 = Titel
% Parameter4 = Text


if (nargin<3+4)    
    return;
end

%varargin(1)
indim=size(varargin{1});

%ist die Eingabe auch eine Matrix ?
if(length(indim)~=2)   
    return;
end

handles.index=varargin{2};
set(handles.figure1,'Name',varargin{3});
set(handles.text,'String',varargin{4});

%sind weniger als 3 Kanle vorhanden, kein Auswerten mglich
if(indim(2)<3)
    return;
end

% Wenn alles ok, sichere Matrix fr sptere zugriffe und setze
% Fensterbreite, ist diese zu gro ....


handles.data = varargin{1};
handles.winsize=4000;

if(indim(1)<handles.winsize)
    handles.winsize=indim(1);
end


% Update handles structure
guidata(hObject, handles);

% Positioniere die GUI im Mittelpunkt
dlgRes=get(handles.figure1,'position');
monRes=get(0,'ScreenSize');
dlgRes(1)=(monRes(3)-dlgRes(3))/2;  %x-achse
dlgRes(2)=(monRes(4)/2)-(dlgRes(4)/2);  %x-achse
set(handles.figure1,'position',dlgRes);

%%-------------------------------------


% zusatzanzeige popupmenu fllen
text='nothing  '; %RS: two blanks to get 9 chars, like 'Channel 1' etc
for(i=1:indim(2)-1)
    text=[text;['Channel ' int2str(i)]];
end
set(handles.pmChannelSel,'String',text)



% Position slider einstellen
width=indim(1);
if(handles.winsize<width)    
    %set(handles.slider,'Max',width-handles.winsize,'Min',0);
    
    %Schrittweite einstellen
    stepratio = .1;                
    steptrough=handles.winsize / (width - handles.winsize); % Fensterbreite        
    steparrow =stepratio * steptrough;    % 10 % der fensterbreite
    set(handles.slider,'sliderstep', [steparrow steptrough]);
else
    set(handles.slider,'Visible','off');    
end


% X Kanal darstellen, zeichne ersten teil
uisubp('init',handles.Graph,1,0);
h=uisubp('select',handles.Graph,1);
r=1:handles.winsize;
plot(handles.data(r,1),handles.data(r,handles.index)); %RS: /1000 to get seconds
set(h,'xlim',[handles.data(1,1) handles.data(handles.winsize,1)]);
set(h,'ButtonDownFcn','uigetdouble(''Graph_ButtonDownFcn'',gcbo,[],guidata(gcbo))');
setminwinhigh(200);




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


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

% gibt es das feld ?
if(isfield(handles,'output'))      
    varargout{1} = handles.output;    
    close();
else
    varargout{1} = -1;
end    



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

handles.output=-1;  
guidata(hObject, handles);

uiresume(handles.figure1);


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


% prfe Daten
l=str2double(get(handles.editL,'String'));
r=str2double(get(handles.editR,'String'));

if isnan(l) | isnan(r)
    return;
end


% sichere result
handles.output=sort([l r]);  
guidata(hObject, handles);

%beende Dialog
uiresume(handles.figure1);



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


% --- Executes during object creation, after setting all properties.
function editL_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editL (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 editR_Callback(hObject, eventdata, handles)
% hObject    handle to editR (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 editR as text
%        str2double(get(hObject,'String')) returns contents of editR as a double


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


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




% --- Executes on slider movement.
function slider_Callback(hObject, eventdata, handles)
% hObject    handle to slider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of

%v2=fix(get(handles.slider,'Value'));
v2=1+fix(get(handles.slider,'Value')* (length(handles.data(:,1))-handles.winsize) );  % workaround matlab 7
v=get(handles.pmChannelSel,'Value');    
r=v2:v2+handles.winsize-1;

h=uisubp('select',handles.Graph,1);
plot(handles.data(r,1),handles.data(r,handles.index)); %RS /1000 to get seconds
set(h,'xlim',[handles.data(r(1),1) handles.data(r(end),1)]); 
setminwinhigh(200);  
set(h,'ButtonDownFcn','uigetdouble(''Graph_ButtonDownFcn'',gcbo,[],guidata(gcbo))');

if(v>1)
    h=uisubp('select',handles.Graph,2);    
    plot(handles.data(r,1),handles.data(r,v));        
    set(h,'xlim',[handles.data(r(1),1) handles.data(r(end),1)]);
    setminwinhigh(200);  
end





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

% Hint: slider controls usually have a light gray background, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




% --- Executes on button press in tbSetL.
function tbSetL_Callback(hObject, eventdata, handles)
% hObject    handle to tbSetL (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 tbSetL

set(handles.tbSetR,'Value',get(handles.tbSetR,'Min'));
if(get(hObject,'Value') ~= get(hObject,'Max'))
    set(hObject,'Value',get(hObject,'Max'));    
end
    


% --- Executes on button press in tbSetR.
function tbSetR_Callback(hObject, eventdata, handles)
% hObject    handle to tbSetR (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.tbSetL,'Value',get(handles.tbSetL,'Min'));
if(get(hObject,'Value') ~= get(hObject,'Max'))
    set(hObject,'Value',get(hObject,'Max'));    
end


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

%v2=fix(get(handles.slider,'Value'));
v2=fix(get(handles.slider,'Value')* (length(handles.data(:,1))-handles.winsize) );  % workaround matlab 7
v=get(handles.pmChannelSel,'Value');    
r=1+v2:v2+handles.winsize;


if(v==1) % nur x darstellen
    uisubp('remove',handles.Graph);
    uisubp('init',handles.Graph,1,0);
    
    h=uisubp('select',handles.Graph,1);    
    plot(handles.data(r,1),handles.data(r,handles.index));
    set(h,'xlim',[handles.data(1+v2,1) handles.data(v2+handles.winsize,1)]);
    setminwinhigh(200);    
    set(h,'ButtonDownFcn','uigetdouble(''Graph_ButtonDownFcn'',gcbo,[],guidata(gcbo))');
else
    uisubp('remove',handles.Graph);
    uisubp('init',handles.Graph,2);
    h=uisubp('select',handles.Graph,1);
    plot(handles.data(r,1),handles.data(r,handles.index));    
    setminwinhigh(200);
    set(h,'xlim',[handles.data(1+v2,1) handles.data(v2+handles.winsize,1)]);    
    set(h,'ButtonDownFcn','uigetdouble(''Graph_ButtonDownFcn'',gcbo,[],guidata(gcbo))');
    
    h=uisubp('select',handles.Graph,2);
    plot(handles.data(r,1),handles.data(r,v));    
    setminwinhigh(200);
    set(h,'xlim',[handles.data(1+v2,1) handles.data(v2+handles.winsize,1)]);        
end






% --- Executes during object creation, after setting all properties.
function pmChannelSel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pmChannelSel (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 mouse press over axes background.
function Graph_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to Graph (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

point1 = get(gca,'CurrentPoint');    % button down detected
%finalRect = rbbox;                   % return figure units
rec=mousesel();
if(~isempty(rec))
    delete(rec);
end
point2 = get(gca,'CurrentPoint');    % button up detected

xrage=sort([point1(1,1) point2(1,1)]);

start=find(handles.data(:,1)>=xrage(1));   % suche startsample
start=start(1);

ende=find(handles.data(:,1)>=xrage(2));   % suche endsample
ende=ende(1);

value=median(handles.data(start:ende,handles.index));

if(get(handles.tbSetL,'Value') == get(handles.tbSetL,'Max'))
    set(handles.editL,'String',num2str(value));
else
    set(handles.editR,'String',num2str(value));
end

Contact us