diff --git a/GUIs/DQ_Spectra_GUI.fig b/GUIs/DQ_Spectra_GUI.fig index 8afcda39..e9129820 100755 Binary files a/GUIs/DQ_Spectra_GUI.fig and b/GUIs/DQ_Spectra_GUI.fig differ diff --git a/GUIs/DQ_Spectra_GUI.m b/GUIs/DQ_Spectra_GUI.m index 5cd89270..bec11ad9 100755 --- a/GUIs/DQ_Spectra_GUI.m +++ b/GUIs/DQ_Spectra_GUI.m @@ -155,8 +155,8 @@ function DQ_Spectra_GUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.orig_ColName = fft_labels; % Set font size of DQ Table -desired_fontsize = erpworkingmemory('fontsizeGUI'); -handles.dq_table.FontSize = desired_fontsize; +FonsizeDefault = f_get_default_fontsize(); if isempty(FonsizeDefault) FonsizeDefault=12; end +handles.dq_table.FontSize = FonsizeDefault; handles.heatmap_on = 0; % Set outliers text window off diff --git a/GUIs/DQ_Table_GUI.fig b/GUIs/DQ_Table_GUI.fig index 64a7f676..c75e3e1d 100755 Binary files a/GUIs/DQ_Table_GUI.fig and b/GUIs/DQ_Table_GUI.fig differ diff --git a/GUIs/DQ_Table_GUI.m b/GUIs/DQ_Table_GUI.m index 8d7cba39..93e7bdbd 100755 --- a/GUIs/DQ_Table_GUI.m +++ b/GUIs/DQ_Table_GUI.m @@ -22,7 +22,7 @@ % Edit the above text to modify the response to pushbutton_help DQ_Table_GUI -% Last Modified by GUIDE v2.5 26-Jan-2023 16:54:38 +% Last Modified by GUIDE v2.5 14-Mar-2024 12:22:31 % Begin initialization code - DO NOT EDIT gui_Singleton = 0; @@ -59,7 +59,7 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) ERP = varargin{1}; ALLERP = varargin{2}; current_ERP = varargin{3}; -guiwin_num = varargin{4}; +guiwin_num = varargin{4}; %GUI positions (for multiple DQ tables) @@ -73,7 +73,7 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) end -%check contents +%check contents try assert(exist('ERP','var')==1) @@ -88,20 +88,20 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) end % Update GUI with ERPSET info -n_erp = numel(ALLERP); +n_erp = numel(ALLERP); if n_erp == 0 %for the case of showing aSME preavg - erp_names = ERP.erpname; + erp_names = ERP.erpname; handles.text_ERPSET_title.String = 'Selected EEG Dataset:'; handles.text_ERPSET_title.FontSize = 12; - handles.text11.Visible = 0; + handles.text11.Visible = 0; handles.newerpwin.Visible = 0; handles.pushbutton_selERP.Visible = 0; - handles.active_erpset.Style = 'text'; + handles.active_erpset.Style = 'text'; if numel(erp_names) > 15 handles.active_erpset.FontSize = 12.0; - set(handles.active_erpset,'FontUnits', 'normalized'); + set(handles.active_erpset,'FontUnits', 'normalized'); end %update handles guidata(hObject, handles); @@ -118,9 +118,9 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.active_erpset.String = erp_names; handles.active_erpset.Value = current_ERP; -%AMS: Multiple ERPset options -handles.newerpwin.String = erp_names; -handles.newerpwin.Value = current_ERP; +%AMS: Multiple ERPset options +handles.newerpwin.String = erp_names; +handles.newerpwin.Value = current_ERP; @@ -130,27 +130,27 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) end handles.popupmenu_DQ_type.String = type_names; -%handles.popupmenu_DQ_type.Value = n_dq; +%handles.popupmenu_DQ_type.Value = n_dq; %default to aSME (if available) or end of list -where_aSME = strcmpi('aSME',type_names); -where_aSME_corr = strcmpi('aSME (Corrected)',type_names); +where_aSME = strcmpi('aSME',type_names); +where_aSME_corr = strcmpi('aSME (Corrected)',type_names); if any(where_aSME) - indx_type = find(where_aSME); + indx_type = find(where_aSME); -elseif any(where_aSME_corr) - indx_type = find(where_aSME_corr); +elseif any(where_aSME_corr) + indx_type = find(where_aSME_corr); else - indx_type = n_dq; + indx_type = n_dq; end handles.popupmenu_DQ_type.Value = indx_type; try -[n_elec, n_tw, n_bin] = size(ERP.dataquality(indx_type).data); %default to aSME (or last metric) + [n_elec, n_tw, n_bin] = size(ERP.dataquality(indx_type).data); %default to aSME (or last metric) catch -[n_elec, n_tw, n_bin] = size(ERP.dataquality.data); %if only one measure + [n_elec, n_tw, n_bin] = size(ERP.dataquality.data); %if only one measure end if n_elec == 0 @@ -159,24 +159,21 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) n_bin = ERP.nbin; end -bin_names = numel(ERP.bindescr); -if bin_names == n_bin +n_bin_names = numel(ERP.bindescr); +if n_bin_names == n_bin + for i=1:n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; + bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; end -elseif bin_names ~= n_bin +else % if not every bin has a bin description, leave then off - for i=1:bin_names - if i <= n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; - elseif i > n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - NO DQ INFO EXISTS' ]; - end + for i=1:n_bin + bin_names{i} = ['BIN ' num2str(i)]; end end -handles.popupmenu_bin.String = n_bin_names; +handles.popupmenu_bin.String = bin_names; % handles.popupmenu_DQ_type.Value saves the indx of the selected DQ Measure selected_DQ_type = handles.popupmenu_DQ_type.Value; @@ -187,30 +184,30 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) pSEM = 0; pointwise_str = {'Point-wise SEM', 'Point-wise SEM, GrandAvg RMS', ... - 'Point-wise SEM Pool ERPSETs, RMS GrandAvg Combine','Point-wise SEM Pool ERPSETs, mean GrandAvg combine',... - 'Point-wise SEM (Corrected), GrandAvg RMS', ... - 'Point-wise SEM Pool ERPSETs(Corrected), RMS GrandAvg Combine',... - 'Point-wise SEM Pool ERPSETs(Corrected), mean GrandAvg combine'}; + 'Point-wise SEM Pool ERPSETs, RMS GrandAvg Combine','Point-wise SEM Pool ERPSETs, mean GrandAvg combine',... + 'Point-wise SEM (Corrected), GrandAvg RMS', ... + 'Point-wise SEM Pool ERPSETs(Corrected), RMS GrandAvg Combine',... + 'Point-wise SEM Pool ERPSETs(Corrected), mean GrandAvg combine'}; -handles.pointwise_str = pointwise_str; +handles.pointwise_str = pointwise_str; if isempty(table_data) %check if potentially pointwise SEM if any(strcmpi(pointwise_str, ERP.dataquality(selected_DQ_type).type)) && isempty(ERP.binerror) == 0 table_data = ERP.binerror(:,:,selected_bin); - pSEM = 1; + pSEM = 1; -% elseif strcmp(ERP.dataquality(selected_DQ_type).type,'Point-wise SEM (Corrected)') && isempty(ERP.binerror) == 0 -% table_data = ERP.binerror(:,:,selected_bin); -% pSEM = 1; -% - - else + % elseif strcmp(ERP.dataquality(selected_DQ_type).type,'Point-wise SEM (Corrected)') && isempty(ERP.binerror) == 0 + % table_data = ERP.binerror(:,:,selected_bin); + % pSEM = 1; + % + + else % Data empty here. table_data = nan(1); disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); end - + end @@ -222,14 +219,14 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) for i=1:n_elec elec_labels{i} = ERP.chanlocs(i).labels; end -else - +else + for i=1:ERP.nchan elec_labels{i} = i; end end handles.dq_table.RowName = elec_labels; -handles.orig_RowName = elec_labels; +handles.orig_RowName = elec_labels; % Time-window labels if isfield(ERP.dataquality(selected_DQ_type),'time_window_labels') && isempty(ERP.dataquality(selected_DQ_type).time_window_labels) == 0 && handles.checkbox_text_labels.Value == 1 @@ -254,7 +251,11 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) % Set font size of DQ Table desired_fontsize = erpworkingmemory('fontsizeGUI'); -handles.dq_table.FontSize = desired_fontsize; +try + handles.dq_table.FontSize = desired_fontsize; +catch + handles.dq_table.FontSize =11; +end handles.heatmap_on = 0; % @@ -262,31 +263,31 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) % nchan = ERP.nchan; % Total number of channels if ~isfield(ERP.chanlocs,'labels') - for e=1:nchan - ERP.chanlocs(e).labels = ['Ch' num2str(e)]; - end + for e=1:nchan + ERP.chanlocs(e).labels = ['Ch' num2str(e)]; + end end listch = {''}; for ch =1:nchan - listch{ch} = [num2str(ch) ' = ' ERP.chanlocs(ch).labels ]; + listch{ch} = [num2str(ch) ' = ' ERP.chanlocs(ch).labels ]; end handles.listch = listch; -chanArray = 1:ERP.nchan; %default +chanArray = 1:ERP.nchan; %default handles.indxlistch = chanArray; %default -handles.orig_indxlistch = chanArray; +handles.orig_indxlistch = chanArray; set(handles.chwindow, 'String', vect2colon(chanArray, 'Delimiter', 'off')); % Set outliers text window off -set(handles.stdwindow,'Enable','Off'); +set(handles.stdwindow,'Enable','Off'); set(handles.chwindow,'Enable','Off'); set(handles.chbutton,'Enable','Off'); set(handles.sdcorrection,'Enable','Off'); -set(handles.sdcorrection,'Visible','Off'); +set(handles.sdcorrection,'Visible','Off'); %set outliers value in handles off initially -handles.outliers_on = 0; +handles.outliers_on = 0; % Update handles structure handles.ERP = ERP; @@ -297,6 +298,25 @@ function DQ_Table_GUI_OpeningFcn(hObject, eventdata, handles, varargin) else handles.ALLERP = ALLERP; end +handles.checkbox_heatmap.BackgroundColor = [0.94 0.94 0.94]; +handles.checkbox_outliers.BackgroundColor = [0.94 0.94 0.94]; +handles.checkbox_text_labels.BackgroundColor = [0.94 0.94 0.94]; +handles.chbutton.BackgroundColor = [0.94 0.94 0.94]; +handles.text13.BackgroundColor = [0.94 0.94 0.94]; +handles.text6.BackgroundColor = [0.94 0.94 0.94]; +handles.text_ERPSET_title.BackgroundColor = [0.94 0.94 0.94]; +handles.text_DQ_type.BackgroundColor = [0.94 0.94 0.94]; +handles.text9.BackgroundColor = [0.94 0.94 0.94]; +handles.pushbutton_mat.BackgroundColor = [1 1 1]; +handles.pushbutton_xls.BackgroundColor = [1 1 1]; +handles.text11.BackgroundColor = [0.94 0.94 0.94]; +handles.pushbutton_selERP.BackgroundColor = [1 1 1]; +handles.pushbutton_help.BackgroundColor = [1 1 1]; +handles.pushbutton_done.BackgroundColor = [1 1 1]; +handles.chbutton.BackgroundColor = [1 1 1]; +handles.text12.BackgroundColor = [0.94 0.94 0.94]; +handles.stdwindow.BackgroundColor = [1 1 1]; +handles.chwindow.BackgroundColor = [1 1 1]; guidata(hObject, handles); @@ -333,30 +353,33 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles) % handles.popupmenu_DQ_type.Value saves the indx of the selected DQ Measure selected_DQ_type = handles.popupmenu_DQ_type.Value; selected_bin = handles.popupmenu_bin.Value; -pointwise_str = handles.pointwise_str; +pointwise_str = handles.pointwise_str; % Check data exists, plot if isempty(handles.ERP.dataquality(selected_DQ_type).data) % if pointwise SEM, use ERP.binerror if any(strcmpi(pointwise_str, handles.ERP.dataquality(selected_DQ_type).type)) && isempty(handles.ERP.binerror) == 0 - table_data = real(handles.ERP.binerror(:,:,selected_bin)); + table_data = handles.ERP.binerror(:,:,selected_bin); else + % elseif strcmp(handles.ERP.dataquality(selected_DQ_type).type,'Point-wise SEM (Corrected)') && isempty(handles.ERP.binerror) == 0 + % table_data = handles.ERP.binerror(:,:,selected_bin); + % else + % + + % Data empty here. table_data = nan(1); disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); end - -elseif selected_bin > length(handles.ERP.dataquality(1).data) - table_data = nan(1); - disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); else % data is present and correct - + + if strcmp(handles.ERP.dataquality(selected_DQ_type).type,'SD Across Trials') && isempty(handles.ERP.binerror) == 0 table_data = handles.ERP.dataquality(selected_DQ_type).data.SD_bias(:,:,selected_bin); %SD (Divided by N-1) set(handles.sdcorrection,'Enable','On'); - set(handles.sdcorrection,'Visible','On'); + set(handles.sdcorrection,'Visible','On'); else table_data = handles.ERP.dataquality(selected_DQ_type).data(:,:,selected_bin); set(handles.sdcorrection,'Enable','Off'); @@ -365,6 +388,10 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles) end +handles.dq_table.Data = table_data; +handles.orig_data = table_data; + + % Time-window labels clear tw_labels ERP = handles.ERP; @@ -375,10 +402,6 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles) [n_elec, n_tw, n_bin] = size(ERP.dataquality(selected_DQ_type).data); end -if selected_DQ_type == 2 % if Point-wise SEM - [n_elec, n_tw, n_bin] = size(ERP.dataquality(selected_DQ_type-1).data); -end - if isfield(ERP.dataquality(selected_DQ_type),'time_window_labels') && isempty(ERP.dataquality(selected_DQ_type).time_window_labels) == 0 && handles.checkbox_text_labels.Value == 1 tw_labels = ERP.dataquality(selected_DQ_type).time_window_labels; elseif isempty(ERP.dataquality(selected_DQ_type).times) @@ -392,38 +415,17 @@ function popupmenu_DQ_type_Callback(hObject, eventdata, handles) end handles.dq_table.ColumnName = tw_labels; -bin_names = numel(ERP.bindescr); -% Bin refresh -if bin_names == n_bin - for i=1:n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; - end -elseif bin_names ~= n_bin - % if not every bin has a bin description, leave then off - for i=1:bin_names - if i <= n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; - elseif i > n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - NO DQ INFO EXISTS' ]; - end - end -end - -handles.popupmenu_bin.String = n_bin_names; -handles.dq_table.Data = table_data; -handles.orig_data = table_data; - if handles.heatmap_on redraw_heatmap(hObject, eventdata, handles); end -if handles.outliers_on - clear_heatmap(hObject, eventdata, handles); - handles.heatmap_on = 0; - - redraw_outliers(hObject, eventdata, handles); - set(handles.checkbox_outliers,'Value',1); +if handles.outliers_on + clear_heatmap(hObject, eventdata, handles); + handles.heatmap_on = 0; + + redraw_outliers(hObject, eventdata, handles); + set(handles.checkbox_outliers,'Value',1); end @@ -456,51 +458,48 @@ function popupmenu_bin_Callback(hObject, eventdata, handles) % handles.popupmenu_DQ_type.Value saves the indx of the selected DQ Measure selected_DQ_type = handles.popupmenu_DQ_type.Value; selected_bin = handles.popupmenu_bin.Value; -pointwise_str = handles.pointwise_str; +pointwise_str = handles.pointwise_str; % Check data exists, plot if isempty(handles.ERP.dataquality(selected_DQ_type).data) % if pointwise SEM, use ERP.binerror - if any(strcmpi(pointwise_str,handles.ERP.dataquality(selected_DQ_type).type)) && isempty(handles.ERP.binerror) == 0 - table_data = real(handles.ERP.binerror(:,:,selected_bin)); + if any(strcmpi(pointwise_str,handles.ERP.dataquality(selected_DQ_type).type)) && isempty(handles.ERP.binerror) == 0 + table_data = handles.ERP.binerror(:,:,selected_bin); else % Data empty here. table_data = nan(1); disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); end - -elseif selected_bin > length(handles.ERP.dataquality(1).data) - table_data = nan(1); - disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); else % data is present and correct table_data = handles.ERP.dataquality(selected_DQ_type).data(:,:,selected_bin); end + handles.dq_table.Data = table_data; handles.orig_data = table_data; %if user switches bin and both heatmap & outliers on, %use shortcircuit to clear outliers and redraw heatmap only -if handles.heatmap_on %|| handles.outliers_on +if handles.heatmap_on %|| handles.outliers_on clear_outliers(hObject, eventdata, handles); redraw_heatmap(hObject, eventdata, handles); - %turn outliers off + %turn outliers off handles.outliers = 0; - set(handles.checkbox_outliers,'Value',0); + set(handles.checkbox_outliers,'Value',0); end %if only outliers on, then clear heatmap and redraw outliers -if handles.outliers_on - clear_heatmap(hObject, eventdata, handles); - handles.heatmap_on = 0; - - redraw_outliers(hObject, eventdata, handles); - set(handles.checkbox_outliers,'Value',1); +if handles.outliers_on + clear_heatmap(hObject, eventdata, handles); + handles.heatmap_on = 0; + + redraw_outliers(hObject, eventdata, handles); + set(handles.checkbox_outliers,'Value',1); end @@ -535,7 +534,7 @@ function checkbox_text_labels_Callback(hObject, eventdata, handles) % table_data = handles.ERP.dataquality(selected_DQ_type).data.SD_bias(:,:,selected_bin); % else % table_data = handles.ERP.dataquality(selected_DQ_type).data(:,:,selected_bin); -% +% % end % handles.dq_table.Data = table_data; % handles.orig_data = table_data; @@ -568,8 +567,8 @@ function checkbox_text_labels_Callback(hObject, eventdata, handles) end - % Update handles structure - guidata(hObject, handles); +% Update handles structure +guidata(hObject, handles); % --- Executes on button press in pushbutton_xls. @@ -579,7 +578,7 @@ function pushbutton_xls_Callback(hObject, eventdata, handles) % handles structure with handles and user data (see GUIDATA) empty_filename = []; selected_DQ_type = handles.popupmenu_DQ_type.Value; -%sd_correction = handles.sdcorrection.Value; +%sd_correction = handles.sdcorrection.Value; save_data_quality(handles.ERP,empty_filename,'xlsx',selected_DQ_type) @@ -631,26 +630,27 @@ function checkbox_heatmap_Callback(hObject, eventdata, handles) heatmap_on = get(hObject,'Value'); if heatmap_on == 1 - + %if heatmap_on, then outliers not possible so clear outliers clear_outliers(hObject, eventdata, handles); - handles.outliers_on = 0; - set(handles.checkbox_outliers, 'Value', 0); - + handles.outliers_on = 0; + set(handles.checkbox_outliers, 'Value', 0); + redraw_heatmap(hObject, eventdata, handles); handles.heatmap_on = 1; -else +else clear_heatmap(hObject, eventdata, handles); handles.heatmap_on = 0; + %if outliers is on, then keep outliers active if handles.outliers_on == 1 - redraw_outliers(hObject, eventdata,handles); + redraw_outliers(hOBject, eventdata,handles); end end % Update handles structure guidata(hObject, handles); - + function redraw_heatmap(hObject, eventdata, handles) @@ -735,8 +735,8 @@ function pushbutton_selERP_Callback(hObject, eventdata, handles) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) selected_erpset = handles.newerpwin.Value; -sel_ERP = handles.ALLERP(selected_erpset); -DQ_Table_GUI(sel_ERP, handles.ALLERP, selected_erpset,2); +sel_ERP = handles.ALLERP(selected_erpset); +DQ_Table_GUI(sel_ERP, handles.ALLERP, selected_erpset,2); % --- Executes on button press in checkbox_outliers. @@ -750,11 +750,11 @@ function checkbox_outliers_Callback(hObject, eventdata, handles) % Hint: get(hObject,'Value') returns toggle state of checkbox_heatmap outliers_on = get(hObject,'Value'); % this is not the same as handles.outliers_on -if outliers_on == 1 +if outliers_on == 1 set(handles.stdwindow,'Enable','On'); set(handles.chwindow,'Enable','On'); set(handles.chbutton,'Enable','On'); -else +else set(handles.stdwindow,'Enable','Off'); set(handles.chwindow,'Enable','Off'); set(handles.chbutton,'Enable','Off'); @@ -764,7 +764,7 @@ function checkbox_outliers_Callback(hObject, eventdata, handles) if outliers_on == 1 handles.outliers_on = 1; else - handles.outliers_on = 0; + handles.outliers_on = 0; end @@ -775,15 +775,15 @@ function checkbox_outliers_Callback(hObject, eventdata, handles) if handles.heatmap_on == 1 clear_heatmap(hObject, eventdata, handles); - handles.heatmap_on = 0; - set(handles.checkbox_heatmap, 'Value', 0); + handles.heatmap_on = 0; + set(handles.checkbox_heatmap, 'Value', 0); %handles.outliers_on = 1; redraw_outliers(hObject, eventdata, handles); else %handles.outliers_on = 1; - clear_outliers(hObject, eventdata, handles); + clear_outliers(hObject, eventdata, handles); %guidata(hObject, handles); redraw_outliers(hObject, eventdata, handles); @@ -792,19 +792,19 @@ function checkbox_outliers_Callback(hObject, eventdata, handles) else %but if outliers is off, and heatmap is wanted, you can do it -% if handles.heatmap_on ==1 -% -% clear_outliers(hObject, eventdata, handles); -% redraw_heatmap(hObject, eventdata, handles); -% handles.outliers_on = 0; -% -% else -% clear_outliers(hObject, eventdata, handles); -% handles.outliers_on = 0; -% -% end + % if handles.heatmap_on ==1 + % + % clear_outliers(hObject, eventdata, handles); + % redraw_heatmap(hObject, eventdata, handles); + % handles.outliers_on = 0; + % + % else + % clear_outliers(hObject, eventdata, handles); + % handles.outliers_on = 0; + % + % end - %also, redraw initial data/channels without outliers + %also, redraw initial data/channels without outliers clear_outliers(hObject, eventdata, handles) end @@ -813,54 +813,54 @@ function checkbox_outliers_Callback(hObject, eventdata, handles) % %if heatmap is currently on, stop it and turn its states off % %before applying outliers fxn % if handles.heatmap_on == 1 -% +% % clear_heatmap(hObject, eventdata, handles); -% handles.heatmap_on = 0; -% set(handles.checkbox_heatmap, 'Value', 0); -% +% handles.heatmap_on = 0; +% set(handles.checkbox_heatmap, 'Value', 0); +% % if outliers_on == 1 % handles.outliers_on = 1; % redraw_outliers(hObject, eventdata, handles); % else -% +% % set(handles.stdwindow,'Enable','Off'); % set(handles.chwindow,'Enable','Off'); -% set(handles.chbutton,'Enable','Off'); +% set(handles.chbutton,'Enable','Off'); % clear_outliers(hObject, eventdata, handles); -% handles.outliers_on = 0; -% +% handles.outliers_on = 0; +% % end -% +% % else -% +% % if outliers_on == 1 % handles.outliers_on = 1; % redraw_outliers(hObject, eventdata, handles); -% else +% else % set(handles.stdwindow,'Enable','Off'); % set(handles.chwindow,'Enable','Off'); -% set(handles.chbutton,'Enable','Off'); +% set(handles.chbutton,'Enable','Off'); % clear_outliers(hObject, eventdata, handles); -% handles.outliers_on = 0; -% -% end -% +% handles.outliers_on = 0; +% +% end +% % end % Update handles structure guidata(hObject, handles); -function redraw_outliers(hObject, eventdata, handles) -handles = guidata(hObject); %get the most updated handles struct +function redraw_outliers(hObject, eventdata, handles) +handles = guidata(hObject); %get the most updated handles struct data = handles.dq_table.Data; -if iscell(data) +if iscell(data) %in case of new std from stdwindow data = handles.orig_data; end -%either default(all) or from chbutton -chans_to_use = handles.indxlistch; -data = data(chans_to_use,:); +%either default(all) or from chbutton +chans_to_use = handles.indxlistch; +data = data(chans_to_use,:); n_elec = length(chans_to_use); ERPtouse = handles.ERP.chanlocs; @@ -874,9 +874,9 @@ function redraw_outliers(hObject, eventdata, handles) %compute outliers as X standard deviations from mean across channels -col_means = mean(data,1); +col_means = mean(data,1); col_std = std(data,0,1); -chosen_std = str2double((handles.stdwindow.String)); +chosen_std = str2double((handles.stdwindow.String)); % Use this @ anonymous function to make HTML tag in box in loop below colergen = @(color,text) ['
',text,'
']; @@ -884,7 +884,7 @@ function redraw_outliers(hObject, eventdata, handles) for cell = 1:numel(data) data_here = data(cell); - [d_row,d_col] = ind2sub(size(data),cell); + [d_row,d_col] = ind2sub(size(data),cell); neg_thresh = col_means(d_col) - (chosen_std*col_std(d_col)); pos_thresh = col_means(d_col) + (chosen_std*col_std(d_col)); @@ -906,14 +906,14 @@ function clear_outliers(hObject, eventdata, handles) %handles = guidata(hObject); handles.dq_table.Data = handles.orig_data; handles.dq_table.RowName = handles.orig_RowName; -handles.indxlistch = handles.orig_indxlistch; +handles.indxlistch = handles.orig_indxlistch; % Re-Prepare List of current Channels -chanArray = handles.orig_indxlistch; %default +chanArray = handles.orig_indxlistch; %default %handles.indxlistch = chanArray; %default set(handles.chwindow, 'String', vect2colon(chanArray, 'Delimiter', 'off')); - % Update handles structure +% Update handles structure guidata(hObject, handles); @@ -926,7 +926,7 @@ function stdwindow_Callback(hObject, eventdata, handles) % handles structure with handles and user data (see GUIDATA) newstd = get(hObject,'String'); -handles.stdwindow.String= newstd; +handles.stdwindow.String= newstd; redraw_outliers(hObject, eventdata, handles); guidata(hObject, handles); @@ -960,61 +960,61 @@ function chwindow_Callback(hObject, eventdata, handles) % Hints: get(hObject,'String') returns contents of chwindow as text % str2double(get(hObject,'String')) returns contents of chwindow as a double -ch = get(hObject,'string'); +ch = get(hObject,'string'); nch = length(handles.listch); -ch_val = eval(ch); +ch_val = eval(ch); if ~isempty(ch) -% testch = regexpi(ch,':') ; -% -% if isempty(testch) -% -% try -% ch_val = eval(ch); -% handles.listch(ch_val); %attempt to index -% -% catch -% msgboxText = 'Invalid channel input: please enter channels as integers, with a space between each number, or ch1:chN array syntax'; -% title = 'ERPLAB: channel GUI input'; -% errorfound(msgboxText, title); -% -% end -% else -% ch_val = eval(ch); -% -% end -% - - tf = checkchannels(ch_val, nch, 1); + % testch = regexpi(ch,':') ; + % + % if isempty(testch) + % + % try + % ch_val = eval(ch); + % handles.listch(ch_val); %attempt to index + % + % catch + % msgboxText = 'Invalid channel input: please enter channels as integers, with a space between each number, or ch1:chN array syntax'; + % title = 'ERPLAB: channel GUI input'; + % errorfound(msgboxText, title); + % + % end + % else + % ch_val = eval(ch); + % + % end + % + + tf = checkchannels(ch_val, nch, 1); if tf return end - -% if length(ch_val) > length(handles.orig_indxlistch) -% msgboxText = 'Exceeded Number of Available Channels'; -% title = 'ERPLAB: channel GUI input'; -% errorfound(msgboxText, title); -% return -% end -% + + % if length(ch_val) > length(handles.orig_indxlistch) + % msgboxText = 'Exceeded Number of Available Channels'; + % title = 'ERPLAB: channel GUI input'; + % errorfound(msgboxText, title); + % return + % end + % set(handles.chwindow, 'String', vect2colon(ch_val, 'Delimiter', 'off')); handles.indxlistch = ch_val; % Update handles structure guidata(hObject, handles); redraw_outliers(hObject, eventdata, handles); guidata(hObject, handles); - + else msgboxText = 'Not valid channel'; title = 'ERPLAB: channel GUI input'; errorfound(msgboxText, title); return end - + % --- Executes during object creation, after setting all properties. @@ -1039,31 +1039,31 @@ function chbutton_Callback(hObject, eventdata, handles) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) listch = handles.listch; %true channels list as labels -indxlistch = handles.indxlistch; %true array of channel indexs +indxlistch = handles.indxlistch; %true array of channel indexs indxlistch = indxlistch(indxlistch<=length(listch)); % true array of channel index if less than expected labels titlename = 'Select Channel(s)'; if get(hObject, 'Value') - if ~isempty(listch) - ch = browsechanbinGUI(listch, indxlistch, titlename); - if ~isempty(ch) - set(handles.chwindow, 'String', vect2colon(ch, 'Delimiter', 'off')); - handles.indxlistch = ch; - % Update handles structure - guidata(hObject, handles); - redraw_outliers(hObject, eventdata, handles); - guidata(hObject, handles); - - - else - disp('User selected Cancel') - return - end + if ~isempty(listch) + ch = browsechanbinGUI(listch, indxlistch, titlename); + if ~isempty(ch) + set(handles.chwindow, 'String', vect2colon(ch, 'Delimiter', 'off')); + handles.indxlistch = ch; + % Update handles structure + guidata(hObject, handles); + redraw_outliers(hObject, eventdata, handles); + guidata(hObject, handles); + + else - msgboxText = 'No channel information was found'; - title = 'ERPLAB: ploterp GUI input'; - errorfound(msgboxText, title); - return + disp('User selected Cancel') + return end + else + msgboxText = 'No channel information was found'; + title = 'ERPLAB: ploterp GUI input'; + errorfound(msgboxText, title); + return + end end @@ -1081,9 +1081,8 @@ function active_erpset_Callback(hObject, eventdata, handles) % handles structure with handles and user data (see GUIDATA) newactive = get(hObject,'Value'); -ERPs = handles.ALLERP; -ERP = ERPs(newactive); -handles.ERP = ERP; +ERPs = handles.ALLERP; +ERP = ERPs(newactive); n_dq = numel(ERP.dataquality); for i=1:n_dq @@ -1091,10 +1090,10 @@ function active_erpset_Callback(hObject, eventdata, handles) end handles.popupmenu_DQ_type.String = type_names; -%handles.popupmenu_DQ_type.Value = n_dq; +handles.popupmenu_DQ_type.Value = n_dq; -[n_elec, n_tw, n_bin] = size(ERP.dataquality(handles.popupmenu_DQ_type.Value).data); +[n_elec, n_tw, n_bin] = size(ERP.dataquality(n_dq).data); if n_elec == 0 % if the dq data is of zero size, then the 3rd dim may be mis-sized. @@ -1102,74 +1101,41 @@ function active_erpset_Callback(hObject, eventdata, handles) n_bin = ERP.nbin; end -bin_names = numel(ERP.bindescr); -if bin_names == n_bin +n_bin_names = numel(ERP.bindescr); +if n_bin_names == n_bin + for i=1:n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; + bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; end -elseif bin_names ~= n_bin +else % if not every bin has a bin description, leave then off - for i=1:bin_names - if i <= n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - ' ERP.bindescr{i}]; - elseif i > n_bin - n_bin_names{i} = ['BIN ' num2str(i) ' - NO DQ INFO EXISTS' ]; - end + for i=1:n_bin + bin_names{i} = ['BIN ' num2str(i)]; end end -handles.popupmenu_bin.String = n_bin_names; + +handles.popupmenu_bin.String = bin_names; % handles.popupmenu_DQ_type.Value saves the indx of the selected DQ Measure selected_DQ_type = handles.popupmenu_DQ_type.Value; selected_bin = handles.popupmenu_bin.Value; -if selected_bin > length(handles.ERP.bindescr) % this fixes issue when switching to ERP with fewer bins - selected_bin = 1; - handles.popupmenu_bin.Value = selected_bin; -else -end - - -% if pointwise SEM, do the following (DRG 05/2024): -if isempty(handles.ERP.dataquality(selected_DQ_type).data) - - % if pointwise SEM, use ERP.binerror - if selected_DQ_type == 2 && isempty(handles.ERP.binerror) == 0 - table_data = real(handles.ERP.binerror(:,:,selected_bin)); - else - - % Data empty here. - table_data = nan(1); - disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); - end - - elseif selected_bin > length(handles.ERP.dataquality(1).data) - table_data = nan(1); - disp('DQ data not found for this DQ type and bin. Perhaps it has been cleared?'); - -else - % data is present and correct - table_data = handles.ERP.dataquality(selected_DQ_type).data(:,:,selected_bin); -end - +table_data = ERP.dataquality(selected_DQ_type).data(:,:,selected_bin); handles.dq_table.Data = table_data; handles.orig_data = table_data; -% electrode labels from ERPset, if present and number matches - +% electrode labels from ERPset, iff present and number matches if isfield(ERP.chanlocs,'labels') && numel(ERP.chanlocs) == n_elec for i=1:n_elec elec_labels{i} = ERP.chanlocs(i).labels; end else - + for i=1:ERP.nchan - elec_labels{i} = ERP.chanlocs(i).labels; - + elec_labels{i} = i; end end - handles.dq_table.RowName = elec_labels; % Time-window labels @@ -1182,68 +1148,51 @@ function active_erpset_Callback(hObject, eventdata, handles) tw_labels{i} = [num2str(ERP.dataquality(selected_DQ_type).times(i,1)) ' : ' num2str(ERP.dataquality(selected_DQ_type).times(i,2))]; end end - -% Time-window labels for SEM (DRG 05/2024): -if n_tw == 0 && selected_DQ_type ~= 2 +if n_tw == 0 tw_labels = 'No data here. Perhaps it was cleared?'; -elseif n_tw == 0 && selected_DQ_type == 2 - tw_labels = []; end - handles.dq_table.ColumnName = tw_labels; - + % Set font size of DQ Table desired_fontsize = erpworkingmemory('fontsizeGUI'); handles.dq_table.FontSize = desired_fontsize; - - -% DRG 05/2024 -% We want heatmap to remain on when users switch erpset -if handles.heatmap_on == 1 - redraw_heatmap(hObject, eventdata, handles); -end - -% We want outliers to remain on when users switch erpset -if handles.outliers_on == 1 - redraw_outliers(hObject, eventdata, handles); -end - +handles.heatmap_on = handles.checkbox_heatmap.Value; % % Prepare List of current Channels % nchan = ERP.nchan; % Total number of channels if ~isfield(ERP.chanlocs,'labels') - for e=1:nchan - ERP.chanlocs(e).labels = ['Ch' num2str(e)]; - end + for e=1:nchan + ERP.chanlocs(e).labels = ['Ch' num2str(e)]; + end end listch = {''}; for ch =1:nchan - listch{ch} = [num2str(ch) ' = ' ERP.chanlocs(ch).labels ]; + listch{ch} = [num2str(ch) ' = ' ERP.chanlocs(ch).labels ]; end handles.listch = listch; -chanArray = 1:ERP.nchan; %default +chanArray = 1:ERP.nchan; %default handles.indxlistch = chanArray; %default set(handles.chwindow, 'String', vect2colon(chanArray, 'Delimiter', 'off')); % Set outliers text window off -set(handles.stdwindow,'Enable','Off'); +set(handles.stdwindow,'Enable','Off'); set(handles.chwindow,'Enable','Off'); -set(handles.chbutton,'Enable','Off'); +set(handles.chbutton,'Enable','Off'); % Update handles structure handles.ERP = ERP; -handles.ALLERP = ERPs; +handles.ALLERP = ERPs; %clear all perviously set options -% set(handles.checkbox_outliers,'Value',0); +set(handles.checkbox_outliers,'Value',0); % set(handles.checkbox_heatmap,'Value',0); -% set(handles.checkbox_text_labels,'Value',0); +set(handles.checkbox_text_labels,'Value',0); set(handles.stdwindow,'Enable','Off'); set(handles.chwindow,'Enable','Off'); set(handles.chbutton,'Enable','Off'); @@ -1251,25 +1200,25 @@ function active_erpset_Callback(hObject, eventdata, handles) %check to see if outliers is on prior to switching active erpset? %checkbox_outliers_Callback(hObject, eventdata, handles) -% outliers_on = get(handles.checkbox_outliers,'Value'); -% -% if outliers_on == 1 -% handles.outliers_on = 1; -% set(handles.stdwindow,'Enable','On'); -% set(handles.chwindow,'Enable','On'); -% set(handles.chbutton,'Enable','On'); -% redraw_outliers(hObject, eventdata, handles); -% -% else -% handles.heatmap_on = 0; -% set(handles.stdwindow,'Enable','Off'); -% set(handles.chwindow,'Enable','Off'); -% set(handles.chbutton,'Enable','Off'); -% clear_outliers(hObject, eventdata, handles); -% -% -% end -%handles.popupmenu_bin.String = bin_names; +heatmap_on = handles.heatmap_on ; +if heatmap_on == 1 + + %if heatmap_on, then outliers not possible so clear outliers + clear_outliers(hObject, eventdata, handles); + handles.outliers_on = 0; + set(handles.checkbox_outliers, 'Value', 0); + redraw_heatmap(hObject, eventdata, handles); + handles.heatmap_on = 1; +else + clear_heatmap(hObject, eventdata, handles); + handles.heatmap_on = 0; + + %if outliers is on, then keep outliers active + if handles.outliers_on == 1 + redraw_outliers(hOBject, eventdata,handles); + end +end + guidata(hObject, handles); % Hints: contents = cellstr(get(hObject,'String')) returns active_erpset contents as cell array @@ -1292,7 +1241,7 @@ function active_erpset_CreateFcn(hObject, eventdata, handles) function tf = checkchannels(chx, nchan, showmsg) if nargin<3 - showmsg = 1; + showmsg = 1; end tf = 0; % no problem by default @@ -1307,42 +1256,42 @@ function active_erpset_CreateFcn(hObject, eventdata, handles) end if isempty(chx) - if showmsg - msgboxText = 'Invalid channel indexing.'; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(msgboxText, title); - end - tf = 1; % - return + if showmsg + msgboxText = 'Invalid channel indexing.'; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(msgboxText, title); + end + tf = 1; % + return end if ~isempty(find(chx>nchan)) - if showmsg - msgboxText = ['You only have %g channels,\n'... - 'so you cannot specify indices greater than this.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText, nchan), title); - end - tf = 1; % - return + if showmsg + msgboxText = ['You only have %g channels,\n'... + 'so you cannot specify indices greater than this.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText, nchan), title); + end + tf = 1; % + return end if ~isempty(find(chx<1)) - if showmsg - msgboxText = 'You cannot use zero or a negative number as a channel indexing'; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(msgboxText, title); - end - tf = 1; % - return + if showmsg + msgboxText = 'You cannot use zero or a negative number as a channel indexing'; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(msgboxText, title); + end + tf = 1; % + return end if length(chx)>length(unique_bc2(chx)) - if showmsg - msgboxText = ['Repeated channels are not allowed.\n'... - 'Therefore, ERPLAB will get rid of them.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText), title, [1 1 0], [0 0 0], 0) - end - tf = 0; % - return + if showmsg + msgboxText = ['Repeated channels are not allowed.\n'... + 'Therefore, ERPLAB will get rid of them.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText), title, [1 1 0], [0 0 0], 0) + end + tf = 0; % + return end @@ -1366,3 +1315,10 @@ function sdcorrection_Callback(hObject, eventdata, handles) guidata(hObject, handles); % Hint: get(hObject,'Value') returns toggle state of sdcorrection + + +% --- Executes during object creation, after setting all properties. +function checkbox_outliers_CreateFcn(hObject, eventdata, handles) +% hObject handle to checkbox_outliers (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called diff --git a/GUIs/abouterplabGUI.fig b/GUIs/abouterplabGUI.fig index de92c5e9..41f8cf37 100755 Binary files a/GUIs/abouterplabGUI.fig and b/GUIs/abouterplabGUI.fig differ diff --git a/GUIs/abouterplabGUI.m b/GUIs/abouterplabGUI.m index 60449b9a..f7a12d7b 100755 --- a/GUIs/abouterplabGUI.m +++ b/GUIs/abouterplabGUI.m @@ -31,19 +31,19 @@ % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @abouterplabGUI_OpeningFcn, ... - 'gui_OutputFcn', @abouterplabGUI_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @abouterplabGUI_OpeningFcn, ... + 'gui_OutputFcn', @abouterplabGUI_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) - gui_State.gui_Callback = str2func(varargin{1}); + gui_State.gui_Callback = str2func(varargin{1}); end if nargout - [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else - gui_mainfcn(gui_State, varargin{:}); + gui_mainfcn(gui_State, varargin{:}); end % ----------------------------------------------------------------------- @@ -52,19 +52,30 @@ function abouterplabGUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.running = 1; handles.numfig = 1; try - if ispc - opengl software - end + if ispc + opengl software + end catch end [version, reldate] = geterplabversion; howold = num2str(datenum(date)-datenum(reldate)); -set(handles.gui_chassis,'Name', ['ABOUT ERPLAB ' version ' (' howold ' days old)']) +ERPtooltype = erpgettoolversion('tooltype'); +handles.ERPtooltype=ERPtooltype; +if strcmpi(ERPtooltype,'estudio') + set(handles.gui_chassis,'Name', ['ABOUT Estudio ' version ' (' howold ' days old)']); + handles.pushbutton_erpinfo.String = 'ESTUDIOINFO'; +else + set(handles.gui_chassis,'Name', ['ABOUT ERPLAB ' version ' (' howold ' days old)']); + handles.pushbutton_erpinfo.String = 'ERPINFO'; +end p = which('eegplugin_erplab'); p = p(1:findstr(p,'eegplugin_erplab.m')-1); - -fid_about = fopen( fullfile(p, 'GUIs', 'aboutext.txt')); +if strcmpi(ERPtooltype,'estudio') + fid_about = fopen( fullfile(p, 'GUIs', 'aboutext_estudio.txt')); +else + fid_about = fopen( fullfile(p, 'GUIs', 'aboutext.txt')); +end formcell = textscan(fid_about, '%s','delimiter', '#'); firstline = {['ERPLAB version ' version]}; handles.textabout = cat(1,firstline, formcell{:}); @@ -72,15 +83,15 @@ function abouterplabGUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.fontcred = 10; try - posgui = erpworkingmemory('abouterplabGUI'); - xfig = posgui(1); - yfig = posgui(2); + posgui = erpworkingmemory('abouterplabGUI'); + xfig = posgui(1); + yfig = posgui(2); catch - valscr = get(0,'MonitorPosition'); - % posgui = plotset.ptime.posgui; - % set(handles.gui_chassis,'Position', posgui) - xfig = min(valscr(:,3))/2; % half width screen pos - yfig = 300; % half width screen pos + valscr = get(0,'MonitorPosition'); + % posgui = plotset.ptime.posgui; + % set(handles.gui_chassis,'Position', posgui) + xfig = min(valscr(:,3))/2; % half width screen pos + yfig = 300; % half width screen pos end % @@ -100,120 +111,120 @@ function abouterplabGUI_OpeningFcn(hObject, eventdata, handles, varargin) % ----------------------------------------------------------------------- function playcredit(numfig, xfig, yfig, hObject, eventdata, handles) try - textabout = handles.textabout; - fontcred = handles.fontcred; - [banner, fcolor1, fcolor2, info ] = loadtheme(numfig, hObject, eventdata, handles); - %set(handles.gui_chassis, 'Position', [xfig-(0.6*info.Width) 100 1.2*info.Width 1.1*info.Height]) - set(handles.gui_chassis, 'Position', [xfig yfig 1.2*info.Width 1.1*info.Height]) - set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Position', [0 50 1.2*info.Width info.Height]) - set(handles.text_cover,'Position', [0 0 1.2*info.Width 0.007*info.Height]); - wb = 88; - hb = 40.92; - yb = 6.38; - wfig = get(handles.gui_chassis, 'Position'); - nbuttons = 5; % number of buttons - kk = 1/(nbuttons*1.03); - x1 = wfig(3)*kk-9*wb/10; - x2 = wfig(3)*2*kk-9*wb/10; - x3 = wfig(3)*3*kk-9*wb/10; - x4 = wfig(3)*4*kk-9*wb/10; - x5 = wfig(3)*5*kk-9*wb/10; - set(handles.pushbutton_erpinfo,'Units', 'pixels'); - set(handles.pushbutton_publication,'Units', 'pixels'); - set(handles.pushbutton_relaunch,'Units', 'pixels'); - set(handles.pushbutton_youtube,'Units', 'pixels'); - set(handles.pushbutton_close,'Units', 'pixels'); - set(handles.pushbutton_erpinfo,'Position', [x1 yb wb hb]); - set(handles.pushbutton_publication,'Position', [x2 yb wb hb]); - set(handles.pushbutton_relaunch,'Position', [x3 yb wb hb]); - set(handles.pushbutton_youtube,'Position', [x4 yb wb hb]); - set(handles.pushbutton_close,'Position', [x5 yb wb hb]); - - axes(handles.axes1) - holgu = 0.12*info.Width; - dimmer = 0.98*sin(0:pi/160:0.8*pi); %[0:9 9 9 9 9:-1:4]; - banner = loadtheme(numfig, hObject, eventdata, handles); - i=1; - - % - % dim the light down effect - % - while i<=length(dimmer) && get(handles.pushbutton_close,'Value')==0 && get(handles.pushbutton_relaunch,'Value')==0 - image(banner); - set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Xlim',[-holgu info.Width+holgu]); - alpha(dimmer(i)) - drawnow - i=i+1; - %pause(0.15) + textabout = handles.textabout; + fontcred = handles.fontcred; + [banner, fcolor1, fcolor2, info ] = loadtheme(numfig, hObject, eventdata, handles); + %set(handles.gui_chassis, 'Position', [xfig-(0.6*info.Width) 100 1.2*info.Width 1.1*info.Height]) + set(handles.gui_chassis, 'Position', [xfig yfig 1.2*info.Width 1.1*info.Height]) + set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Position', [0 50 1.2*info.Width info.Height]) + set(handles.text_cover,'Position', [0 0 1.2*info.Width 0.007*info.Height]); + wb = 88; + hb = 40.92; + yb = 6.38; + wfig = get(handles.gui_chassis, 'Position'); + nbuttons = 5; % number of buttons + kk = 1/(nbuttons*1.03); + x1 = wfig(3)*kk-9*wb/10; + x2 = wfig(3)*2*kk-9*wb/10; + x3 = wfig(3)*3*kk-9*wb/10; + x4 = wfig(3)*4*kk-9*wb/10; + x5 = wfig(3)*5*kk-9*wb/10; + set(handles.pushbutton_erpinfo,'Units', 'pixels'); + set(handles.pushbutton_publication,'Units', 'pixels'); + set(handles.pushbutton_relaunch,'Units', 'pixels'); + set(handles.pushbutton_youtube,'Units', 'pixels'); + set(handles.pushbutton_close,'Units', 'pixels'); + set(handles.pushbutton_erpinfo,'Position', [x1 yb wb hb]); + set(handles.pushbutton_publication,'Position', [x2 yb wb hb]); + set(handles.pushbutton_relaunch,'Position', [x3 yb wb hb]); + set(handles.pushbutton_youtube,'Position', [x4 yb wb hb]); + set(handles.pushbutton_close,'Position', [x5 yb wb hb]); + + axes(handles.axes1) + holgu = 0.12*info.Width; + dimmer = 0.98*sin(0:pi/160:0.8*pi); %[0:9 9 9 9 9:-1:4]; + banner = loadtheme(numfig, hObject, eventdata, handles); + i=1; + + % + % dim the light down effect + % + while i<=length(dimmer) && get(handles.pushbutton_close,'Value')==0 && get(handles.pushbutton_relaunch,'Value')==0 + image(banner); + set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Xlim',[-holgu info.Width+holgu]); + alpha(dimmer(i)) + drawnow + i=i+1; + %pause(0.15) + end + + % + % Displaying text + % + namefont = 'Arial'; + mleft = -holgu*0.65; + kbottom = 2.1; + i = 0; + banner = loadtheme(numfig, hObject, eventdata, handles); + while i<=2.72*info.Height && get(handles.pushbutton_close,'Value')==0 && get(handles.pushbutton_relaunch,'Value')==0 + text(mleft, kbottom*info.Height-i, textabout,'FontName', namefont, 'Fontsize', fontcred,'Color', fcolor1) + drawnow + image(banner); + set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Xlim',[-holgu info.Width+holgu]); + alpha(dimmer(end)) + i = i + 1; + end + + % + % checking "Theme" button + % + if get(handles.pushbutton_relaunch,'Value')==1 + set(handles.pushbutton_relaunch,'Value', 0) + numfig = round(rand*9) + 1; + while numfig==handles.numfig + numfig = round(rand*9) + 1; end - - % - % Displaying text - % - namefont = 'Arial'; - mleft = -holgu*0.65; - kbottom = 2.1; - i = 0; - banner = loadtheme(numfig, hObject, eventdata, handles); - while i<=2.72*info.Height && get(handles.pushbutton_close,'Value')==0 && get(handles.pushbutton_relaunch,'Value')==0 - text(mleft, kbottom*info.Height-i, textabout,'FontName', namefont, 'Fontsize', fontcred,'Color', fcolor1) - drawnow - image(banner); - set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Xlim',[-holgu info.Width+holgu]); - alpha(dimmer(end)) - i = i + 1; - end - - % - % checking "Theme" button - % - if get(handles.pushbutton_relaunch,'Value')==1 - set(handles.pushbutton_relaunch,'Value', 0) - numfig = round(rand*9) + 1; - while numfig==handles.numfig - numfig = round(rand*9) + 1; - end - handles.numfig = numfig; - % Update handles structure - guidata(hObject, handles); - - posgui = get(handles.gui_chassis,'Position'); - xfig = posgui(1); - yfig = posgui(2); - playcredit(numfig, xfig, yfig, hObject, eventdata, handles) - return - end - - % - % dim the light up effect - % - i=length(dimmer); - while i>length(dimmer)/2 && get(handles.pushbutton_close,'Value')==0 && get(handles.pushbutton_relaunch,'Value')==0 - image(banner); - set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Xlim',[-holgu info.Width+holgu]); - alpha(dimmer(i)) - drawnow - i=i-1; - %pause(0.15) - end - - handles.running = 0; + handles.numfig = numfig; % Update handles structure guidata(hObject, handles); - if get(handles.pushbutton_close,'Value')==1 - delete(handles.gui_chassis) - end + posgui = get(handles.gui_chassis,'Position'); + xfig = posgui(1); + yfig = posgui(2); + playcredit(numfig, xfig, yfig, hObject, eventdata, handles) return + end + + % + % dim the light up effect + % + i=length(dimmer); + while i>length(dimmer)/2 && get(handles.pushbutton_close,'Value')==0 && get(handles.pushbutton_relaunch,'Value')==0 + image(banner); + set(handles.axes1, 'Visible', 'off', 'Units', 'pixels', 'Xlim',[-holgu info.Width+holgu]); + alpha(dimmer(i)) + drawnow + i=i-1; + %pause(0.15) + end + + handles.running = 0; + % Update handles structure + guidata(hObject, handles); + + if get(handles.pushbutton_close,'Value')==1 + delete(handles.gui_chassis) + end + return catch - try - posgui = get(handles.gui_chassis,'Position'); - erpworkingmemory('abouterplabGUI', posgui); - catch - end - if handles.running == 0; - delete(handles.gui_chassis) - end + try + posgui = get(handles.gui_chassis,'Position'); + erpworkingmemory('abouterplabGUI', posgui); + catch + end + if handles.running == 0; + delete(handles.gui_chassis) + end end % ----------------------------------------------------------------------- @@ -221,7 +232,7 @@ function pushbutton_close_Callback(hObject, eventdata, handles) posgui = get(handles.gui_chassis,'Position'); erpworkingmemory('abouterplabGUI', posgui); if handles.running == 0; - delete(handles.gui_chassis) + delete(handles.gui_chassis) end % ----------------------------------------------------------------------- @@ -231,8 +242,8 @@ function pushbutton_relaunch_Callback(hObject, eventdata, handles) yfig = posgui(2); if handles.running==0 - %abouterplabGUI - playcredit(1, xfig, yfig, hObject, eventdata, handles) + %abouterplabGUI + playcredit(1, xfig, yfig, hObject, eventdata, handles) end % ----------------------------------------------------------------------- @@ -242,10 +253,14 @@ function pushbutton_erpinfo_Callback(hObject, eventdata, handles) set(handles.pushbutton_close,'Value', 1) if handles.running == 0; - delete(handles.gui_chassis) + delete(handles.gui_chassis) end pause(0.2) -web('https://github.com/lucklab/erplab/','-browser') +if strcmpi(handles.ERPtooltype,'estudio') + web('https://github.com/lucklab/erplab/','-browser') +else + web('https://github.com/lucklab/erplab/','-browser') +end % ----------------------------------------------------------------------- function pushbutton_publication_Callback(hObject, eventdata, handles) @@ -254,29 +269,37 @@ function pushbutton_publication_Callback(hObject, eventdata, handles) set(handles.pushbutton_close,'Value', 1) if handles.running == 0; - delete(handles.gui_chassis) + delete(handles.gui_chassis) end pause(0.2) -web('http://journal.frontiersin.org/article/10.3389/fnhum.2014.00213/abstract','-browser') - +if strcmpi(handles.ERPtooltype,'estudio') + +else + web('http://journal.frontiersin.org/article/10.3389/fnhum.2014.00213/abstract','-browser') +end % ----------------------------------------------------------------------- function [banner, fcolor1, fcolor2, info ] = loadtheme(numfig, hObject, eventdata, handles) if numfig==8 || numfig==1 - set(handles.gui_chassis,'Color',[0 0 0]); - set(handles.text_cover,'BackgroundColor',[0 0 0]); - fcolor1 = [1 1 1]; - fcolor2 = [0 0 0]; + set(handles.gui_chassis,'Color',[0 0 0]); + set(handles.text_cover,'BackgroundColor',[0 0 0]); + fcolor1 = [1 1 1]; + fcolor2 = [0 0 0]; else - set(handles.gui_chassis,'Color',[1 1 1]); - set(handles.text_cover,'BackgroundColor',[1 1 1]); - fcolor1 = [0 0 0]; - fcolor2 = [1 1 1]; + set(handles.gui_chassis,'Color',[1 1 1]); + set(handles.text_cover,'BackgroundColor',[1 1 1]); + fcolor1 = [0 0 0]; + fcolor2 = [1 1 1]; end %if numfig==9 % namefig = 'logoerplab2010ny.jpg'; %else +ERPtooltype = handles.ERPtooltype; +if strcmpi(ERPtooltype,'estudio') + namefig = ['EstudioLogo.jpg']; +else namefig = ['logoerplab' num2str(numfig) '.jpg']; +end %end set(hObject, 'Units', 'pixels'); @@ -293,14 +316,14 @@ function pushbutton_publication_Callback(hObject, eventdata, handles) % bindx = ismember_bc2(edmask(:,:,2),255); % cindx = ismember_bc2(edmask(:,:,3),0); % edmask = repmat(aindx&bindx&cindx, [1 1 3]); -% +% % edsum = edition; % aindx = ~ismember_bc2(edsum(:,:,1),12); % bindx = ~ismember_bc2(edsum(:,:,2),255); % cindx = ~ismember_bc2(edsum(:,:,3),0); % edsum = repmat(aindx&bindx&cindx, [1 1 3]); % edsum = edition.*edsum; -% +% % banner = banner .* edmask; % banner = banner + edsum*0.9; @@ -316,23 +339,26 @@ function pushbutton_youtube_Callback(hObject, eventdata, handles) set(handles.pushbutton_close,'Value', 1) if handles.running == 0; - delete(handles.gui_chassis) + delete(handles.gui_chassis) end pause(0.2) -web('https://github.com/lucklab/erplab/wiki/Videos','-browser') - +if strcmpi(handles.ERPtooltype,'estudio') + +else + web('https://github.com/lucklab/erplab/wiki/Videos','-browser') +end %-------------------------------------------------------------------------- function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) posgui = get(handles.gui_chassis,'Position'); erpworkingmemory('abouterplabGUI', posgui); if get(handles.pushbutton_close,'Value')==1 % in case of problems... - delete(handles.gui_chassis) + delete(handles.gui_chassis) end % or set(handles.pushbutton_close,'Value', 1) % normal closing if handles.running == 0; - delete(handles.gui_chassis) + delete(handles.gui_chassis) end diff --git a/GUIs/aboutext_estudio.txt b/GUIs/aboutext_estudio.txt new file mode 100644 index 00000000..103a791d --- /dev/null +++ b/GUIs/aboutext_estudio.txt @@ -0,0 +1,71 @@ +# +# +ERPLAB Studio designed by Steve Luck, Guanghui Zhang, and Andrew X Stewart# +# +Main developers of ERPLAB Studio: # +Guanghui Zhang # +ghzhang@ucdavis.edu # +Andrew X Stewart # +axstewart@ucdavis.edu # +Center for Mind and Brain, University of California, Davis # +# +# +Find latest on Github: +https://github.com/lucklab/erplab +# +# +Makes extensive use of: # +ERPLAB Classic designed by Javier Lopez-Calderon and Steve Luck # +at UC Davis # +and EEGLAB Toolbox designed by Scott Makeig and Arnauld Delorme # +at UCSD. # +# +ERPLAB Studio Development Assistants: # +Carter Luck # +# +UC-Davis Testing Team: # +[To be added]. # +# +# +# +This is not commercial software, and bugs can happen # +In some cases, errors will occur leading to a message that # +instructs you to report the error to the EEGLAB developers. # +If this happens, please report the error to erplabtoolbox@gmail.com # +and not to the EEGLAB developers. ERPLAB has primarily been # +tested using EEG collected with a Biosemi ActiveTwo System, # +along with a smaller amount of testing using EEG collected # +with Neuroscan and EGI systems. Consequently, you should be # +particularly careful when using this version of ERPLAB with # +data collected with systems other than the Biosemi ActiveTwo. # +# +# +This program 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. # +# +This program 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. # +# +This software is intended for research purposes only and is # +not approved for use in medical diagnosis or treatment. # +# +You should have received a copy of the GNU General Public # +License long with this program. If not, see # +. # +# +# +# +# +# +# +# +# +# +# +Davis, California # +a great place to live, work, and study # +# diff --git a/GUIs/artifactinterpGUI.fig b/GUIs/artifactinterpGUI.fig index c42bb3dd..13351e84 100755 Binary files a/GUIs/artifactinterpGUI.fig and b/GUIs/artifactinterpGUI.fig differ diff --git a/GUIs/artifactinterpGUI.m b/GUIs/artifactinterpGUI.m index 752a2b83..09ba0508 100755 --- a/GUIs/artifactinterpGUI.m +++ b/GUIs/artifactinterpGUI.m @@ -43,7 +43,7 @@ % Edit the above text to modify the response to help artifactinterpGUI -% Last Modified by GUIDE v2.5 31-May-2023 11:45:41 +% Last Modified by GUIDE v2.5 25-Apr-2024 15:15:16 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; @@ -179,7 +179,7 @@ function artifactinterpGUI_OpeningFcn(hObject, eventdata, handles, varargin) set(handles.flag_1, 'Value',1); %flag 1 is reserved set(handles.flag_1, 'Enable', 'inactive');% flag 1 is pressed but inactive %set(handles.flag_1, 'Visible', 'off'); -set(handles.radiobutton1, 'Enable', 'inactive'); +set(handles.radiobutton1, 'Enable', 'on'); %set(handles.radiobutton1, 'Visibile', 'off'); %set interpolate method choice @@ -337,7 +337,7 @@ function pushbutton_interpolate_Callback(hObject, eventdata, handles) % handles structure with handles and user data (see GUIDATA) %query flag selected -for i=2:8 %only flags 2-8 for now +for i=1:8 %only flags 2-8 for now if get(handles.(['radiobutton' num2str(i)]),'Value') handles.flagx = i; end; @@ -348,7 +348,6 @@ function pushbutton_interpolate_Callback(hObject, eventdata, handles) error_msg = sprintf('Error: No flags on epoched data. Cannot selectively interpolate epochs!'); error(error_msg); - end %query interpolation method @@ -356,7 +355,7 @@ function pushbutton_interpolate_Callback(hObject, eventdata, handles) if get(handles.radiobutton_spherical,'Value') handles.methodx = 'spherical'; else - handles.methodx = 'inverse_distance'; + handles.methodx = 'invdist'; end %query channel selected @@ -509,12 +508,12 @@ function flag_2_CreateFcn(hObject, eventdata, handles) % --- Executes on button press in pushbutton_help. -function pushbutton_help_Callback(hObject, eventdata, handles) -% hObject handle to pushbutton_help (see GCBO) -% eventdata reserved - to be defined in a future version of MATLAB -% handles structure with handles and user data (see GUIDATA) -web('https://github.com/lucklab/erplab/wiki/Artifact-Detection-in-Epoched-Data#ERPLAB-Post-Artifact-Detection-Epoch-Interpolation',... - '-browser'); +% function pushbutton_help_Callback(hObject, eventdata, handles) +% % hObject handle to pushbutton_help (see GCBO) +% % eventdata reserved - to be defined in a future version of MATLAB +% % handles structure with handles and user data (see GUIDATA) +% web('https://github.com/lucklab/erplab/wiki/Artifact-Detection-in-Epoched-Data#ERPLAB-Post-Artifact-Detection-Epoch-Interpolation',... +% '-browser'); % --- Executes on button press in pushbutton_cancel. @@ -718,3 +717,12 @@ function pushbutton14_Callback(hObject, eventdata, handles) %set channels popup menu set(handles.popupmenu1, 'string', listch); + + +% --- Executes on button press in radiobutton2. +function radiobutton2_Callback(hObject, eventdata, handles) +% hObject handle to radiobutton2 (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 radiobutton2 diff --git a/GUIs/basicfilterGUI2.fig b/GUIs/basicfilterGUI2.fig index 5d697c63..b4cc7962 100755 Binary files a/GUIs/basicfilterGUI2.fig and b/GUIs/basicfilterGUI2.fig differ diff --git a/GUIs/basicfilterGUI2.m b/GUIs/basicfilterGUI2.m index b9033edf..5c4edfc9 100755 --- a/GUIs/basicfilterGUI2.m +++ b/GUIs/basicfilterGUI2.m @@ -8,7 +8,7 @@ %b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b % % ERPLAB Toolbox -% Copyright © 2007 The Regents of the University of California +% Copyright © 2007 The Regents of the University of California % Created by Javier Lopez-Calderon and Steven Luck % Center for Mind and Brain, University of California, Davis, % javlopez@ucdavis.edu, sjluck@ucdavis.edu @@ -31,19 +31,19 @@ % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @basicfilterGUI2_OpeningFcn, ... - 'gui_OutputFcn', @basicfilterGUI2_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @basicfilterGUI2_OpeningFcn, ... + 'gui_OutputFcn', @basicfilterGUI2_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) - gui_State.gui_Callback = str2func(varargin{1}); + gui_State.gui_Callback = str2func(varargin{1}); end if nargout - [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else - gui_mainfcn(gui_State, varargin{:}); + gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT @@ -55,35 +55,42 @@ function basicfilterGUI2_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = []; outstr = []; % I know, I failed...This is just cause it eliminates some issues using handles.output... try - ERPLAB = varargin{1}; + ERPLAB = varargin{1}; catch - ERPLAB = []; - ERPLAB.srate = 500; - ERPLAB.epoch = []; - ERPLAB.event = []; - ERPLAB.chanlocs = []; - ERPLAB.nbchan = 0; + ERPLAB = []; + ERPLAB.srate = 500; + ERPLAB.epoch = []; + ERPLAB.event = []; + ERPLAB.chanlocs = []; + ERPLAB.nbchan = 0; + ERPLAB.nbin = 0; end try - def = varargin{2}; + def = varargin{2}; catch - % locutoff = def{1}; % for high pass filter - % hicutoff = def{2}; % for low pass filter - % filterorder = def{3}; - % chanArray = def{4}; - % typefilter = def{5}; - % remove_dc = def{6}; - % boundary = def{7}; - def = {0 30 2 1 1 0 0 []}; + % locutoff = def{1}; % for high pass filter + % hicutoff = def{2}; % for low pass filter + % filterorder = def{3}; + % chanArray = def{4}; + % typefilter = def{5}; + % remove_dc = def{6}; + % boundary = def{7}; + def = {0 30 2 1 1 0 0 [],1}; end handles.ERPLAB = ERPLAB; if isfield(ERPLAB, 'nbchan') - nchan = ERPLAB.nbchan; + nchan = ERPLAB.nbchan; elseif isfield(ERPLAB, 'nchan') - nchan = ERPLAB.nchan; + nchan = ERPLAB.nchan; else - nchan = 0; + nchan = 0; end +if isfield(ERPLAB, 'nbin') + nbin = ERPLAB.nbin; +else + nbin = 0; +end +handles.nbin = nbin; handles.fs = ERPLAB.srate; handles.nchan = nchan; fnyq = ERPLAB.srate/2; @@ -119,18 +126,34 @@ function basicfilterGUI2_OpeningFcn(hObject, eventdata, handles, varargin) % Prepare List of current Channels % if isempty(ERPLAB.chanlocs) - for e = 1:nchan - ERPLAB.chanlocs(e).labels = ['Ch' num2str(e)]; - end + for e = 1:nchan + ERPLAB.chanlocs(e).labels = ['Ch' num2str(e)]; + end end listch = {''}; for ch =1:nchan - listch{ch} = [num2str(ch) ' = ' ERPLAB.chanlocs(ch).labels ]; + listch{ch} = [num2str(ch) ' = ' ERPLAB.chanlocs(ch).labels ]; end handles.listch = listch; handles.indxlistch = def{4}; % channel array +handles.listbin = []; +handles.indxlistbin = []; % channel array +if nbin~=0 + if isfield(ERPLAB,'bindescr') + for Numofbin = 1:nbin + if ~isempty(ERPLAB.bindescr) + listbin{Numofbin} = ERPLAB.bindescr{Numofbin}; + else + listbin{Numofbin} = ['Bin',32,num2str(Numofbin)]; + end + end + handles.listbin = listbin; + handles.indxlistbin =def{9}; + end +end + % Update handles structure guidata(hObject, handles); @@ -191,15 +214,15 @@ function slider_highpass_Callback(hObject, eventdata, handles) valueh = round(valueh*10)/10; if valueh<0.1; - valueh = 0; - set(handles.slider_highpass, 'Value', 0); + valueh = 0; + set(handles.slider_highpass, 'Value', 0); end if get(handles.radiobutton_butter, 'Value'); - typef = 0; % 0 means Butterworth + typef = 0; % 0 means Butterworth elseif get(handles.radiobutton_fir, 'Value'); - typef = 1;% 1 means FIR + typef = 1;% 1 means FIR elseif get(handles.radiobutton_PM_notch, 'Value'); - typef = 2; % 2 means PM Notch + typef = 2; % 2 means PM Notch end posh = get(handles.popupmenu_order,'Value'); % order pop menu current position @@ -211,77 +234,77 @@ function slider_highpass_Callback(hObject, eventdata, handles) order = getorder(handles); if isempty(order) - return + return end tonhp = get(handles.togglebutton_highpass, 'Value'); if typef==2 - if valueh>=5 && valueh<=handles.maxsliders-5 - set(handles.slider_lowpass, 'Value', valueh); - valuehstr = sprintf('%.1f', valueh); - set(handles.edit_highpass, 'String', valuehstr); - else - if valueh<5 - nvaln = 5; - elseif valueh>handles.maxsliders-5 - nvaln = handles.maxsliders-5; - end - - nvalstr = sprintf('%.1f',nvaln); - set(handles.edit_highpass, 'String', nvalstr); - set(handles.slider_highpass, 'Value', nvaln); + if valueh>=5 && valueh<=handles.maxsliders-5 + set(handles.slider_lowpass, 'Value', valueh); + valuehstr = sprintf('%.1f', valueh); + set(handles.edit_highpass, 'String', valuehstr); + else + if valueh<5 + nvaln = 5; + elseif valueh>handles.maxsliders-5 + nvaln = handles.maxsliders-5; end + + nvalstr = sprintf('%.1f',nvaln); + set(handles.edit_highpass, 'String', nvalstr); + set(handles.slider_highpass, 'Value', nvaln); + end else - if tonhp - if valueh==0 - set(handles.edit_highpass, 'String', '0'); - set(handles.edit_highpass, 'Enable', 'off'); - set(handles.togglebutton_highpass, 'Value', 0); - set(handles.slider_highpass, 'Enable','off'); - set(handles.checkbox_removedc, 'Enable', 'off') - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); - else - valuehstr = sprintf('%.1f', valueh); - set(handles.edit_highpass, 'String', valuehstr); - set(handles.edit_highpass, 'Enable', 'on'); - set(handles.checkbox_removedc, 'Enable', 'on') - %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]); - end + if tonhp + if valueh==0 + set(handles.edit_highpass, 'String', '0'); + set(handles.edit_highpass, 'Enable', 'off'); + set(handles.togglebutton_highpass, 'Value', 0); + set(handles.slider_highpass, 'Enable','off'); + set(handles.checkbox_removedc, 'Enable', 'off') + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); else - set(handles.edit_highpass, 'String', '0'); - set(handles.edit_highpass, 'Enable', 'off'); - set(handles.togglebutton_highpass, 'Value', 0); - set(handles.slider_highpass, 'Enable','off'); - set(handles.checkbox_removedc, 'Enable', 'off') - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + valuehstr = sprintf('%.1f', valueh); + set(handles.edit_highpass, 'String', valuehstr); + set(handles.edit_highpass, 'Enable', 'on'); + set(handles.checkbox_removedc, 'Enable', 'on') + %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]); end + else + set(handles.edit_highpass, 'String', '0'); + set(handles.edit_highpass, 'Enable', 'off'); + set(handles.togglebutton_highpass, 'Value', 0); + set(handles.slider_highpass, 'Enable','off'); + set(handles.checkbox_removedc, 'Enable', 'off') + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + end end if typef==0 && autorder==1 - % order starts again for auto butter - orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list - orderlist{1} = 'automin:2'; - set(handles.popupmenu_order, 'String', orderlist); - set(handles.popupmenu_order, 'Value',1); - set(handles.popupmenu_dboct, 'Value',1); - set(handles.popupmenu_dbdec, 'Value',1); + % order starts again for auto butter + orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list + orderlist{1} = 'automin:2'; + set(handles.popupmenu_order, 'String', orderlist); + set(handles.popupmenu_order, 'Value',1); + set(handles.popupmenu_dboct, 'Value',1); + set(handles.popupmenu_dbdec, 'Value',1); end % % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end % ------------------------------------------------------------------------- function slider_highpass_CreateFcn(hObject, eventdata, handles) if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor',[.9 .9 .9]); + set(hObject,'BackgroundColor',[.9 .9 .9]); end %-------------------------------------------------------------------------- @@ -292,26 +315,26 @@ function slider_lowpass_Callback(hObject, eventdata, handles) fs = handles.fs; if valuel<0.1; - valuel = 0; - set(handles.slider_lowpass, 'Value', 0); + valuel = 0; + set(handles.slider_lowpass, 'Value', 0); end if valuel>round(fs/10) && (get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_fdatafr,'Value')) - handles.xmaxfreqr = [0 round(fs/2)]; %100 - set(handles.edit_xmaxplot, 'String', sprintf('%d %d', handles.xmaxfreqr)); - % Update handles structure - guidata(hObject, handles); + handles.xmaxfreqr = [0 round(fs/2)]; %100 + set(handles.edit_xmaxplot, 'String', sprintf('%d %d', handles.xmaxfreqr)); + % Update handles structure + guidata(hObject, handles); elseif valuel<=round(fs/10) && (get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_fdatafr,'Value')) - handles.xmaxfreqr = [0 round(fs/10)]; %100 - set(handles.edit_xmaxplot, 'String', sprintf('%d %d', handles.xmaxfreqr)); - % Update handles structure - guidata(hObject, handles); + handles.xmaxfreqr = [0 round(fs/10)]; %100 + set(handles.edit_xmaxplot, 'String', sprintf('%d %d', handles.xmaxfreqr)); + % Update handles structure + guidata(hObject, handles); end if get(handles.radiobutton_butter, 'Value'); - typef = 0; % 0 means Butterworth + typef = 0; % 0 means Butterworth elseif get(handles.radiobutton_fir, 'Value'); - typef = 1;% 1 means FIR + typef = 1;% 1 means FIR elseif get(handles.radiobutton_PM_notch, 'Value'); - typef = 2; % 2 means PM Notch + typef = 2; % 2 means PM Notch end autorder = handles.autorder; @@ -322,54 +345,54 @@ function slider_lowpass_Callback(hObject, eventdata, handles) order = getorder(handles); if isempty(order) - return + return end tonlp = get(handles.togglebutton_lowpass, 'Value'); if tonlp - if valuel==0 - set(handles.edit_lowpass, 'String', '0'); - set(handles.edit_lowpass, 'Enable', 'off'); - set(handles.togglebutton_lowpass, 'Value', 0); - set(handles.slider_lowpass, 'Enable','off'); - %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); - else - valuelstr = sprintf('%.1f', valuel); - set(handles.edit_lowpass, 'String', valuelstr); - set(handles.edit_lowpass, 'Enable', 'on'); - %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); - end -else + if valuel==0 set(handles.edit_lowpass, 'String', '0'); set(handles.edit_lowpass, 'Enable', 'off'); set(handles.togglebutton_lowpass, 'Value', 0); set(handles.slider_lowpass, 'Enable','off'); %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); + else + valuelstr = sprintf('%.1f', valuel); + set(handles.edit_lowpass, 'String', valuelstr); + set(handles.edit_lowpass, 'Enable', 'on'); + %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); + end +else + set(handles.edit_lowpass, 'String', '0'); + set(handles.edit_lowpass, 'Enable', 'off'); + set(handles.togglebutton_lowpass, 'Value', 0); + set(handles.slider_lowpass, 'Enable','off'); + %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); end if typef==0 && autorder==1 - % order starts again for auto butter - orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list - orderlist{1} = 'automin:2'; - set(handles.popupmenu_order, 'String', orderlist); - set(handles.popupmenu_order, 'Value',1); - set(handles.popupmenu_dboct, 'Value',1); - set(handles.popupmenu_dbdec, 'Value',1); + % order starts again for auto butter + orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list + orderlist{1} = 'automin:2'; + set(handles.popupmenu_order, 'String', orderlist); + set(handles.popupmenu_order, 'Value',1); + set(handles.popupmenu_dboct, 'Value',1); + set(handles.popupmenu_dbdec, 'Value',1); end % % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function slider_lowpass_CreateFcn(hObject, eventdata, handles) if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor',[.9 .9 .9]); + set(hObject,'BackgroundColor',[.9 .9 .9]); end %-------------------------------------------------------------------------- @@ -379,26 +402,26 @@ function popupmenu_order_Callback(hObject, eventdata, handles) orderlist = cellstr(get(handles.popupmenu_order, 'String')); if orderindx==1 - orderlist = regexprep(orderlist,'automin:','','ignorecase'); %get rid of auto: (if any) - newlaborder = ['automin:' orderlist{2}]; - orderlist{1} = newlaborder; - set(handles.popupmenu_order,'String', orderlist); - handles.autorder = 1; - - if get(handles.radiobutton_butter,'Value') - order = str2num(strrep(orderlist{1},'automin:','')); % get rid of auto (in case of) - set(handles.popupmenu_dboct,'Value', 1); - set(handles.popupmenu_dbdec,'Value', 1); - end + orderlist = regexprep(orderlist,'automin:','','ignorecase'); %get rid of auto: (if any) + newlaborder = ['automin:' orderlist{2}]; + orderlist{1} = newlaborder; + set(handles.popupmenu_order,'String', orderlist); + handles.autorder = 1; + + if get(handles.radiobutton_butter,'Value') + order = str2num(strrep(orderlist{1},'automin:','')); % get rid of auto (in case of) + set(handles.popupmenu_dboct,'Value', 1); + set(handles.popupmenu_dbdec,'Value', 1); + end else - orderlist{1} = 'automin'; - set(handles.popupmenu_order,'String', orderlist); - handles.autorder = 0; - - if get(handles.radiobutton_butter,'Value') - set(handles.popupmenu_dboct,'Value', orderindx-1); - set(handles.popupmenu_dbdec,'Value', orderindx-1); - end + orderlist{1} = 'automin'; + set(handles.popupmenu_order,'String', orderlist); + handles.autorder = 0; + + if get(handles.radiobutton_butter,'Value') + set(handles.popupmenu_dboct,'Value', orderindx-1); + set(handles.popupmenu_dbdec,'Value', orderindx-1); + end end % Update handles structure @@ -407,16 +430,16 @@ function popupmenu_order_Callback(hObject, eventdata, handles) % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function popupmenu_order_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -425,110 +448,110 @@ function edit_highpass_Callback(hObject, eventdata, handles) valueh = str2num(get(handles.edit_highpass, 'String')); if length(valueh)~=1 - msgboxText = 'Invalid input for high pass cutoff'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - return + msgboxText = 'Invalid input for high pass cutoff'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + return end if valueh<0.001; - set(handles.edit_highpass, 'String', num2str(handles.maxsliders)) - set(handles.slider_highpass, 'Value', handles.maxsliders); - set(handles.slider_highpass, 'Enable', 'on'); - set(handles.togglebutton_highpass, 'Value', 1); - set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); - plotresponsefilter(hObject, eventdata, handles); - return + set(handles.edit_highpass, 'String', num2str(handles.maxsliders)) + set(handles.slider_highpass, 'Value', handles.maxsliders); + set(handles.slider_highpass, 'Enable', 'on'); + set(handles.togglebutton_highpass, 'Value', 1); + set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); + plotresponsefilter(hObject, eventdata, handles); + return end if valueh<0 - msgboxText = 'Invalid input for high pass cutoff'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - set(handles.edit_highpass, 'String', '0') - set(handles.edit_highpass, 'Enable', 'off') - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_highpass, 'Enable', 'off'); - set(handles.togglebutton_highpass, 'Value', 0); - set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); - plotresponsefilter(hObject, eventdata, handles); - return + msgboxText = 'Invalid input for high pass cutoff'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + set(handles.edit_highpass, 'String', '0') + set(handles.edit_highpass, 'Enable', 'off') + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.slider_highpass, 'Value', 0); + set(handles.slider_highpass, 'Enable', 'off'); + set(handles.togglebutton_highpass, 'Value', 0); + set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); + plotresponsefilter(hObject, eventdata, handles); + return end if valueh>handles.maxsliders - msgboxText = 'Too high!!!'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - set(handles.edit_highpass, 'String', num2str(handles.maxsliders)) - set(handles.slider_highpass, 'Value', handles.maxsliders); - set(handles.slider_highpass, 'Enable', 'on'); - set(handles.togglebutton_highpass, 'Value', 1); - set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); - plotresponsefilter(hObject, eventdata, handles); - return + msgboxText = 'Too high!!!'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + set(handles.edit_highpass, 'String', num2str(handles.maxsliders)) + set(handles.slider_highpass, 'Value', handles.maxsliders); + set(handles.slider_highpass, 'Enable', 'on'); + set(handles.togglebutton_highpass, 'Value', 1); + set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); + plotresponsefilter(hObject, eventdata, handles); + return end set(handles.edit_highpass, 'String', num2str(valueh)); autorder = handles.autorder; if get(handles.radiobutton_butter, 'Value'); - typef = 0; % 0 means Butterworth + typef = 0; % 0 means Butterworth elseif get(handles.radiobutton_fir, 'Value'); - typef = 1;% 1 means FIR + typef = 1;% 1 means FIR elseif get(handles.radiobutton_PM_notch, 'Value'); - typef = 2; % 2 means PM Notch + typef = 2; % 2 means PM Notch end notchpm = get(handles.radiobutton_PM_notch,'Value'); if notchpm - if valueh>=5 && valueh<=handles.maxsliders-5 - set(handles.slider_highpass, 'Value', valueh); - else - if valueh<5 - nvaln = 5; - elseif valueh>handles.maxsliders-5 - nvaln = handles.maxsliders-5; - end - - nvalstr = sprintf('%.1f',nvaln); - set(handles.edit_highpass, 'String', nvalstr); - set(handles.slider_highpass, 'Value', nvaln); - end - - % - % Plot corresponding response - % - - if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) - elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); - end -else + if valueh>=5 && valueh<=handles.maxsliders-5 set(handles.slider_highpass, 'Value', valueh); - - if typef==0 && autorder==1 - % order starts again for auto butter - orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list - orderlist{1} = 'automin:2'; - set(handles.popupmenu_order, 'String', orderlist); - set(handles.popupmenu_order, 'Value',1); + else + if valueh<5 + nvaln = 5; + elseif valueh>handles.maxsliders-5 + nvaln = handles.maxsliders-5; end - % - % Plot corresponding response - % - if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) - elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); - end + nvalstr = sprintf('%.1f',nvaln); + set(handles.edit_highpass, 'String', nvalstr); + set(handles.slider_highpass, 'Value', nvaln); + end + + % + % Plot corresponding response + % + + if get(handles.radiobutton_fdatafr,'Value') + plotresponse_fd_data(hObject, eventdata, handles) + elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') + plotresponsefilter(hObject, eventdata, handles); + end +else + set(handles.slider_highpass, 'Value', valueh); + + if typef==0 && autorder==1 + % order starts again for auto butter + orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list + orderlist{1} = 'automin:2'; + set(handles.popupmenu_order, 'String', orderlist); + set(handles.popupmenu_order, 'Value',1); + end + + % + % Plot corresponding response + % + if get(handles.radiobutton_fdatafr,'Value') + plotresponse_fd_data(hObject, eventdata, handles) + elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') + plotresponsefilter(hObject, eventdata, handles); + end end %-------------------------------------------------------------------------- function edit_highpass_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -537,45 +560,45 @@ function edit_lowpass_Callback(hObject, eventdata, handles) valuel = str2num(get(handles.edit_lowpass, 'String')); if length(valuel)~=1 - msgboxText = 'Invalid input for low pass cutoff'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - return + msgboxText = 'Invalid input for low pass cutoff'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + return end if valuel<0.001; - set(handles.edit_lowpass, 'String', num2str(handles.maxsliders)) - set(handles.slider_lowpass, 'Value', handles.maxsliders); - set(handles.slider_lowpass, 'Enable', 'on'); - set(handles.togglebutton_lowpass, 'Value', 1); - set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); - plotresponsefilter(hObject, eventdata, handles); - return + set(handles.edit_lowpass, 'String', num2str(handles.maxsliders)) + set(handles.slider_lowpass, 'Value', handles.maxsliders); + set(handles.slider_lowpass, 'Enable', 'on'); + set(handles.togglebutton_lowpass, 'Value', 1); + set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); + plotresponsefilter(hObject, eventdata, handles); + return end if valuel<0 - msgboxText = 'Invalid input for low pass cutoff'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - set(handles.edit_lowpass, 'String', '0') - set(handles.edit_lowpass, 'Enable', 'off') - %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.slider_lowpass, 'Value', 0); - set(handles.slider_lowpass, 'Enable', 'off'); - set(handles.togglebutton_lowpass, 'Value', 0); - set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); - plotresponsefilter(hObject, eventdata, handles); - return + msgboxText = 'Invalid input for low pass cutoff'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + set(handles.edit_lowpass, 'String', '0') + set(handles.edit_lowpass, 'Enable', 'off') + %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.slider_lowpass, 'Value', 0); + set(handles.slider_lowpass, 'Enable', 'off'); + set(handles.togglebutton_lowpass, 'Value', 0); + set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); + plotresponsefilter(hObject, eventdata, handles); + return end if valuel>handles.maxsliders - msgboxText = 'Too high!!!'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - set(handles.edit_lowpass, 'String', num2str(handles.maxsliders)) - set(handles.slider_lowpass, 'Value', handles.maxsliders); - set(handles.slider_lowpass, 'Enable', 'on'); - set(handles.togglebutton_lowpass, 'Value', 1); - set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); - plotresponsefilter(hObject, eventdata, handles); - return + msgboxText = 'Too high!!!'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + set(handles.edit_lowpass, 'String', num2str(handles.maxsliders)) + set(handles.slider_lowpass, 'Value', handles.maxsliders); + set(handles.slider_lowpass, 'Enable', 'on'); + set(handles.togglebutton_lowpass, 'Value', 1); + set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); + plotresponsefilter(hObject, eventdata, handles); + return end set(handles.edit_lowpass, 'String', num2str(valuel)); @@ -583,39 +606,39 @@ function edit_lowpass_Callback(hObject, eventdata, handles) set(handles.slider_lowpass, 'Value', valuel); if get(handles.radiobutton_butter, 'Value'); - typef = 0; % 0 means Butterworth + typef = 0; % 0 means Butterworth elseif get(handles.radiobutton_fir, 'Value'); - typef = 1;% 1 means FIR + typef = 1;% 1 means FIR elseif get(handles.radiobutton_PM_notch, 'Value'); - typef = 2; % 2 means PM Notch + typef = 2; % 2 means PM Notch end if typef==0 && autorder==1 - % order starts again for auto butter - orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list - orderlist{1} = 'automin:2'; - set(handles.popupmenu_order, 'String', orderlist); - set(handles.popupmenu_order, 'Value',1); + % order starts again for auto butter + orderlist = cellstr(get(handles.popupmenu_order, 'String')); % whole list + orderlist{1} = 'automin:2'; + set(handles.popupmenu_order, 'String', orderlist); + set(handles.popupmenu_order, 'Value',1); end % % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function edit_lowpass_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- % % % function popupmenu_channels_Callback(hObject, eventdata, handles) -% % % +% % % % % % numch = get(hObject, 'Value'); % % % nums = str2num(get(handles.edit_channels, 'String')); % % % nums = [nums numch]; @@ -633,7 +656,7 @@ function edit_lowpass_CreateFcn(hObject, eventdata, handles) %-------------------------------------------------------------------------- % % function popupmenu_channels_CreateFcn(hObject, eventdata, handles) -% % +% % % % if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) % % set(hObject,'BackgroundColor','white'); % % end @@ -645,67 +668,60 @@ function edit_channels_Callback(hObject, eventdata, handles) chx = str2num(get(handles.edit_channels,'String')); tf = checkchannels(chx, nchan); if tf - return -end -if length(chx)==nchan - set(handles.checkbox_filterallchannels, 'Value', 1) - set(handles.edit_channels, 'String', vect2colon([1:nchan], 'Delimiter', 'off')); - set(handles.edit_channels, 'Enable', 'off'); - set(handles.pushbutton_browsechan, 'Enable', 'off'); -else - chxstr = vect2colon(chx,'Delimiter','off', 'Repeat', 'off'); - set(handles.edit_channels,'String', chxstr) + return end +chxstr = vect2colon(chx,'Delimiter','off', 'Repeat', 'off'); +set(handles.edit_channels,'String', chxstr) if get(handles.radiobutton_ufdatafr,'Value'); - plotresponse_uf_data(hObject, eventdata, handles); + plotresponse_uf_data(hObject, eventdata, handles); elseif get(handles.radiobutton_fdatafr,'Value'); - plotresponse_fd_data(hObject, eventdata, handles); + plotresponse_fd_data(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function tf = checkchannels(chx, nchan, showmsg) if nargin<3 - showmsg = 1; + showmsg = 1; end tf = 0; % no problem by default if isempty(chx) - if showmsg - msgboxText = 'Invalid channel indexing.'; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(msgboxText, title); - end - tf = 1; % - return + if showmsg + msgboxText = 'Invalid channel indexing.'; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(msgboxText, title); + end + tf = 1; % + return end if ~isempty(find(chx>nchan)) - if showmsg - msgboxText = ['You only have %g channels,\n'... - 'so you cannot specify indices greater than this.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText, nchan), title); - end - tf = 1; % - return + if showmsg + msgboxText = ['You only have %g channels,\n'... + 'so you cannot specify indices greater than this.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText, nchan), title); + end + tf = 1; % + return end if ~isempty(find(chx<1)) - if showmsg - msgboxText = 'You cannot use zero or a negative number as a channel indexing'; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(msgboxText, title); - end - tf = 1; % - return + if showmsg + msgboxText = 'You cannot use zero or a negative number as a channel indexing'; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(msgboxText, title); + end + tf = 1; % + return end if length(chx)>length(unique_bc2(chx)) - if showmsg - msgboxText = ['Repeated channels are not allowed.\n'... - 'Therefore, ERPLAB will get rid of them.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText), title, [1 1 0], [0 0 0], 0) - end - tf = 0; % - return + if showmsg + msgboxText = ['Repeated channels are not allowed.\n'... + 'Therefore, ERPLAB will get rid of them.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText), title, [1 1 0], [0 0 0], 0) + end + tf = 0; % + return end return @@ -713,7 +729,7 @@ function edit_channels_Callback(hObject, eventdata, handles) function edit_channels_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -741,7 +757,7 @@ function pushbutton_apply_Callback(hObject, eventdata, handles) [readobjects v] = read_GUI(hObject, eventdata, handles); % v=1 means everythink is ok. if v~=1 % means something was wrong - return + return end channelArray = readobjects{1}; @@ -758,102 +774,110 @@ function pushbutton_apply_Callback(hObject, eventdata, handles) iswarnroff = handles.iswarnroff; if (iswarngain==1 || iswarngain==2) && ~strcmpi(typefilter,'notch') - - BackERPLABcolor = [1 0.9 0.3]; % yellow - - if iswarngain==1 - question = ['With this filter setting, there will be significant \n'... - 'attenuation at passband. This is almost always a \n'... - 'bad thing. This problem can usually be eliminated by \n'... - 'selecting a lower high-pass cuttoff, higher low-pass \n'... - 'cuttoff, and/or a higher filter order. ']; - elseif iswarngain==2 - question = ['With this filter setting, there will be some \n'... - 'amplification at the passband frequencies. \n'... - 'This problem can be eliminated by selecting \n'... - 'a higher filter order. ']; - end - - title = 'WARNING!'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question), title,'Proceed anyway', 'Cancel','Proceed anyway'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - if ~strcmpi(button,'Proceed anyway') - disp('User selected Cancel') - return - end + + BackERPLABcolor = [1 0.9 0.3]; % yellow + + if iswarngain==1 + question = ['With this filter setting, there will be significant \n'... + 'attenuation at passband. This is almost always a \n'... + 'bad thing. This problem can usually be eliminated by \n'... + 'selecting a lower high-pass cuttoff, higher low-pass \n'... + 'cuttoff, and/or a higher filter order. ']; + elseif iswarngain==2 + question = ['With this filter setting, there will be some \n'... + 'amplification at the passband frequencies. \n'... + 'This problem can be eliminated by selecting \n'... + 'a higher filter order. ']; + end + + title = 'WARNING!'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Proceed anyway', 'Cancel','Proceed anyway'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + + if ~strcmpi(button,'Proceed anyway') + disp('User selected Cancel') + return + end end if highpasscutoff==0 && lowpasscutoff==0 - msgboxText = ['I beg your pardon?\n\n'... - 'You must define one frequency cutoff at least.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText), title); - return + msgboxText = ['I beg your pardon?\n\n'... + 'You must define one frequency cutoff at least.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText), title); + return end if strcmp(typefilter, 'fir') || strcmp(typefilter, 'notch') - - minboundarysamdist = handles.minboundarysamdist; - if boundarycheck==1 - if minboundarysamdist<3*order - BackERPLABcolor = [ 1 1 0]; - question = ['You have set the checkbox for filtering between boundary events.\n'... - 'Event codes ''boundary'' or -99 were found in you dataset.\n\n'... - 'However, at least one of the segments among boundaries \n'... - 'has less samples than 3 times the filter order you are currently setting.\n\n'... - 'You may either decrese the order of the filter - if it is possible - (recommended),\n'... - 'or uncheck the option for filtering between boundary events (not recommended).']; - - questionstr = sprintf(question); - titlex = 'ERPLAB: Filter order vs number of samples'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(questionstr, titlex,'OK','OK'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - return - end + + minboundarysamdist = handles.minboundarysamdist; + if boundarycheck==1 + if minboundarysamdist<3*order + BackERPLABcolor = [ 1 1 0]; + question = ['You have set the checkbox for filtering between boundary events.\n'... + 'Event codes ''boundary'' or -99 were found in you dataset.\n\n'... + 'However, at least one of the segments among boundaries \n'... + 'has less samples than 3 times the filter order you are currently setting.\n\n'... + 'You may either decrese the order of the filter - if it is possible - (recommended),\n'... + 'or uncheck the option for filtering between boundary events (not recommended).']; + + questionstr = sprintf(question); + titlex = 'ERPLAB: Filter order vs number of samples'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(questionstr, titlex,'OK','OK'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + return end + end end if boundarycheck==1 - if strcmpi(boundarystr,'boundary')||strcmpi(boundarystr,'''boundary''') - boundary = 'boundary'; + if strcmpi(boundarystr,'boundary')||strcmpi(boundarystr,'''boundary''') + boundary = 'boundary'; + else + if ~strcmp(boundarystr,'') + boundary = str2num(boundarystr); + if isempty(boundary); + boundary = boundarystr; + end else - if ~strcmp(boundarystr,'') - boundary = str2num(boundarystr); - if isempty(boundary); - boundary = boundarystr; - end - else - %boundary = []; - msgboxText = ['You have set the checkbox for filtering between boundary events.\n'... - 'So, you must define a boundary event code.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText), title); - return - end + %boundary = []; + msgboxText = ['You have set the checkbox for filtering between boundary events.\n'... + 'So, you must define a boundary event code.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText), title); + return end + end else - boundary = []; + boundary = []; end nchan = handles.nchan; tf = checkchannels(channelArray, nchan, 0); % 0 means no problems if tf - return + return end + +binArray = str2num(handles.edit_bin.String); +if iserpstruct(handles.ERPLAB) && handles.nbin>0 + if isempty(binArray) || any(binArray(:)>handles.ERPLAB.nbin) || any(binArray(:)<1) + binArray = [1:handles.ERPLAB.nbin]; + end +end +filterallch=0; if ~isempty(highpasscutoff) && ~isempty(lowpasscutoff) && ~isempty(order) && ~isempty(channelArray) - %v=1; - outstr = {highpasscutoff, lowpasscutoff, order, channelArray, filterallch, typefilter, remove_dc, boundary}; - %handles.output = outstr; - %guidata(hObject, handles); - uiresume(handles.gui_chassis); + %v=1; + outstr = {highpasscutoff, lowpasscutoff, order, channelArray, filterallch, typefilter, remove_dc, boundary,binArray}; + %handles.output = outstr; + %guidata(hObject, handles); + uiresume(handles.gui_chassis); else - msgboxText = 'Something went wrong...Please try again'; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(msgboxText, title); - return + msgboxText = 'Something went wrong...Please try again'; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(msgboxText, title); + return end %-------------------------------------------------------------------------- @@ -864,55 +888,48 @@ function pushbutton_apply_Callback(hObject, eventdata, handles) channelArray = str2num(get(handles.edit_channels, 'string')); channelArray = unique_bc2(channelArray); len1 = length(channelArray); -filterallch = get(handles.checkbox_filterallchannels, 'Value'); -if filterallch - nchan = handles.nchan; - channelArray = 1:nchan; % all channels - len2 = length(channelArray); - if len1~=len2 - fprintf('Index of channels to be filtered was adjusted since current %s has %g channels.\n', typedata, nchan); - end - if len2==nchan - set(handles.checkbox_filterallchannels, 'Value', 1) - set(handles.edit_channels, 'String', vect2colon([1:nchan], 'Delimiter', 'off')); - set(handles.edit_channels, 'Enable', 'off'); - set(handles.pushbutton_browsechan, 'Enable', 'off'); - end -end + highpasscutoff = str2num(get(handles.edit_highpass, 'string')); if length(highpasscutoff)~=1 - msgboxText = 'Invalid input for high pass cutoff'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - v=0; - return + msgboxText = 'Invalid input for high pass cutoff'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + v=0; + return end remove_dc = get(handles.checkbox_removedc, 'Value'); boundarystr = get(handles.edit_boundary, 'String'); boundarycheck = get(handles.checkbox_boundary,'Value'); if get(handles.radiobutton_butter, 'Value'); % 0 means Butterworth - typefilter = 'butter'; + typefilter = 'butter'; elseif get(handles.radiobutton_fir, 'Value'); % 1 means FIR - typefilter = 'fir'; + typefilter = 'fir'; elseif get(handles.radiobutton_PM_notch, 'Value'); % 2 means PM Notch - typefilter = 'notch'; + typefilter = 'notch'; end if strcmp(typefilter, 'notch') - lowpasscutoff = highpasscutoff; - order = 180; + lowpasscutoff = highpasscutoff; + order = 180; else - lowpasscutoff = str2num(get(handles.edit_lowpass, 'string')); - - if length(lowpasscutoff)~=1 - msgboxText = 'Invalid input for low pass cutoff'; - title = 'ERPLAB: basicfilterGUI2() error'; - errorfound(msgboxText, title); - v=0; - return - end - order = getorder(handles); + lowpasscutoff = str2num(get(handles.edit_lowpass, 'string')); + + if length(lowpasscutoff)~=1 + msgboxText = 'Invalid input for low pass cutoff'; + title = 'ERPLAB: basicfilterGUI2() error'; + errorfound(msgboxText, title); + v=0; + return + end + order = getorder(handles); +end +filterallch=0; +binArray = str2num(handles.edit_bin.String); +if iserpstruct(handles.ERPLAB) && handles.nbin>0 + if isempty(binArray) || any(binArray(:)>handles.ERPLAB.nbin) || any(binArray(:)<1) + binArray = [1:handles.ERPLAB.nbin]; + end end -readobjects = {channelArray, filterallch, highpasscutoff, lowpasscutoff, order, typefilter, remove_dc, boundarycheck, boundarystr}; +readobjects = {channelArray, filterallch, highpasscutoff, lowpasscutoff, order, typefilter, remove_dc, boundarycheck, boundarystr,binArray}; %-------------------------------------------------------------------------- function checkbox_removedc_Callback(hObject, eventdata, handles) @@ -920,220 +937,220 @@ function checkbox_removedc_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function togglebutton_highpass_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.edit_highpass, 'Enable', 'on'); - set(handles.edit2_highpass, 'Enable', 'on'); - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_highpass, 'Enable', 'inactive'); - set(handles.togglebutton_highpass, 'Value', 1); - set(handles.slider_highpass, 'Enable','on'); - mvalueh = round(handles.mvalueh*10)/10; - - if mvalueh<0.1 - handles.mvalueh = 0.1; - end - - set(handles.slider_highpass, 'Value', handles.mvalueh); - set(handles.edit_highpass, 'String', num2str(handles.mvalueh)); - set(handles.checkbox_removedc, 'Enable', 'on') - set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); - - % - % Roll off - % - set(handles.popupmenu_dboct, 'Enable', 'on'); - set(handles.popupmenu_dbdec, 'Enable', 'on'); - set(handles.popupmenu_order, 'Enable', 'on'); - - % - % Plot filter related responses - % - set(handles.radiobutton_freqr, 'Enable', 'on'); - set(handles.radiobutton_impr, 'Enable', 'on'); - set(handles.radiobutton_fdatafr, 'Enable', 'on'); - - % Update handles structure - guidata(hObject, handles); + set(handles.edit_highpass, 'Enable', 'on'); + set(handles.edit2_highpass, 'Enable', 'on'); + set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit2_highpass, 'Enable', 'inactive'); + set(handles.togglebutton_highpass, 'Value', 1); + set(handles.slider_highpass, 'Enable','on'); + mvalueh = round(handles.mvalueh*10)/10; + + if mvalueh<0.1 + handles.mvalueh = 0.1; + end + + set(handles.slider_highpass, 'Value', handles.mvalueh); + set(handles.edit_highpass, 'String', num2str(handles.mvalueh)); + set(handles.checkbox_removedc, 'Enable', 'on') + set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); + + % + % Roll off + % + set(handles.popupmenu_dboct, 'Enable', 'on'); + set(handles.popupmenu_dbdec, 'Enable', 'on'); + set(handles.popupmenu_order, 'Enable', 'on'); + + % + % Plot filter related responses + % + set(handles.radiobutton_freqr, 'Enable', 'on'); + set(handles.radiobutton_impr, 'Enable', 'on'); + set(handles.radiobutton_fdatafr, 'Enable', 'on'); + + % Update handles structure + guidata(hObject, handles); else - set(handles.togglebutton_highpass, 'Value', 0); - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_highpass, 'Enable','off'); - set(handles.edit_highpass, 'String', '0'); - set(handles.edit_highpass, 'Enable', 'off'); - set(handles.edit2_highpass, 'String', '---'); - set(handles.edit2_highpass, 'Enable', 'off'); - set(handles.checkbox_removedc, 'Enable', 'off') - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); + set(handles.togglebutton_highpass, 'Value', 0); + set(handles.slider_highpass, 'Value', 0); + set(handles.slider_highpass, 'Enable','off'); + set(handles.edit_highpass, 'String', '0'); + set(handles.edit_highpass, 'Enable', 'off'); + set(handles.edit2_highpass, 'String', '---'); + set(handles.edit2_highpass, 'Enable', 'off'); + set(handles.checkbox_removedc, 'Enable', 'off') + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); end if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) else - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function togglebutton_lowpass_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.edit_lowpass, 'Enable', 'on'); - set(handles.edit2_lowpass, 'Enable', 'on'); - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_lowpass, 'Enable', 'inactive'); - set(handles.slider_lowpass, 'Enable','on'); - fc = round(handles.mvaluel*10)/10; - - if fc==0 - fc = round(handles.maxsliders*5)/10; - end - - set(handles.slider_lowpass, 'Value', fc); - set(handles.edit_lowpass, 'String', num2str(fc)); - %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); - set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); - - % - % Roll off - % - set(handles.popupmenu_dboct, 'Enable', 'on'); - set(handles.popupmenu_dbdec, 'Enable', 'on'); - set(handles.popupmenu_order, 'Enable', 'on'); - - % - % Plot filter related responses - % - set(handles.radiobutton_freqr, 'Enable', 'on'); - set(handles.radiobutton_impr, 'Enable', 'on'); - set(handles.radiobutton_fdatafr, 'Enable', 'on'); + set(handles.edit_lowpass, 'Enable', 'on'); + set(handles.edit2_lowpass, 'Enable', 'on'); + set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit2_lowpass, 'Enable', 'inactive'); + set(handles.slider_lowpass, 'Enable','on'); + fc = round(handles.mvaluel*10)/10; + + if fc==0 + fc = round(handles.maxsliders*5)/10; + end + + set(handles.slider_lowpass, 'Value', fc); + set(handles.edit_lowpass, 'String', num2str(fc)); + %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); + set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); + + % + % Roll off + % + set(handles.popupmenu_dboct, 'Enable', 'on'); + set(handles.popupmenu_dbdec, 'Enable', 'on'); + set(handles.popupmenu_order, 'Enable', 'on'); + + % + % Plot filter related responses + % + set(handles.radiobutton_freqr, 'Enable', 'on'); + set(handles.radiobutton_impr, 'Enable', 'on'); + set(handles.radiobutton_fdatafr, 'Enable', 'on'); else - set(handles.edit_lowpass, 'String', '0'); - set(handles.edit_lowpass, 'Enable', 'off'); - set(handles.edit2_lowpass, 'String', '---'); - set(handles.edit2_lowpass, 'Enable', 'off'); - set(handles.slider_lowpass, 'Enable','off'); - set(handles.slider_lowpass, 'Value', 0); - %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); + set(handles.edit_lowpass, 'String', '0'); + set(handles.edit_lowpass, 'Enable', 'off'); + set(handles.edit2_lowpass, 'String', '---'); + set(handles.edit2_lowpass, 'Enable', 'off'); + set(handles.slider_lowpass, 'Enable','off'); + set(handles.slider_lowpass, 'Value', 0); + %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); end if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) else - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function radiobutton_freqr_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.radiobutton_impr,'Value', 0); - set(handles.radiobutton_ufdatafr,'Value', 0); - set(handles.radiobutton_fdatafr,'Value', 0); - %set(handles.popupmenu_FRscale,'Value', 1); - set(handles.popupmenu_FRscale,'Enable', 'on'); - set(handles.radiobutton_butter, 'Enable', 'on') - set(handles.radiobutton_fir, 'Enable', 'on') - set(handles.radiobutton_PM_notch,'Enable','on') - set(handles.radiobutton_ideal, 'Enable','on') - plotresponsefilter(hObject, eventdata, handles); + set(handles.radiobutton_impr,'Value', 0); + set(handles.radiobutton_ufdatafr,'Value', 0); + set(handles.radiobutton_fdatafr,'Value', 0); + %set(handles.popupmenu_FRscale,'Value', 1); + set(handles.popupmenu_FRscale,'Enable', 'on'); + set(handles.radiobutton_butter, 'Enable', 'on') + set(handles.radiobutton_fir, 'Enable', 'on') + set(handles.radiobutton_PM_notch,'Enable','on') + set(handles.radiobutton_ideal, 'Enable','on') + plotresponsefilter(hObject, eventdata, handles); else - set(handles.radiobutton_freqr,'Value', 1); + set(handles.radiobutton_freqr,'Value', 1); end %-------------------------------------------------------------------------- function radiobutton_impr_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.radiobutton_freqr,'Value', 0); - set(handles.radiobutton_ufdatafr,'Value', 0); - set(handles.radiobutton_fdatafr,'Value', 0); - %set(handles.popupmenu_FRscale,'Value', 1); - set(handles.popupmenu_FRscale,'Enable', 'off'); - set(handles.radiobutton_butter, 'Enable', 'on') - set(handles.radiobutton_fir, 'Enable', 'on') - set(handles.radiobutton_PM_notch,'Enable','on') - set(handles.radiobutton_ideal, 'Enable','off') - plotresponsefilter(hObject, eventdata, handles); + set(handles.radiobutton_freqr,'Value', 0); + set(handles.radiobutton_ufdatafr,'Value', 0); + set(handles.radiobutton_fdatafr,'Value', 0); + %set(handles.popupmenu_FRscale,'Value', 1); + set(handles.popupmenu_FRscale,'Enable', 'off'); + set(handles.radiobutton_butter, 'Enable', 'on') + set(handles.radiobutton_fir, 'Enable', 'on') + set(handles.radiobutton_PM_notch,'Enable','on') + set(handles.radiobutton_ideal, 'Enable','off') + plotresponsefilter(hObject, eventdata, handles); else - set(handles.radiobutton_impr,'Value', 1); + set(handles.radiobutton_impr,'Value', 1); end %-------------------------------------------------------------------------- function radiobutton_ufdatafr_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.radiobutton_freqr,'Value', 0); - set(handles.radiobutton_impr,'Value', 0); - set(handles.radiobutton_fdatafr,'Value', 0); - % set(handles.popupmenu_FRscale,'Value', 1); - set(handles.popupmenu_FRscale,'Enable', 'on'); - set(handles.radiobutton_butter, 'Enable', 'off') - set(handles.radiobutton_fir, 'Enable', 'off') - set(handles.radiobutton_PM_notch,'Enable','off') - set(handles.radiobutton_ideal, 'Enable','off') - drawnow - plotresponse_uf_data(hObject, eventdata, handles); + set(handles.radiobutton_freqr,'Value', 0); + set(handles.radiobutton_impr,'Value', 0); + set(handles.radiobutton_fdatafr,'Value', 0); + % set(handles.popupmenu_FRscale,'Value', 1); + set(handles.popupmenu_FRscale,'Enable', 'on'); + set(handles.radiobutton_butter, 'Enable', 'off') + set(handles.radiobutton_fir, 'Enable', 'off') + set(handles.radiobutton_PM_notch,'Enable','off') + set(handles.radiobutton_ideal, 'Enable','off') + drawnow + plotresponse_uf_data(hObject, eventdata, handles); else - set(handles.radiobutton_ufdatafr,'Value', 1); + set(handles.radiobutton_ufdatafr,'Value', 1); end %-------------------------------------------------------------------------- function radiobutton_fdatafr_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.radiobutton_freqr,'Value', 0); - set(handles.radiobutton_impr,'Value', 0); - set(handles.radiobutton_ufdatafr,'Value', 0); - % set(handles.popupmenu_FRscale,'Value', 1); - set(handles.popupmenu_FRscale,'Enable', 'on'); - set(handles.radiobutton_butter, 'Enable', 'on') - set(handles.radiobutton_fir, 'Enable', 'on') - set(handles.radiobutton_PM_notch,'Enable','on') - set(handles.radiobutton_ideal, 'Enable','on') - drawnow - plotresponse_fd_data(hObject, eventdata, handles); + set(handles.radiobutton_freqr,'Value', 0); + set(handles.radiobutton_impr,'Value', 0); + set(handles.radiobutton_ufdatafr,'Value', 0); + % set(handles.popupmenu_FRscale,'Value', 1); + set(handles.popupmenu_FRscale,'Enable', 'on'); + set(handles.radiobutton_butter, 'Enable', 'on') + set(handles.radiobutton_fir, 'Enable', 'on') + set(handles.radiobutton_PM_notch,'Enable','on') + set(handles.radiobutton_ideal, 'Enable','on') + drawnow + plotresponse_fd_data(hObject, eventdata, handles); else - set(handles.radiobutton_fdatafr,'Value', 1); + set(handles.radiobutton_fdatafr,'Value', 1); end %-------------------------------------------------------------------------- function checkbox_boundary_Callback(hObject, eventdata, handles) if get(hObject, 'Value') + + set(handles.edit_boundary,'Enable', 'on'); + %set(handles.edit_boundary,'BackgroundColor', [1 1 1]); + + if get(handles.radiobutton_butter, 'Value'); % 0 means Butterworth + typef = 0; + elseif get(handles.radiobutton_fir, 'Value'); % 1 means FIR + typef = 1; + elseif get(handles.radiobutton_PM_notch, 'Value'); % 2 means PM Notch + typef = 2; + end + if typef==1 || typef==2 - set(handles.edit_boundary,'Enable', 'on'); - %set(handles.edit_boundary,'BackgroundColor', [1 1 1]); + % + % FILTER order + % + order = getorder(handles); - if get(handles.radiobutton_butter, 'Value'); % 0 means Butterworth - typef = 0; - elseif get(handles.radiobutton_fir, 'Value'); % 1 means FIR - typef = 1; - elseif get(handles.radiobutton_PM_notch, 'Value'); % 2 means PM Notch - typef = 2; - end - if typef==1 || typef==2 - - % - % FILTER order - % - order = getorder(handles); - - minboundarysamdist = handles.minboundarysamdist; - - if get(handles.checkbox_boundary,'Value') - if minboundarysamdist<3*order - BackERPLABcolor = [ 1 1 0]; - question = ['You have set the checkbox for filtering between boundary events.\n'... - 'Event codes ''boundary'' or -99 were found in you dataset.\n\n'... - 'However, at least one of the segments among boundaries \n'... - 'has less samples than 3 times the filter order you are currently setting.\n\n'... - 'You may either decrese the order of the filter - if it is possible - (recommended),\n'... - 'or uncheck the option for filtering between boundary events (not recommended).']; - questionstr = sprintf(question); - titlex = 'ERPLAB: Filter order vs number of samples'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(questionstr, titlex,'OK','OK'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - return - end - end + minboundarysamdist = handles.minboundarysamdist; + + if get(handles.checkbox_boundary,'Value') + if minboundarysamdist<3*order + BackERPLABcolor = [ 1 1 0]; + question = ['You have set the checkbox for filtering between boundary events.\n'... + 'Event codes ''boundary'' or -99 were found in you dataset.\n\n'... + 'However, at least one of the segments among boundaries \n'... + 'has less samples than 3 times the filter order you are currently setting.\n\n'... + 'You may either decrese the order of the filter - if it is possible - (recommended),\n'... + 'or uncheck the option for filtering between boundary events (not recommended).']; + questionstr = sprintf(question); + titlex = 'ERPLAB: Filter order vs number of samples'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(questionstr, titlex,'OK','OK'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + return + end end + end else - set(handles.edit_boundary,'Enable', 'off'); - set(handles.edit_boundary,'BackgroundColor', [0.75 0.75 0.75]); + set(handles.edit_boundary,'Enable', 'off'); + set(handles.edit_boundary,'BackgroundColor', [0.75 0.75 0.75]); end %-------------------------------------------------------------------------- @@ -1185,25 +1202,25 @@ function no_filter(hObject,handles, msgtx) axes(handles.axes1); if valueh==0 && valuel==0 - if get(handles.radiobutton_freqr, 'Value') ||... - get(handles.radiobutton_impr, 'Value') ||... - get(handles.radiobutton_fdatafr, 'Value') - msgtx = '--NO FILTERING--'; - no_filter(hObject, handles, msgtx) - end - return + if get(handles.radiobutton_freqr, 'Value') ||... + get(handles.radiobutton_impr, 'Value') ||... + get(handles.radiobutton_fdatafr, 'Value') + msgtx = '--NO FILTERING--'; + no_filter(hObject, handles, msgtx) + end + return else - xmaxp = handles.xmaxfreqr; - if nargout==0 - %if ~isempty(xmaxp) - if get(handles.radiobutton_freqr, 'Value') || get(handles.radiobutton_impr, 'Value') - % posaxes1 = get(gca,'YLim'); - msgtx = 'Working, please wait...'; - text(mean(xmaxp)/3, 1.12, msgtx,'FontSize',14, 'color', 'k') - drawnow - end - %end + xmaxp = handles.xmaxfreqr; + if nargout==0 + %if ~isempty(xmaxp) + if get(handles.radiobutton_freqr, 'Value') || get(handles.radiobutton_impr, 'Value') + % posaxes1 = get(gca,'YLim'); + msgtx = 'Working, please wait...'; + text(mean(xmaxp)/3, 1.12, msgtx,'FontSize',14, 'color', 'k') + drawnow end + %end + end end fs = handles.fs; @@ -1215,15 +1232,15 @@ function no_filter(hObject,handles, msgtx) order = getorder(handles); if isempty(order) - disp('Still busy...') - return + disp('Still busy...') + return end if get(handles.radiobutton_butter, 'Value'); % 0 means Butterworth - typef = 0; + typef = 0; elseif get(handles.radiobutton_fir, 'Value'); % 1 means FIR - typef = 1; + typef = 1; elseif get(handles.radiobutton_PM_notch, 'Value'); % 2 means PM Notch - typef = 2; + typef = 2; end n = round(fnyq); % number of points for frequency response. @@ -1233,12 +1250,12 @@ function no_filter(hObject,handles, msgtx) % Augmented number of points for frequency response. % if hpzoom<=5 - n = n*50; + n = n*50; elseif hpzoom<=0.5 - n = n*1000; + n = n*1000; end if typef==2 % PM Notch - valuel = valueh; + valuel = valueh; end bt = []; @@ -1247,171 +1264,171 @@ function no_filter(hObject,handles, msgtx) [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, order, valuel, valueh, fs); if ~v % something is wrong or turned off - disp('Filter coefficient calculation failed...') - if get(handles.radiobutton_freqr, 'Value') ||... - get(handles.radiobutton_impr, 'Value') ||... - get(handles.radiobutton_fdatafr, 'Value') - msgtx = '--NO FILTERING--'; - no_filter(hObject, handles, msgtx) - end - - handles.autorder = 0; - % Update handles structure - guidata(hObject, handles); - return + disp('Filter coefficient calculation failed...') + if get(handles.radiobutton_freqr, 'Value') ||... + get(handles.radiobutton_impr, 'Value') ||... + get(handles.radiobutton_fdatafr, 'Value') + msgtx = '--NO FILTERING--'; + no_filter(hObject, handles, msgtx) + end + + handles.autorder = 0; + % Update handles structure + guidata(hObject, handles); + return else - autorder = handles.autorder; + autorder = handles.autorder; end if ~isempty(orderx) - if orderx~=order - order = orderx; - str = ['\nWARNING: Odd order symmetric FIR filters must have a gain of zero \n'... - 'at the Nyquist frequency. The order has been increased to %g.\n']; - fprintf(str, order); - end + if orderx~=order + order = orderx; + str = ['\nWARNING: Odd order symmetric FIR filters must have a gain of zero \n'... + 'at the Nyquist frequency. The order has been increased to %g.\n']; + fprintf(str, order); + end end % % Automin for FIR % if autorder == 1 && typef==1 - slidersoff(hObject, eventdata, handles) - orderlist = cellstr(get(handles.popupmenu_order,'String')); - orderlist{1} = 'automin...'; - set(handles.popupmenu_order, 'String', orderlist) - set(handles.popupmenu_order, 'Value', 1) - set(handles.text_halfamp, 'String','updating...'); - set(handles.text_halfpow, 'String','updating...'); - drawnow - xdB_at_fx = 0; - order = 4; - j=1; + slidersoff(hObject, eventdata, handles) + orderlist = cellstr(get(handles.popupmenu_order,'String')); + orderlist{1} = 'automin...'; + set(handles.popupmenu_order, 'String', orderlist) + set(handles.popupmenu_order, 'Value', 1) + set(handles.text_halfamp, 'String','updating...'); + set(handles.text_halfpow, 'String','updating...'); + drawnow + xdB_at_fx = 0; + order = 4; + j=1; + + while mean(xdB_at_fx)~=-6 && order<=4096-2 && j<=2000% && get(handles.popupmenu_order,'Value')==1 - while mean(xdB_at_fx)~=-6 && order<=4096-2 && j<=2000% && get(handles.popupmenu_order,'Value')==1 - - if mean(xdB_at_fx)==0 - order = order + 32; - elseif mean(xdB_at_fx)>-3 && mean(xdB_at_fx)<0 - order = order + 8; - else - order = order + 4; - end - - [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, order, valuel, valueh, fs); - - if isempty(xdB_at_fx) - xdB_at_fx = 0; - end - if v - if orderx~=order - if mod(orderx,4)==0 - order = orderx; - else - order = orderx + 2; - end - str = ['\nWARNING: Odd order symmetric FIR filters must have a gain of zero \n'... - 'at the Nyquist frequency. The order has been increased to %g.\n']; - fprintf(str, order); - end - end - end - if mean(xdB_at_fx)==-6 - orderlist{1} = ['automin:' num2str(order)]; - set(handles.popupmenu_order, 'String', orderlist) - set(handles.popupmenu_order, 'Value', 1) - disp('min order was found.') - iswarnroff = 0; + if mean(xdB_at_fx)==0 + order = order + 32; + elseif mean(xdB_at_fx)>-3 && mean(xdB_at_fx)<0 + order = order + 8; else - orderlist{1} = 'automin'; - set(handles.popupmenu_order, 'String', orderlist) - set(handles.popupmenu_order, 'Value', length(orderlist)) - handles.autorder = 0; - iswarnroff = 1; % atenuation at frquency cutoff was impposible... - - % Update handles structure - guidata(hObject, handles); - disp('min order was not found...') + order = order + 4; end - sliderson(hObject, eventdata, handles) - drawnow -else - if mean(xdB_at_fx)==-6 - iswarnroff =0; - else - iswarnroff =1; + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, order, valuel, valueh, fs); + + if isempty(xdB_at_fx) + xdB_at_fx = 0; end -end -if ~v % something is wrong or turned off (1 means everything is ok) - if get(handles.radiobutton_freqr, 'Value') ||... - get(handles.radiobutton_impr, 'Value') ||... - get(handles.radiobutton_fdatafr, 'Value') - - msgtx = '--NO FILTERING--'; - no_filter(hObject, handles, msgtx) + if v + if orderx~=order + if mod(orderx,4)==0 + order = orderx; + else + order = orderx + 2; + end + str = ['\nWARNING: Odd order symmetric FIR filters must have a gain of zero \n'... + 'at the Nyquist frequency. The order has been increased to %g.\n']; + fprintf(str, order); + end end - disp('Filter coefficient calculation failed....') + end + if mean(xdB_at_fx)==-6 + orderlist{1} = ['automin:' num2str(order)]; + set(handles.popupmenu_order, 'String', orderlist) + set(handles.popupmenu_order, 'Value', 1) + disp('min order was found.') + iswarnroff = 0; + else + orderlist{1} = 'automin'; + set(handles.popupmenu_order, 'String', orderlist) + set(handles.popupmenu_order, 'Value', length(orderlist)) handles.autorder = 0; + iswarnroff = 1; % atenuation at frquency cutoff was impposible... + % Update handles structure guidata(hObject, handles); - return + disp('min order was not found...') + end + + sliderson(hObject, eventdata, handles) + drawnow +else + if mean(xdB_at_fx)==-6 + iswarnroff =0; + else + iswarnroff =1; + end +end +if ~v % something is wrong or turned off (1 means everything is ok) + if get(handles.radiobutton_freqr, 'Value') ||... + get(handles.radiobutton_impr, 'Value') ||... + get(handles.radiobutton_fdatafr, 'Value') + + msgtx = '--NO FILTERING--'; + no_filter(hObject, handles, msgtx) + end + disp('Filter coefficient calculation failed....') + handles.autorder = 0; + % Update handles structure + guidata(hObject, handles); + return end % % Final filter coefficients % if size(bt,1)==2 - if strcmpi(labelf,'Band-Pass') - % cascade filter transfer function - b = conv(bt(1,:),bt(2,:)); - a = conv(at(1,:),at(2,:)); - else - % parallel filter transfer function - b = conv(bt(1,:),at(2,:)) + conv(bt(2,:),at(1,:)); - a = conv(at(1,:),at(2,:)); - end + if strcmpi(labelf,'Band-Pass') + % cascade filter transfer function + b = conv(bt(1,:),bt(2,:)); + a = conv(at(1,:),at(2,:)); + else + % parallel filter transfer function + b = conv(bt(1,:),at(2,:)) + conv(bt(2,:),at(1,:)); + a = conv(at(1,:),at(2,:)); + end else - b = bt; - a = at; + b = bt; + a = at; end % % Half power cuttoff (-3 dB) (ONLY FOR FILTFILT!) % if ~isempty(frec3dB) - if strcmpi(labelf, 'Low-pass') - f3str = sprintf('%7.2f', frec3dB); - set(handles.edit2_highpass,'String','---') - set(handles.edit2_highpass,'Enable','off') - set(handles.edit2_lowpass,'String', f3str) - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - elseif strcmpi(labelf, 'High-pass') - f3str = sprintf('%7.2f', frec3dB); - set(handles.edit2_highpass,'String',f3str) - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_lowpass,'String', '---') - set(handles.edit2_lowpass,'Enable','off') - else - try - f3str1 = sprintf('%7.2f', frec3dB(1)); - f3str2 = sprintf('%7.2f', frec3dB(2)); - set(handles.edit2_highpass,'String', f3str2) - set(handles.edit2_lowpass,'String', f3str1) - %set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - catch - set(handles.edit2_highpass,'String','---') - set(handles.edit2_lowpass,'String', '---') - set(handles.edit2_highpass,'Enable','off') - set(handles.edit2_lowpass,'Enable','off') - end - end -else + if strcmpi(labelf, 'Low-pass') + f3str = sprintf('%7.2f', frec3dB); set(handles.edit2_highpass,'String','---') - set(handles.edit2_lowpass,'String','---') set(handles.edit2_highpass,'Enable','off') + set(handles.edit2_lowpass,'String', f3str) + set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); + elseif strcmpi(labelf, 'High-pass') + f3str = sprintf('%7.2f', frec3dB); + set(handles.edit2_highpass,'String',f3str) + set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit2_lowpass,'String', '---') set(handles.edit2_lowpass,'Enable','off') + else + try + f3str1 = sprintf('%7.2f', frec3dB(1)); + f3str2 = sprintf('%7.2f', frec3dB(2)); + set(handles.edit2_highpass,'String', f3str2) + set(handles.edit2_lowpass,'String', f3str1) + %set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); + catch + set(handles.edit2_highpass,'String','---') + set(handles.edit2_lowpass,'String', '---') + set(handles.edit2_highpass,'Enable','off') + set(handles.edit2_lowpass,'Enable','off') + end + end +else + set(handles.edit2_highpass,'String','---') + set(handles.edit2_lowpass,'String','---') + set(handles.edit2_highpass,'Enable','off') + set(handles.edit2_lowpass,'Enable','off') end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1436,365 +1453,365 @@ function no_filter(hObject,handles, msgtx) gain_postU = 1+0.05; % 5% criteria if max(abs(hfr))>=gain_postL && max(abs(hfr))<=gain_postU && (max(abs(hfr))-min(abs(hfr)))>0.95 + + iswarngain = 0; % gain is fine + + % + % Slider memory + % + handles.memvaluel = round(valuel); + handles.memvalueh = round(valueh); + handles.mem6dbl = num2str(ceil(str2num(get(handles.edit_lowpass,'String')))); + handles.mem6dbh = num2str(floor(str2num(get(handles.edit_highpass,'String')))); + handles.mem3dbl = num2str(ceil(str2num(get(handles.edit2_lowpass,'String')))); + handles.mem3dbh = num2str(floor(str2num(get(handles.edit2_highpass,'String')))); + +elseif max(abs(hfr))>=gain_postL && max(abs(hfr))<=gain_postU && (max(abs(hfr))-min(abs(hfr)))<=0.75 + iswarngain = 3; + xdB_at_fx = []; +else + if max(abs(hfr))=4096 + BackERPLABcolor = [ 1 1 0]; - iswarngain = 0; % gain is fine + question = ['Unable to achieve specified cutoff (-6dB). Higher filter order is needed,\n'... + 'but order greater than 4096 is not allowed for this ERPLAB version.\n'... + 'You may either select a wider passband with automin (recommended),\n'... + 'or turn off automin and leave with the reduced attenuation (not recommended)']; + + questionstr = sprintf(question); + titlex = 'ERPLAB: Filter order'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(questionstr, titlex,'OK','Reset filters','OK'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) % - % Slider memory + % reset order % - handles.memvaluel = round(valuel); - handles.memvalueh = round(valueh); - handles.mem6dbl = num2str(ceil(str2num(get(handles.edit_lowpass,'String')))); - handles.mem6dbh = num2str(floor(str2num(get(handles.edit_highpass,'String')))); - handles.mem3dbl = num2str(ceil(str2num(get(handles.edit2_lowpass,'String')))); - handles.mem3dbh = num2str(floor(str2num(get(handles.edit2_highpass,'String')))); + orderlist = cellstr(get(handles.popupmenu_order, 'String')); + orderindx = get(handles.popupmenu_order, 'Value'); + order = str2num(strrep(orderlist{orderindx},'automin:','')); + orderlist{1} = 'automin'; + [tfx, posord] = ismember_bc2(order,[-1 4:4:4096]); -elseif max(abs(hfr))>=gain_postL && max(abs(hfr))<=gain_postU && (max(abs(hfr))-min(abs(hfr)))<=0.75 - iswarngain = 3; - xdB_at_fx = []; -else - if max(abs(hfr))=4096 - BackERPLABcolor = [ 1 1 0]; - - question = ['Unable to achieve specified cutoff (-6dB). Higher filter order is needed,\n'... - 'but order greater than 4096 is not allowed for this ERPLAB version.\n'... - 'You may either select a wider passband with automin (recommended),\n'... - 'or turn off automin and leave with the reduced attenuation (not recommended)']; - - questionstr = sprintf(question); - titlex = 'ERPLAB: Filter order'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(questionstr, titlex,'OK','Reset filters','OK'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - % - % reset order - % - orderlist = cellstr(get(handles.popupmenu_order, 'String')); - orderindx = get(handles.popupmenu_order, 'Value'); - order = str2num(strrep(orderlist{orderindx},'automin:','')); - orderlist{1} = 'automin'; - [tfx, posord] = ismember_bc2(order,[-1 4:4:4096]); - - set(handles.popupmenu_order, 'String',orderlist) - set(handles.popupmenu_order, 'Value',posord) - set(handles.popupmenu_dboct, 'String','---') - set(handles.popupmenu_dbdec, 'String','---') - set(handles.popupmenu_dboct, 'Value',1) - set(handles.popupmenu_dbdec, 'Value',1) - handles.autorder = 0; + end +elseif iswarngain~=0 && iswarnroff==0 + if autorder == 1 && typef==0 + slidersoff(hObject, eventdata, handles) + + % + % Filter order + % + order = getorder(handles); + + if isempty(order) + disp('Ops, I could not read the filter order...') + sliderson(hObject, eventdata, handles) + return + end + + order = order + 2; % increase the order + ishopermission = handles.ishopermission; % permission for higher order when high-pass filter cutoff is <=0.5 + + if order>2 && order<=8 && valueh>0 && valueh<=0.5 && ~ishopermission + question = ['We do not recommend a filter order greater than 2 for a Butterworth filter\n '... + 'when the high-pass cutoff is <= 0.5 Hz\n'... + 'Continue anyway?']; + titlex = 'ERPLAB: Filter order'; + button = askquest(sprintf(question), titlex); + + if ~strcmpi(button,'yes') + set(handles.slider_highpass, 'Value', 0); + set(handles.slider_lowpass, 'Value', handles.memvaluel); - if strcmpi(button,'OK') - set(handles.slider_highpass, 'Value', handles.memvalueh); - set(handles.slider_lowpass, 'Value', handles.memvaluel); - chksliders(hObject, eventdata, handles) - set(handles.edit_highpass, 'String', handles.mem6dbh); - set(handles.edit_lowpass, 'String', handles.mem6dbl); - set(handles.edit2_highpass, 'String', handles.mem3dbh); - set(handles.edit2_lowpass, 'String', handles.mem3dbl); - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - sliderson(hObject, eventdata, handles) - - % Update handles structure - guidata(hObject, handles); - plotresponsefilter(hObject, eventdata, handles); - return + if handles.memvaluel==0 + set(handles.slider_lowpass, 'Enable', 'off'); + set(handles.togglebutton_lowpass,'Value',0) + set(handles.edit_lowpass, 'String', '0'); + set(handles.edit_lowpass, 'Enable', 'off'); + set(handles.edit2_lowpass, 'String', '---'); + set(handles.edit2_lowpass, 'Enable', 'off'); else - sliderson(hObject, eventdata, handles) - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_lowpass, 'Value', fnyq/2); - chksliders(hObject, eventdata, handles) - handles.memvalueh = 0.1; - handles.mvalueh = 0.1; % memory value highpass - - % Update handles structure - guidata(hObject, handles); - plotresponsefilter(hObject, eventdata, handles); - return + set(handles.edit_lowpass, 'String', handles.mem6dbl); + set(handles.edit2_lowpass, 'String', handles.mem3dbl); + set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); end - end -elseif iswarngain~=0 && iswarnroff==0 - if autorder == 1 && typef==0 - slidersoff(hObject, eventdata, handles) - % - % Filter order - % - order = getorder(handles); + set(handles.edit_highpass, 'String', handles.mem6dbh); + set(handles.edit2_highpass, 'String', handles.mem3dbh); + set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.popupmenu_order, 'Value', 2); + handles.autorder = 0; + handles.ishopermission =0; + chksliders(hObject, eventdata, handles) - if isempty(order) - disp('Ops, I could not read the filter order...') - sliderson(hObject, eventdata, handles) - return - end + % Update handles structure + guidata(hObject, handles); + plotresponsefilter(hObject, eventdata, handles); + sliderson(hObject, eventdata, handles) + return + else + chksliders(hObject, eventdata, handles) + handles.ishopermission = 1; + % Update handles structure + guidata(hObject, handles); + end + + sliderson(hObject, eventdata, handles) + return + end + if order>8 + + BackERPLABcolor = [ 1 1 0]; + + if iswarngain==3 + line01 = 'You are losing stopband attenuation!'; + else + line01 = 'You are losing passband gain!'; + end + + question = ['WARNING: %s \n\n'... + 'In order to use the automin feature, a higher Butterworth filter order is needed, '... + 'but an order greater than 8 is not allowed for this ERPLAB version. '... + 'You may select a wider passband with automin (recommended), '... + 'or turn off automin and leave with the reduced gain (not recommended).']; + + titlex = 'ERPLAB: Filter order'; + + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question, line01), titlex,'OK','Reset filters','OK'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + + % + % reset order + % + orderlist = cellstr(get(handles.popupmenu_order, 'String')); + orderindx = get(handles.popupmenu_order, 'Value'); + order = str2num(strrep(orderlist{orderindx},'automin:','')); + orderlist{1} = 'automin'; + [tfx, posord] = ismember_bc2(order,[-1 2 4 6 8]); + + set(handles.popupmenu_order, 'String',orderlist) + set(handles.popupmenu_order, 'Value',posord) + set(handles.popupmenu_dboct, 'Value',posord-1) + set(handles.popupmenu_dbdec, 'Value',posord-1) + handles.autorder = 0; + + if strcmpi(button,'OK') + set(handles.slider_highpass, 'Value', handles.memvalueh); + set(handles.slider_lowpass, 'Value', handles.memvaluel); + chksliders(hObject, eventdata, handles) + set(handles.edit_highpass, 'String', handles.mem6dbh); + set(handles.edit_lowpass, 'String', handles.mem6dbl); + set(handles.edit2_highpass, 'String', handles.mem3dbh); + set(handles.edit2_lowpass, 'String', handles.mem3dbl); + set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); + % Update handles structure + guidata(hObject, handles); - order = order + 2; % increase the order - ishopermission = handles.ishopermission; % permission for higher order when high-pass filter cutoff is <=0.5 + sliderson(hObject, eventdata, handles) + plotresponsefilter(hObject, eventdata, handles); + return + else + sliderson(hObject, eventdata, handles) + set(handles.slider_highpass, 'Value', 0); + set(handles.slider_lowpass, 'Value', fnyq/2); + chksliders(hObject, eventdata, handles) + handles.memvalueh = 0.1; + handles.mvalueh = 0.1; % memory value highpass - if order>2 && order<=8 && valueh>0 && valueh<=0.5 && ~ishopermission - question = ['We do not recommend a filter order greater than 2 for a Butterworth filter\n '... - 'when the high-pass cutoff is <= 0.5 Hz\n'... - 'Continue anyway?']; - titlex = 'ERPLAB: Filter order'; - button = askquest(sprintf(question), titlex); - - if ~strcmpi(button,'yes') - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_lowpass, 'Value', handles.memvaluel); - - if handles.memvaluel==0 - set(handles.slider_lowpass, 'Enable', 'off'); - set(handles.togglebutton_lowpass,'Value',0) - set(handles.edit_lowpass, 'String', '0'); - set(handles.edit_lowpass, 'Enable', 'off'); - set(handles.edit2_lowpass, 'String', '---'); - set(handles.edit2_lowpass, 'Enable', 'off'); - else - set(handles.edit_lowpass, 'String', handles.mem6dbl); - set(handles.edit2_lowpass, 'String', handles.mem3dbl); - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - end - - set(handles.edit_highpass, 'String', handles.mem6dbh); - set(handles.edit2_highpass, 'String', handles.mem3dbh); - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.popupmenu_order, 'Value', 2); - handles.autorder = 0; - handles.ishopermission =0; - chksliders(hObject, eventdata, handles) - - % Update handles structure - guidata(hObject, handles); - plotresponsefilter(hObject, eventdata, handles); - sliderson(hObject, eventdata, handles) - return - else - chksliders(hObject, eventdata, handles) - handles.ishopermission = 1; - % Update handles structure - guidata(hObject, handles); - end - - sliderson(hObject, eventdata, handles) - return - end - if order>8 - - BackERPLABcolor = [ 1 1 0]; - - if iswarngain==3 - line01 = 'You are losing stopband attenuation!'; - else - line01 = 'You are losing passband gain!'; - end - - question = ['WARNING: %s \n\n'... - 'In order to use the automin feature, a higher Butterworth filter order is needed, '... - 'but an order greater than 8 is not allowed for this ERPLAB version. '... - 'You may select a wider passband with automin (recommended), '... - 'or turn off automin and leave with the reduced gain (not recommended).']; - - titlex = 'ERPLAB: Filter order'; - - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question, line01), titlex,'OK','Reset filters','OK'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - % - % reset order - % - orderlist = cellstr(get(handles.popupmenu_order, 'String')); - orderindx = get(handles.popupmenu_order, 'Value'); - order = str2num(strrep(orderlist{orderindx},'automin:','')); - orderlist{1} = 'automin'; - [tfx, posord] = ismember_bc2(order,[-1 2 4 6 8]); - - set(handles.popupmenu_order, 'String',orderlist) - set(handles.popupmenu_order, 'Value',posord) - set(handles.popupmenu_dboct, 'Value',posord-1) - set(handles.popupmenu_dbdec, 'Value',posord-1) - handles.autorder = 0; - - if strcmpi(button,'OK') - set(handles.slider_highpass, 'Value', handles.memvalueh); - set(handles.slider_lowpass, 'Value', handles.memvaluel); - chksliders(hObject, eventdata, handles) - set(handles.edit_highpass, 'String', handles.mem6dbh); - set(handles.edit_lowpass, 'String', handles.mem6dbl); - set(handles.edit2_highpass, 'String', handles.mem3dbh); - set(handles.edit2_lowpass, 'String', handles.mem3dbl); - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); - % Update handles structure - guidata(hObject, handles); - - sliderson(hObject, eventdata, handles) - plotresponsefilter(hObject, eventdata, handles); - return - else - sliderson(hObject, eventdata, handles) - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_lowpass, 'Value', fnyq/2); - chksliders(hObject, eventdata, handles) - handles.memvalueh = 0.1; - handles.mvalueh = 0.1; % memory value highpass - - ordervector = 2:2:8; - set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list - set(handles.popupmenu_order,'Value', 2); - - % Update handles structure - guidata(hObject, handles); - - plotresponsefilter(hObject, eventdata, handles); - return - end - else - rolloffindx = get(handles.popupmenu_dboct,'Value'); - rolloffindx = rolloffindx + 1; - set(handles.popupmenu_dboct,'Value', rolloffindx); - set(handles.popupmenu_dbdec,'Value', rolloffindx); - end + ordervector = 2:2:8; + set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list + set(handles.popupmenu_order,'Value', 2); - orderlist = cellstr(get(handles.popupmenu_order, 'String')); - orderlist{1} = ['automin:' num2str(order)]; - set(handles.popupmenu_order, 'String', orderlist) - set(handles.popupmenu_order, 'Value', 1) - sliderson(hObject, eventdata, handles) + % Update handles structure + guidata(hObject, handles); plotresponsefilter(hObject, eventdata, handles); return + end + else + rolloffindx = get(handles.popupmenu_dboct,'Value'); + rolloffindx = rolloffindx + 1; + set(handles.popupmenu_dboct,'Value', rolloffindx); + set(handles.popupmenu_dbdec,'Value', rolloffindx); end + + orderlist = cellstr(get(handles.popupmenu_order, 'String')); + orderlist{1} = ['automin:' num2str(order)]; + set(handles.popupmenu_order, 'String', orderlist) + set(handles.popupmenu_order, 'Value', 1) + sliderson(hObject, eventdata, handles) + + plotresponsefilter(hObject, eventdata, handles); + return + end end % hfig = axes(handles.axes1); if get(handles.radiobutton_freqr,'Value') - h = hfr; - f = f1; - color = [0 0 0.75]; - FRscale = get(handles.popupmenu_FRscale, 'Value'); - - if FRscale==1 - ymax = 1.25; - ymin = -0.075; %6.25% of ymax - - ymaxb = 1; - yminb = 0; - plot(f, h, 'linewidth', 2, 'LineSmoothing','on','Color', color) - ylabel('passband gain') - else - ymax = 10; - ymin = -65; - ymaxb = 0; - yminb = -90; - plot(f, 20*log10(h), 'linewidth', 2, 'LineSmoothing','on','Color', color) - ylabel('passband gain in dB') - end - - xlabel('frequency (Hz)') - - if get(handles.radiobutton_ideal, 'Value') - drawidealresp(handles, labelf, fnyq, valuel, valueh, yminb, ymaxb) - end - if typef~=2 - if iswarngain==1 - yym = max(hfr); - - if yym>1 - yym=0.3; - end - - xxm = hpzoom/5; - text(xxm, yym+0.2,' Losing passband gain!','FontSize',10) - text(xxm, yym+0.1,' Increase the order of the filter or select automin.','FontSize',10) - set(gca,'Color', 'y') - - elseif iswarngain==2 - - yym = max(hfr); - - if yym>1 - yym=0.3; - end - - xxm = hpzoom/5; - text(xxm, yym+0.2,' Passband gain of 1 was overpassed!','FontSize',10) - text(xxm, yym+0.1,' Increase the order of the filter or select automin.','FontSize',10) - set(gca,'Color', 'y') - - elseif iswarngain==3 - - yym = max(hfr); - - if yym>1 - yym=0.3; - end - - xxm = hpzoom/5; - text(xxm, yym+0.2,' Losing stopband attenuation','FontSize',10) - text(xxm, yym+0.1,' Increase the order of the filter or select automin.','FontSize',10) - set(gca,'Color', 'y') - - elseif iswarnroff==0 && iswarngain==0 - set(gca,'Color', 'w') - end - else - set(gca,'Color', 'w') + h = hfr; + f = f1; + color = [0 0 0.75]; + FRscale = get(handles.popupmenu_FRscale, 'Value'); + + if FRscale==1 + ymax = 1.25; + ymin = -0.075; %6.25% of ymax - + ymaxb = 1; + yminb = 0; + plot(f, h, 'linewidth', 2, 'LineSmoothing','on','Color', color) + ylabel('passband gain') + else + ymax = 10; + ymin = -65; + ymaxb = 0; + yminb = -90; + plot(f, 20*log10(h), 'linewidth', 2, 'LineSmoothing','on','Color', color) + ylabel('passband gain in dB') + end + + xlabel('frequency (Hz)') + + if get(handles.radiobutton_ideal, 'Value') + drawidealresp(handles, labelf, fnyq, valuel, valueh, yminb, ymaxb) + end + if typef~=2 + if iswarngain==1 + yym = max(hfr); + + if yym>1 + yym=0.3; + end + + xxm = hpzoom/5; + text(xxm, yym+0.2,' Losing passband gain!','FontSize',10) + text(xxm, yym+0.1,' Increase the order of the filter or select automin.','FontSize',10) + set(gca,'Color', 'y') + + elseif iswarngain==2 + + yym = max(hfr); + + if yym>1 + yym=0.3; + end + + xxm = hpzoom/5; + text(xxm, yym+0.2,' Passband gain of 1 was overpassed!','FontSize',10) + text(xxm, yym+0.1,' Increase the order of the filter or select automin.','FontSize',10) + set(gca,'Color', 'y') + + elseif iswarngain==3 + + yym = max(hfr); + + if yym>1 + yym=0.3; + end + + xxm = hpzoom/5; + text(xxm, yym+0.2,' Losing stopband attenuation','FontSize',10) + text(xxm, yym+0.1,' Increase the order of the filter or select automin.','FontSize',10) + set(gca,'Color', 'y') + + elseif iswarnroff==0 && iswarngain==0 + set(gca,'Color', 'w') end - + else + set(gca,'Color', 'w') + end + elseif get(handles.radiobutton_impr,'Value') - h = hir; % impulse - f = f3; %1:length(h); - ymax = max(h)*1.2; - ymin = min(h)*1.2; - color = [0.78 0 0.1]; - stem(f, h, 'linewidth', 2, 'Color', color); - xlabel('time (msec)') - ylabel('amplitude') + h = hir; % impulse + f = f3; %1:length(h); + ymax = max(h)*1.2; + ymin = min(h)*1.2; + color = [0.78 0 0.1]; + stem(f, h, 'linewidth', 2, 'Color', color); + xlabel('time (msec)') + ylabel('amplitude') else - return + return end % % True attenuation value at specified cutoff frequency (it must be -6db, otherwise...) % if ~isempty(xdB_at_fx) - - attvaldB = round(mean(xdB_at_fx)); - - if attvaldB==-6 && typef==0 - string4HA = ['Half-Amp(' num2str(attvaldB) 'dB)']; + + attvaldB = round(mean(xdB_at_fx)); + + if attvaldB==-6 && typef==0 + string4HA = ['Half-Amp(' num2str(attvaldB) 'dB)']; + coloratt = 'k'; + else + if typef~=2 + attvalgain = 10^(attvaldB/20); + string4HA = [sprintf('%.2f',attvalgain) '-Amp(' num2str(attvaldB) 'dB)']; + + if attvaldB==-6 && typef==1 coloratt = 'k'; + else + coloratt = 'r'; + end else - if typef~=2 - attvalgain = 10^(attvaldB/20); - string4HA = [sprintf('%.2f',attvalgain) '-Amp(' num2str(attvaldB) 'dB)']; - - if attvaldB==-6 && typef==1 - coloratt = 'k'; - else - coloratt = 'r'; - end - else - string4HA = 'Center frequency'; - coloratt = 'k'; - end + string4HA = 'Center frequency'; + coloratt = 'k'; end - set(handles.text_halfamp,'String', string4HA, 'ForegroundColor', coloratt) - set(handles.text_halfpow,'String', 'Half-Power(-3dB)', 'ForegroundColor', 'k') + end + set(handles.text_halfamp,'String', string4HA, 'ForegroundColor', coloratt) + set(handles.text_halfpow,'String', 'Half-Power(-3dB)', 'ForegroundColor', 'k') else - set(handles.text_halfamp,'String', '--- ???dB ---', 'ForegroundColor', 'r') - set(handles.text_halfpow,'String', '--- ???dB ---', 'ForegroundColor', 'r') + set(handles.text_halfamp,'String', '--- ???dB ---', 'ForegroundColor', 'r') + set(handles.text_halfpow,'String', '--- ???dB ---', 'ForegroundColor', 'r') end % @@ -1803,18 +1820,18 @@ function no_filter(hObject,handles, msgtx) xmaxp = str2num(char(get(handles.edit_xmaxplot, 'String'))); if isempty(xmaxp) - xmaxp = [0 max(f)]; - if get(handles.radiobutton_fdatafr,'Value') || get(handles.radiobutton_freqr,'Value') - handles.xmaxfreqr = xmaxp; - else - handles.xmaxpimpz = xmaxp; - end + xmaxp = [0 max(f)]; + if get(handles.radiobutton_fdatafr,'Value') || get(handles.radiobutton_freqr,'Value') + handles.xmaxfreqr = xmaxp; + else + handles.xmaxpimpz = xmaxp; + end else - if get(handles.radiobutton_fdatafr,'Value') || get(handles.radiobutton_freqr,'Value') - xmaxp = handles.xmaxfreqr; - else - xmaxp = handles.xmaxpimpz; - end + if get(handles.radiobutton_fdatafr,'Value') || get(handles.radiobutton_freqr,'Value') + xmaxp = handles.xmaxfreqr; + else + xmaxp = handles.xmaxpimpz; + end end set(handles.edit_xmaxplot, 'String', num2str(xmaxp)); @@ -1834,27 +1851,27 @@ function no_filter(hObject,handles, msgtx) handles.datafr.yf = hfr; if typef==1 || typef==2 - - minboundarysamdist = handles.minboundarysamdist; - - if get(handles.checkbox_boundary,'Value') - if minboundarysamdist<3*order - BackERPLABcolor = [ 1 1 0]; - question = ['You have set the checkbox for filtering between boundary events.\n'... - 'Event codes ''boundary'' or -99 were found in your dataset.\n\n'... - 'However, at least one of the segments among boundaries \n'... - 'has fewer samples than 3 times the filter order you are currently setting.\n\n'... - 'You may either decrese the order of the filter - if it is possible - (recommended),\n'... - 'or uncheck the option for filtering between boundary events.']; - questionstr = sprintf(question); - titlex = 'ERPLAB: Filter order vs number of samples'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(questionstr, titlex,'OK','OK'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - return - end + + minboundarysamdist = handles.minboundarysamdist; + + if get(handles.checkbox_boundary,'Value') + if minboundarysamdist<3*order + BackERPLABcolor = [ 1 1 0]; + question = ['You have set the checkbox for filtering between boundary events.\n'... + 'Event codes ''boundary'' or -99 were found in your dataset.\n\n'... + 'However, at least one of the segments among boundaries \n'... + 'has fewer samples than 3 times the filter order you are currently setting.\n\n'... + 'You may either decrese the order of the filter - if it is possible - (recommended),\n'... + 'or uncheck the option for filtering between boundary events.']; + questionstr = sprintf(question); + titlex = 'ERPLAB: Filter order vs number of samples'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(questionstr, titlex,'OK','OK'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + return end + end end % Update handles structure @@ -1871,35 +1888,35 @@ function drawidealresp(handles, labelf, fnyq, valuel, valueh, yminb, ymaxb) alphaval = 0.7; if ismember_bc2(labelf, {'Low-pass','High-pass','Band-pass'}) - - if strcmpi(labelf,'High-pass') - valuelx = fnyq; - else - valuelx = valuel; - end - - patch([valueh valueh valuelx valuelx],[yminb ymaxb ymaxb yminb],'r',... - 'facecolor',colorband,... - 'edgecolor',colorband,... - 'facealpha',alphaval) + + if strcmpi(labelf,'High-pass') + valuelx = fnyq; + else + valuelx = valuel; + end + + patch([valueh valueh valuelx valuelx],[yminb ymaxb ymaxb yminb],'r',... + 'facecolor',colorband,... + 'edgecolor',colorband,... + 'facealpha',alphaval) elseif ismember_bc2(labelf,'Stop-band (Parks-McClellan Notch)') - patch([0 0 valuel-1.5 valuel-1.5],[yminb ymaxb ymaxb yminb],'r',... - 'facecolor',colorband,... - 'edgecolor',colorband,... - 'facealpha',alphaval) - patch([valueh+1.5 valueh+1.5 fnyq fnyq],[yminb ymaxb ymaxb yminb],'r',... - 'facecolor',colorband,... - 'edgecolor',colorband,... - 'facealpha',alphaval) + patch([0 0 valuel-1.5 valuel-1.5],[yminb ymaxb ymaxb yminb],'r',... + 'facecolor',colorband,... + 'edgecolor',colorband,... + 'facealpha',alphaval) + patch([valueh+1.5 valueh+1.5 fnyq fnyq],[yminb ymaxb ymaxb yminb],'r',... + 'facecolor',colorband,... + 'edgecolor',colorband,... + 'facealpha',alphaval) else - patch([0 0 valuel valuel],[yminb ymaxb ymaxb yminb],'r',... - 'facecolor',colorband,... - 'edgecolor',colorband,... - 'facealpha',alphaval) - patch([valueh valueh fnyq fnyq],[yminb ymaxb ymaxb yminb],'r',... - 'facecolor',colorband,... - 'edgecolor',colorband,... - 'facealpha',alphaval) + patch([0 0 valuel valuel],[yminb ymaxb ymaxb yminb],'r',... + 'facecolor',colorband,... + 'edgecolor',colorband,... + 'facealpha',alphaval) + patch([valueh valueh fnyq fnyq],[yminb ymaxb ymaxb yminb],'r',... + 'facecolor',colorband,... + 'edgecolor',colorband,... + 'facealpha',alphaval) end return @@ -1909,23 +1926,23 @@ function popupmenu_dboct_Callback(hObject, eventdata, handles) dboct = get(handles.popupmenu_dboct,'Value'); if get(handles.radiobutton_butter,'Value') - set(handles.popupmenu_order,'Value', dboct+1) - set(handles.popupmenu_dbdec,'Value', dboct) + set(handles.popupmenu_order,'Value', dboct+1) + set(handles.popupmenu_dbdec,'Value', dboct) end % % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function popupmenu_dboct_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -1934,144 +1951,144 @@ function popupmenu_dbdec_Callback(hObject, eventdata, handles) dbdec = get(handles.popupmenu_dbdec,'Value'); if get(handles.radiobutton_butter,'Value') - set(handles.popupmenu_order,'Value', dbdec+1); - set(handles.popupmenu_dboct,'Value', dbdec); + set(handles.popupmenu_order,'Value', dbdec+1); + set(handles.popupmenu_dboct,'Value', dbdec); end % % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function popupmenu_dbdec_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- function radiobutton_butter_Callback(hObject, eventdata, handles) if get(hObject,'Value') + + unsetnotchpm(hObject, eventdata, handles) + + if get(handles.togglebutton_lowpass,'Value')==1 && get(handles.togglebutton_highpass,'Value')==0 + set(handles.checkbox_removedc, 'Value', 0); + set(handles.checkbox_removedc, 'Enable', 'off'); + set(handles.slider_highpass, 'Value', 0); + set(handles.slider_highpass, 'Enable', 'off') + set(handles.togglebutton_highpass, 'Value', 0) + set(handles.edit_highpass,'String','0') + set(handles.edit_highpass,'Enable','off') + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); - unsetnotchpm(hObject, eventdata, handles) - - if get(handles.togglebutton_lowpass,'Value')==1 && get(handles.togglebutton_highpass,'Value')==0 - set(handles.checkbox_removedc, 'Value', 0); - set(handles.checkbox_removedc, 'Enable', 'off'); - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_highpass, 'Enable', 'off') - set(handles.togglebutton_highpass, 'Value', 0) - set(handles.edit_highpass,'String','0') - set(handles.edit_highpass,'Enable','off') - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); - - elseif get(handles.togglebutton_lowpass,'Value')==0 && get(handles.togglebutton_highpass,'Value')==1 - colorband = [0.9922 0.9176 0.7961]; - set(handles.checkbox_removedc, 'Value', 1); - set(handles.checkbox_removedc, 'Enable', 'on'); - set(handles.slider_highpass, 'Enable', 'on') - set(handles.togglebutton_highpass, 'Value', 1) - %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]); - end - - set(handles.radiobutton_fir,'Value',0) - ordervector = 2:2:8; - set(handles.popupmenu_order,'Enable','on') - set(handles.popupmenu_dboct,'Enable','on') - set(handles.popupmenu_dbdec,'Enable','on') - set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list - set(handles.popupmenu_dboct,'String', num2str(6*ordervector')) % set db/oct list - set(handles.popupmenu_dbdec,'String', num2str(20*ordervector')) % set db/dec list - set(handles.popupmenu_order,'Value',2) - set(handles.popupmenu_dboct,'Value',1) - set(handles.popupmenu_dbdec,'Value',1) - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end + elseif get(handles.togglebutton_lowpass,'Value')==0 && get(handles.togglebutton_highpass,'Value')==1 + colorband = [0.9922 0.9176 0.7961]; + set(handles.checkbox_removedc, 'Value', 1); + set(handles.checkbox_removedc, 'Enable', 'on'); + set(handles.slider_highpass, 'Enable', 'on') + set(handles.togglebutton_highpass, 'Value', 1) + %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]); + end + + set(handles.radiobutton_fir,'Value',0) + ordervector = 2:2:8; + set(handles.popupmenu_order,'Enable','on') + set(handles.popupmenu_dboct,'Enable','on') + set(handles.popupmenu_dbdec,'Enable','on') + set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list + set(handles.popupmenu_dboct,'String', num2str(6*ordervector')) % set db/oct list + set(handles.popupmenu_dbdec,'String', num2str(20*ordervector')) % set db/dec list + set(handles.popupmenu_order,'Value',2) + set(handles.popupmenu_dboct,'Value',1) + set(handles.popupmenu_dbdec,'Value',1) + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); + end else - set(handles.radiobutton_butter,'Value',1) + set(handles.radiobutton_butter,'Value',1) end %-------------------------------------------------------------------------- function radiobutton_fir_Callback(hObject, eventdata, handles) if get(hObject,'Value') - - unsetnotchpm(hObject, eventdata, handles) - - if get(handles.togglebutton_lowpass,'Value')==1 && get(handles.togglebutton_highpass,'Value')==0 - set(handles.checkbox_removedc, 'Value', 0); - set(handles.checkbox_removedc, 'Enable', 'off'); - set(handles.slider_highpass, 'Value', 0); - set(handles.slider_highpass, 'Enable', 'off') - set(handles.togglebutton_highpass, 'Value', 0) - set(handles.edit_highpass,'String','0') - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); - set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); - elseif get(handles.togglebutton_lowpass,'Value')==0 && get(handles.togglebutton_highpass,'Value')==1 - colorband = [0.9922 0.9176 0.7961]; - set(handles.checkbox_removedc, 'Value', 1); - set(handles.checkbox_removedc, 'Enable', 'on'); - set(handles.slider_highpass, 'Enable', 'on') - set(handles.togglebutton_highpass, 'Value', 1) - %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]) - else - %... - end - - highpasscutoff = str2num(get(handles.edit_highpass, 'string')); - %lowpasscutoff = str2num(get(handles.edit_lowpass, 'string')); - - if highpasscutoff>0 && highpasscutoff<0.2 - set(handles.edit_highpass, 'string','0.4') - set(handles.slider_highpass, 'Value', 0.4) - end - - set(handles.radiobutton_butter,'Value',0) - ordervector = 4:4:4096; - set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list - set(handles.popupmenu_dboct,'String', '---') % set db/oct list - set(handles.popupmenu_dbdec,'String', '---') % set db/dec list - set(handles.popupmenu_order,'Value',10) - set(handles.popupmenu_dboct,'Value',1) - set(handles.popupmenu_dbdec,'Value',1) - - handles.ishopermission = 0; - % Update handles structure - guidata(hObject, handles); - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end + + unsetnotchpm(hObject, eventdata, handles) + + if get(handles.togglebutton_lowpass,'Value')==1 && get(handles.togglebutton_highpass,'Value')==0 + set(handles.checkbox_removedc, 'Value', 0); + set(handles.checkbox_removedc, 'Enable', 'off'); + set(handles.slider_highpass, 'Value', 0); + set(handles.slider_highpass, 'Enable', 'off') + set(handles.togglebutton_highpass, 'Value', 0) + set(handles.edit_highpass,'String','0') + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); + elseif get(handles.togglebutton_lowpass,'Value')==0 && get(handles.togglebutton_highpass,'Value')==1 + colorband = [0.9922 0.9176 0.7961]; + set(handles.checkbox_removedc, 'Value', 1); + set(handles.checkbox_removedc, 'Enable', 'on'); + set(handles.slider_highpass, 'Enable', 'on') + set(handles.togglebutton_highpass, 'Value', 1) + %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]) + else + %... + end + + highpasscutoff = str2num(get(handles.edit_highpass, 'string')); + %lowpasscutoff = str2num(get(handles.edit_lowpass, 'string')); + + if highpasscutoff>0 && highpasscutoff<0.2 + set(handles.edit_highpass, 'string','0.4') + set(handles.slider_highpass, 'Value', 0.4) + end + + set(handles.radiobutton_butter,'Value',0) + ordervector = 4:4:4096; + set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list + set(handles.popupmenu_dboct,'String', '---') % set db/oct list + set(handles.popupmenu_dbdec,'String', '---') % set db/dec list + set(handles.popupmenu_order,'Value',10) + set(handles.popupmenu_dboct,'Value',1) + set(handles.popupmenu_dbdec,'Value',1) + + handles.ishopermission = 0; + % Update handles structure + guidata(hObject, handles); + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); + end else - set(handles.radiobutton_fir,'Value',1) + set(handles.radiobutton_fir,'Value',1) end %-------------------------------------------------------------------------- function radiobutton_PM_notch_Callback(hObject, eventdata, handles) if get(hObject,'Value') - valhp = get(handles.edit_highpass,'String'); - vallp = get(handles.edit_lowpass,'String'); - handles.valhp = valhp; - handles.vallp = vallp; - - % Update handles structure - guidata(hObject, handles); - setnotchpm(handles) - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end + valhp = get(handles.edit_highpass,'String'); + vallp = get(handles.edit_lowpass,'String'); + handles.valhp = valhp; + handles.vallp = vallp; + + % Update handles structure + guidata(hObject, handles); + setnotchpm(handles) + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); + end else - set(handles.radiobutton_PM_notch,'Value',1) + set(handles.radiobutton_PM_notch,'Value',1) end %-------------------------------------------------------------------------- @@ -2116,27 +2133,27 @@ function setnotchpm(handles) %------------------------------------------------------------------------ function unsetnotchpm(hObject, eventdata, handles) if strcmp(get(handles.slider_lowpass,'Visible'),'off') - set(handles.togglebutton_highpass, 'Visible', 'on') - set(handles.togglebutton_highpass,'Value',1) - set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.checkbox_removedc, 'Enable', 'on'); - set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); - vals = get(handles.slider_highpass, 'Value'); - set(handles.edit_highpass,'String',sprintf('%.1f',vals)); - set(handles.slider_lowpass, 'Visible', 'on') - set(handles.slider_lowpass, 'Value', 0) - set(handles.slider_lowpass, 'Enable', 'off') - set(handles.togglebutton_lowpass, 'Visible', 'on') - set(handles.togglebutton_lowpass,'Value',0) - set(handles.edit_lowpass,'String','0'); - set(handles.edit_lowpass,'Enable','off'); - %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); - set(handles.text_hzlp,'Visible','on') + set(handles.togglebutton_highpass, 'Visible', 'on') + set(handles.togglebutton_highpass,'Value',1) + set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.checkbox_removedc, 'Enable', 'on'); + set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); + vals = get(handles.slider_highpass, 'Value'); + set(handles.edit_highpass,'String',sprintf('%.1f',vals)); + set(handles.slider_lowpass, 'Visible', 'on') + set(handles.slider_lowpass, 'Value', 0) + set(handles.slider_lowpass, 'Enable', 'off') + set(handles.togglebutton_lowpass, 'Visible', 'on') + set(handles.togglebutton_lowpass,'Value',0) + set(handles.edit_lowpass,'String','0'); + set(handles.edit_lowpass,'Enable','off'); + %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); + set(handles.text_hzlp,'Visible','on') else - set(handles.togglebutton_highpass, 'Visible', 'on') - set(handles.togglebutton_lowpass, 'Visible', 'on') - %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); - set(handles.text_hzlp,'Visible','on') + set(handles.togglebutton_highpass, 'Visible', 'on') + set(handles.togglebutton_lowpass, 'Visible', 'on') + %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); + set(handles.text_hzlp,'Visible','on') end set(handles.edit_lowpass,'Visible','on'); @@ -2154,7 +2171,7 @@ function edit_boundary_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function edit_boundary_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -2166,93 +2183,93 @@ function edit_xmaxplot_Callback(hObject, eventdata, handles) xmaxp = str2num(xmaxpstr); if isempty(xmaxp) + msgboxText{1} = 'Your must enter a positive number greater than 0.1!'; + title = 'ERPLAB: Basic Filter Error'; + errorfound(msgboxText, title); + set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) + + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + elseif get(handles.radiobutton_fdatafr,'Value') + plotresponse_fd_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); + end + return +elseif length(xmaxp)==1 + if xmaxp<0.1 msgboxText{1} = 'Your must enter a positive number greater than 0.1!'; title = 'ERPLAB: Basic Filter Error'; errorfound(msgboxText, title); set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); + plotresponse_uf_data(hObject, eventdata, handles); elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); + plotresponse_fd_data(hObject, eventdata, handles); else - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end return -elseif length(xmaxp)==1 - if xmaxp<0.1 - msgboxText{1} = 'Your must enter a positive number greater than 0.1!'; - title = 'ERPLAB: Basic Filter Error'; - errorfound(msgboxText, title); - set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) - - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end - return - end - xmaxp = [0 xmaxp]; + end + xmaxp = [0 xmaxp]; elseif length(xmaxp)==2 - if xmaxp(1)>=xmaxp(2) - msgboxText{1} = 'Frenquency range must be sorted [minf maxf].'; - title = 'ERPLAB: Basic Filter Error'; - errorfound(msgboxText, title); - set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) - - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end - return - end - if xmaxp(1)<0 || xmaxp(2)<0 - msgboxText{1} = 'Your must enter 1 or 2 positive numbers.'; - title = 'ERPLAB: Basic Filter Error'; - errorfound(msgboxText, title); - set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) - - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end - return + if xmaxp(1)>=xmaxp(2) + msgboxText{1} = 'Frenquency range must be sorted [minf maxf].'; + title = 'ERPLAB: Basic Filter Error'; + errorfound(msgboxText, title); + set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) + + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + elseif get(handles.radiobutton_fdatafr,'Value') + plotresponse_fd_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); end - if abs(xmaxp(2)-xmaxp(1))<0.1 - msgboxText{1} = 'Bandwidth for plotting must be greater than 0.1 Hz.'; - title = 'ERPLAB: Basic Filter Error'; - errorfound(msgboxText, title); - set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) - - if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); - elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); - else - plotresponsefilter(hObject, eventdata, handles); - end - return + return + end + if xmaxp(1)<0 || xmaxp(2)<0 + msgboxText{1} = 'Your must enter 1 or 2 positive numbers.'; + title = 'ERPLAB: Basic Filter Error'; + errorfound(msgboxText, title); + set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) + + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + elseif get(handles.radiobutton_fdatafr,'Value') + plotresponse_fd_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); end -else - msgboxText = 'Wrong frenquency range!'; + return + end + if abs(xmaxp(2)-xmaxp(1))<0.1 + msgboxText{1} = 'Bandwidth for plotting must be greater than 0.1 Hz.'; title = 'ERPLAB: Basic Filter Error'; errorfound(msgboxText, title); set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) + + if get(handles.radiobutton_ufdatafr,'Value') + plotresponse_uf_data(hObject, eventdata, handles); + elseif get(handles.radiobutton_fdatafr,'Value') + plotresponse_fd_data(hObject, eventdata, handles); + else + plotresponsefilter(hObject, eventdata, handles); + end return + end +else + msgboxText = 'Wrong frenquency range!'; + title = 'ERPLAB: Basic Filter Error'; + errorfound(msgboxText, title); + set(handles.edit_xmaxplot, 'String', num2str(handles.xmaxfreqr)) + return end if get(handles.radiobutton_impr,'Value') - handles.xmaxpimpz = xmaxp; + handles.xmaxpimpz = xmaxp; else - handles.xmaxfreqr = xmaxp; + handles.xmaxfreqr = xmaxp; end % Update handles structure @@ -2260,24 +2277,24 @@ function edit_xmaxplot_Callback(hObject, eventdata, handles) if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); + plotresponse_uf_data(hObject, eventdata, handles); elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); + plotresponse_fd_data(hObject, eventdata, handles); else - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end return %-------------------------------------------------------------------------- function edit_xmaxplot_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- function noncausal_Callback(hObject, eventdata, handles) if ~get(hObject,'Value') - set(hObject,'Value',1) + set(hObject,'Value',1) end %-------------------------------------------------------------------------- @@ -2286,11 +2303,11 @@ function causal_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function popupmenu_FRscale_Callback(hObject, eventdata, handles) if get(handles.radiobutton_ufdatafr,'Value') - plotresponse_uf_data(hObject, eventdata, handles); + plotresponse_uf_data(hObject, eventdata, handles); elseif get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles); + plotresponse_fd_data(hObject, eventdata, handles); else - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- @@ -2298,32 +2315,32 @@ function chksliders(hObject, eventdata, handles) sH = get(handles.slider_highpass,'Value'); sL = get(handles.slider_lowpass,'Value'); if sH<0.001 - set(handles.slider_highpass,'Value', 0) - set(handles.edit_highpass,'String', '0') - set(handles.edit2_highpass,'String', '---') - set(handles.slider_highpass,'Enable', 'off') - set(handles.edit_highpass,'Enable', 'off') - set(handles.edit2_highpass,'Enable', 'off') - set(handles.togglebutton_highpass,'Value', 0) - set(handles.checkbox_removedc,'Value', 0) + set(handles.slider_highpass,'Value', 0) + set(handles.edit_highpass,'String', '0') + set(handles.edit2_highpass,'String', '---') + set(handles.slider_highpass,'Enable', 'off') + set(handles.edit_highpass,'Enable', 'off') + set(handles.edit2_highpass,'Enable', 'off') + set(handles.togglebutton_highpass,'Value', 0) + set(handles.checkbox_removedc,'Value', 0) else - set(handles.edit_highpass, 'String', sprintf('%.1f',sH)); - set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit_highpass, 'String', sprintf('%.1f',sH)); + set(handles.edit2_highpass, 'BackgroundColor', [1 1 0.5]); end if sL<0.001 - set(handles.slider_lowpass,'Value', 0) - set(handles.edit_lowpass,'String', '0') - set(handles.edit2_lowpass,'String', '---') - set(handles.slider_lowpass,'Enable', 'off') - set(handles.edit_lowpass,'Enable', 'off') - set(handles.edit2_lowpass,'Enable', 'off') - set(handles.togglebutton_lowpass,'Value', 0) + set(handles.slider_lowpass,'Value', 0) + set(handles.edit_lowpass,'String', '0') + set(handles.edit2_lowpass,'String', '---') + set(handles.slider_lowpass,'Enable', 'off') + set(handles.edit_lowpass,'Enable', 'off') + set(handles.edit2_lowpass,'Enable', 'off') + set(handles.togglebutton_lowpass,'Value', 0) else - set(handles.edit_lowpass, 'String', sprintf('%.1f',sL)); - set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit_lowpass, 'String', sprintf('%.1f',sL)); + set(handles.edit2_lowpass, 'BackgroundColor', [1 1 0.5]); end if sL<0.001 && sH<0.001 - set(handles.popupmenu_order,'Value', 2) + set(handles.popupmenu_order,'Value', 2) end drawnow return @@ -2341,22 +2358,22 @@ function pushbutton_refresh_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function sliderson(hObject, eventdata, handles) if get(handles.togglebutton_highpass,'value') - set(handles.slider_highpass,'Enable','on') + set(handles.slider_highpass,'Enable','on') end if get(handles.togglebutton_lowpass,'value') - set(handles.slider_lowpass,'Enable','on') + set(handles.slider_lowpass,'Enable','on') end drawnow %-------------------------------------------------------------------------- function slidersoff(hObject, eventdata, handles) if get(handles.togglebutton_highpass,'value') - set(handles.slider_highpass,'Enable','off') + set(handles.slider_highpass,'Enable','off') end if get(handles.togglebutton_lowpass,'value') - set(handles.slider_lowpass,'Enable','off') + set(handles.slider_lowpass,'Enable','off') end drawnow @@ -2373,13 +2390,13 @@ function edit_tip_cutoff_CreateFcn(hObject, eventdata, handles) frecp = str2num(get(handles.edit_xmaxplot,'String')); if isempty(frecp) - return + return end ch = str2num(get(handles.edit_channels,'String')); if isempty(ch) - return + return end axes(handles.axes1); @@ -2389,21 +2406,21 @@ function edit_tip_cutoff_CreateFcn(hObject, eventdata, handles) drawnow if isempty(setxor(ch, [handles.datafr.chan])) % are equal? - ym = handles.datafr.ym; - f = handles.datafr.f; + ym = handles.datafr.ym; + f = handles.datafr.f; else - ERPLAB = handles.ERPLAB; - np = round(ERPLAB.srate/2); - - if iserpstruct(ERPLAB) % for erpset - % [ym f] = fourierp(ERPLAB,ch,frecp(1),np,np); - [ym f] = fourierp(ERPLAB,ch,[], 0,np,np); - elseif iseegstruct(ERPLAB) % for erpset - % [ym f] = fourieeg(ERPLAB,ch,frecp(1),np,np); - [ym f] = fourieeg(ERPLAB,ch,[],0,np,np); - else - return - end + ERPLAB = handles.ERPLAB; + np = round(ERPLAB.srate/2); + + if iserpstruct(ERPLAB) % for erpset + % [ym f] = fourierp(ERPLAB,ch,frecp(1),np,np); + [ym f] = fourierp(ERPLAB,ch,[], 0,np,np); + elseif iseegstruct(ERPLAB) % for erpset + % [ym f] = fourieeg(ERPLAB,ch,frecp(1),np,np); + [ym f] = fourieeg(ERPLAB,ch,[],0,np,np); + else + return + end end [frecpxx frecpsam2] = min(abs(f-frecp(2))); @@ -2413,15 +2430,15 @@ function edit_tip_cutoff_CreateFcn(hObject, eventdata, handles) color = [0 0.2 0]; if FRscale==1 - ymax = max(ym)+0.2; - ymin = -0.0625*ymax; %6.25% of ymax - - plot(f(frecpsam1:frecpsam2), ym(frecpsam1:frecpsam2), 'linewidth', 2, 'LineSmoothing','on','Color', color) - ylabel('Data amplitude') + ymax = max(ym)+0.2; + ymin = -0.0625*ymax; %6.25% of ymax - + plot(f(frecpsam1:frecpsam2), ym(frecpsam1:frecpsam2), 'linewidth', 2, 'LineSmoothing','on','Color', color) + ylabel('Data amplitude') else - ymax = 20*log(max(ym))+0.2; - ymin = -65; - plot(f(frecpsam1:frecpsam2), 20*log10(ym(frecpsam1:frecpsam2)), 'linewidth', 2, 'LineSmoothing','on','Color', color) - ylabel('Data amplitude in dB') + ymax = 20*log(max(ym))+0.2; + ymin = -65; + plot(f(frecpsam1:frecpsam2), 20*log10(ym(frecpsam1:frecpsam2)), 'linewidth', 2, 'LineSmoothing','on','Color', color) + ylabel('Data amplitude in dB') end ylim = [ymin ymax]; @@ -2444,17 +2461,17 @@ function plotresponse_fd_data(hObject, eventdata, handles) valuel = get(handles.slider_lowpass, 'Value'); if valueh==0 && valuel==0 - msgtx = '--NO FILTERING--'; - no_filter(hObject, handles, msgtx) - return + msgtx = '--NO FILTERING--'; + no_filter(hObject, handles, msgtx) + return end frecp = str2num(get(handles.edit_xmaxplot,'String')); if isempty(frecp) - return + return end ch = str2num(get(handles.edit_channels,'String')); if isempty(ch) - return + return end axes(handles.axes1); @@ -2469,23 +2486,23 @@ function plotresponse_fd_data(hObject, eventdata, handles) ymax = ylim(2); if FRscale==1 - %ymax = max(yfildata)+0.2; - %ymin = -0.075; - ymaxb = 1; - yminb = 0; - plot(f, yfildata, 'linewidth', 2, 'LineSmoothing','on','Color', color) - ylabel('Data amplitude') + %ymax = max(yfildata)+0.2; + %ymin = -0.075; + ymaxb = 1; + yminb = 0; + plot(f, yfildata, 'linewidth', 2, 'LineSmoothing','on','Color', color) + ylabel('Data amplitude') else - %ymax = 20*log(ymax)+0.2; - %ymin = -65; - ymaxb = 0; - yminb = -90; - plot(f, 20*log10(yfildata), 'linewidth', 2, 'LineSmoothing','on','Color', color) - ylabel('Data amplitude in dB') + %ymax = 20*log(ymax)+0.2; + %ymin = -65; + ymaxb = 0; + yminb = -90; + plot(f, 20*log10(yfildata), 'linewidth', 2, 'LineSmoothing','on','Color', color) + ylabel('Data amplitude in dB') end fnyq = round(handles.fs/2); if get(handles.radiobutton_ideal, 'Value') - drawidealresp(handles, labelf, fnyq, valuel, valueh, yminb, ymaxb) + drawidealresp(handles, labelf, fnyq, valuel, valueh, yminb, ymaxb) end % text(mean(frecp), posaxes1(2)/2, msgtx,'FontSize',14, 'color', 'w') % erase text...temporary... @@ -2502,39 +2519,39 @@ function plotresponse_fd_data(hObject, eventdata, handles) % Minimum number of sample among boundaries % if isempty(EVENTSTRUCT) - minboundarysamdist = inf; - return + minboundarysamdist = inf; + return end if ischar(EVENTSTRUCT(1).type) - ecpos = strmatch('boundary', {EVENTSTRUCT.type}); + ecpos = strmatch('boundary', {EVENTSTRUCT.type}); else - ecpos = find([EVENTSTRUCT.type]==-99); + ecpos = find([EVENTSTRUCT.type]==-99); end if isempty(ecpos) - minboundarysamdist = inf; + minboundarysamdist = inf; else - minboundarysamdist = min(diff([EVENTSTRUCT(ecpos).latency])); + minboundarysamdist = min(diff([EVENTSTRUCT(ecpos).latency])); end %-------------------------------------------------------------------------- function setall(hObject, eventdata, handles, ERPLAB, def) if nargin<5 - def = handles.def; + def = handles.def; end if nargin<4 - ERPLAB = handles.ERPLAB; + ERPLAB = handles.ERPLAB; end if isempty(ERPLAB) - try - ERPLAB = handles.ERPLAB; - catch - ERPLAB = buildERPstruct([]); - end + try + ERPLAB = handles.ERPLAB; + catch + ERPLAB = buildERPstruct([]); + end end fs = ERPLAB.srate; if isempty(fs) - fs=1000; + fs=1000; end % def = {highpasscutoff, lowpasscutoff, order, channelArray, typefilter, remove_dc, boundary}; @@ -2549,64 +2566,69 @@ function setall(hObject, eventdata, handles, ERPLAB, def) remove_dc = def{7}; boundary = def{8}; colorband = [0.9922 0.9176 0.7961]; - +try binArray = def{9}; catch binArray = []; end if iserpstruct(ERPLAB) % for erpset - typedata = 'ERP'; - set(handles.checkbox_removedc, 'Visible', 'on') + typedata = 'ERP'; + set(handles.checkbox_removedc, 'Visible', 'on') + set(handles.checkbox_removedc, 'Value', remove_dc) + set(handles.checkbox_removedc, 'String', 'Remove mean value (DC bias) before filtering (not usually appropriate for baseline-corrected data)') + %set(handles.checkbox_removedc, 'Enable', 'off') + set(handles.checkbox_boundary, 'Visible', 'off') + set(handles.edit_boundary,'Visible', 'off'); + set(handles.text_boundary,'Visible', 'off'); + minboundarysamdist = inf; + %nchan = ERPLAB.nchan; +else + if isempty(ERPLAB.epoch) % for continuous dataset + set(handles.checkbox_boundary, 'Enable', 'on') + + if isempty(boundary) + set(handles.checkbox_boundary, 'Value', 0) + set(handles.edit_boundary, 'string', 'boundary'); % default + set(handles.edit_boundary,'Enable', 'off'); + %set(handles.edit_boundary,'BackgroundColor', [0.75 0.75 0.75]); + else + set(handles.checkbox_boundary, 'Value', 1) + set(handles.edit_boundary,'Enable', 'on'); + %set(handles.edit_boundary,'BackgroundColor', [1 1 1]); + set(handles.edit_boundary, 'string', boundary); + end + + label1 = 'Apply filter to segments defined'; + label2 = 'by boundary events (Strongly Recommended)'; + set(handles.checkbox_boundary, 'string',[label1 '
' label2]); set(handles.checkbox_removedc, 'Value', remove_dc) + typedata = 'continuous EEG'; + minboundarysamdist = boundarydistance(ERPLAB.event); + else % for epoched dataset + set(handles.checkbox_boundary, 'Value', 0) + set(handles.checkbox_boundary, 'Enable', 'off') + set(handles.edit_boundary, 'string', ''); + set(handles.edit_boundary,'Enable', 'off'); + %set(handles.edit_boundary,'BackgroundColor', [0.75 0.75 0.75]); + label1 = 'Apply filter to segments defined'; + label2 = 'by boundary events (Strongly Recommended)'; + set(handles.checkbox_boundary, 'string',[label1 '
' label2]); + set(handles.text_boundary,'Enable', 'off'); set(handles.checkbox_removedc, 'String', 'Remove mean value (DC bias) before filtering (not usually appropriate for baseline-corrected data)') + set(handles.checkbox_removedc, 'Value', remove_dc) %set(handles.checkbox_removedc, 'Enable', 'off') - set(handles.checkbox_boundary, 'Visible', 'off') - set(handles.edit_boundary,'Visible', 'off'); - set(handles.text_boundary,'Visible', 'off'); + typedata = 'epoched EEG'; minboundarysamdist = inf; - %nchan = ERPLAB.nchan; -else - if isempty(ERPLAB.epoch) % for continuous dataset - set(handles.checkbox_boundary, 'Enable', 'on') - - if isempty(boundary) - set(handles.checkbox_boundary, 'Value', 0) - set(handles.edit_boundary, 'string', 'boundary'); % default - set(handles.edit_boundary,'Enable', 'off'); - %set(handles.edit_boundary,'BackgroundColor', [0.75 0.75 0.75]); - else - set(handles.checkbox_boundary, 'Value', 1) - set(handles.edit_boundary,'Enable', 'on'); - %set(handles.edit_boundary,'BackgroundColor', [1 1 1]); - set(handles.edit_boundary, 'string', boundary); - end - - label1 = 'Apply filter to segments defined'; - label2 = 'by boundary events (Strongly Recommended)'; - set(handles.checkbox_boundary, 'string',[label1 '
' label2]); - set(handles.checkbox_removedc, 'Value', remove_dc) - typedata = 'continuous EEG'; - minboundarysamdist = boundarydistance(ERPLAB.event); - else % for epoched dataset - set(handles.checkbox_boundary, 'Value', 0) - set(handles.checkbox_boundary, 'Enable', 'off') - set(handles.edit_boundary, 'string', ''); - set(handles.edit_boundary,'Enable', 'off'); - %set(handles.edit_boundary,'BackgroundColor', [0.75 0.75 0.75]); - label1 = 'Apply filter to segments defined'; - label2 = 'by boundary events (Strongly Recommended)'; - set(handles.checkbox_boundary, 'string',[label1 '
' label2]); - set(handles.text_boundary,'Enable', 'off'); - set(handles.checkbox_removedc, 'String', 'Remove mean value (DC bias) before filtering (not usually appropriate for baseline-corrected data)') - set(handles.checkbox_removedc, 'Value', remove_dc) - %set(handles.checkbox_removedc, 'Enable', 'off') - typedata = 'epoched EEG'; - minboundarysamdist = inf; - end - %nchan = ERPLAB.nbchan; + end + %nchan = ERPLAB.nbchan; end % % Name & version % version = geterplabversion; -set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Basic Filter GUI for ' typedata]) +ERPtooltype = erpgettoolversion('tooltype'); +if strcmpi(ERPtooltype,'estudio') + set(handles.gui_chassis,'Name', ['Estudio ' version ' - Basic Filter GUI for ' typedata]); +else + set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Basic Filter GUI for ' typedata]); +end highpasscutoff = locutoff; lowpasscutoff = hicutoff; maxsliders = handles.maxsliders; @@ -2620,28 +2642,28 @@ function setall(hObject, eventdata, handles, ERPLAB, def) slider_step(2) = 0.5/maxsliders; switch typefilter - case 'butter' - set(handles.radiobutton_butter, 'Value', 1); % 0 means Butterworth - ordervector = 2:2:8; - [tf, ordenp] = ismember_bc2(filterorder, ordervector); - set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list - set(handles.popupmenu_order,'Value', ordenp+1); - set(handles.popupmenu_dboct,'String', num2str(6*ordervector')) % set db/oct list - set(handles.popupmenu_dbdec,'String', num2str(20*ordervector')) % set db/dec list - set(handles.popupmenu_dboct,'Value', ordenp) % set db/oct list - set(handles.popupmenu_dbdec,'Value', ordenp) % set db/dec list - case 'fir' - set(handles.radiobutton_fir, 'Value', 1); % 1 means FIR - ordervector = 4:4:4096; - [tf, ordenp] = ismember_bc2(filterorder, ordervector); - set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list - set(handles.popupmenu_order,'Value', ordenp+1); - set(handles.popupmenu_dboct,'String', '---') % set db/oct list - set(handles.popupmenu_dbdec,'String', '---') % set db/dec list - case 'notch' - set(handles.radiobutton_PM_notch, 'Value', 1); - setnotchpm(handles) - handles.freqdef = highpasscutoff; + case 'butter' + set(handles.radiobutton_butter, 'Value', 1); % 0 means Butterworth + ordervector = 2:2:8; + [tf, ordenp] = ismember_bc2(filterorder, ordervector); + set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list + set(handles.popupmenu_order,'Value', ordenp+1); + set(handles.popupmenu_dboct,'String', num2str(6*ordervector')) % set db/oct list + set(handles.popupmenu_dbdec,'String', num2str(20*ordervector')) % set db/dec list + set(handles.popupmenu_dboct,'Value', ordenp) % set db/oct list + set(handles.popupmenu_dbdec,'Value', ordenp) % set db/dec list + case 'fir' + set(handles.radiobutton_fir, 'Value', 1); % 1 means FIR + ordervector = 4:4:4096; + [tf, ordenp] = ismember_bc2(filterorder, ordervector); + set(handles.popupmenu_order,'String', char([{'automin'}; cellstr(num2str(ordervector'))])) % set order list + set(handles.popupmenu_order,'Value', ordenp+1); + set(handles.popupmenu_dboct,'String', '---') % set db/oct list + set(handles.popupmenu_dbdec,'String', '---') % set db/dec list + case 'notch' + set(handles.radiobutton_PM_notch, 'Value', 1); + setnotchpm(handles) + handles.freqdef = highpasscutoff; end set(handles.slider_highpass, 'Value', highpasscutoff, 'Max', maxsliders, 'Min', 0, 'SliderStep', slider_step) @@ -2653,30 +2675,31 @@ function setall(hObject, eventdata, handles, ERPLAB, def) set(handles.radiobutton_ufdatafr,'Value', 0); set(handles.radiobutton_fdatafr,'Value', 0); set(handles.radiobutton_ideal, 'Enable','on') -nchan = handles.nchan; -if filterallch - set(handles.checkbox_filterallchannels, 'Value', 1) - set(handles.edit_channels, 'String', vect2colon([1:nchan], 'Delimiter', 'off')); - set(handles.edit_channels, 'Enable', 'off'); - set(handles.pushbutton_browsechan, 'Enable', 'off'); +nchan = handles.nchan;%%et for chans +len1 = length(chanArray); +chanArray = chanArray(chanArray<=nchan); +len2 = length(chanArray); +if len1~=len2 + fprintf('Index of channels to be filtered was adjusted since current %s has only %g channels.\n', typedata, nchan); +end +chanArraystr = vect2colon(chanArray, 'Delimiter','off', 'Repeat', 'off'); +set(handles.edit_channels, 'String', chanArraystr) + +if handles.nbin~=0 && iserpstruct(ERPLAB) + handles.edit_bin.Enable = 'on'; + handles.pushbutton_bin_browse.Enable = 'on'; + if isempty(binArray) || any(binArray(:)>ERPLAB.nbin) || any(binArray(:)<1) + binArray=1:ERPLAB.nbin; + end + binArraystr = vect2colon(binArray, 'Delimiter','off', 'Repeat', 'off'); + handles.edit_bin.String = binArraystr; else - len1 = length(chanArray); - chanArray = chanArray(chanArray<=nchan); - len2 = length(chanArray); - if len1~=len2 - fprintf('Index of channels to be filtered was adjusted since current %s has only %g channels.\n', typedata, nchan); - end - if len2==nchan - set(handles.checkbox_filterallchannels, 'Value', 1) - set(handles.edit_channels, 'String', vect2colon([1:nchan], 'Delimiter', 'off')); - set(handles.edit_channels, 'Enable', 'off'); - set(handles.pushbutton_browsechan, 'Enable', 'off'); - else - chanArraystr = vect2colon(chanArray, 'Delimiter','off', 'Repeat', 'off'); - set(handles.edit_channels, 'String', chanArraystr) - end + handles.edit_bin.String = ''; + handles.edit_bin.Enable = 'off'; + handles.pushbutton_bin_browse.Enable = 'off'; end + % % Causality (pending) % @@ -2686,44 +2709,44 @@ function setall(hObject, eventdata, handles, ERPLAB, def) tooltip1 = 'Cutoff frequency = frequency where the magnitude
response of the filter is either 0.5 (-6dB) or 0.707 (-3dB)'; tooltip2 = ['The filter does not attenuate all frequencies outside the desired frequency range completely;
'... - 'in particular, there is a region just outside the intended passband where frequencies are attenuated,
'... - 'but not rejected. This is known as the filter roll-off, and it is usually expressed in dB of attenuation
'... - 'per octave or decade of frequency. In general, the roll-off for an order-n filter is 6n dB per octave or
'... - '20n dB per decade.']; + 'in particular, there is a region just outside the intended passband where frequencies are attenuated,
'... + 'but not rejected. This is known as the filter roll-off, and it is usually expressed in dB of attenuation
'... + 'per octave or decade of frequency. In general, the roll-off for an order-n filter is 6n dB per octave or
'... + '20n dB per decade.']; set(handles.edit_tip_cutoff, 'tooltip',tooltip1); set(handles.edit_tip_rolloff, 'tooltip',tooltip2); if highpasscutoff== 0 - set(handles.togglebutton_highpass, 'Value',0); - set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); - set(handles.slider_highpass, 'Enable', 'off'); - set(handles.edit_highpass, 'String', '0'); - - set(handles.edit_highpass, 'Enable', 'off'); - %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_highpass, 'Value',0); + set(handles.togglebutton_highpass, 'BackgroundColor', [0.8 0.8 0.75]); + set(handles.slider_highpass, 'Enable', 'off'); + set(handles.edit_highpass, 'String', '0'); + + set(handles.edit_highpass, 'Enable', 'off'); + %set(handles.edit_highpass, 'BackgroundColor', [0.75 0.75 0.75]); else - set(handles.togglebutton_highpass, 'Value',1); - set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit_highpass, 'Enable', 'on'); - - set(handles.edit_highpass, 'String', sprintf('%.1f',highpasscutoff)); - %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]); + set(handles.togglebutton_highpass, 'Value',1); + set(handles.togglebutton_highpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit_highpass, 'Enable', 'on'); + + set(handles.edit_highpass, 'String', sprintf('%.1f',highpasscutoff)); + %set(handles.edit_highpass, 'BackgroundColor', [1 1 1]); end if lowpasscutoff== 0 - set(handles.togglebutton_lowpass, 'Value',0); - set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); - set(handles.slider_lowpass, 'Enable', 'off'); - set(handles.edit_lowpass, 'String', '0'); - set(handles.edit_lowpass, 'Enable', 'off'); - %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); + set(handles.togglebutton_lowpass, 'Value',0); + set(handles.togglebutton_lowpass, 'BackgroundColor', [0.8 0.8 0.75]); + set(handles.slider_lowpass, 'Enable', 'off'); + set(handles.edit_lowpass, 'String', '0'); + set(handles.edit_lowpass, 'Enable', 'off'); + %set(handles.edit_lowpass, 'BackgroundColor', [0.75 0.75 0.75]); else - set(handles.togglebutton_lowpass, 'Value',1); - set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); - set(handles.edit_lowpass, 'Enable', 'on'); - - set(handles.edit_lowpass, 'String', sprintf('%.1f',lowpasscutoff)); - %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); + set(handles.togglebutton_lowpass, 'Value',1); + set(handles.togglebutton_lowpass, 'BackgroundColor', [1 1 0.5]); + set(handles.edit_lowpass, 'Enable', 'on'); + + set(handles.edit_lowpass, 'String', sprintf('%.1f',lowpasscutoff)); + %set(handles.edit_lowpass, 'BackgroundColor', [1 1 1]); end set(handles.radiobutton_gaussian,'Enable','off') @@ -2746,17 +2769,17 @@ function radiobutton_ideal_Callback(hObject, eventdata, handles) % Plot corresponding response % if get(handles.radiobutton_fdatafr,'Value') - plotresponse_fd_data(hObject, eventdata, handles) + plotresponse_fd_data(hObject, eventdata, handles) elseif get(handles.radiobutton_freqr,'Value') || get(handles.radiobutton_impr,'Value') - plotresponsefilter(hObject, eventdata, handles); + plotresponsefilter(hObject, eventdata, handles); end %-------------------------------------------------------------------------- function pushbutton_import_settings_Callback(hObject, eventdata, handles) [filename, pathname] = uigetfile({'*.bfil','Basic Filter seetings (*.bfil)'}, 'Load settings'); if isequal(filename,0) - disp('User selected Cancel') - return + disp('User selected Cancel') + return end L = load(fullfile(pathname, filename), '-mat'); readobjects = L.outstr; @@ -2781,17 +2804,17 @@ function pushbutton_save_settings_Callback(hObject, eventdata, handles) % global readobjects [readobjects v] = read_GUI(hObject, eventdata, handles); if v~=1 % means something was going wrong - msgboxText = 'Setting is not ready to be saved. Please check it out.'; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText), title); - return + msgboxText = 'Setting is not ready to be saved. Please check it out.'; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText), title); + return end channelArray = readobjects{1}; -filterallch = readobjects{2}; +filterallch = readobjects{2}; if filterallch - nchan = handles.nchan; - channelArray = 1:nchan; + nchan = handles.nchan; + channelArray = 1:nchan; end highpasscutoff = readobjects{3}; lowpasscutoff = readobjects{4}; @@ -2802,25 +2825,25 @@ function pushbutton_save_settings_Callback(hObject, eventdata, handles) boundarystr = readobjects{9}; if boundarycheck==1 - if strcmpi(boundarystr,'boundary')||strcmpi(boundarystr,'''boundary''') - boundary = 'boundary'; + if strcmpi(boundarystr,'boundary')||strcmpi(boundarystr,'''boundary''') + boundary = 'boundary'; + else + if ~strcmp(boundarystr,'') + boundary = str2num(boundarystr); + if isempty(boundary); + boundary = boundarystr; + end else - if ~strcmp(boundarystr,'') - boundary = str2num(boundarystr); - if isempty(boundary); - boundary = boundarystr; - end - else - %boundary = []; - msgboxText = ['You have set the checkbox for filtering between boundary events.\n'... - 'So, you must define a boundary event code.']; - title = 'ERPLAB: basicfilterGUI() error:'; - errorfound(sprintf(msgboxText), title); - return - end + %boundary = []; + msgboxText = ['You have set the checkbox for filtering between boundary events.\n'... + 'So, you must define a boundary event code.']; + title = 'ERPLAB: basicfilterGUI() error:'; + errorfound(sprintf(msgboxText), title); + return end + end else - boundary = []; + boundary = []; end % @@ -2829,30 +2852,30 @@ function pushbutton_save_settings_Callback(hObject, eventdata, handles) [filename, filepath, filterindex] = uiputfile({'*.bfil','Basic Filter settings (*.bfil)'},'Save filter settings as'); if isequal(filename,0) - disp('User selected Cancel') - return + disp('User selected Cancel') + return else - outstr = {highpasscutoff, lowpasscutoff, order, channelArray, filterallch, typefilter, remove_dc, boundary}; - - [px, fname, ext] = fileparts(filename); - if strcmp(ext,'') - if filterindex==1 - ext = '.bfil'; - end + outstr = {highpasscutoff, lowpasscutoff, order, channelArray, filterallch, typefilter, remove_dc, boundary}; + + [px, fname, ext] = fileparts(filename); + if strcmp(ext,'') + if filterindex==1 + ext = '.bfil'; end - - fname = [ fname ext]; - fullname = fullfile(filepath, fname); - save(fullname, 'outstr'); - - % fid_list = fopen( fullname , 'w'); - % - % for i=1:size(fulltext,1) - % fprintf(fid_list,'%s\n', fulltext(i,:)); - % end - % - % fclose(fid_list); - % set(handles.button_savelist, 'Enable','on') + end + + fname = [ fname ext]; + fullname = fullfile(filepath, fname); + save(fullname, 'outstr'); + + % fid_list = fopen( fullname , 'w'); + % + % for i=1:size(fulltext,1) + % fprintf(fid_list,'%s\n', fulltext(i,:)); + % end + % + % fclose(fid_list); + % set(handles.button_savelist, 'Enable','on') end %-------------------------------------------------------------------------- @@ -2871,11 +2894,11 @@ function togglebutton_highpass_CreateFcn(hObject, eventdata, handles) function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') - % The GUI is still in UIWAIT, us UIRESUME - uiresume(handles.gui_chassis); + % The GUI is still in UIWAIT, us UIRESUME + uiresume(handles.gui_chassis); else - % The GUI is no longer waiting, just close it - delete(handles.gui_chassis); + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); end @@ -2887,33 +2910,77 @@ function pushbutton_browsechan_Callback(hObject, eventdata, handles) titlename = 'Select Channel(s)'; if get(hObject, 'Value') - if ~isempty(listch) - ch = browsechanbinGUI(listch, indxlistch, titlename); - if ~isempty(ch) - set(handles.edit_channels, 'String', vect2colon(ch, 'Delimiter', 'off')); - handles.indxlistch = ch; - % Update handles structure - guidata(hObject, handles); - else - disp('User selected Cancel') - return - end + if ~isempty(listch) + ch = browsechanbinGUI(listch, indxlistch, titlename); + if ~isempty(ch) + set(handles.edit_channels, 'String', vect2colon(ch, 'Delimiter', 'off')); + handles.indxlistch = ch; + % Update handles structure + guidata(hObject, handles); else - msgboxText = 'No channel information was found'; - title = 'ERPLAB: basicfilter GUI input'; - errorfound(msgboxText, title); - return + disp('User selected Cancel') + return end + else + msgboxText = 'No channel information was found'; + title = 'ERPLAB: basicfilter GUI input'; + errorfound(msgboxText, title); + return + end end -function checkbox_filterallchannels_Callback(hObject, eventdata, handles) -if get(hObject, 'Value') - nchan = handles.nchan; - set(handles.edit_channels, 'String', vect2colon([1:nchan], 'Delimiter', 'off')); - set(handles.edit_channels, 'Enable', 'off'); - set(handles.pushbutton_browsechan, 'Enable', 'off'); -else - set(handles.edit_channels, 'Enable', 'on'); - set(handles.pushbutton_browsechan, 'Enable', 'on'); +% function checkbox_filterallchannels_Callback(hObject, eventdata, handles) +% if get(hObject, 'Value') +% nchan = handles.nchan; +% set(handles.edit_channels, 'String', vect2colon([1:nchan], 'Delimiter', 'off')); +% set(handles.edit_channels, 'Enable', 'off'); +% set(handles.pushbutton_browsechan, 'Enable', 'off'); +% else +% set(handles.edit_channels, 'Enable', 'on'); +% set(handles.pushbutton_browsechan, 'Enable', 'on'); +% end + + + +function edit_bin_Callback(hObject, eventdata, handles) + + +nbin = handles.nbin; +chx = str2num(handles.edit_bin.String); +if isempty(chx) || any(chx(:)>nbin) || any(chx(:)<1) + chx = 1:nbin; +end +handles.edit_bin.String = vect2colon(chx, 'Delimiter','off', 'Repeat', 'off'); + + + + + + + +% --- Executes during object creation, after setting all properties. +function edit_bin_CreateFcn(hObject, eventdata, handles) + +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in pushbutton_bin_browse. +function pushbutton_bin_browse_Callback(hObject, eventdata, handles) +listbin = handles.listbin; +indxlistbin = handles.indxlistbin; +indxlistbin = indxlistbin(indxlistbin<=length(listbin)); +titlename = 'Select Bin(s)'; + +if ~isempty(listbin) + bins = browsechanbinGUI(listbin, indxlistbin, titlename); + if ~isempty(bins) + set(handles.edit_bin, 'String', vect2colon(bins, 'Delimiter', 'off')); + handles.indxlistbin = bins; + guidata(hObject, handles); + else + return + end end diff --git a/GUIs/binoperGUI.m b/GUIs/binoperGUI.m index 56b3c7b7..8e45dbc4 100755 --- a/GUIs/binoperGUI.m +++ b/GUIs/binoperGUI.m @@ -175,17 +175,16 @@ function binoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) else Toolabel = 1; end - +handles.Toolabel=Toolabel; +version = geterplabversion; if Toolabel - erplab_studio_default_values; - version = erplabstudiover; set(handles.gui_chassis,'Name', ['EStudio',version,' - Bin Operation > Advanced GUI for ']) handles = painterplabstudio(handles); handles = setfonterplabestudio(handles); handles.RUN.String = 'OK'; else - version = geterplabversion; + set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Bin Operation GUI ']) % handles = painterplab(handles); @@ -203,7 +202,11 @@ function binoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Gui memory % -binopGUI = erpworkingmemory('binopGUI'); +if Toolabel==0 + binopGUI = erpworkingmemory('binopGUI'); +else + binopGUI = estudioworkingmemory('binopGUI'); +end if isempty(binopGUI) set(handles.button_recursive,'Value', 1); % default is Modify existing ERPset (recursive updating) @@ -378,7 +381,11 @@ function RUN_Callback(hObject, eventdata, handles) binopGUI.emode = editormode; binopGUI.hmode = get(handles.checkbox_sendfile2history,'Value'); binopGUI.listname = listname; -erpworkingmemory('binopGUI', binopGUI); +if handles.Toolabel==0 + erpworkingmemory('binopGUI', binopGUI); +else + estudioworkingmemory('binopGUI', binopGUI); +end % Update handles structure guidata(hObject, handles); diff --git a/GUIs/blcerpGUI.fig b/GUIs/blcerpGUI.fig index 0daf0601..8380915b 100755 Binary files a/GUIs/blcerpGUI.fig and b/GUIs/blcerpGUI.fig differ diff --git a/GUIs/blcerpGUI.m b/GUIs/blcerpGUI.m index 425b9393..2d6c7786 100755 --- a/GUIs/blcerpGUI.m +++ b/GUIs/blcerpGUI.m @@ -8,7 +8,7 @@ %b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b % % ERPLAB Toolbox -% Copyright © 2007 The Regents of the University of California +% Copyright © 2007 The Regents of the University of California % Created by Javier Lopez-Calderon and Steven Luck % Center for Mind and Brain, University of California, Davis, % javlopez@ucdavis.edu, sjluck@ucdavis.edu @@ -31,19 +31,19 @@ % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @blcerpGUI_OpeningFcn, ... - 'gui_OutputFcn', @blcerpGUI_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @blcerpGUI_OpeningFcn, ... + 'gui_OutputFcn', @blcerpGUI_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) - gui_State.gui_Callback = str2func(varargin{1}); + gui_State.gui_Callback = str2func(varargin{1}); end if nargout - [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else - gui_mainfcn(gui_State, varargin{:}); + gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT @@ -54,57 +54,58 @@ function blcerpGUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = []; try - ERP = varargin{1}; - xmin = 1000*ERP.xmin; - xmax = 1000*ERP.xmax; + ERP = varargin{1}; + xmin = 1000*ERP.xmin; + xmax = 1000*ERP.xmax; catch - ERP = []; - xmin = -200; - xmax = 800; + ERP = []; + xmin = -200; + xmax = 800; end +handles.ERP = ERP; try - Titlegui = varargin{2}; + Titlegui = varargin{2}; catch - Titlegui = 'Testing this GUI...'; + Titlegui = 'Testing this GUI...'; end try - interval = varargin{3}; + interval = varargin{3}; catch - interval = 'pre'; + interval = 'pre'; end set(handles.uipanel_blc,'Title', Titlegui) if strcmpi(interval,'pre') - intvl = [xmin 0]; - set(handles.edit_custom,'Enable','off') - set(handles.radiobutton_pre,'Value', 1) + intvl = [xmin 0]; + set(handles.edit_custom,'Enable','off') + set(handles.radiobutton_pre,'Value', 1) elseif strcmpi(interval,'post') - intvl = [0 xmax]; - set(handles.edit_custom,'Enable','off') - set(handles.radiobutton_post,'Value', 1) + intvl = [0 xmax]; + set(handles.edit_custom,'Enable','off') + set(handles.radiobutton_post,'Value', 1) elseif strcmpi(interval,'all') - intvl = [xmin xmax]; - set(handles.edit_custom,'Enable','off') - set(handles.radiobutton_all,'Value', 1) + intvl = [xmin xmax]; + set(handles.edit_custom,'Enable','off') + set(handles.radiobutton_all,'Value', 1) else - if ischar(interval) - intvl = str2num(interval); % interv in ms - else - intvl = interval; - end - if length(intvl)~=2 - intvl = []; - else - set(handles.edit_custom,'Enable','on') - set(handles.radiobutton_custom,'Value', 1) - end + if ischar(interval) + intvl = str2num(interval); % interv in ms + else + intvl = interval; + end + if length(intvl)~=2 + intvl = []; + else + set(handles.edit_custom,'Enable','on') + set(handles.radiobutton_custom,'Value', 1) + end end if ~isempty(intvl) - blcstr = sprintf('%.1f %.1f',intvl); - set(handles.edit_custom,'String',blcstr); + blcstr = sprintf('%.1f %.1f',intvl); + set(handles.edit_custom,'String',blcstr); else - set(handles.edit_custom,'Enable','off') - set(handles.radiobutton_none,'Value', 1) + set(handles.edit_custom,'Enable','off') + set(handles.radiobutton_none,'Value', 1) end handles.xmin = xmin; @@ -121,6 +122,36 @@ function blcerpGUI_OpeningFcn(hObject, eventdata, handles, varargin) % handles = setfonterplab(handles); +handles.bin_browse.BackgroundColor = [1 1 1]; +handles.chans_browse.BackgroundColor = [1 1 1]; + +if ~isempty(ERP) && ~iserpstruct(ERP) + handles.bin_browse.Enable = 'off'; + handles.edit_bins.Enable = 'off'; +elseif ~isempty(ERP) && iserpstruct(ERP) + handles.bin_browse.Enable = 'on'; + handles.edit_bins.Enable = 'on'; + BinArray = 1:ERP.nbin; + BinArray = vect2colon(BinArray,'Sort', 'on'); + BinArray = erase(BinArray,{'[',']'}); + handles.edit_bins.String = BinArray; +end + +if ~isempty(ERP) + try + chanArray = 1:ERP.nbchan; + catch + chanArray = 1:ERP.nchan; + end + chanArray = vect2colon(chanArray,'Sort', 'on'); + chanArray = erase(chanArray,{'[',']'}); + handles.edit_chans.String = chanArray; +end + + + + + % Update handles structure guidata(hObject, handles); @@ -154,7 +185,7 @@ function edit_custom_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function edit_custom_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end % ------------------------------------------------------------------------- @@ -170,7 +201,7 @@ function pushbutton_help_Callback(hObject, eventdata, handles) % doc pop_blcerp % fctn = dbstack; % fctn = fctn(end).name; -% doc(fctn) +% doc(fctn) web https://github.com/lucklab/erplab/wiki/ERP-Bin-Operations -browser % ------------------------------------------------------------------------- @@ -181,105 +212,125 @@ function pushbutton_run_Callback(hObject, eventdata, handles) epoch = [xmin xmax]; if isempty(epoch) - msgboxText = 'Wrong epoch range!'; - title = 'ERPLAB: Bin-based epoch inputs'; - errorfound(msgboxText, title); - return -else - repoch = size(epoch,1); % rows for epoch - cepoch = size(epoch,2); % columns for epoch - blc = handles.blc; - cusbutt = get(handles.radiobutton_custom,'Value'); + msgboxText = 'Wrong epoch range!'; + title = 'ERPLAB: Bin-based epoch inputs'; + errorfound(msgboxText, title); + return +else + repoch = size(epoch,1); % rows for epoch + cepoch = size(epoch,2); % columns for epoch + blc = handles.blc; + cusbutt = get(handles.radiobutton_custom,'Value'); + + % + % Checks updated custom blc values + % + if cusbutt + blctest = get(handles.edit_custom,'String'); + if isempty(blctest) + msgboxText = 'You must enter 2 values first.'; + title = 'ERPLAB: Time range inputs'; + errorfound(sprintf(msgboxText), title); + return + end + blctest = str2num(blctest); + if isempty(blctest) + if strcmpi(get(handles.edit_custom,'String'),'none') + custupdated = 1; + blc = 'none'; + elseif strcmpi(get(handles.edit_custom,'String'),'pre') + custupdated = 1; + blc = 'pre'; + elseif strcmpi(get(handles.edit_custom,'String'),'post') + custupdated = 1; + blc = 'post'; + elseif strcmpi(get(handles.edit_custom,'String'),'all')|| strcmpi(get(handles.edit_custom,'String'),'whole') + custupdated = 1; + blc = 'all'; + else + custupdated = 0; + end + else + rblc = size(blctest,1); + cblc = size(blctest,2); + extvalcond = max(epoch)>=max(blctest) && min(epoch)<=min(blctest); + custupdated = rblc==1 && cblc==2 && extvalcond; + blc = blctest; + end + else + custupdated = 1; + end + + if repoch==1 && cepoch==2 && custupdated + if isnumeric(blc) && blc(1)>=blc(2) + msgboxText = ['For time range, lower limit must be on the left.\n'... + 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; + title = 'ERPLAB: Time range inputs'; + errorfound(sprintf(msgboxText), title); + return + end + if epoch(1)>0 || epoch(2)<0 + msgboxText = 'Epoch range must span across time zero.'; + title = 'ERPLAB: Time range inputs'; + errorfound(msgboxText, title); + return + end + if epoch(1)>=0 && ~isnumeric(blc) && strcmpi(blc,'pre') + msgboxText = 'There is no pre-stimulus interval.'; + title = 'ERPLAB: Time range inputs'; + errorfound(msgboxText, title); + return + end + if epoch(2)<=0 && ~isnumeric(blc) && strcmpi(blc,'post') + msgboxText = 'There is no post-stimulus interval.'; + title = 'ERPLAB: Time range inputs'; + errorfound(msgboxText, title); + return + end + ERP = handles.ERP; + try + chanArraydef = 1:ERP.nbchan; + nchan = ERP.nbchan; + catch + chanArraydef = 1:ERP.nchan; + nchan = ERP.nchan; + end + chanArray = str2num(handles.edit_chans.String); + if isempty(chanArray) || any(chanArray(:)>nchan) || any(chanArray(:)<1) + chanArray = chanArraydef; + end - % - % Checks updated custom blc values - % - if cusbutt - blctest = get(handles.edit_custom,'String'); - if isempty(blctest) - msgboxText = 'You must enter 2 values first.'; - title = 'ERPLAB: Time range inputs'; - errorfound(sprintf(msgboxText), title); - return - end - blctest = str2num(blctest); - if isempty(blctest) - if strcmpi(get(handles.edit_custom,'String'),'none') - custupdated = 1; - blc = 'none'; - elseif strcmpi(get(handles.edit_custom,'String'),'pre') - custupdated = 1; - blc = 'pre'; - elseif strcmpi(get(handles.edit_custom,'String'),'post') - custupdated = 1; - blc = 'post'; - elseif strcmpi(get(handles.edit_custom,'String'),'all')|| strcmpi(get(handles.edit_custom,'String'),'whole') - custupdated = 1; - blc = 'all'; - else - custupdated = 0; - end - else - rblc = size(blctest,1); - cblc = size(blctest,2); - extvalcond = max(epoch)>=max(blctest) && min(epoch)<=min(blctest); - custupdated = rblc==1 && cblc==2 && extvalcond; - blc = blctest; - end + if iserpstruct(ERP) + binArray = str2num( handles.edit_bins.String); + if isempty(binArray) || any(binArray(:)>ERP.nbin) || any(binArray(:)<1) + binArray = 1:ERP.nbin; + end else - custupdated = 1; + binArray = []; end + handles.output = {blc,chanArray,binArray}; - if repoch==1 && cepoch==2 && custupdated - if isnumeric(blc) && blc(1)>=blc(2) - msgboxText = ['For time range, lower limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; - title = 'ERPLAB: Time range inputs'; - errorfound(sprintf(msgboxText), title); - return - end - if epoch(1)>0 || epoch(2)<0 - msgboxText = 'Epoch range must span across time zero.'; - title = 'ERPLAB: Time range inputs'; - errorfound(msgboxText, title); - return - end - if epoch(1)>=0 && ~isnumeric(blc) && strcmpi(blc,'pre') - msgboxText = 'There is no pre-stimulus interval.'; - title = 'ERPLAB: Time range inputs'; - errorfound(msgboxText, title); - return - end - if epoch(2)<=0 && ~isnumeric(blc) && strcmpi(blc,'post') - msgboxText = 'There is no post-stimulus interval.'; - title = 'ERPLAB: Time range inputs'; - errorfound(msgboxText, title); - return - end - - handles.output = {blc}; - - % Update handles structure - guidata(hObject, handles); - uiresume(handles.gui_chassis); + % Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); + else + if custupdated + msgboxText = 'Wrong time range! Please, enter 2 values.'; + title = 'ERPLAB: Time range inputs'; + errorfound(msgboxText, title); else - if custupdated - msgboxText = 'Wrong time range! Please, enter 2 values.'; - title = 'ERPLAB: Time range inputs'; - errorfound(msgboxText, title); - else - msgboxText = 'Wrong baseline range! Please, enter 2 values.'; - title = 'ERPLAB: Time range inputs'; - errorfound(msgboxText, title); - end - return + msgboxText = 'Wrong baseline range! Please, enter 2 values.'; + title = 'ERPLAB: Time range inputs'; + errorfound(msgboxText, title); end + return + end end % ------------------------------------------------------------------------- function radiobutton_none_Callback(hObject, eventdata, handles) if ~get(hObject,'Value') - set(hObject,'Value',1) + set(hObject,'Value',1) end set(handles.edit_custom,'Enable','off') set(handles.edit_custom,'String','') @@ -293,9 +344,9 @@ function radiobutton_none_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function radiobutton_pre_Callback(hObject, eventdata, handles) if ~get(hObject,'Value') - set(hObject,'Value',1) + set(hObject,'Value',1) end - + set(handles.edit_custom,'Enable','off') set(handles.edit_custom,'String','') blc = 'pre'; @@ -310,7 +361,7 @@ function radiobutton_pre_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function radiobutton_post_Callback(hObject, eventdata, handles) if ~get(hObject,'Value') - set(hObject,'Value',1) + set(hObject,'Value',1) end set(handles.edit_custom,'Enable','off') set(handles.edit_custom,'String','') @@ -326,7 +377,7 @@ function radiobutton_post_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function radiobutton_all_Callback(hObject, eventdata, handles) if ~get(hObject,'Value') - set(hObject,'Value',1) + set(hObject,'Value',1) end set(handles.edit_custom,'Enable','off') set(handles.edit_custom,'String','') @@ -344,7 +395,7 @@ function radiobutton_all_Callback(hObject, eventdata, handles) function radiobutton_custom_Callback(hObject, eventdata, handles) if ~get(hObject,'Value') - set(hObject,'Value',1) + set(hObject,'Value',1) end set(handles.edit_custom,'Enable','on') @@ -359,31 +410,167 @@ function radiobutton_custom_Callback(hObject, eventdata, handles) % ------------------------------------------------------------------------- function checkbox_blc_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.radiobutton_none,'Enable','on') - set(handles.radiobutton_pre,'Enable','on') - set(handles.radiobutton_post,'Enable','on') - set(handles.radiobutton_all,'Enable','on') - set(handles.radiobutton_custom,'Enable','on') - set(handles.edit_custom,'Enable','on') + set(handles.radiobutton_none,'Enable','on') + set(handles.radiobutton_pre,'Enable','on') + set(handles.radiobutton_post,'Enable','on') + set(handles.radiobutton_all,'Enable','on') + set(handles.radiobutton_custom,'Enable','on') + set(handles.edit_custom,'Enable','on') else - set(handles.radiobutton_none,'Enable','off') - set(handles.radiobutton_pre,'Enable','off') - set(handles.radiobutton_post,'Enable','off') - set(handles.radiobutton_all,'Enable','off') - set(handles.radiobutton_custom,'Enable','off') - set(handles.edit_custom,'Enable','off') + set(handles.radiobutton_none,'Enable','off') + set(handles.radiobutton_pre,'Enable','off') + set(handles.radiobutton_post,'Enable','off') + set(handles.radiobutton_all,'Enable','off') + set(handles.radiobutton_custom,'Enable','off') + set(handles.edit_custom,'Enable','off') end %-------------------------------------------------------------------------- function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') - %The GUI is still in UIWAIT, us UIRESUME - handles.output = []; - %Update handles structure - guidata(hObject, handles); - uiresume(handles.gui_chassis); + %The GUI is still in UIWAIT, us UIRESUME + handles.output = []; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + + +function edit_chans_Callback(hObject, eventdata, handles) +chanArray = str2num(handles.edit_chans.String); +ERP = handles.ERP; +if ~isempty(ERP) + if iserpstruct(ERP) + bchan = ERP.nchan; + else + bchan = ERP.nbchan; + end + if isempty(chanArray) || any(chanArray(:)>bchan) || any(chanArray(:)<1) + msgboxText = ['Channel index(es) should be between 1 and',32,num2str(bchan)]; + title = 'ERPLAB: channel inputs'; + errorfound(sprintf(msgboxText), title); + end + chanArray = 1:bchan; + chanArray = vect2colon(chanArray,'Sort', 'on'); + chanArray = erase(chanArray,{'[',']'}); + handles.edit_chans.String = chanArray; +end + + + + + + +% --- Executes during object creation, after setting all properties. +function edit_chans_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_chans (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 + + +% --- Executes on button press in chans_browse. +function chans_browse_Callback(hObject, eventdata, handles) +ERP = handles.ERP; +chanArray = str2num(handles.edit_chans.String); +if ~isempty(ERP) + if iserpstruct(ERP) + bchan = ERP.nchan; + else + bchan = ERP.nbchan; + end + if isempty(chanArray) || any(chanArray(:)>bchan) || any(chanArray(:)<1) + chanArray = 1:bchan; + end + + for Numofchan = 1:bchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',ERP.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat(num2str(Numofchan),'.','chan',num2str(Numofchan)); + end + end + titlename = 'Select Channel(s):'; + chan_label_select = browsechanbinGUI(listb, chanArray, titlename); + if ~isempty(chan_label_select) + chanset = vect2colon(chan_label_select,'Sort', 'on'); + chanset = erase(chanset,{'[',']'}); + handles.edit_chans.String=chanset; + end +end + + + + +function edit_bins_Callback(hObject, eventdata, handles) +binArray = str2num(handles.edit_bins.String); + +ERP = handles.ERP; +if ~isempty(ERP) && iserpstruct(ERP) + if isempty(binArray) || any(binArray(:)>ERP.nbin) || any(binArray(:)<1) + msgboxText = ['Bin index(es) should be between 1 and',32,num2str(ERP.nbin)]; + title = 'ERPLAB: bin inputs'; + errorfound(sprintf(msgboxText), title); + end + handles.bin_browse.Enable = 'on'; + handles.edit_bins.Enable = 'on'; + BinArray = 1:ERP.nbin; + BinArray = vect2colon(BinArray,'Sort', 'on'); + BinArray = erase(BinArray,{'[',']'}); + handles.edit_bins.String = BinArray; +else + handles.bin_browse.Enable = 'off'; + handles.edit_bins.Enable = 'off'; + handles.edit_bins.String = ''; +end + + +% --- Executes during object creation, after setting all properties. +function edit_bins_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_bins (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 + + +% --- Executes on button press in bin_browse. +function bin_browse_Callback(hObject, eventdata, handles) + +ERP = handles.ERP; +if ~isempty(ERP) && iserpstruct(ERP) + BinArray = str2num(handles.edit_bins.String); + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = 1:ERP.nbin; + end + + for Numofbin = 1:length(ERP.bindescr) + listb{Numofbin} = char(strcat(num2str(Numofbin),'.',ERP.bindescr{Numofbin})); + end + titlename = 'Select Bin(s):'; + %----------------judge the number of latency/latencies-------- + bin_label_select = browsechanbinGUI(listb, BinArray, titlename); + if ~isempty(bin_label_select) + binset = vect2colon(bin_label_select,'Sort', 'on'); + binset = erase(binset,{'[',']'}); + handles.edit_bins.String=binset; + end else - % The GUI is no longer waiting, just close it - delete(handles.gui_chassis); + handles.bin_browse.Enable = 'off'; + handles.edit_bins.Enable = 'off'; + handles.edit_bins.String = ''; end diff --git a/GUIs/browsechanbinGUI.fig b/GUIs/browsechanbinGUI.fig index e951a90c..c12a8284 100755 Binary files a/GUIs/browsechanbinGUI.fig and b/GUIs/browsechanbinGUI.fig differ diff --git a/GUIs/chanoperGUI.fig b/GUIs/chanoperGUI.fig index 274c65c8..9f99916c 100755 Binary files a/GUIs/chanoperGUI.fig and b/GUIs/chanoperGUI.fig differ diff --git a/GUIs/chanoperGUI.m b/GUIs/chanoperGUI.m index 3617c69c..4750dac8 100755 --- a/GUIs/chanoperGUI.m +++ b/GUIs/chanoperGUI.m @@ -3,19 +3,19 @@ function varargout = chanoperGUI(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @chanoperGUI_OpeningFcn, ... - 'gui_OutputFcn', @chanoperGUI_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @chanoperGUI_OpeningFcn, ... + 'gui_OutputFcn', @chanoperGUI_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) - gui_State.gui_Callback = str2func(varargin{1}); + gui_State.gui_Callback = str2func(varargin{1}); end if nargout - [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else - gui_mainfcn(gui_State, varargin{:}); + gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT @@ -33,36 +33,36 @@ function chanoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) example{8} = 'ch@ = abs(ch110) label E110 rectified '; try - ERPLAB = varargin{1}; - - if iserpstruct(ERPLAB) - nchan = ERPLAB.nchan; % Total number of channels - typedata = 'ERP'; - datastr = 'ERPset'; - formtype = 'erpchanformulas'; - example{5} = 'ch@ = mgfperp(ERP) label MGFPower'; - else - example{3} = 'ch@ = chinterpol'; - nchan = ERPLAB.nbchan; % Total number of channels - typedata = 'EEG'; - datastr = 'dataset'; - formtype = 'eegchanformulas'; - end + ERPLAB = varargin{1}; + + if iserpstruct(ERPLAB) + nchan = ERPLAB.nchan; % Total number of channels + typedata = 'ERP'; + datastr = 'ERPset'; + formtype = 'erpchanformulas'; + example{5} = 'ch@ = mgfperp(ERP) label MGFPower'; + else + example{3} = 'ch@ = chinterpol'; + nchan = ERPLAB.nbchan; % Total number of channels + typedata = 'EEG'; + datastr = 'dataset'; + formtype = 'eegchanformulas'; + end catch - ERPLAB.chanlocs = []; - listch = ''; - nchan = 1; - formtype = []; - typedata = 'unspecific data'; - datastr = 'who-knows-what'; + ERPLAB.chanlocs = []; + listch = ''; + nchan = 1; + formtype = []; + typedata = 'unspecific data'; + datastr = 'who-knows-what'; end try - def = varargin{2}; - formulas = def{1}; - wchmsgon = def{2}; + def = varargin{2}; + formulas = def{1}; + wchmsgon = def{2}; catch - formulas = []; - wchmsgon = 1; + formulas = []; + wchmsgon = 1; end handles.nchan = nchan; @@ -78,24 +78,22 @@ function chanoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) ERPtooltype = erpgettoolversion('tooltype'); if ~isempty(ERPtooltype) if strcmpi(ERPtooltype,'EStudio') - Toolabel = 1;%%Get label from work space to confirm whether EStudio was executed. + Toolabel = 1;%%Get label from work space to confirm whether EStudio was executed. else Toolabel = 0; end else - Toolabel = 1; + Toolabel = 0; end - +handles.Toolabel = Toolabel; +version = geterplabversion; if Toolabel - erplab_studio_default_values; - version = erplabstudiover; set(handles.gui_chassis,'Name', ['EStudio',version,' - Channel Operation > Advanced GUI for ',typedata]) handles = painterplabstudio(handles); handles = setfonterplabestudio(handles); handles.pushbutton_RUN.String = 'OK'; else - version = geterplabversion; -set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Channel Operation GUI for ' typedata]) + set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Channel Operation GUI for ' typedata]) % handles = painterplab(handles); handles = setfonterplab(handles); @@ -107,9 +105,9 @@ function chanoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) % formulas = erpworkingmemory(formtype); if isempty(formulas) - set(handles.editor,'String',''); + set(handles.editor,'String',''); else - set(handles.editor, 'String', formulas) + set(handles.editor, 'String', formulas) end % For undo & redo @@ -123,13 +121,13 @@ function chanoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) % listch=[]; if isempty(ERPLAB.chanlocs) - for e=1:nchan - ERPLAB.chanlocs(e).labels = ['Ch' num2str(e)]; - end + for e=1:nchan + ERPLAB.chanlocs(e).labels = ['Ch' num2str(e)]; + end end listch = cell(1,nchan); for ch =1:nchan - listch{ch} = [num2str(ch) ' = ' ERPLAB.chanlocs(ch).labels ]; + listch{ch} = [num2str(ch) ' = ' ERPLAB.chanlocs(ch).labels ]; end set(handles.listboxchan1,'String', listch) @@ -147,50 +145,54 @@ function chanoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Gui memory % -chanopGUI = erpworkingmemory('chanopGUI'); +if Toolabel==0 + chanopGUI = erpworkingmemory('chanopGUI'); +else + chanopGUI = estudioworkingmemory('chanopGUI'); +end if isempty(chanopGUI) - set(handles.button_recursive,'Value', 1); % default is Modify existing ERPset (recursive updating) - set(handles.button_savelist, 'Enable','off') - set(handles.chkeeplocs,'Value', 1) %default is Preserve Channel locations - - % - % File List - % - set(handles.edit_filelist,'String',''); - set(handles.checkbox_sendfile2history,'Value',0) - handles.listname = []; + set(handles.button_recursive,'Value', 1); % default is Modify existing ERPset (recursive updating) + set(handles.button_savelist, 'Enable','off') + set(handles.chkeeplocs,'Value', 1) %default is Preserve Channel locations + + % + % File List + % + set(handles.edit_filelist,'String',''); + set(handles.checkbox_sendfile2history,'Value',0) + handles.listname = []; else - if chanopGUI.emode==0 - set(handles.button_recursive,'Value', 1); - set(handles.button_no_recu,'Value', 0); - else - set(handles.button_recursive,'Value', 0); - set(handles.button_no_recu,'Value', 1); - end - if chanopGUI.hmode==0 - set(handles.checkbox_sendfile2history,'Value', 0); - else - set(handles.checkbox_sendfile2history,'Value', 1); - end - if chanopGUI.keeplocs ==1 - set(handles.chkeeplocs,'Value',1); - else - set(handles.chkeeplocs,'Value',0); - end - listname = chanopGUI.listname; - set(handles.edit_filelist,'String', listname ); - handles.listname = listname; % JLC Sept 1, 2012 + if chanopGUI.emode==0 + set(handles.button_recursive,'Value', 1); + set(handles.button_no_recu,'Value', 0); + else + set(handles.button_recursive,'Value', 0); + set(handles.button_no_recu,'Value', 1); + end + if chanopGUI.hmode==0 + set(handles.checkbox_sendfile2history,'Value', 0); + else + set(handles.checkbox_sendfile2history,'Value', 1); + end + if chanopGUI.keeplocs ==1 + set(handles.chkeeplocs,'Value',1); + else + set(handles.chkeeplocs,'Value',0); + end + listname = chanopGUI.listname; + set(handles.edit_filelist,'String', listname ); + handles.listname = listname; % JLC Sept 1, 2012 end % wchmsgon = erpworkingmemory('wchmsgon'); if isempty(wchmsgon) || wchmsgon==0 - set(handles.chwarning,'Value', 0) + set(handles.chwarning,'Value', 0) elseif wchmsgon==1 - set(handles.chwarning,'Value', 1) + set(handles.chwarning,'Value', 1) else - error('Oops...checkbox_warning memory failed') + error('Oops...checkbox_warning memory failed') end handles.locs = ERPLAB.chanlocs; @@ -245,7 +247,7 @@ function editor_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function editor_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -263,65 +265,65 @@ function pushbutton_RUN_Callback(hObject, eventdata, handles) if strcmp(formulalist,'') - msgboxText = 'You have not written any formula!'; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(msgboxText, title); - return + msgboxText = 'You have not written any formula!'; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(msgboxText, title); + return end if size(formulalist,2)>256 - msgboxText = ['Formulas length exceed 256 characters.\n\n'... - 'Be sure to press [Enter] after you have entered each formula.']; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(sprintf(msgboxText), title); - return + msgboxText = ['Formulas length exceed 256 characters.\n\n'... + 'Be sure to press [Enter] after you have entered each formula.']; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(sprintf(msgboxText), title); + return end % % Check formulas % if get(handles.button_recursive,'Value') - editormode = 0; + editormode = 0; else - editormode = 1; + editormode = 1; end typedata = lower(handles.typedata); [option, recall, goeson] = checkformulas(cellstr(formulalist), [typedata 'chanoperGUI'], editormode); if goeson==0 - return + return end if isempty(listname) && get(handles.checkbox_sendfile2history,'Value')==1 - BackERPLABcolor = [1 0.9 0.3]; % yellow - question = ['Equations at editor window have not been saved yet.\n\n'... - 'What would you like to do?']; - title = 'WARNING: Save List of edited chans'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question), title,'Save and run','Run without saving', 'Cancel','Run without saving'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - if strcmpi(button,'Save and run') - fullname = savelist(hObject, eventdata, handles); - listname = fullname; - handles.output = {listname, wchmsgon}; % sent filenam string) - elseif strcmpi(button,'Run without saving') - handles.output = {cellstr(formulalist), wchmsgon}; % sent like a cell string (with formulas) - elseif strcmpi(button,'Cancel') || strcmpi(button,'') - handles.output = []; - handles.listname = []; - % Update handles structure - guidata(hObject, handles); - return - end -elseif isempty(listname) && get(handles.checkbox_sendfile2history,'Value')==0 + BackERPLABcolor = [1 0.9 0.3]; % yellow + question = ['Equations at editor window have not been saved yet.\n\n'... + 'What would you like to do?']; + title = 'WARNING: Save List of edited chans'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Save and run','Run without saving', 'Cancel','Run without saving'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + + if strcmpi(button,'Save and run') + fullname = savelist(hObject, eventdata, handles); + listname = fullname; + handles.output = {listname, wchmsgon}; % sent filenam string) + elseif strcmpi(button,'Run without saving') handles.output = {cellstr(formulalist), wchmsgon}; % sent like a cell string (with formulas) - + elseif strcmpi(button,'Cancel') || strcmpi(button,'') + handles.output = []; + handles.listname = []; + % Update handles structure + guidata(hObject, handles); + return + end +elseif isempty(listname) && get(handles.checkbox_sendfile2history,'Value')==0 + handles.output = {cellstr(formulalist), wchmsgon}; % sent like a cell string (with formulas) + elseif ~isempty(listname) && get(handles.checkbox_sendfile2history,'Value')==1 - handles.output = {listname, wchmsgon}; % sent filename string - + handles.output = {listname, wchmsgon}; % sent filename string + elseif ~isempty(listname) && get(handles.checkbox_sendfile2history,'Value')==0 - handles.output = {cellstr(formulalist), wchmsgon}; % sent like a cell string (with formulas) + handles.output = {cellstr(formulalist), wchmsgon}; % sent like a cell string (with formulas) end % handles.output @@ -337,12 +339,16 @@ function pushbutton_RUN_Callback(hObject, eventdata, handles) chanopGUI.keeplocs = keeplocs; chanopGUI.chanlocs = handles.locs; disp(chanopGUI.chanlocs) -erpworkingmemory('chanopGUI', chanopGUI); +if handles.Toolabel==0 + erpworkingmemory('chanopGUI', chanopGUI); +else + estudioworkingmemory('chanopGUI', chanopGUI); +end try handles.output{3} = keeplocs; catch - disp('Problem setting location preference') + disp('Problem setting location preference') end @@ -370,7 +376,7 @@ function eraser_Callback(hObject, eventdata, handles) % handles.undocount = undocount; formulas = get(handles.editor, 'String'); if isempty(formulas) - return + return end % handles = editorbackup(hObject, eventdata, handles); @@ -395,29 +401,29 @@ function button_saveaslist_Callback(hObject, eventdata, handles) fulltext = strtrim(get(handles.editor,'String')); if size(fulltext,2)>256 - msgboxText = ['Formulas length exceed 256 characters.\n\n'... - 'Be sure to press [Enter] after you have entered each formula.']; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(sprintf(msgboxText), title); - return + msgboxText = ['Formulas length exceed 256 characters.\n\n'... + 'Be sure to press [Enter] after you have entered each formula.']; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(sprintf(msgboxText), title); + return end if ~strcmp(fulltext,'') - fullname = savelist(hObject, eventdata, handles); - if isempty(fullname) - return - end - set(handles.edit_filelist, 'String', fullname ) - set(handles.button_savelist, 'Enable', 'on') - handles.listname = fullname; - % Update handles structure - guidata(hObject, handles); -else - set(handles.button_saveaslist,'Enable','off') - msgboxText = 'You have not written any formula yet!'; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(msgboxText, title); - set(handles.button_saveaslist,'Enable','on') + fullname = savelist(hObject, eventdata, handles); + if isempty(fullname) return + end + set(handles.edit_filelist, 'String', fullname ) + set(handles.button_savelist, 'Enable', 'on') + handles.listname = fullname; + % Update handles structure + guidata(hObject, handles); +else + set(handles.button_saveaslist,'Enable','off') + msgboxText = 'You have not written any formula yet!'; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(msgboxText, title); + set(handles.button_saveaslist,'Enable','on') + return end %-------------------------------------------------------------------------- @@ -425,34 +431,34 @@ function button_loadlist_Callback(hObject, eventdata, handles) [filename, filepath] = uigetfile({'*.txt';'*.*'},'Select a formulas-file'); if isequal(filename,0) - disp('User selected Cancel') - return + disp('User selected Cancel') + return else - fullname = fullfile(filepath, filename); - disp(['pop_chanoperation(): For formulas-file, user selected ', fullname]) + fullname = fullfile(filepath, filename); + disp(['pop_chanoperation(): For formulas-file, user selected ', fullname]) end set(handles.edit_filelist,'String',fullname); fid_formula = fopen( fullname ); try - formcell = textscan(fid_formula, '%s','delimiter', '\r'); - formulas = char(formcell{:}); + formcell = textscan(fid_formula, '%s','delimiter', '\r'); + formulas = char(formcell{:}); catch - serr = lasterror; - msgboxText = ['Please, check your file: \n'; - fullname '\n'... - serr.message]; - title = 'ERPLAB: pop_chanoperation() error:'; - errorfound(sprintf(msgboxText), title); - return + serr = lasterror; + msgboxText = ['Please, check your file: \n'; + fullname '\n'... + serr.message]; + title = 'ERPLAB: pop_chanoperation() error:'; + errorfound(sprintf(msgboxText), title); + return end if size(formulas,2)>256 - msgboxText = ['Formulas length exceed 256 characters.\n\n'... - 'Be sure to press [Enter] after you have entered each formula.']; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(sprintf(msgboxText), title); - return + msgboxText = ['Formulas length exceed 256 characters.\n\n'... + 'Be sure to press [Enter] after you have entered each formula.']; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(sprintf(msgboxText), title); + return end compacteditor(hObject, eventdata, handles); @@ -469,13 +475,13 @@ function listboxchan1_Callback(hObject, eventdata, handles) numchan = get(hObject, 'Value'); if isempty(numchan) - return + return end linet = get(handles.editor, 'Value'); if nnz(linet) == 0 - linet = 1; + linet = 1; end formulas = cellstr(get(handles.editor, 'String')); @@ -486,7 +492,7 @@ function listboxchan1_Callback(hObject, eventdata, handles) function listboxchan1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -508,19 +514,19 @@ function button_example_Callback(hObject, eventdata, handles) text = cellstr(get(handles.editor, 'String')); if get(handles.button_no_recu,'Value') - prechar = 'n'; + prechar = 'n'; else - prechar = ''; + prechar = ''; end if isempty([text{:}]) || exacounter>length(example) - exacounter = 1; + exacounter = 1; end if length(text)==1 && strcmp(text{1}, '') - exacurr = char(regexprep(example{exacounter},'@',num2str(nchan+exacounter))); - text{1} = [prechar exacurr]; + exacurr = char(regexprep(example{exacounter},'@',num2str(nchan+exacounter))); + text{1} = [prechar exacurr]; else - exacurr = char(regexprep(example{exacounter},'@',num2str(nchan+exacounter))); - text{end+1} = [prechar exacurr]; + exacurr = char(regexprep(example{exacounter},'@',num2str(nchan+exacounter))); + text{end+1} = [prechar exacurr]; end set(handles.editor, 'String', char(text)); @@ -534,7 +540,7 @@ function button_example_Callback(hObject, eventdata, handles) fulltext = char(get(handles.editor,'String')); if isempty(fulltext) - return + return end fullnamepre = get(handles.edit_filelist,'String'); @@ -545,31 +551,31 @@ function button_example_Callback(hObject, eventdata, handles) [filename, filepath, filterindex] = uiputfile({'*.txt';'*.dat';'*.*'},'Save formulas-file as', fullnamepre); if isequal(filename,0) - disp('User selected Cancel') - fullname = []; - return + disp('User selected Cancel') + fullname = []; + return else - [px, fname, ext] = fileparts(filename); - - if strcmp(ext,'') - if filterindex==1 || filterindex==3 - ext = '.txt'; - else - ext = '.dat'; - end - end - - fname = [ fname ext]; - fullname = fullfile(filepath, fname); - - fid_list = fopen( fullname , 'w'); - - for i=1:size(fulltext,1) - fprintf(fid_list,'%s\n', fulltext(i,:)); + [px, fname, ext] = fileparts(filename); + + if strcmp(ext,'') + if filterindex==1 || filterindex==3 + ext = '.txt'; + else + ext = '.dat'; end - - fclose(fid_list); - set(handles.button_savelist, 'Enable','on') + end + + fname = [ fname ext]; + fullname = fullfile(filepath, fname); + + fid_list = fopen( fullname , 'w'); + + for i=1:size(fulltext,1) + fprintf(fid_list,'%s\n', fulltext(i,:)); + end + + fclose(fid_list); + set(handles.button_savelist, 'Enable','on') end %-------------------------------------------------------------------------- @@ -577,7 +583,7 @@ function compacteditor(hObject, eventdata, handles) texteditor = strtrim(get(handles.editor,'String')); if isempty(texteditor) - return + return end formul = cellstr(texteditor); @@ -587,11 +593,11 @@ function compacteditor(hObject, eventdata, handles) % removes blank lines for i=1:nfl - if ~strcmp(formul{i},'') - % removes blank lines - formulalist{k} = regexprep(formul{i},'[^\s](label)[^\s]',' $1 ', 'ignorecase'); - k = k+1; - end + if ~strcmp(formul{i},'') + % removes blank lines + formulalist{k} = regexprep(formul{i},'[^\s](label)[^\s]',' $1 ', 'ignorecase'); + k = k+1; + end end formulalist = strtrimx(formulalist); % special white space removing @@ -602,7 +608,7 @@ function compacteditor(hObject, eventdata, handles) function check_aoperations(hObject, eventdata, handles) texteditor = strtrim(get(handles.editor,'String')); if isempty(texteditor) - return + return end formul = cellstr(texteditor); @@ -611,10 +617,10 @@ function check_aoperations(hObject, eventdata, handles) formulalist = cell(1); for i=1:nfl - if ~strcmp(formul{i},'') - formulalist{k} = formul{i}; - k = k+1; - end + if ~strcmp(formul{i},'') + formulalist{k} = formul{i}; + k = k+1; + end end formulalist = strtrimx(formulalist); @@ -626,39 +632,39 @@ function button_savelist_Callback(hObject, eventdata, handles) fulltext = strtrim(get(handles.editor,'String')); if size(fulltext,2)>256 - msgboxText = ['Formulas length exceed 256 characters.\n\n'... - 'Be sure to press [Enter] after you have entered each formula.']; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(sprintf(msgboxText), title); - return + msgboxText = ['Formulas length exceed 256 characters.\n\n'... + 'Be sure to press [Enter] after you have entered each formula.']; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(sprintf(msgboxText), title); + return end if ~isempty(fulltext) + + fullname = get(handles.edit_filelist, 'String'); + + if ~strcmp(fullname,'') + fid_list = fopen( fullname , 'w'); - fullname = get(handles.edit_filelist, 'String'); - - if ~strcmp(fullname,'') - fid_list = fopen( fullname , 'w'); - - for i=1:size(fulltext,1) - fprintf(fid_list,'%s\n', fulltext(i,:)); - end - - fclose(fid_list); - handles.listname = fullname; - % Update handles structure - guidata(hObject, handles); - disp(['Saving equation list at ' fullname '']) - else - button_saveaslist_Callback(hObject, eventdata, handles) - return + for i=1:size(fulltext,1) + fprintf(fid_list,'%s\n', fulltext(i,:)); end -else - set(handles.button_saveaslist,'Enable','off') - msgboxText = 'You have not written any formula yet!'; - title = 'ERPLAB: chanoperGUI few inputs'; - errorfound(msgboxText, title); - set(handles.button_saveaslist,'Enable','on') + + fclose(fid_list); + handles.listname = fullname; + % Update handles structure + guidata(hObject, handles); + disp(['Saving equation list at ' fullname '']) + else + button_saveaslist_Callback(hObject, eventdata, handles) return + end +else + set(handles.button_saveaslist,'Enable','off') + msgboxText = 'You have not written any formula yet!'; + title = 'ERPLAB: chanoperGUI few inputs'; + errorfound(msgboxText, title); + set(handles.button_saveaslist,'Enable','on') + return end %-------------------------------------------------------------------------- @@ -671,7 +677,7 @@ function edit_filelist_Callback(hObject, eventdata, handles) function edit_filelist_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -682,35 +688,35 @@ function button_clearfile_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function button_recursive_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.button_no_recu,'Value',0) - val = testsyntaxtype(hObject, eventdata, handles, 'recu'); - - if val==0; - set(handles.button_recursive, 'Value', 0) - set(handles.button_no_recu, 'Value', 1) - end - - %%% handles = editorbackup(hObject, eventdata, handles); - %%% Update handles structure - %%guidata(hObject, handles); + set(handles.button_no_recu,'Value',0) + val = testsyntaxtype(hObject, eventdata, handles, 'recu'); + + if val==0; + set(handles.button_recursive, 'Value', 0) + set(handles.button_no_recu, 'Value', 1) + end + + %%% handles = editorbackup(hObject, eventdata, handles); + %%% Update handles structure + %%guidata(hObject, handles); else - set(hObject,'Value',1) + set(hObject,'Value',1) end %-------------------------------------------------------------------------- function button_no_recu_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.button_recursive,'Value',0) - val = testsyntaxtype(hObject, eventdata, handles, 'norecu'); - if val==0 - set(handles.button_recursive, 'Value', 1) - set(handles.button_no_recu, 'Value', 0) - end - %%% handles = editorbackup(hObject, eventdata, handles); - %%% Update handles structure - %%%guidata(hObject, handles); + set(handles.button_recursive,'Value',0) + val = testsyntaxtype(hObject, eventdata, handles, 'norecu'); + if val==0 + set(handles.button_recursive, 'Value', 1) + set(handles.button_no_recu, 'Value', 0) + end + %%% handles = editorbackup(hObject, eventdata, handles); + %%% Update handles structure + %%%guidata(hObject, handles); else - set(hObject,'Value',1) + set(hObject,'Value',1) end %-------------------------------------------------------------------------- @@ -719,9 +725,9 @@ function button_no_recu_Callback(hObject, eventdata, handles) formulaArray = get(handles.editor,'String'); if isempty(formulaArray) - return + return else - formulaArray = strtrim(cellstr(formulaArray)); + formulaArray = strtrim(cellstr(formulaArray)); end nformulas = length(formulaArray); @@ -730,81 +736,81 @@ function button_no_recu_Callback(hObject, eventdata, handles) wantfix = 0; newnumchan = 1; -for t=1:nformulas - fcomm = formulaArray{t}; - tokcommentb = regexpi(fcomm, '^#', 'match'); % comment symbol (June 3, 2013) +for t=1:nformulas + fcomm = formulaArray{t}; + tokcommentb = regexpi(fcomm, '^#', 'match'); % comment symbol (June 3, 2013) + + if isempty(tokcommentb) % skip comment symbol + pleft = regexpi(parts{t}{1}, '(\s*nch[an]*\d+)', 'tokens'); + plcom = regexpi(parts{t}{1}, '(\s*ch[an]*\d+)', 'tokens'); - if isempty(tokcommentb) % skip comment symbol - pleft = regexpi(parts{t}{1}, '(\s*nch[an]*\d+)', 'tokens'); - plcom = regexpi(parts{t}{1}, '(\s*ch[an]*\d+)', 'tokens'); + if isempty(pleft) && ~isempty(plcom) && strcmpi(whocall,'norecu') + if ask4fix + BackERPLABcolor = [1 0.9 0.3]; % yellow + question = ['For non recursive mode, left side of equation\nmust be define as a new channel.\n'... + 'For instance, nchan1 = ...\n\n'... + 'Do you want that ERPLAB corrects the syntax for you?']; + title = 'WARNING: Syntax is not proper for non recursive mode'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Cancel','No', 'Yes','Yes'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) - if isempty(pleft) && ~isempty(plcom) && strcmpi(whocall,'norecu') - if ask4fix - BackERPLABcolor = [1 0.9 0.3]; % yellow - question = ['For non recursive mode, left side of equation\nmust be define as a new channel.\n'... - 'For instance, nchan1 = ...\n\n'... - 'Do you want that ERPLAB corrects the syntax for you?']; - title = 'WARNING: Syntax is not proper for non recursive mode'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question), title,'Cancel','No', 'Yes','Yes'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - if strcmpi(button,'Yes') - ask4fix = 0; - wantfix = 1; - elseif strcmpi(button,'Cancel') - val = 0; % cancel - break - else - ask4fix = 0; - wantfix = 0; - end - %else - % wantfix =1; - end - elseif ~isempty(pleft) && strcmpi(whocall,'recu') - if ask4fix - BackERPLABcolor = [1 0.9 0.3]; % yellow - question = ['For recursive mode, left side of equation cannot\nbe define as a new channel.\n'... - 'For instance, you must write chan1 = ...\n\n'... - 'Do you want that ERPLAB corrects the syntax for you?']; - title = 'WARNING: Syntax is not proper for recursive mode'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question), title,'Cancel','No', 'Yes','Yes'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - if strcmpi(button,'Yes') - ask4fix = 0; - wantfix =1; - elseif strcmpi(button,'Cancel') - val = 0; % cancel - break - else - ask4fix = 0; - wantfix = 0; - end - %else - % wantfix =1; - end - %else - % wantfix = 0; + if strcmpi(button,'Yes') + ask4fix = 0; + wantfix = 1; + elseif strcmpi(button,'Cancel') + val = 0; % cancel + break + else + ask4fix = 0; + wantfix = 0; end - if wantfix && (~isempty(pleft) || ~isempty(plcom))% fixed (June 3, 2013): JLC - fprintf('WARNING: equation %s ', formulaArray{t}) - if strcmpi(whocall,'recu') % for recursive mode delete the n in nch - formulaArray{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '^n*','','ignorecase')), strtrim(parts{t}{2})); - else - formulaArray{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '^n*ch(\D*)(\d*)',['nch$1' num2str(newnumchan)],'ignorecase')), strtrim(parts{t}{2})); - newnumchan = newnumchan+1; - end - fprintf('was changed to equation %s \n', formulaArray{t}) + %else + % wantfix =1; + end + elseif ~isempty(pleft) && strcmpi(whocall,'recu') + if ask4fix + BackERPLABcolor = [1 0.9 0.3]; % yellow + question = ['For recursive mode, left side of equation cannot\nbe define as a new channel.\n'... + 'For instance, you must write chan1 = ...\n\n'... + 'Do you want that ERPLAB corrects the syntax for you?']; + title = 'WARNING: Syntax is not proper for recursive mode'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Cancel','No', 'Yes','Yes'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + + if strcmpi(button,'Yes') + ask4fix = 0; + wantfix =1; + elseif strcmpi(button,'Cancel') + val = 0; % cancel + break + else + ask4fix = 0; + wantfix = 0; end + %else + % wantfix =1; + end + %else + % wantfix = 0; end + if wantfix && (~isempty(pleft) || ~isempty(plcom))% fixed (June 3, 2013): JLC + fprintf('WARNING: equation %s ', formulaArray{t}) + if strcmpi(whocall,'recu') % for recursive mode delete the n in nch + formulaArray{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '^n*','','ignorecase')), strtrim(parts{t}{2})); + else + formulaArray{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '^n*ch(\D*)(\d*)',['nch$1' num2str(newnumchan)],'ignorecase')), strtrim(parts{t}{2})); + newnumchan = newnumchan+1; + end + fprintf('was changed to equation %s \n', formulaArray{t}) + end + end end if val==1 - set(handles.editor,'String', char(formulaArray)); + set(handles.editor,'String', char(formulaArray)); end %-------------------------------------------------------------------------- @@ -828,7 +834,7 @@ function pushbutton_export_chan_list_Callback(hObject, eventdata, handles) nloch = length(list_of_chans); for i=1:nloch - fprintf('%s\n',list_of_chans{i}); + fprintf('%s\n',list_of_chans{i}); end fprintf('\n\nEnd of list.\n\n') @@ -840,45 +846,45 @@ function pushbutton_removechan_Callback(hObject, eventdata, handles) nchan = handles.nchan; keeplocs = get(handles.chkeeplocs,'Value'); -if ~isempty(chan2del) - chan2del = unique_bc2(cell2mat(chan2del)); - if max(chan2del)>nchan && nnz(isinf(chan2del))==0 - msgboxText = 'You are specifying non-existing channels!'; - title = 'ERPLAB: chanoperGUI remove channels'; - errorfound(sprintf(msgboxText), title); - return - end - if min(chan2del)<1 && nnz(isinf(chan2del))==0 - msgboxText = 'You are specifying freaky non-existing channels!'; - title = 'ERPLAB: chanoperGUI remove channels'; - errorfound(sprintf(msgboxText), title); - return - end - if nnz(isnan(chan2del))>0 || nnz(isinf(chan2del))>0 - msgboxText = ['Channel problem\n'... - 'You are specifying freaky non-existing channels!']; - title = 'ERPLAB: chanoperGUI remove channels'; - errorfound(sprintf(msgboxText), title); - return - end - if strcmpi(typedata, 'EEG') - eqtn = sprintf('deletechan(%s)', vect2colon(chan2del, 'Delimiter','off')); - else - eqtn = sprintf('delerpchan(%s)', vect2colon(chan2del, 'Delimiter','off')); - end - - wchmsgon = get(handles.chwarning,'Value'); - handles.output = {{eqtn}, wchmsgon}; % sent like a cell string (with formulas) - try - handles.output{3} = keeplocs; - catch - disp('Problem setting location preference') - end - % Update handles structure - guidata(hObject, handles); - uiresume(handles.gui_chassis); -else +if ~isempty(chan2del) + chan2del = unique_bc2(cell2mat(chan2del)); + if max(chan2del)>nchan && nnz(isinf(chan2del))==0 + msgboxText = 'You are specifying non-existing channels!'; + title = 'ERPLAB: chanoperGUI remove channels'; + errorfound(sprintf(msgboxText), title); + return + end + if min(chan2del)<1 && nnz(isinf(chan2del))==0 + msgboxText = 'You are specifying freaky non-existing channels!'; + title = 'ERPLAB: chanoperGUI remove channels'; + errorfound(sprintf(msgboxText), title); return + end + if nnz(isnan(chan2del))>0 || nnz(isinf(chan2del))>0 + msgboxText = ['Channel problem\n'... + 'You are specifying freaky non-existing channels!']; + title = 'ERPLAB: chanoperGUI remove channels'; + errorfound(sprintf(msgboxText), title); + return + end + if strcmpi(typedata, 'EEG') + eqtn = sprintf('deletechan(%s)', vect2colon(chan2del, 'Delimiter','off')); + else + eqtn = sprintf('delerpchan(%s)', vect2colon(chan2del, 'Delimiter','off')); + end + + wchmsgon = get(handles.chwarning,'Value'); + handles.output = {{eqtn}, wchmsgon}; % sent like a cell string (with formulas) + try + handles.output{3} = keeplocs; + catch + disp('Problem setting location preference') + end + % Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + return end %-------------------------------------------------------------------------- @@ -890,29 +896,29 @@ function pushbutton_rerefwizard_Callback(hObject, eventdata, handles) % open reference wizard formulalist = rerefassistantGUI(handles.nchan, handles.listch); if isempty(formulalist) - return + return end compacteditor(hObject, eventdata, handles); formulas = get(handles.editor, 'String'); if get(handles.button_no_recu,'Value') - formulalist = cellstr([formulalist{:}]); - for t=1:length(formulalist) - [expspliter parts] = regexp(formulalist, '=','match','split'); - formulalist{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '[^n]*ch','nch','ignorecase')), strtrim(parts{t}{2})); - end - formulalist = char(formulalist); + formulalist = cellstr([formulalist{:}]); + for t=1:length(formulalist) + [expspliter parts] = regexp(formulalist, '=','match','split'); + formulalist{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '[^n]*ch','nch','ignorecase')), strtrim(parts{t}{2})); + end + formulalist = char(formulalist); end if isempty(formulas) - set(handles.editor,'String',formulalist); + set(handles.editor,'String',formulalist); else - formulalist = cellstr(formulalist); - formulas = cellstr(formulas); - formt = [formulas ;formulalist]; - formt = char(formt); - set(handles.editor,'String',formt); + formulalist = cellstr(formulalist); + formulas = cellstr(formulas); + formt = [formulas ;formulalist]; + formt = char(formt); + set(handles.editor,'String',formt); end % %-------------------------------------------------------------------------- @@ -1022,11 +1028,11 @@ function cancel_CreateFcn(hObject, eventdata, handles) function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') - % The GUI is still in UIWAIT, us UIRESUME - uiresume(handles.gui_chassis); + % The GUI is still in UIWAIT, us UIRESUME + uiresume(handles.gui_chassis); else - % The GUI is no longer waiting, just close it - delete(handles.gui_chassis); + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); end diff --git a/GUIs/creabasiceventlistGUI.fig b/GUIs/creabasiceventlistGUI.fig index e4ce87ea..1bf57055 100755 Binary files a/GUIs/creabasiceventlistGUI.fig and b/GUIs/creabasiceventlistGUI.fig differ diff --git a/GUIs/creabasiceventlistGUI.m b/GUIs/creabasiceventlistGUI.m index 188cb5ef..b3c6af60 100755 --- a/GUIs/creabasiceventlistGUI.m +++ b/GUIs/creabasiceventlistGUI.m @@ -31,33 +31,33 @@ % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @creabasiceventlistGUI_OpeningFcn, ... - 'gui_OutputFcn', @creabasiceventlistGUI_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @creabasiceventlistGUI_OpeningFcn, ... + 'gui_OutputFcn', @creabasiceventlistGUI_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) - gui_State.gui_Callback = str2func(varargin{1}); + gui_State.gui_Callback = str2func(varargin{1}); end if nargout - [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else - gui_mainfcn(gui_State, varargin{:}); + gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT %-------------------------------------------------------------------------- function creabasiceventlistGUI_OpeningFcn(hObject, eventdata, handles, varargin) try - def = varargin{1}; + def = varargin{1}; catch - def = {'' 'boundary' -99 1 1}; + def = {'' 'boundary' -99 1 1}; end try - multieeg = varargin{2}; + multieeg = varargin{2}; catch - multieeg = 0; + multieeg = 0; end elname = def{1}; @@ -67,7 +67,7 @@ function creabasiceventlistGUI_OpeningFcn(hObject, eventdata, handles, varargin) alphanum = def{5}; if iscell(newboundarynumcode) - newboundarynumcode = cell2mat(newboundarynumcode); + newboundarynumcode = cell2mat(newboundarynumcode); end handles.output = []; @@ -75,46 +75,60 @@ function creabasiceventlistGUI_OpeningFcn(hObject, eventdata, handles, varargin) set(handles.edit_elname,'String',elname); if isempty(elname) - set(handles.edit_elname,'Enable','off'); - set(handles.pushbutton_browse,'Enable','off'); - set(handles.checkbox_create_eventlist,'Value',0); + set(handles.edit_elname,'Enable','off'); + set(handles.pushbutton_browse,'Enable','off'); + set(handles.checkbox_create_eventlist,'Value',0); else - set(handles.checkbox_create_eventlist,'Value',1); - set(handles.edit_elname,'Enable','on'); - set(handles.pushbutton_browse,'Enable','on'); + set(handles.checkbox_create_eventlist,'Value',1); + set(handles.edit_elname,'Enable','on'); + set(handles.pushbutton_browse,'Enable','on'); end set(handles.checkbox_addm99,'Value',0); if isempty(boundarystrcode) - set(handles.checkbox_convert_boundary,'Value',0); - set(handles.edit_boundarycode,'Enable', 'off'); - set(handles.edit_numericode,'Enable', 'off'); + set(handles.checkbox_convert_boundary,'Value',0); + set(handles.edit_boundarycode,'Enable', 'off'); + set(handles.edit_numericode,'Enable', 'off'); else - set(handles.checkbox_convert_boundary,'Value',1); - set(handles.edit_boundarycode,'Enable', 'on'); - set(handles.edit_numericode,'Enable', 'on'); - - if iscell(boundarystrcode) - bb = sprintf('%s ', boundarystrcode{:}); - else - bb = char(boundarystrcode); - end - set(handles.edit_boundarycode, 'String', bb); - set(handles.edit_numericode, 'String',num2str(newboundarynumcode)); + set(handles.checkbox_convert_boundary,'Value',1); + set(handles.edit_boundarycode,'Enable', 'on'); + set(handles.edit_numericode,'Enable', 'on'); + + if iscell(boundarystrcode) + bb = sprintf('%s ', boundarystrcode{:}); + else + bb = char(boundarystrcode); + end + set(handles.edit_boundarycode, 'String', bb); + set(handles.edit_numericode, 'String',num2str(newboundarynumcode)); end set(handles.ELwarning,'Value', rwwarn); set(handles.checkbox_alphanum,'Value', alphanum); if multieeg==1 - set(handles.pushbutton_advanced, 'Enable', 'off') + set(handles.pushbutton_advanced, 'Enable', 'off') else - set(handles.pushbutton_advanced, 'Enable', 'on') + set(handles.pushbutton_advanced, 'Enable', 'on') end % % Name & version % version = geterplabversion; -set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - CREATE BASIC EVENTLIST GUI']) +ERPtooltype = erpgettoolversion('tooltype');%%GH Jan 2024 +if strcmpi(ERPtooltype,'EStudio') + set(handles.gui_chassis,'Name', ['Estudio ' version ' - CREATE BASIC EVENTLIST GUI']); +else + set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - CREATE BASIC EVENTLIST GUI']); +end +if multieeg==1 + set(handles.checkbox_create_eventlist,'Enable','off','Value',0); + set(handles.pushbutton_browse,'Enable','off'); + set(handles.edit_elname,'Enable','off'); + set(handles.edit_elname,'String','Export to text file is unavailable when multiple EEGsets are selected'); + set(handles.pushbutton_advanced,'String','Unavailable for
multi-EEGsets') +else + set(handles.pushbutton_advanced,'String','Advanced') ; +end % % Color GUI @@ -150,11 +164,11 @@ function creabasiceventlistGUI_OpeningFcn(hObject, eventdata, handles, varargin) function checkbox_create_eventlist_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.edit_elname,'Enable','on'); - set(handles.pushbutton_browse,'Enable','on'); + set(handles.edit_elname,'Enable','on'); + set(handles.pushbutton_browse,'Enable','on'); else - set(handles.edit_elname,'Enable','off'); - set(handles.pushbutton_browse,'Enable','off'); + set(handles.edit_elname,'Enable','off'); + set(handles.pushbutton_browse,'Enable','off'); end %-------------------------------------------------------------------------- @@ -164,10 +178,10 @@ function edit_elname_Callback(hObject, eventdata, handles) [elpathname, elfilename, ext] = fileparts(fullname); if strcmpi(elpathname,'') - elpathname = cd; + elpathname = cd; end if ~strcmpi(ext,'.txt') - ext='.txt'; + ext='.txt'; end elfilename = [elfilename ext]; @@ -181,7 +195,7 @@ function edit_elname_Callback(hObject, eventdata, handles) function edit_elname_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -194,26 +208,26 @@ function pushbutton_browse_Callback(hObject, eventdata, handles) [elfname, elpathname] = uiputfile({'*.txt';'*.*'},'Save EVENTLIST text file as', prename); if isequal(elfname,0) - disp('User selected Cancel') - handles.owfp = 0; % over write file permission - guidata(hObject, handles); - return + disp('User selected Cancel') + handles.owfp = 0; % over write file permission + guidata(hObject, handles); + return else - [pathx, elfilename, ext] = fileparts(elfname); - - if ~strcmpi(ext,'.txt') - ext='.txt'; - end - - elfilename = [elfilename ext]; - handles.elfilename = elfilename; - handles.elpathname = elpathname; - set(handles.edit_elname,'String', fullfile(elpathname, elfilename)); - handles.owfp = 1; % over write file permission - - % Update handles structure - guidata(hObject, handles); - disp(['For EVENTLIST text file, user selected ', fullfile(elpathname, elfilename)]) + [pathx, elfilename, ext] = fileparts(elfname); + + if ~strcmpi(ext,'.txt') + ext='.txt'; + end + + elfilename = [elfilename ext]; + handles.elfilename = elfilename; + handles.elpathname = elpathname; + set(handles.edit_elname,'String', fullfile(elpathname, elfilename)); + handles.owfp = 1; % over write file permission + + % Update handles structure + guidata(hObject, handles); + disp(['For EVENTLIST text file, user selected ', fullfile(elpathname, elfilename)]) end %-------------------------------------------------------------------------- @@ -227,83 +241,83 @@ function pushbutton_apply_Callback(hObject, eventdata, handles) fullname = char(get(handles.edit_elname, 'String')); if get(handles.checkbox_create_eventlist, 'Value') && ~strcmp(fullname,'') + + [elpathname, elfilename, ext] = fileparts(fullname); + + if strcmpi(elpathname,'') + elpathname = cd; + end + if ~strcmpi(ext,'.txt') + ext='.txt'; + end + + elfilename = fullfile(elpathname, [elfilename ext]); + owfp = handles.owfp; % over write file permission + + if exist(elfilename, 'file')~=0 && owfp==0 + question = ['%s already exists!\n\n'... + 'Do you want to replace it?']; + title = 'ERPLAB: Overwriting Confirmation'; + button = askquest(sprintf(question, elfilename), title); - [elpathname, elfilename, ext] = fileparts(fullname); - - if strcmpi(elpathname,'') - elpathname = cd; - end - if ~strcmpi(ext,'.txt') - ext='.txt'; - end - - elfilename = fullfile(elpathname, [elfilename ext]); - owfp = handles.owfp; % over write file permission - - if exist(elfilename, 'file')~=0 && owfp==0 - question = ['%s already exists!\n\n'... - 'Do you want to replace it?']; - title = 'ERPLAB: Overwriting Confirmation'; - button = askquest(sprintf(question, elfilename), title); - - if ~strcmpi(button, 'yes') - return - end + if ~strcmpi(button, 'yes') + return end - - disp(['For EVENTLIST text file, user selected ', fullfile(elpathname, elfilename)]) + end + + disp(['For EVENTLIST text file, user selected ', fullfile(elpathname, elfilename)]) else - elfilename = ''; + elfilename = ''; end if get(handles.checkbox_addm99,'Value') - boundarystrcode1 = {'boundary'}; - newboundarynumcode1 = -99; + boundarystrcode1 = {'boundary'}; + newboundarynumcode1 = -99; else - boundarystrcode1 = {''}; - newboundarynumcode1 = []; + boundarystrcode1 = {''}; + newboundarynumcode1 = []; end if get(handles.checkbox_convert_boundary,'Value') - boundarystrcode2 = strtrim(char(get(handles.edit_boundarycode, 'String'))); - boundarystrcode2 = regexp(boundarystrcode2,'\s*\w*\s*', 'match'); - newboundarynumcode2 = str2num(get(handles.edit_numericode, 'String')); - - if isempty(newboundarynumcode2) - msgboxText = 'You must specify a numeric code!'; - title = 'ERPLAB: empty input'; - errorfound(msgboxText, title); - return - end - if isempty(boundarystrcode2) - msgboxText = 'You must specify a boundary code!'; - title = 'ERPLAB: empty input'; - errorfound(msgboxText, title); - return - end - if length(newboundarynumcode2)~=length(boundarystrcode2) - msgboxText = 'You must specify the same amount of numeric and string codes!'; - title = 'ERPLAB: different inputs'; - errorfound(msgboxText, title); - return - end - if get(handles.checkbox_addm99,'Value') - newboundarynumcode2 = newboundarynumcode2(~ismember_bc2(boundarystrcode2, 'boundary')); - boundarystrcode2 = boundarystrcode2(~ismember_bc2(boundarystrcode2, 'boundary')); - if isempty(boundarystrcode2) - msgboxText = '''boundary'' event is already specified!\nUncheck one option or change the event name.'; - title = 'ERPLAB: redundant input'; - errorfound(sprintf(msgboxText), title); - return - end - end - if strcmp(boundarystrcode2, boundarystrcode1) - msgboxText = '''boundary'' event is already specified to be numerically encoded.'; - title = 'ERPLAB: duplicated inputs'; - errorfound(msgboxText, title); + boundarystrcode2 = strtrim(char(get(handles.edit_boundarycode, 'String'))); + boundarystrcode2 = regexp(boundarystrcode2,'\s*\w*\s*', 'match'); + newboundarynumcode2 = str2num(get(handles.edit_numericode, 'String')); + + if isempty(newboundarynumcode2) + msgboxText = 'You must specify a numeric code!'; + title = 'ERPLAB: empty input'; + errorfound(msgboxText, title); + return + end + if isempty(boundarystrcode2) + msgboxText = 'You must specify a boundary code!'; + title = 'ERPLAB: empty input'; + errorfound(msgboxText, title); + return + end + if length(newboundarynumcode2)~=length(boundarystrcode2) + msgboxText = 'You must specify the same amount of numeric and string codes!'; + title = 'ERPLAB: different inputs'; + errorfound(msgboxText, title); + return + end + if get(handles.checkbox_addm99,'Value') + newboundarynumcode2 = newboundarynumcode2(~ismember_bc2(boundarystrcode2, 'boundary')); + boundarystrcode2 = boundarystrcode2(~ismember_bc2(boundarystrcode2, 'boundary')); + if isempty(boundarystrcode2) + msgboxText = '''boundary'' event is already specified!\nUncheck one option or change the event name.'; + title = 'ERPLAB: redundant input'; + errorfound(sprintf(msgboxText), title); return - end + end + end + if strcmp(boundarystrcode2, boundarystrcode1) + msgboxText = '''boundary'' event is already specified to be numerically encoded.'; + title = 'ERPLAB: duplicated inputs'; + errorfound(msgboxText, title); + return + end else - boundarystrcode2 = []; - newboundarynumcode2 = []; + boundarystrcode2 = []; + newboundarynumcode2 = []; end alphanum = get(handles.checkbox_alphanum, 'Value'); % for letterkilla. Oct 10, 2012 @@ -340,7 +354,7 @@ function edit_boundarycode_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function edit_boundarycode_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- @@ -349,27 +363,27 @@ function edit_numericode_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function edit_numericode_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); + set(hObject,'BackgroundColor','white'); end %-------------------------------------------------------------------------- function checkbox_addm99_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.checkbox_convert_boundary,'Value', 0); - set(handles.edit_boundarycode,'Enable', 'off'); - set(handles.edit_numericode,'Enable', 'off'); + set(handles.checkbox_convert_boundary,'Value', 0); + set(handles.edit_boundarycode,'Enable', 'off'); + set(handles.edit_numericode,'Enable', 'off'); else - set(hObject, 'Value', 1) + set(hObject, 'Value', 1) end %-------------------------------------------------------------------------- function checkbox_convert_boundary_Callback(hObject, eventdata, handles) if get(hObject,'Value') - set(handles.checkbox_addm99,'Value', 0); - set(handles.edit_boundarycode,'Enable', 'on'); - set(handles.edit_numericode,'Enable', 'on'); + set(handles.checkbox_addm99,'Value', 0); + set(handles.edit_boundarycode,'Enable', 'on'); + set(handles.edit_numericode,'Enable', 'on'); else - set(hObject, 'Value', 1) + set(hObject, 'Value', 1) end %-------------------------------------------------------------------------- @@ -388,13 +402,13 @@ function pushbutton_advanced_Callback(hObject, eventdata, handles) %-------------------------------------------------------------------------- function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') - % The GUI is still in UIWAIT, us UIRESUME - handles.output = []; - % Update handles structure - guidata(hObject, handles); - uiresume(handles.gui_chassis); + % The GUI is still in UIWAIT, us UIRESUME + handles.output = []; + % Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); else - % The GUI is no longer waiting, just close it - delete(handles.gui_chassis); + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); end diff --git a/GUIs/errorGUI.fig b/GUIs/errorGUI.fig index 94d1647c..404a047e 100755 Binary files a/GUIs/errorGUI.fig and b/GUIs/errorGUI.fig differ diff --git a/GUIs/errorGUI.m b/GUIs/errorGUI.m index 337c164a..029f8825 100755 --- a/GUIs/errorGUI.m +++ b/GUIs/errorGUI.m @@ -30,21 +30,21 @@ % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @errorGUI_OpeningFcn, ... - 'gui_OutputFcn', @errorGUI_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @errorGUI_OpeningFcn, ... + 'gui_OutputFcn', @errorGUI_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) - if isempty(strfind(varargin{1},' ')) && isempty(str2num(varargin{1})) - gui_State.gui_Callback = str2func(varargin{1}); - end + if isempty(strfind(varargin{1},' ')) && isempty(str2num(varargin{1})) + gui_State.gui_Callback = str2func(varargin{1}); + end end if nargout - [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else - gui_mainfcn(gui_State, varargin{:}); + gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT @@ -54,41 +54,41 @@ function errorGUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = []; try - message = varargin{1}; - title = varargin{2}; - imagein = varargin{3}; - map = varargin{4}; - - if nargin<7 - showfig = 1; - else - showfig = varargin{7}; - end - if nargin<6 - fcolor = [0 0 0]; - else - fcolor = varargin{6}; - end - if nargin<5 - bcolor = [1 0 0]; - else - bcolor = varargin{5}; - end + message = varargin{1}; + title = varargin{2}; + imagein = varargin{3}; + map = varargin{4}; + + if nargin<7 + showfig = 1; + else + showfig = varargin{7}; + end + if nargin<6 + fcolor = [0 0 0]; + else + fcolor = varargin{6}; + end + if nargin<5 + bcolor = [0.702,0.77,0.85]; + else + bcolor = varargin{5}; + end catch - message = 'Hello Erpers!'; - title = 'Test'; - [imagein, map] = imread('steve_erpss.jpg'); - showfig = 1; - bcolor = [1 0 0]; - fcolor = [0 0 0]; + message = 'Hello Erpers!'; + title = 'Test'; + [imagein, map] = imread('steve_erpss.jpg'); + showfig = 1; + bcolor = [0.702,0.77,0.85]; + fcolor = [0 0 0]; end - +bcolor = [0.702,0.77,0.85]; defquack = erpworkingmemory('errorGUI'); % message on command window fprintf('%s\n', repmat('*',1,50)); if iscell(message) - message = [message{:}]; + message = [message{:}]; end fprintf('Full error message: \n %s\n', message); @@ -105,41 +105,41 @@ function errorGUI_OpeningFcn(hObject, eventdata, handles, varargin) set(handles.checkbox_quack,'Backgroundcolor', bcolor) try - he = findobj('tag','EEGLAB'); - posgui = get(he,'Position'); - %poseeg = get(handles.main_figure_error,'Position') - movegui(handles.main_figure_error,[posgui(1) posgui(2)]) + he = findobj('tag','EEGLAB'); + posgui = get(he,'Position'); + %poseeg = get(handles.main_figure_error,'Position') + movegui(handles.main_figure_error,[posgui(1) posgui(2)]) catch - %disp('no funciona') + %disp('no funciona') end -if showfig - imR = imagein(:,:,1); - imG = imagein(:,:,2); - imB = imagein(:,:,3); - aindx = ismember_bc2(imR,12); - bindx = ismember_bc2(imG,255); - cindx = ismember_bc2(imB,0); - edmask = aindx&bindx&cindx; - imR(edmask) = bcolor(1)*255; - imG(edmask) = bcolor(2)*255; - imB(edmask) = bcolor(3)*255; - imagein = cat(3, imR, imG, imB); -% H = fspecial('gaussian', [6 6]); -% imagein = imfilter(imagein, H); - axes(handles.axes_pict) - sizep = size(imagein); % Determine the size of the image file - set(handles.axes_pict,'Units', 'pixels'); - canvasize = get(handles.axes_pict,'Position'); % size of the image - factors = sizep(1)/canvasize(4); - xoffset = (canvasize(3)-sizep(2)/factors)/2; - image(imagein) - colormap(map) - set(handles.axes_pict, 'Visible', 'off','Position', [xoffset canvasize(2) sizep(2)/factors sizep(1)/factors]) +if showfig + imR = imagein(:,:,1); + imG = imagein(:,:,2); + imB = imagein(:,:,3); + aindx = ismember_bc2(imR,12); + bindx = ismember_bc2(imG,255); + cindx = ismember_bc2(imB,0); + edmask = aindx&bindx&cindx; + imR(edmask) = bcolor(1)*255; + imG(edmask) = bcolor(2)*255; + imB(edmask) = bcolor(3)*255; + imagein = cat(3, imR, imG, imB); + % H = fspecial('gaussian', [6 6]); + % imagein = imfilter(imagein, H); + axes(handles.axes_pict) + sizep = size(imagein); % Determine the size of the image file + set(handles.axes_pict,'Units', 'pixels'); + canvasize = get(handles.axes_pict,'Position'); % size of the image + factors = sizep(1)/canvasize(4); + xoffset = (canvasize(3)-sizep(2)/factors)/2; + image(imagein) + colormap(map) + set(handles.axes_pict, 'Visible', 'off','Position', [xoffset canvasize(2) sizep(2)/factors sizep(1)/factors]) else - set(handles.axes_pict, 'Visible', 'off') + set(handles.axes_pict, 'Visible', 'off') end if isempty(defquack) || defquack==1 % for making it faster - set(handles.checkbox_quack, 'Value', 1) + set(handles.checkbox_quack, 'Value', 1) end set(handles.checkbox_quack, 'ForegroundColor', fcolor) @@ -184,9 +184,9 @@ function axes_pict_CreateFcn(hObject, eventdata, handles) % --- Executes on button press in button_OK. function button_ok_Callback(hObject, eventdata, handles) if get(handles.checkbox_quack, 'Value') - erpworkingmemory('errorGUI', 1); + erpworkingmemory('errorGUI', 1); else - erpworkingmemory('errorGUI', 0); + erpworkingmemory('errorGUI', 0); end handles.output = 'ok'; @@ -207,7 +207,7 @@ function checkbox_quack_Callback(hObject, eventdata, handles) % % Quack % - % quick 3 beeps, rather than loading the quack + % quick 3 beeps, rather than loading the quack for bp = 1:3 beep pause(0.08) @@ -221,9 +221,9 @@ function main_figure_error_CloseRequestFcn(hObject, eventdata, handles) guidata(hObject, handles); if isequal(get(handles.main_figure_error, 'waitstatus'), 'waiting') - % The GUI is still in UIWAIT, us UIRESUME - uiresume(handles.main_figure_error); + % The GUI is still in UIWAIT, us UIRESUME + uiresume(handles.main_figure_error); else - % The GUI is no longer waiting, just close it - delete(handles.main_figure_error); + % The GUI is no longer waiting, just close it + delete(handles.main_figure_error); end diff --git a/GUIs/geterpvaluesGUI2.fig b/GUIs/geterpvaluesGUI2.fig index a7d814c8..8b800838 100755 Binary files a/GUIs/geterpvaluesGUI2.fig and b/GUIs/geterpvaluesGUI2.fig differ diff --git a/GUIs/grandaveragerGUI.fig b/GUIs/grandaveragerGUI.fig index 11f6ca1a..94aadb0c 100755 Binary files a/GUIs/grandaveragerGUI.fig and b/GUIs/grandaveragerGUI.fig differ diff --git a/GUIs/grandaverager_DQ.m b/GUIs/grandaverager_DQ.m index d21a8c89..ef3197b2 100755 --- a/GUIs/grandaverager_DQ.m +++ b/GUIs/grandaverager_DQ.m @@ -370,8 +370,9 @@ function pushbutton_apply_Callback(hObject, eventdata, handles) else % DQ mismatch beep - errordlg('Not all requested measures are present in all ERPsets to be averaged. Please check requested measures and ERPsets.') - pause(0.1) +% errordlg('Not all requested measures are present in all ERPsets to be averaged. Please check requested measures and ERPsets.') + errordlg('ERPLAB cannot average the data quality measures across ERPsets unless all ERPsets have the same data quality measures. The data quality measures are not identical across the selected ERPsets, so this grand average cannot be computed. You can either make sure that all selected ERPsets have the same data quality measures, or you can disable the computation of data quality measures in the grand average.') + pause(0.1);%%GH Feb 20 2024 end diff --git a/GUIs/gui_eegtrim.m b/GUIs/gui_eegtrim.m index 9f661db1..1b27d4d8 100755 --- a/GUIs/gui_eegtrim.m +++ b/GUIs/gui_eegtrim.m @@ -35,9 +35,23 @@ function gui_eegtrim_OpeningFcn(hObject, eventdata, handles, varargin) % % Name & version % +ERPtooltype = erpgettoolversion('tooltype'); +if ~isempty(ERPtooltype) + if strcmpi(ERPtooltype,'EStudio') + Toolabel = 1;%%Get label from work space to confirm whether EStudio was executed. + else + Toolabel = 0; + end +else + Toolabel = 0; +end + version = geterplabversion; +if Toolabel==1 + set(handles.gui_chassis,'Name', ['EStudio ' version ' - Data Trimmer GUI']) +else set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Data Trimmer GUI']) - +end % memory set(handles.edit_pretime, 'String', sprintf('%g', pretime)); set(handles.edit_posttime, 'String', sprintf('%g', posttime)); diff --git a/GUIs/gui_erplabShiftEventCodes.m b/GUIs/gui_erplabShiftEventCodes.m index 9ed7a6a2..11e33ef4 100755 --- a/GUIs/gui_erplabShiftEventCodes.m +++ b/GUIs/gui_erplabShiftEventCodes.m @@ -1,4 +1,4 @@ - function varargout = gui_erplabShiftEventCodes(varargin) +function varargout = gui_erplabShiftEventCodes(varargin) % GUI_ERPLABSHIFTEVENTCODES MATLAB code for gui_erplabShiftEventCodes.fig % GUI_ERPLABSHIFTEVENTCODES, by itself, creates a new GUI_ERPLABSHIFTEVENTCODES or raises the existing % singleton*. @@ -27,11 +27,11 @@ % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @gui_erplabShiftEventCodes_OpeningFcn, ... - 'gui_OutputFcn', @gui_erplabShiftEventCodes_OutputFcn, ... - 'gui_LayoutFcn', [] , ... - 'gui_Callback', []); + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @gui_erplabShiftEventCodes_OpeningFcn, ... + 'gui_OutputFcn', @gui_erplabShiftEventCodes_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end @@ -74,7 +74,7 @@ function gui_erplabShiftEventCodes_OpeningFcn(hObject, eventdata, handles, varar if iscell(handles.eventcodes) handles.eventcodes_txt = strjoin(handles.eventcodes, ','); else - handles.eventcodes_txt = handles.eventcodes; + handles.eventcodes_txt = handles.eventcodes; end set(handles.editboxEventCodes, ... @@ -101,6 +101,14 @@ function gui_erplabShiftEventCodes_OpeningFcn(hObject, eventdata, handles, varar 'SelectedObject', handles.radioBtnRoundEarlier); end +ERPtooltype = erpgettoolversion('tooltype');%%GH Jan 2024 +if strcmpi(ERPtooltype,'EStudio') + handles.checkbox_displayEEG.Enable = 'off'; + handles.checkbox_displayEEG.Value = 0; +else + handles.checkbox_displayEEG.Enable = 'on'; +end%%end + % Set Window title windowTitle = ['ERPLAB ' geterplabversion() ' - Shift Event Codes GUI']; @@ -168,7 +176,7 @@ function pushbutton_shiftEvents_Callback(hObject, eventdata, handles) %#ok<*DEFN % editString = editString(~cellfun('isempty',editString)); % handles.eventcodes = (editString); % end -% +% %handles.eventcodes = str2num(editString); %#ok % Save the input variables to output @@ -193,7 +201,7 @@ function pushbutton_cancel_Callback(hObject, eventdata, handles) disp('User selected Cancel') % Clear all input variables -handles.output = []; +handles.output = []; % Update handles structure guidata(hObject, handles); @@ -201,7 +209,7 @@ function pushbutton_cancel_Callback(hObject, eventdata, handles) % --- Executes when selected object changed in uipanelRounding. function uipanelRounding_SelectionChangedFcn(hObject, eventdata, handles) -% hObject handle to the selected object in uipanelRounding +% hObject handle to the selected object in uipanelRounding % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) @@ -239,8 +247,8 @@ function editboxEventCodes_Callback(hObject, eventdata, handles) % Strip any non-numeric token and replace w/ whitespace (' ') %editString = regexprep(get(hObject,'String'), '[^0-9:]', ' '); -%in 2023, accept both non-numeric and numeric ecodes -try +%in 2023, accept both non-numeric and numeric ecodes +try editString = eval(num2str(get(hObject,'String'))); %if numeric catch editString = regexp(get(hObject,'String'),'(?<=\d)\s(?=\d)|,\s*','split'); %remove commas if exist @@ -248,19 +256,18 @@ function editboxEventCodes_Callback(hObject, eventdata, handles) end %handles.eventcodes = str2num(editString); %#ok %numeric events -need_to_flat = 0; +need_to_flat = 0; for ec = 1:length(editString); - try - + try temp_nums = num2cell(eval(num2str(editString{ec}))); %evaluate & flatten any numeric expression editString{ec} = cellfun(@num2str,temp_nums,'UniformOutput',false); %change to string - need_to_flat = 1; + need_to_flat = 1; catch - end + end end - + %flatten cell array if need_to_flat == 1 editString =[editString{:}]; @@ -315,7 +322,7 @@ function checkbox_displayEEG_Callback(hObject, eventdata, handles) % Hint: get(hObject,'Value') returns toggle state of checkbox_displayEEG % returns contents of editbox_EndEventCodeBufferMS as a double -handles.displayEEG = get(hObject,'Value'); +handles.displayEEG = get(hObject,'Value'); % Save the new value guidata(hObject,handles); diff --git a/GUIs/saveRTGUI.fig b/GUIs/saveRTGUI.fig index ab3a5b33..6bd3b9c4 100755 Binary files a/GUIs/saveRTGUI.fig and b/GUIs/saveRTGUI.fig differ diff --git a/GUIs/saveRTGUI.m b/GUIs/saveRTGUI.m index b880ec8d..14c0b213 100755 --- a/GUIs/saveRTGUI.m +++ b/GUIs/saveRTGUI.m @@ -69,7 +69,7 @@ function saveRTGUI_OpeningFcn(hObject, eventdata, handles, varargin) % Name & version % version = geterplabversion; -set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Save Reaction Time GUI']) +% set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Save Reaction Time GUI']) set(handles.edit_saveas,'String', filename) set(handles.checkbox_header,'Value', header) @@ -79,6 +79,15 @@ function saveRTGUI_OpeningFcn(hObject, eventdata, handles, varargin) set(handles.popupmenu_elindex,'String', cellstr(num2str([1:numEL]'))) set(handles.popupmenu_elindex,'Value', indexel) +ERPtooltype = erpgettoolversion('tooltype');%%GH Jan 2024 +if strcmpi(ERPtooltype,'EStudio') + handles.uipanel1.Title = 'File name suffix (will be added to dataset name)'; + set(handles.gui_chassis,'Name', ['Estudio ' version ' - Save Reaction Time GUI']) +else + handles.uipanel1.Title = 'File name'; + set(handles.gui_chassis,'Name', ['ERPLAB ' version ' - Save Reaction Time GUI']) +end%%end + % % Color GUI % diff --git a/GUIs/scalplotGUI.fig b/GUIs/scalplotGUI.fig index fa559078..1ee5d4e7 100755 Binary files a/GUIs/scalplotGUI.fig and b/GUIs/scalplotGUI.fig differ diff --git a/README.md b/README.md index cdd2def7..ab433e38 100755 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ Click the Wiki icon at the top of the page for documentation, tutorials, and FAQ

To ask questions, subscribe to the ERPLAB email list (https://erpinfo.org/erplab-email-list). Bug reports can be submitted via GitHub or by sending an email to erplab-bugreports@ucdavis.edu. -## ERPLAB v10.11 +## ERPLAB v11

- +
@@ -15,56 +15,34 @@ To ask questions, subscribe to the ERPLAB email list (https://erpinfo.org/erplab

-To install ERPLAB v10.11, download the zip file (linked above), unzip and place the folder in the 'plugins' folder of your existing [EEGLAB](https://sccn.ucsd.edu/eeglab/download.php) installation (e.g. `/Users/Steve/Documents/MATLAB/eeglab2019_1/plugins/erplab/`). More [installation help can be found here](https://github.com/lucklab/erplab/wiki/Installation). +This download contains both [ERPLAB Studio](./ERPLAB-Studio-Manual) (our standalone Matlab program) and [ERPLAB Classic](./Manual) (an EEGLAB plugin). If you are new to ERPLAB, we strongly recommend that you go through the [ERPLAB Studio Tutorial](./ERPLAB-Studio-Tutorial) or ERPLAB Classic Tutorial before trying to analyze your own data. -To run ERPLAB, ensure that the correct EEGLAB folder is in your current Matlab path, and run `eeglab` as a command from the Matlab Command Window. If you are new to ERPLAB, we strongly recommend that you go through the [ERPLAB Tutorial](https://github.com/lucklab/erplab/wiki/Tutorial) before using ERPLAB with your own data. +[Click here](./Installation) for installation instructions. + +[Click here](./Compatability-and-Required-Toolboxes) for information about required Matlab toolboxes and compatibility with different versions of Matlab, EEGLAB, Windows, MacOS, and Linux. We encourage most users to use this latest major version. - ---- -## Compatibility and Required Toolboxes - -We anticipate that ERPLAB will work with most recent OSs, Matlab versions and EEGLAB versions. - -- The [Matlab Signal Processing Toolbox](https://www.mathworks.com/products/signal.html) is required. -- [EEGLAB v2021 or later](https://sccn.ucsd.edu/eeglab/download.php) is almost always necessary. - -However, in order to use the latest MVPC routines (see [here](https://github.com/ucdavis/erplab/wiki/Decoding-Tutorial)), Matlab versions and EEGLAB versions must be recent. In addition, some MATLAB toolboxes are required. -- Matlab 2020b + is REQUIRED for MVPC routines. -- EEGLAB 2023.1 + is REQUIRED for MVPC routines. -- The [Matlab Statistics and Machine Learning Toolbox](https://www.mathworks.com/products/statistics.html) -- The [Matlab Parallel Processing Toolbox](https://www.mathworks.com/products/parallel-computing.html) (recommended) - -Find [more ERPLAB installation help here](http://erpinfo.org/erplab). - - -### ERPLAB compatibility table - -Here is a list of some confirmed-working environments for ERPLAB. - -**ERPLAB v10.0+ works with...** -| **OS** | **Matlab** | **EEGLAB** | Working? | -| --- | --- | --- | --- | -| Mac OS 14.2.1 'Sonoma' | Matlab R 2023a | EEGLAB v2023.1 | ✓| -| Mac OS 11.7.6 'Big Sur' | Matlab R 2020a | EEGLAB v2023.0 | ✓| -| Mac OS 10.15.7 'Catalina' | Matlab R2020b | EEGLAB v2023.0 | ✓ | -| Mac OS 10.15 'Catalina' | Matlab R2016a | EEGLAB v2019_1 | ✓ | -(https://www.mathworks.com/downloads/web_downloads/download_update?release=R2018a&s_tid=ebrg_R2018a_2_1757132&s_tid=mwa_osa_a) | -| Mac OS 10.13.5 'High Sierra' | Matlab R2015a | EEGLAB v14.1.2 | ✓ | -| Windows 10 | Matlab R2021a | EEGLAB v2023.0 | ✓ | -| Windows 10 | Matlab R2020b | EEGLAB v2021.1 | ✓ | -| Ubuntu 18.04 LTS | Matlab R2019a | EEGLAB v2020 | ✓ | -| Ubuntu 18.04 LTS | Matlab R2019a | EEGLAB v2019_1 | ✓ | - -ERPLAB should work with most modern OSs, Matlab versions, and EEGLAB releases. Let us know if you see any incompatibility. -**Starting in ERPLAB v10.0, MATLAB'S "App Designer" was the default GUI system used for the MVPC routines and require at least MATLAB 2020a+ & EEGLAB 2023.1+ in order to work as expected.** -

## Release Notes +### ERPLAB v11.0 Release Notes + +ERPLAB can now be accessed from two different user interfaces: +- [ERPLAB Classic](./Manual) (our original software, which operates as an EEGLAB plugin) +- [ERPLAB Studio](./ERPLAB-Studio-Manual) (a standalone application that provides a more user-friendly GUI) + +ERPLAB Studio makes use of the same underlying code as EEGLAB and ERPLAB Classic. It is essentially a different user interface for the same functions. You will therefore get identical results with ERPLAB Studio and ERPLAB Classic, and scripting is the same for both packages. But ERPLAB Studio is much easier to use. + +[Click here](https://www.youtube.com/watch?v=lIaKVQ9DD6E) for a 2-minute video overview of ERPLAB Studio. + +The most commonly used EEGLAB functions are available from within ERPLAB Studio. For example, you can import EEG data into ERPLAB Studio, filter the EEG, apply ICA for artifact correction, etc. If you need an EEGLAB function that is not implemented within ERPLAB Studio, you can apply that function using the EEGLAB GUI or a script. + +If you are already familiar with ERPLAB, you can rapidly learn how to use ERPLAB Studio with our [Transition Guide](). If you are new to ERPLAB, please go through the [ERPLAB Studio Tutorial](./ERPLAB-Studio-Tutorial) before attempting to process your own data. Once you understand the basics of ERPLAB Studio, you can get detailed information about the individual processing steps in the [ERPLAB Studio Manual](./ERPLAB-Studio-Manual). + + ### ERPLAB v10.1 Release Notes Now Includes: Update to decoding toolbox. By default, beta weights will no longer be saved with MVPC files, dramatically reducing file size. diff --git a/eegplugin_erplab.m b/eegplugin_erplab.m index c0d851e6..fc6bc192 100755 --- a/eegplugin_erplab.m +++ b/eegplugin_erplab.m @@ -1,10 +1,10 @@ -% Author: Aaron Matthew Simmons, Guanghui Zhang, David R Garrett, -% Andrew X Stewart, Javier Lopez-Calderon & Steven Luck +% Author: Aaron Matthew Simmons, Guanghui Zhang, Andrew X Stewart, +% Javier Lopez-Calderon & Steven Luck % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2007-2024 -% Version 10.1 +% 2007-2023 +% Version 10.0 %b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b % @@ -64,8 +64,13 @@ catch end +%%running erplab%%GH 2024 +p_location = which('o_ERPDAT'); +p_location = p_location(1:findstr(p_location,'o_ERPDAT.m')-1); +tooltype = 'ERPLAB'; +save(fullfile(p_location,'erplab_running_version.erpm'),'tooltype'); + -%erplab_running_version('Version',erplabver,'tooltype','ERPLAB');%%GH,Mar 2023 global observe_EEGDAT; observe_EEGDAT = o_EEGDATA; @@ -87,6 +92,7 @@ observe_ERPDAT.Count_ERP = 0; observe_ERPDAT.Count_currentERP = 0; observe_ERPDAT.Process_messg = 0;%%change end +observe_ERPDAT.erp_between_panels = 0; % % CHECK VERSION NUMBER & FOLDER NAME @@ -105,11 +111,6 @@ fprintf('\nERPLAB''s folder does not show the current version number.\n') end -%%running estudio -p_location = which('o_ERPDAT'); -p_location = p_location(1:findstr(p_location,'o_ERPDAT.m')-1); -tooltype = 'erplab'; -save(fullfile(p_location,'erplab_running_version.erpm'),'tooltype'); % % CHECK EEGLAB Version @@ -200,7 +201,7 @@ ERP = []; % Start ERP Structure on workspace ALLERPCOM = []; CURRENTERP = 0; -BEST = []; %Start BEST structure on workspace +BEST = []; %Start BEST structure on workspace CURRENTBEST = 0; plotset.ptime = []; plotset.pscalp = []; @@ -293,10 +294,10 @@ comDeleteTimeSegments = [trystrs.no_check '[EEG, LASTCOM] = pop_erplabDeleteTimeSegments(EEG);' catchstrs.new_and_hist]; comRemoveResponseMistakes = [trystrs.no_check '[ALLEEG,EEG,LASTCOM] = pop_remove_response_mistakes(ALLEEG,EEG,CURRENTSET);' catchstrs.new_and_hist]; comInterpolateElectrodes = [trystrs.no_check '[EEG, LASTCOM] = pop_erplabInterpolateElectrodes(EEG);' catchstrs.new_and_hist]; -%comDFT = [trystrs.no_check '[EEG, fft_out, LASTCOM] = pop_continuousFFT(EEG);' catchstrs.add_to_hist]; comDFT = ['[EEG, fft_out, LASTCOM] = pop_continuousFFT(EEG);']; + % % EVENTLIST callback % diff --git a/erplab_default_values.m b/erplab_default_values.m index d1a4a294..4c9a07c8 100755 --- a/erplab_default_values.m +++ b/erplab_default_values.m @@ -1,5 +1,5 @@ -erplabver = '10.11'; % current erplab version -erplabrel = '17-May-2024'; % DOB +erplabver = '11'; % current erplab version +erplabrel = '10-June-2024'; % DOB erplabdeveloper = 'Simmons,Zhang,Garrett'; %ColorB = [170 180 195]/255; % old background color (until version 3) %ColorB = [0.9216 0.8353 0.6078]; % background color for version 4 diff --git a/functions/averager.m b/functions/averager.m index de43db75..6f5367ac 100755 --- a/functions/averager.m +++ b/functions/averager.m @@ -66,7 +66,12 @@ end if nargin<8 - avgText = 1; + ERPtooltype = erpgettoolversion('tooltype'); + if strcmpi(ERPtooltype,'EStudio') + avgText = 0; + else + avgText = 1; + end end if nargin<7 @@ -401,9 +406,9 @@ if stderror == 1 sample_SD_rearrange = sqrt((sumERP2(:,:,k) - N*ERP.bindata(:,:,k).^2)/(N-1)); % get ERP's standard deviation elseif stderror == 2 %corrected point-wise SEM - sample_SD_rearrange = sqrt((sumERP2(:,:,k) - N*ERP.bindata(:,:,k).^2)/(N-(3/2)+(1/(8*(N-1))))); + sample_SD_rearrange = sqrt((sumERP2(:,:,k) - N*ERP.bindata(:,:,k).^2)/(N-(3/2)+(1/(8*(N-1))))); end - + % The Standard Error of the Mean is then: ERP.binerror(:,:,k) = sample_SD_rearrange./sqrt(N); % get ERP's standard error end @@ -441,7 +446,7 @@ ERP.datatype = 'TFFT'; end ERP.pnts = size(ERP.bindata, 2); -if ~iscell(artcrite) +if ~iscell(artcrite) && avgText == 1 fprintf('----------------------------------------------------------------------------------------\n'); else countbiORI = countbinOK; @@ -472,8 +477,8 @@ tapwin(s1:s2,1) = hann(winpnts); case 'blackmanharris' tapwin(s1:s2,1) = blackmanharris(winpnts); - case 'rectangular' - tapwin(s1:s2,1) = rectwin(winpnts); + case 'rectangular' + tapwin(s1:s2,1) = rectwin(winpnts); otherwise error('Invalid taper function name (only ''Hamming'', ''Hanning'', ''blackmanharris'' or ''rectangular'' can be used)') end diff --git a/functions/delerpchan.m b/functions/delerpchan.m index 4061f184..83aaad13 100755 --- a/functions/delerpchan.m +++ b/functions/delerpchan.m @@ -42,39 +42,39 @@ cherror = 0; if nargin<1 - help avgchan - return + help avgchan + return end if ~iserpstruct(ERP) - error('ERPLAB says: delerpchan() only works with ERP structure.') + error('ERPLAB says: delerpchan() only works with ERP structure.') end if ischar(chin) - chin = str2num(char(regexp(chin,'\d+','match')'))'; + chin = str2num(char(regexp(chin,'\d+','match')'))'; end if size(chin,1)>1 - error('ERPLAB says: error, delerpchan works with row-array inputs') + error('ERPLAB says: error, delerpchan works with row-array inputs') end chanarray = unique_bc2(chin); if length(chanarray)~=length(chin) - fprintf('\n*** WARNING: Repeated channels were ignored.\n\n') + fprintf('\n*** WARNING: Repeated channels were ignored.\n\n') end nchan = ERP.nchan; if max(chanarray)>nchan - error('ERPLAB says: error at delerpchan. Some specified channels do not exist!') + error('ERPLAB says: error at delerpchan. Some specified channels do not exist!') end ERP.bindata(chanarray,:,:)=[]; -if ~isempty(ERP.binerror) %% GH March 2024 +if ~isempty(ERP.binerror)%%GH Mar 2024 ERP.binerror(chanarray,:,:)=[]; end ERP.nchan = size(ERP.bindata, 1); if isfield(ERP.chanlocs, 'labels') - if ~isempty([ERP.chanlocs.labels]) - labaux = {ERP.chanlocs.labels}; - [labaux{chanarray}] = deal([]); - indxl = ~cellfun(@isempty, labaux); - labelout = labaux(indxl); - ERP.chanlocs = []; - [ERP.chanlocs(1:ERP.nchan).labels] = labelout{:}; - end + if ~isempty([ERP.chanlocs.labels]) + labaux = {ERP.chanlocs.labels}; + [labaux{chanarray}] = deal([]); + indxl = ~cellfun(@isempty, labaux); + labelout = labaux(indxl); + ERP.chanlocs = []; + [ERP.chanlocs(1:ERP.nchan).labels] = labelout{:}; + end end diff --git a/functions/erpworkingmemory.m b/functions/erpworkingmemory.m index a123ea27..677c4245 100755 --- a/functions/erpworkingmemory.m +++ b/functions/erpworkingmemory.m @@ -65,17 +65,6 @@ vmemoryerp = []; end -ERPtooltype = erpgettoolversion('tooltype'); -if ~isempty(ERPtooltype) - if strcmpi(ERPtooltype,'EStudio') - Toolabel = 1;%%Get label from work space to confirm whether EStudio was executed. - else - Toolabel = 0; - end -else - Toolabel = 1; -end - if nargin==1 % read if ~isempty(vmemoryerp) % variable at the workspace for storing/reading memory @@ -98,25 +87,12 @@ end else % file for storing/reading memory try - if Toolabel==1%%When using EStudio - p = which('o_ERPDAT'); - p = p(1:findstr(p,'o_ERPDAT.m')-1); - v = load(fullfile(p,'memoryerpstudio.erpm'), '-mat'); - else%%When using ERPLAB - p = which('eegplugin_erplab'); - p = p(1:findstr(p,'eegplugin_erplab.m')-1); - v = load(fullfile(p,'memoryerp.erpm'), '-mat'); - end + p = which('eegplugin_erplab'); + p = p(1:findstr(p,'eegplugin_erplab.m')-1); + v = load(fullfile(p,'memoryerp.erpm'), '-mat'); catch - if Toolabel==1%%When using EStudio - msgboxText = ['ERPLAB Studio (erpworkingmemory.m) could not find "memoryerpstudio.erpm" or does not have permission for reading it.\n'... - 'Please, run EEGLAB once again or go to ERPLAB''s Setting menu and specify/create a new memory file.\n']; - else - msgboxText = ['ERPLAB Studio (erpworkingmemory.m) could not find "memoryerpstudio.erpm" or does not have permission for reading it.\n'... - 'Please, run EEGLAB Studio once again or go to EStudio''s Setting menu and specify/create a new memory file.\n']; - - end - + msgboxText = ['ERPLAB Studio (erpworkingmemory.m) could not find "memoryerpstudio.erpm" or does not have permission for reading it.\n'... + 'Please, run EEGLAB Studio once again or go to EStudio''s Setting menu and specify/create a new memory file.\n']; try cprintf([0.45 0.45 0.45], msgboxText'); catch @@ -148,26 +124,16 @@ end else % file for storing/reading memory try - if Toolabel==1%%When using EStudio - eval([field '=input2store;']) - p = which('o_ERPDAT'); - p = p(1:findstr(p,'o_ERPDAT.m')-1); - save(fullfile(p,'memoryerpstudio.erpm'), field,'-append'); - - else%%When using ERPLAB - eval([field '=input2store;']) - p = which('eegplugin_erplab'); - p = p(1:findstr(p,'eegplugin_erplab.m')-1); - save(fullfile(p,'memoryerp.erpm'), field,'-append'); - end + + eval([field '=input2store;']) + p = which('eegplugin_erplab'); + p = p(1:findstr(p,'eegplugin_erplab.m')-1); + save(fullfile(p,'memoryerp.erpm'), field,'-append'); + catch - if Toolabel==1%%When using EStudio - msgboxText = ['ERPLAB Studio could not find "memoryerpstudio.erpm" or does not have permission for writting on it.\n'... - 'Please, run EEGLAB Studio once again or go to EStudio''s Setting menu and specify/create a new memory file.\n']; - else - msgboxText = ['ERPLAB could not find "memoryerp.erpm" or does not have permission for writting on it.\n'... - 'Please, run EEGLAB once again or go to ERPLAB''s Setting menu and specify/create a new memory file.\n']; - end + + msgboxText = ['ERPLAB could not find "memoryerp.erpm" or does not have permission for writting on it.\n'... + 'Please, run EEGLAB once again or go to ERPLAB''s Setting menu and specify/create a new memory file.\n']; try cprintf([0.45 0.45 0.45], msgboxText'); catch diff --git a/functions/filterp.m b/functions/filterp.m index 57f41738..a4db05b8 100755 --- a/functions/filterp.m +++ b/functions/filterp.m @@ -48,106 +48,114 @@ % You should have received a copy of the GNU General Public License % along with this program. If not, see . -function ERP = filterp(ERP, chanArray, locutoff, hicutoff, filterorder, typef, remove_dc) +function ERP = filterp(ERP, chanArray, locutoff, hicutoff, filterorder, typef, remove_dc,binArray) if nargin < 1 - help filterp - return + help filterp + return end if exist('filtfilt','file') ~= 2 - disp('filterp error: cannot find the Signal Processing Toolbox'); - return + disp('filterp error: cannot find the Signal Processing Toolbox'); + return end if isempty(ERP.bindata) - disp('filterp error: cannot filter an empty erpset') - return + disp('filterp error: cannot filter an empty erpset') + return end -if nargin < 7 - disp('filterp error: please, enter all arguments!') - return +if nargin < 8%%GH Apr. 2024 + disp('filterp error: please, enter all arguments!') + return end + + if ERP.pnts <= 3*filterorder - msgboxText = 'Error: The length of the data must be more than three times the filter order.'; - title = 'ERPLAB: filterp(), filtfilt constraint'; - errorfound(msgboxText, title); - return + msgboxText = 'Error: The length of the data must be more than three times the filter order.'; + title = 'ERPLAB: filterp(), filtfilt constraint'; + errorfound(msgboxText, title); + return end if locutoff == 0 && hicutoff == 0, - msgboxText = 'Error: What???? low cutoff == 0 && high cutoff == 0?'; - title = 'ERPLAB: filterp(), Cutoff frequency'; - errorfound(msgboxText, title); - return + msgboxText = 'Error: What???? low cutoff == 0 && high cutoff == 0?'; + title = 'ERPLAB: filterp(), Cutoff frequency'; + errorfound(msgboxText, title); + return end chanArray = unique_bc2(chanArray); % does not allow repeated channels fnyquist = 0.5*ERP.srate; % half sample rate pnts = size(ERP.bindata,2); numchan = length(chanArray); +binArray = unique_bc2(binArray);%%GH Apr. 2024 +nbin = ERP(1).nbin; +if isempty(binArray) || any(binArray(:)>nbin) || any(binArray(:)<1) + binArray = [1:nbin]; +end + if numchan>ERP.nchan - msgboxText = 'Error: You have selected more channels than are contained within your data!'; - title = 'ERPLAB: filterp() error:'; - errorfound(msgboxText, title); - return + msgboxText = 'Error: You have selected more channels than are contained within your data!'; + title = 'ERPLAB: filterp() error:'; + errorfound(msgboxText, title); + return end nbin = ERP.nbin; fprintf('Channels to be filtered : %s\n\n', vect2colon(chanArray, 'Delimiter', 'on')); if locutoff >= fnyquist - error('ERPLAB says: errot at filterp(). Low cutoff frequency cannot be >= srate/2'); + error('ERPLAB says: errot at filterp(). Low cutoff frequency cannot be >= srate/2'); end if hicutoff >= fnyquist - error('ERPLAB says: errot at filterp().High cutoff frequency cannot be >= srate/2'); + error('ERPLAB says: errot at filterp().High cutoff frequency cannot be >= srate/2'); end if ~typef && filterorder*3 > pnts % filtfilt restriction - fprintf('filterp: filter order too high'); - error('ERPLAB says: errot at filterp(). Samples must be at least 3 times the filter order.'); + fprintf('filterp: filter order too high'); + error('ERPLAB says: errot at filterp(). Samples must be at least 3 times the filter order.'); end if locutoff >0 % option in order to remove dc value is only for high-pass filtering - if remove_dc - disp('Removing DC bias from ERPs...') - for i = 1:nbin - auxdata = ERP.bindata(chanArray,:,i); - ERP.bindata(chanArray,:,i) = detrend(auxdata', 'constant')'; - end - fprintf('\n') + if remove_dc + disp('Removing DC bias from ERPs...') + for i = binArray + auxdata = ERP.bindata(chanArray,:,i); + ERP.bindata(chanArray,:,i) = detrend(auxdata', 'constant')'; end + fprintf('\n') + end end [b, a, labelf, v] = filter_tf(typef, filterorder, hicutoff, locutoff, ERP.srate); if ~v % something is wrong or turned off - msgboxText = 'filterp() error: Wrong parameters for filtering.'; - title = 'ERPLAB: filterp():'; - errorfound(msgboxText, title); - return + msgboxText = 'filterp() error: Wrong parameters for filtering.'; + title = 'ERPLAB: filterp():'; + errorfound(msgboxText, title); + return end disp([labelf ' filtering input data, please wait...']) -for j=1:nbin - if size(b,1)>1 - if strcmpi(labelf,'Band-Pass') - % Butterworth bandpass (cascade) - ERP.bindata(chanArray,:,j) = filtfilt(b(1,:),a(1,:), ERP.bindata(chanArray,:,j)')'; - ERP.bindata(chanArray,:,j) = filtfilt(b(2,:),a(2,:), ERP.bindata(chanArray,:,j)')'; - else - %Butterworth Notch (parallel) - datalowpass = filtfilt(b(1,:),a(1,:), ERP.bindata(chanArray,:,j)')'; - datahighpass = filtfilt(b(2,:),a(2,:), ERP.bindata(chanArray,:,j)')'; - ERP.bindata(chanArray,:,j) = datalowpass + datahighpass; - end +for j= binArray%%GH Apr. 2024 + if size(b,1)>1 + if strcmpi(labelf,'Band-Pass') + % Butterworth bandpass (cascade) + ERP.bindata(chanArray,:,j) = filtfilt(b(1,:),a(1,:), ERP.bindata(chanArray,:,j)')'; + ERP.bindata(chanArray,:,j) = filtfilt(b(2,:),a(2,:), ERP.bindata(chanArray,:,j)')'; else - % Butterworth lowpass) - % Butterworth highpass - % FIR lowpass - % FIR highpass - % FIR bandpass - % FIR notch - % Parks-McClellan Notch - ERP.bindata(chanArray,:,j) = filtfilt(b,a, ERP.bindata(chanArray,:,j)')'; + %Butterworth Notch (parallel) + datalowpass = filtfilt(b(1,:),a(1,:), ERP.bindata(chanArray,:,j)')'; + datahighpass = filtfilt(b(2,:),a(2,:), ERP.bindata(chanArray,:,j)')'; + ERP.bindata(chanArray,:,j) = datalowpass + datahighpass; end + else + % Butterworth lowpass) + % Butterworth highpass + % FIR lowpass + % FIR highpass + % FIR bandpass + % FIR notch + % Parks-McClellan Notch + ERP.bindata(chanArray,:,j) = filtfilt(b,a, ERP.bindata(chanArray,:,j)')'; + end end % @@ -155,14 +163,14 @@ % ERP = clear_dq(ERP); if isfield(ERP, 'binerror') - if ~isempty(ERP.binerror) - - if numchan ERP.binerror = []; - end + if ~isempty(ERP.binerror) + + if numchan ERP.binerror = []; end + end end ERP.isfilt = 1; diff --git a/functions/gaverager.m b/functions/gaverager.m old mode 100644 new mode 100755 index 71ee08c1..c25b88dd --- a/functions/gaverager.m +++ b/functions/gaverager.m @@ -122,8 +122,8 @@ % basic test for number of points (for now...) if pre_pnts ~= ERPT.pnts msgboxText = sprintf('Erpsets #%g and #%g have different number of points!', j-1, j); - msgboxText = sprintf([msgboxText,'\n','ERPset',32, num2str(j-1),32,'has',32,num2str(ALLERP(j-1).pnts),32,'points.\n',... - 'ERPset',32, num2str(j),32,'has',32,num2str(ALLERP(j).pnts),32,'points.\n']); + msgboxText = sprintf([msgboxText,'\n','ERPset',32, num2str(j-1),32,'has',32,num2str(ALLERP(j-1).pnts),32,'points (from',32,num2str(ALLERP(j-1).times(1)),32,'to',32,num2str(ALLERP(j-1).times(end)),'ms; fs=',num2str(ALLERP(j-1).srate),'Hz).\n',... + 'ERPset',32, num2str(j),32,'has',32,num2str(ALLERP(j).pnts),32,'points (from',32,num2str(ALLERP(j).times(1)),32,'to',32,num2str(ALLERP(j).times(end)),'ms; fs=',num2str(ALLERP(j).srate),'Hz).\n']); %title = 'ERPLAB: pop_gaverager() Error'; %errorfound(msgboxText, title); %return diff --git a/functions/geterpvalues.m b/functions/geterpvalues.m index 1ef90de5..e60d04c3 100755 --- a/functions/geterpvalues.m +++ b/functions/geterpvalues.m @@ -90,95 +90,95 @@ function varargout = geterpvalues(ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, localopt, frac, fracmearep, intfactor,peakonset) if nargin<1 - help geterpvalues - return + help geterpvalues + return end if nargin<2 - error('ERROR geterpvalues(): You must specify ERP struct and latency(ies), at least.') + error('ERROR geterpvalues(): You must specify ERP struct and latency(ies), at least.') end if nargin<14 peakonset = 1; end if nargin<13 - intfactor = 1; + intfactor = 1; end if nargin<12 - fracmearep = 0; %0=write a NaN when frac measure is not found. 1 = export frac absolute peak when frac local peak is not found.; 2=shows error message + fracmearep = 0; %0=write a NaN when frac measure is not found. 1 = export frac absolute peak when frac local peak is not found.; 2=shows error message end if nargin<11 - frac = 0.5; % 50% area latency (if needed, by default) + frac = 0.5; % 50% area latency (if needed, by default) end if nargin<10 - localopt = 0; % 0=write a NaN when local peak is not found. 1=export absolute peak when local peak is not found. + localopt = 0; % 0=write a NaN when local peak is not found. 1=export absolute peak when local peak is not found.; 2=shows error message end if nargin<9 - sampeak = 0; % absolute peak. No neighbor samples + sampeak = 0; % absolute peak. No neighbor samples end if nargin<8 - polpeak = 1; % positive + polpeak = 1; % positive end if nargin<7 - coi = 0; % 0= as it is; 1=first component; 2=2nd component + coi = 0; % 0= as it is; 1=first component; 2=2nd component end if nargin<6 - blc = 'pre'; + blc = 'pre'; end if nargin<5 - moption = 'instabl'; + moption = 'instabl'; end if nargin<4 - chanArray = 1:ERP.nchan; + chanArray = 1:ERP.nchan; end if nargin<3 - binArray = 1:ERP.nbin; + binArray = 1:ERP.nbin; end if ischar(blc) - blcnum = str2num(blc); - if isempty(blcnum) - if ~ismember_bc2(blc,{'no','none','pre','post','all','whole'}) - msgboxText = 'Invalid baseline range dude!'; - %title = 'ERPLAB: geterpvalues() baseline input'; - %errorfound(msgboxText, title); - %return - varargout{1} = msgboxText; - varargout{2} = []; - return - end - else - if size(blcnum,1)>1 || size(blcnum,2)>2 - msgboxText = 'Invalid baseline range, dude!'; - %title = 'ERPLAB: geterpvalues() baseline input'; - %errorfound(msgboxText, title); - %return - varargout{1} = msgboxText; - varargout{2} = []; - return - end + blcnum = str2num(blc); + if isempty(blcnum) + if ~ismember_bc2(blc,{'no','none','pre','post','all','whole'}) + msgboxText = 'Invalid baseline range dude!'; + %title = 'ERPLAB: geterpvalues() baseline input'; + %errorfound(msgboxText, title); + %return + varargout{1} = msgboxText; + varargout{2} = []; + return end + else + if size(blcnum,1)>1 || size(blcnum,2)>2 + msgboxText = 'Invalid baseline range, dude!'; + %title = 'ERPLAB: geterpvalues() baseline input'; + %errorfound(msgboxText, title); + %return + varargout{1} = msgboxText; + varargout{2} = []; + return + end + end end if ~ismember_bc2({moption}, {'instabl', 'meanbl', 'peakampbl', 'peaklatbl', 'fpeaklat',... - 'area','areat', 'areap', 'arean','areazt','areazp','areazn','fareatlat',... - 'fareaplat', 'fninteglat', 'fareanlat', 'ninteg','nintegz' }); - msgboxText = [moption ' is not a valid option for geterpvalues!']; - %title = 'ERPLAB: geterpvalues wrong inputs'; - %errorfound(msgboxText, title); - %return - varargout{1} = msgboxText; - varargout{2} = []; - return + 'area','areat', 'areap', 'arean','areazt','areazp','areazn','fareatlat',... + 'fareaplat', 'fninteglat', 'fareanlat', 'ninteg','nintegz' }); + msgboxText = [moption ' is not a valid option for geterpvalues!']; + %title = 'ERPLAB: geterpvalues wrong inputs'; + %errorfound(msgboxText, title); + %return + varargout{1} = msgboxText; + varargout{2} = []; + return end if isempty(coi) - coi = 1; + coi = 1; end if nargout==1 - condf = 0; % only includes area values + condf = 0; % only includes area values elseif nargout==2 - condf = 1; % include latency values and limits... + condf = 1; % include latency values and limits... else - error('ERPLAB says: error at geterpvalues(). Too many output arguments!') + error('ERPLAB says: error at geterpvalues(). Too many output arguments!') end if isempty(sampeak) - sampeak =0; + sampeak =0; end fs = ERP.srate; @@ -195,19 +195,19 @@ p1 = timeor(1); p2 = timeor(end); if intfactor~=1 - timex = linspace(p1,p2,round(pnts*intfactor)); - pnts = length(timex); - fs = round(fs*intfactor); + timex = linspace(p1,p2,round(pnts*intfactor)); + pnts = length(timex); + fs = round(fs*intfactor); else - timex = timeor; + timex = timeor; end msgboxText4peak = ['The requested measurement window is invalid given the number of points specified for finding a local peak '... - 'and the epoch length of the ERP waveform.\n\n You have specified a local peak over ±%g points, which means that '... - 'there must be %g sample points between the onset of your measurement window and the onset of the waveform, '... - 'and/or %g sample points between the end of your measurement window and the end of the waveform.\n\n'... - 'Because the waveform starts at %.1f ms and ends at %.1f ms, your measurement window cannot go beyond [%.1f %.1f] ms (unless you reduce '... - 'the number of points required to define the local peak).']; + 'and the epoch length of the ERP waveform.\n\n You have specified a local peak over ±%g points, which means that '... + 'there must be %g sample points between the onset of your measurement window and the onset of the waveform, '... + 'and/or %g sample points between the end of your measurement window and the end of the waveform.\n\n'... + 'Because the waveform starts at %.1f ms and ends at %.1f ms, your measurement window cannot go beyond [%.1f %.1f] ms (unless you reduce '... + 'the number of points required to define the local peak).']; % latsamp = [find(ERP.times>=latency(1), 1, 'first') find(ERP.times<=550, 1, 'last')]; % % its fields are "value" and "ilimits" @@ -217,366 +217,402 @@ [worklate{1:nbin,1:nchan}] = deal(latency); % specified latency(ies) for getting measurements. if length(latency)==2 - [xxx, latsamp, latdiffms] = closest(timex, latency); - if latency(1)2 %JLC.10/16/2013 - msgboxText = sprintf('The onset of your measurement window cannot be more than 2 samples earlier than the ERP window (%.1f ms)\n', timex(1)); - varargout{1} = msgboxText; - varargout{2} = 'limit'; - return - end - if latency(2)2 %JLC.10/16/2013 + msgboxText = sprintf('The onset of your measurement window cannot be more than 2 samples earlier than the ERP window (%.1f ms)\n', timex(1)); + varargout{1} = msgboxText; + varargout{2} = 'limit'; + return + end + if latency(2)=(pnts-sampeak)) && (ms2sample(latdiffms(1),fs)<(-2+sampeak) || ms2sample(latdiffms(1),fs)>(2-sampeak)) %JLC.20/08/13 - msgboxText = sprintf('The specified latency is more than 2 samples away from the ERP window [%.1f %.1f] ms\n', timex(1), timex(end)); - varargout{1} = msgboxText; - varargout{2} = 'limit'; - return - end - if latsamp(1)<1 - latsamp(1) = 1; - fprintf('\n%s\n', repmat('*',1,60)); - fprintf('WARNING: Latency %.1f ms was adjusted to %.1f ms \n', latency(2), mintime); - fprintf('%s\n\n', repmat('*',1,60)); - elseif latsamp(1)>pnts - latsamp(1) = pnts; - fprintf('\n%s\n', repmat('*',1,60)); - fprintf('WARNING: Latency %.1f ms was adjusted to %.1f ms \n', latency(2), maxtime); - fprintf('%s\n\n', repmat('*',1,60)); - end + [xxx, latsamp, latdiffms] = closest(timex, latency(1)); + if (latsamp(1)<=(1+sampeak) || latsamp(1)>=(pnts-sampeak)) && (ms2sample(latdiffms(1),fs)<(-2+sampeak) || ms2sample(latdiffms(1),fs)>(2-sampeak)) %JLC.20/08/13 + msgboxText = sprintf('The specified latency is more than 2 samples away from the ERP window [%.1f %.1f] ms\n', timex(1), timex(end)); + varargout{1} = msgboxText; + varargout{2} = 'limit'; + return + end + if latsamp(1)<1 + latsamp(1) = 1; + fprintf('\n%s\n', repmat('*',1,60)); + fprintf('WARNING: Latency %.1f ms was adjusted to %.1f ms \n', latency(2), mintime); + fprintf('%s\n\n', repmat('*',1,60)); + elseif latsamp(1)>pnts + latsamp(1) = pnts; + fprintf('\n%s\n', repmat('*',1,60)); + fprintf('WARNING: Latency %.1f ms was adjusted to %.1f ms \n', latency(2), maxtime); + fprintf('%s\n\n', repmat('*',1,60)); + end else - error('Wrong number of latencies...') + error('Wrong number of latencies...') end try - for b=1:nbin - for ch = 1:nchan - % - % Get data - % - dataux = ERP.bindata(chanArray(ch), :, binArray(b)); - - % - % re-sampling - % - if intfactor~=1 - dataux = spline(timeor, dataux, timex); % re-sampled data - end + for b=1:nbin + for ch = 1:nchan + % + % Get data + % + dataux = ERP.bindata(chanArray(ch), :, binArray(b)); + + % + % re-sampling + % + if intfactor~=1 + dataux = spline(timeor, dataux, timex); % re-sampled data + end + + % + % Baseline correction + % + blv = blvalue2(dataux, timex, blc); + dataux = dataux - blv; + + if nlat==1 % 1 latency was specified + if strcmpi(moption,'areazt') || strcmpi(moption,'areazp') || strcmpi(moption,'areazn') + + % + % get area (automatic limits, 1 seed latency) + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + switch moption + case 'areazt' + aoption = 'autot'; + case 'areazp' + aoption = 'autop'; + case 'areazn' + aoption = 'auton'; + end + + % gets values + [A, Lx, il] = areaerp(dataux, fs, latsamp, aoption, coi); + worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integratin limits + VALUES(b,ch) = A; + elseif strcmpi(moption,'nintegz') + + % + % get numerical integration (automatic limits) + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + [A, Lx, il] = areaerp(dataux, fs,latsamp, 'auto', coi); + worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integratin limits + VALUES(b,ch) = A; + elseif strcmpi(moption,'instabl') + + % + % get instantaneous amplitud (at 1 latency) + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + VALUES(b,ch) = dataux(latsamp); + else + stre1 = 'ERROR in geterpvalues.m: You must enter 2 latencies for '; + stre2 = '''meanbl'', ''peakampbl'', ''peaklatbl'', or ''area'''; + strerr = [stre1 stre2]; + error( strerr ) + end + else % between 2 latencies measurements. + if strcmpi(moption,'meanbl') + + % + % get mean value + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + VALUES(b,ch) = mean(dataux(latsamp(1):latsamp(2))); + elseif strcmpi(moption,'peakampbl') + + % + % get peak amplitude + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + try + dataux = dataux(latsamp(1)-sampeak:latsamp(2)+sampeak); % no filtered + timex2 = timex(latsamp(1)-sampeak:latsamp(2)+sampeak); + catch + extrastr = msgboxText4peak; + error('Error:peakampbl', extrastr, sampeak, sampeak, sampeak, mintime, maxtime, mintime+sample2ms(sampeak,fs), maxtime-sample2ms(sampeak,fs)); + end + + if localopt==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. + localoptstr = 'abs'; + elseif localopt==2 %% GH May 2024 + localoptstr = 'errormsg'; + else + localoptstr = 'NaN'; + end + + % gets values + [valx, latpeak] = localpeak(dataux, timex2, 'Neighborhood',sampeak, 'Peakpolarity', polpeak, 'Measure','amplitude',... + 'Peakreplace', localoptstr); + + if isempty(valx) + error('Peak-related measurement failed...') + end + + worklate{b,ch} = latpeak; %((il-1)/fs + ERP.xmin)*1000; + VALUES(b,ch) = valx; % value of amplitude + elseif strcmpi(moption,'peaklatbl') + + % + % get peak latency + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + + try + dataux = dataux(latsamp(1)-sampeak:latsamp(2)+sampeak); % no filtered + timex2 = timex(latsamp(1)-sampeak:latsamp(2)+sampeak); + catch + extrastr = msgboxText4peak; + error('Error:peaklatbl', extrastr, sampeak, sampeak, sampeak, mintime, maxtime, mintime+sample2ms(sampeak,fs), maxtime-sample2ms(sampeak,fs)); + end + if localopt==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. + localoptstr = 'abs'; + elseif localopt==2 %% GH May 2024 + localoptstr = 'errormsg'; - % - % Baseline correction - % - blv = blvalue2(dataux, timex, blc); - dataux = dataux - blv; + else + localoptstr = 'NaN'; + end + + % gets values + valx = localpeak(dataux, timex2, 'Neighborhood', sampeak, 'Peakpolarity', polpeak, 'Measure','peaklat',... + 'Peakreplace', localoptstr); + if isempty(valx) + error('Peak-related measurement failed...') + end + + VALUES(b,ch) = valx; + elseif strcmpi(moption,'area') || strcmpi(moption,'areat') || strcmpi(moption,'areap') || strcmpi(moption,'arean') + + % + % get area + % + switch moption + case {'areat', 'area'} + aoption = 'total'; + case 'areap' + aoption = 'positive'; + case 'arean' + aoption = 'negative'; + end + + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + A = areaerp(dataux, fs, latsamp, aoption, coi); + VALUES(b,ch) = A; + elseif strcmpi(moption,'50arealat') % deprecated + + % + % get 50% area latency (old) + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + [aaaxxx, L] = areaerp(dataux, fs,latsamp, 'total', coi); + VALUES(b,ch) = sample2ms((L-1),fs,0) + mintime; % 50 % area latency (temporary) + elseif strcmpi(moption,'fareatlat') || strcmpi(moption,'fninteglat') || strcmpi(moption,'fareaplat') || strcmpi(moption,'fareanlat') + + % + % get fractional area latency + % + if frac<0 || frac>1 + error('ERPLAB says: error at geterpvalues(). Fractional area value must be between 0 and 1') + end + switch moption + case 'fareatlat' + aoption = 'total'; + case 'fninteglat' + aoption = 'integral'; % default + case 'fareaplat' + aoption = 'positive'; + case 'fareanlat' + aoption = 'negative'; + end + + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + [aaaxxx, L] = areaerp(dataux, fs,latsamp, aoption, coi, frac, fracmearep); + VALUES(b,ch) = sample2ms((L-1),fs,0) + mintime; % frac area latency + elseif strcmpi(moption,'fpeaklat') + + % + % get fractional "peak" latency + % + if frac<0 || frac>1 + error('ERPLAB says: error at geterpvalues(). Fractional peak value must be between 0 and 1') + end + + % try + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + + try + dataux = dataux(latsamp(1)-sampeak:latsamp(2)+sampeak); % no filtered + timex2 = timex(latsamp(1)-sampeak:latsamp(2)+sampeak); + catch + extrastr = msgboxText4peak; + error('Error:fpeaklat', extrastr, sampeak, sampeak, sampeak, mintime, maxtime, mintime+sample2ms(sampeak,fs), maxtime-sample2ms(sampeak,fs)); + end + if localopt==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. + localoptstr = 'abs'; + elseif localopt==2 %% GH May 2024 + localoptstr = 'errormsg'; + else + localoptstr = 'NaN'; + end + if fracmearep==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. + fracmearepstr = 'abs'; - if nlat==1 % 1 latency was specified - if strcmpi(moption,'areazt') || strcmpi(moption,'areazp') || strcmpi(moption,'areazn') - - % - % get area (automatic limits, 1 seed latency) - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - switch moption - case 'areazt' - aoption = 'autot'; - case 'areazp' - aoption = 'autop'; - case 'areazn' - aoption = 'auton'; - end - - % gets values - [A, Lx, il] = areaerp(dataux, fs, latsamp, aoption, coi); - worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integratin limits - VALUES(b,ch) = A; - elseif strcmpi(moption,'nintegz') - - % - % get numerical integration (automatic limits) - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - [A, Lx, il] = areaerp(dataux, fs,latsamp, 'auto', coi); - worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integratin limits - VALUES(b,ch) = A; - elseif strcmpi(moption,'instabl') - - % - % get instantaneous amplitud (at 1 latency) - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - VALUES(b,ch) = dataux(latsamp); - else - stre1 = 'ERROR in geterpvalues.m: You must enter 2 latencies for '; - stre2 = '''meanbl'', ''peakampbl'', ''peaklatbl'', or ''area'''; - strerr = [stre1 stre2]; - error( strerr ) - end - else % between 2 latencies measurements. - if strcmpi(moption,'meanbl') - - % - % get mean value - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - VALUES(b,ch) = mean(dataux(latsamp(1):latsamp(2))); - elseif strcmpi(moption,'peakampbl') - - % - % get peak amplitude - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - try - dataux = dataux(latsamp(1)-sampeak:latsamp(2)+sampeak); % no filtered - timex2 = timex(latsamp(1)-sampeak:latsamp(2)+sampeak); - catch - extrastr = msgboxText4peak; - error('Error:peakampbl', extrastr, sampeak, sampeak, sampeak, mintime, maxtime, mintime+sample2ms(sampeak,fs), maxtime-sample2ms(sampeak,fs)); - end - - if localopt==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. - localoptstr = 'abs'; - else - localoptstr = 'NaN'; - end - - % gets values - [valx, latpeak] = localpeak(dataux, timex2, 'Neighborhood',sampeak, 'Peakpolarity', polpeak, 'Measure','amplitude',... - 'Peakreplace', localoptstr); - - if isempty(valx) - error('Peak-related measurement failed...') - end - - worklate{b,ch} = latpeak; %((il-1)/fs + ERP.xmin)*1000; - VALUES(b,ch) = valx; % value of amplitude - elseif strcmpi(moption,'peaklatbl') - - % - % get peak latency - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - - try - dataux = dataux(latsamp(1)-sampeak:latsamp(2)+sampeak); % no filtered - timex2 = timex(latsamp(1)-sampeak:latsamp(2)+sampeak); - catch - extrastr = msgboxText4peak; - error('Error:peaklatbl', extrastr, sampeak, sampeak, sampeak, mintime, maxtime, mintime+sample2ms(sampeak,fs), maxtime-sample2ms(sampeak,fs)); - end - if localopt==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. - localoptstr = 'abs'; - else - localoptstr = 'NaN'; - end - - % gets values - valx = localpeak(dataux, timex2, 'Neighborhood', sampeak, 'Peakpolarity', polpeak, 'Measure','peaklat',... - 'Peakreplace', localoptstr); - if isempty(valx) - error('Peak-related measurement failed...') - end - - VALUES(b,ch) = valx; - elseif strcmpi(moption,'area') || strcmpi(moption,'areat') || strcmpi(moption,'areap') || strcmpi(moption,'arean') - - % - % get area - % - switch moption - case {'areat', 'area'} - aoption = 'total'; - case 'areap' - aoption = 'positive'; - case 'arean' - aoption = 'negative'; - end - - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - A = areaerp(dataux, fs, latsamp, aoption, coi); - VALUES(b,ch) = A; - elseif strcmpi(moption,'50arealat') % deprecated - - % - % get 50% area latency (old) - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - [aaaxxx, L] = areaerp(dataux, fs,latsamp, 'total', coi); - VALUES(b,ch) = sample2ms((L-1),fs,0) + mintime; % 50 % area latency (temporary) - elseif strcmpi(moption,'fareatlat') || strcmpi(moption,'fninteglat') || strcmpi(moption,'fareaplat') || strcmpi(moption,'fareanlat') - - % - % get fractional area latency - % - if frac<0 || frac>1 - error('ERPLAB says: error at geterpvalues(). Fractional area value must be between 0 and 1') - end - switch moption - case 'fareatlat' - aoption = 'total'; - case 'fninteglat' - aoption = 'integral'; % default - case 'fareaplat' - aoption = 'positive'; - case 'fareanlat' - aoption = 'negative'; - end - - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - [aaaxxx, L] = areaerp(dataux, fs,latsamp, aoption, coi, frac, fracmearep); - VALUES(b,ch) = sample2ms((L-1),fs,0) + mintime; % frac area latency - elseif strcmpi(moption,'fpeaklat') - - % - % get fractional "peak" latency - % - if frac<0 || frac>1 - error('ERPLAB says: error at geterpvalues(). Fractional peak value must be between 0 and 1') - end - - % try - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - - try - dataux = dataux(latsamp(1)-sampeak:latsamp(2)+sampeak); % no filtered - timex2 = timex(latsamp(1)-sampeak:latsamp(2)+sampeak); - catch - extrastr = msgboxText4peak; - error('Error:fpeaklat', extrastr, sampeak, sampeak, sampeak, mintime, maxtime, mintime+sample2ms(sampeak,fs), maxtime-sample2ms(sampeak,fs)); - end - if localopt==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. - localoptstr = 'abs'; - else - localoptstr = 'NaN'; - end - if fracmearep==1 %0=writes a NaN when local peak is not found. 1=export absolute peak when local peak is not found. - fracmearepstr = 'abs'; - else - fracmearepstr = 'NaN'; - end - - % gets values - [aaaxxx, latpeak, latfracpeak] = localpeak(dataux, timex2, 'Neighborhood',sampeak, 'Peakpolarity', polpeak, 'Measure','fraclat',... - 'Peakreplace', localoptstr, 'Fraction', frac, 'Fracpeakreplace', fracmearepstr, 'Peakonset',peakonset); - - if isempty(aaaxxx) - error('Peak-related measurement failed...') - end - - worklate{b,ch} = latpeak; % peak - VALUES(b,ch) = latfracpeak; % fractional peak - elseif strcmpi(moption,'areazt') || strcmpi(moption,'areazp') || strcmpi(moption,'areazn') - - % - % get area (automatic limits) - % - switch moption - case 'areazt' - aoption = 'autot'; - case 'areazp' - aoption = 'autop'; - case 'areazn' - aoption = 'auton'; - end - - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - [A, L, il] = areaerp(dataux, fs,latsamp, aoption, coi); - worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integration limits - VALUES(b,ch) = A; - elseif strcmpi(moption,'errorbl') % for Rick Addante - - % - % get standard deviation - % - if isempty(ERP.binerror) - error('ERPLAB says: The data field for standard deviation is empty!') - end - - dataux = ERP.bindata; % temporary store for data field - ERP.bindata = ERP.binerror; % error data to data - blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - VALUES(b,ch) = mean(ERP.bindata(chanArray(ch),latsamp(1):latsamp(2), binArray(b))) - blv; - ERP.bindata = dataux; % recover original data - elseif strcmpi(moption,'rmsbl') - - % - % get root mean square value (RMS) - % - VALUES(b,ch) = sqrt(mean(dataux(latsamp(1):latsamp(2)).^2)); - elseif strcmpi(moption,'ninteg') - - % - % get numerical integration - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - A = areaerp(dataux, fs,latsamp, 'integral', coi); - VALUES(b,ch) = A; - elseif strcmpi(moption,'nintegz') - - % - % get numerical integration (automatic limits) - % - %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value - %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; - - % gets values - [A, Lx, il] = areaerp(dataux, fs,latsamp, 'auto', coi); - worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integratin limits - VALUES(b,ch) = A; - end - end + else + fracmearepstr = 'NaN'; + end + + % gets values + [aaaxxx, latpeak, latfracpeak] = localpeak(dataux, timex2, 'Neighborhood',sampeak, 'Peakpolarity', polpeak, 'Measure','fraclat',... + 'Peakreplace', localoptstr, 'Fraction', frac, 'Fracpeakreplace', fracmearepstr, 'Peakonset',peakonset); + + if isempty(aaaxxx) + error('Peak-related measurement failed...') + end + + worklate{b,ch} = latpeak; % peak + VALUES(b,ch) = latfracpeak; % fractional peak + elseif strcmpi(moption,'areazt') || strcmpi(moption,'areazp') || strcmpi(moption,'areazn') + + % + % get area (automatic limits) + % + switch moption + case 'areazt' + aoption = 'autot'; + case 'areazp' + aoption = 'autop'; + case 'areazn' + aoption = 'auton'; + end + + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + [A, L, il] = areaerp(dataux, fs,latsamp, aoption, coi); + worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integration limits + VALUES(b,ch) = A; + elseif strcmpi(moption,'errorbl') % for Rick Addante + + % + % get standard deviation + % + if isempty(ERP.binerror) + error('ERPLAB says: The data field for standard deviation is empty!') + end + + dataux = ERP.bindata; % temporary store for data field + ERP.bindata = ERP.binerror; % error data to data + blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + VALUES(b,ch) = mean(ERP.bindata(chanArray(ch),latsamp(1):latsamp(2), binArray(b))) - blv; + ERP.bindata = dataux; % recover original data + elseif strcmpi(moption,'rmsbl') + + % + % get root mean square value (RMS) + % + VALUES(b,ch) = sqrt(mean(dataux(latsamp(1):latsamp(2)).^2)); + elseif strcmpi(moption,'ninteg') + + % + % get numerical integration + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + A = areaerp(dataux, fs,latsamp, 'integral', coi); + VALUES(b,ch) = A; + elseif strcmpi(moption,'nintegz') + + % + % get numerical integration (automatic limits) + % + %blv = blvalue(ERP, chanArray(ch), binArray(b), blc); % baseline value + %dataux = ERP.bindata(chanArray(ch), :, binArray(b)) - blv; + + % gets values + [A, Lx, il] = areaerp(dataux, fs,latsamp, 'auto', coi); + worklate{b,ch} = sample2ms((il-1),fs,0) + mintime; % integratin limits + VALUES(b,ch) = A; end + end end + end catch - serr = lasterror; - varargout{1} = serr.message; - varargout{2} = []; - return + serr = lasterror; + switch moption%%GH May 2024 + case 'fareanlat' + varargout{1} = ['Error: There was no negative area (i.e., area below the baseline) in one or more of the waveforms during the specified measurement window. It is impossible to quantify the fractional area latency when there is no negative area. To solve this problem, you can either change the measurement parameters (e.g., the time window) so that a negative area exists for all waveforms, or you can use the Options button to output a value of "not a number (NaN)" when there is no negative area. Here is the first waveform in which there was no negative area detected: bin',num2str(b),', chan',num2str(ch)]; + case 'fareaplat' + varargout{1} = ['Error: There was no positive area (i.e., area above the baseline) in one or more of the waveforms during the specified measurement window. It is impossible to quantify the fractional area latency when there is no positive area. To solve this problem, you can either change the measurement parameters (e.g., the time window) so that a positive area exists for all waveforms, or you can use the Options button to output a value of "not a number (NaN)" when there is no positive area. Here is the first waveform in which there was no positive area detected: bin',num2str(b),', chan',num2str(ch)]; + case 'peakampbl' + varargout{1} = ['Error: There was no local peak in one or more of the waveforms during the specified measurement window. To solve this problem, you can either change the measurement parameters (e.g., reducing the number of points required for a local peak) so that a local peak exists for all waveforms, or you can use the Options button to output a value of "non a number (NaN)" when there is no local peak. Here is the first waveform in which there was no local peak detected: bin',num2str(b),', chan',num2str(ch)]; + case 'peaklatbl' + if polpeak==1 + polpeakstr = 'positive'; + else + polpeakstr = 'negative'; + end + varargout{1} = ['Error: There was no',32,polpeakstr,32,'latency in one or more of the waveforms during the specified measurement window. It is impossible to quantify the peak latency when there is no',... + 32,polpeakstr,32,'latency. To solve this problem, you can either change the measurement parameters (e.g., the time window) so that a',32,polpeakstr,32,'latency exists for all waveforms, or you can use the Options button to output a value of "not a number (NaN)" when there is no',32,polpeakstr,32,... + 'latency. Here is the first waveform in which there was no',32,polpeakstr,32,'latency detected: bin',num2str(b),', chan',num2str(ch)]; + case 'fpeaklat' + if polpeak==1 + polpeakstr = 'positive'; + else + polpeakstr = 'negative'; + end + varargout{1} = ['Error: There was no',32,polpeakstr,32,'latency in one or more of the waveforms during the specified measurement window. It is impossible to quantify the fractional peak latency when there is no',... + 32,polpeakstr,32,'latency. To solve this problem, you can either change the measurement parameters (e.g., the time window) so that a',32,polpeakstr,32,'latency exists for all waveforms, or you can use the Options button to output a value of "not a number (NaN)" when there is no',32,polpeakstr,32,... + 'latency. Here is the first waveform in which there was no',32,polpeakstr,32,'latency detected: bin',num2str(b),', chan',num2str(ch)]; + otherwise + varargout{1} = serr.message; + end + + varargout{2} = []; + return end % % Creates Output % if ~condf - varargout{1} = VALUES; + varargout{1} = VALUES; elseif condf - varargout{1} = VALUES; - varargout{2} = worklate; + varargout{1} = VALUES; + varargout{2} = worklate; else - error('ERPLAB says: error at geterpvalues. Too many output arguments!') + error('ERPLAB says: error at geterpvalues. Too many output arguments!') end diff --git a/functions/inputvalue.m b/functions/inputvalue.m index 1f5ffee6..f716993c 100755 --- a/functions/inputvalue.m +++ b/functions/inputvalue.m @@ -1,7 +1,13 @@ function [response] = inputvalue(prompt,dlg_title,num_lines,def) BackERPLABcolor = erpworkingmemory('ColorB'); +if isempty(BackERPLABcolor) || numel(BackERPLABcolor)~=3 || any(BackERPLABcolor(:)>1) || any(BackERPLABcolor(:)<0) + BackERPLABcolor = [0.7020 0.77 0.85]; +end ForeERPLABcolor = erpworkingmemory('ColorF'); +if isempty(ForeERPLABcolor) || numel(ForeERPLABcolor)~=3 || any(ForeERPLABcolor(:)>1) || any(ForeERPLABcolor(:)<0) + ForeERPLABcolor = [0 0 0]; +end BKGoldcolor = get(0,'DefaultUicontrolBackgroundColor'); % current background color FORoldcolor = get(0,'DefaultUicontrolForegroundColor'); % current foreground color oldimage = get(0,'DefaultImageVisible'); diff --git a/functions/localpeak.m b/functions/localpeak.m index ebbc066e..489eeb9b 100755 --- a/functions/localpeak.m +++ b/functions/localpeak.m @@ -226,11 +226,14 @@ poslocalpf = posabspf; latlocalpeak = timex(posabspf); ltypeoutput = 2; % abs peak - else % replace with NaN + elseif strcmpi(p.Results.Peakreplace,'NaN') % replace with NaN %%GH May 2024 vlocalpf = NaN; poslocalpf = NaN; latlocalpeak = NaN; ltypeoutput = 3; % NaN instead of a peak + else%%GH May 2024 + errorcode = 1; % no fractional value was specified + return end end diff --git a/functions/setcodebit.m b/functions/setcodebit.m index a48b4503..483a8b65 100755 --- a/functions/setcodebit.m +++ b/functions/setcodebit.m @@ -1,9 +1,9 @@ % PURPOSE: subroutine for pop_setcodebit.m % sets the bit(s) at position(s) "bitindex" in each EEG.event(i).type value to 0 (off). % "bitindex" must contain number(s) between 1 and 16. -% +% % EEG = setcodebit(EEG, bitindex, newvalue) sets the bit(s) at position(s) "bitindex" to the value "newvalue", which must be either 0 or 1. -% +% % Example: % In Biosemi system you have a 16-bit word for sending your event codes. However, you generally use event codes from 1 to 255 % (8-bit numbers). In this case, the upper byte (bits 9 to 16) should be silent, and these bits should be zero. @@ -13,11 +13,11 @@ % Hence, you will be able to set each bit, or a group of them, to either "0" or "1", using a single line command. % For example, if you want to assure that your event codes keep values from 1 to 255, you must set the upper byte % (bits 9 to 16) to zero (cleaning any spuriously activated bit), using a command like the following: -% +% % EEG = setcodebit(EEG, 9:16, 0); -% +% % Note, EEG = setcodebit(EEG, 9:16); will work as well, since "0" is the default value for "newvalue". -% +% % % *** This function is part of ERPLAB Toolbox *** % Author: Javier Lopez-Calderon & Johanna Kreither @@ -30,53 +30,53 @@ function EEG = setcodebit(EEG,bitindex, newvalue) if nargin<1 - help setcodebit - return + help setcodebit + return end if nargin<3 - newvalue = 0; + newvalue = 0; end if nargin<2 - msgboxText = 'Error: setcodebit() works with 3 inputs.'; - error(msgboxText) + msgboxText = 'Error: setcodebit() works with 3 inputs.'; + error(msgboxText) end if ~isempty(EEG.epoch) - msgboxText = 'setcodebit.m only works for continuous dataset.'; - error(msgboxText) + msgboxText = 'setcodebit.m only works for continuous dataset.'; + error(msgboxText) end if isempty(bitindex) - msgboxText = 'Error: you must specify one bit index, at least.'; - error(msgboxText) + msgboxText = 'Error: you must specify one bit index, at least.'; + error(msgboxText) else - if isnumeric(bitindex) - if min(bitindex)<1 || max(bitindex)>16 - msgboxText = 'Error: bit index must be a positive integer between 1 and 16.'; - error(msgboxText) - end - else - msgboxText = 'Error: bit index must be numeric.'; - error(msgboxText) - end - bitindex = unique_bc2(bitindex); + if isnumeric(bitindex) + if min(bitindex)<1 || max(bitindex)>16 + msgboxText = 'Error: bit index must be a positive integer between 1 and 16.'; + error(msgboxText) + end + else + msgboxText = 'Error: bit index must be numeric.'; + error(msgboxText) + end + bitindex = unique_bc2(bitindex); end if ischar(newvalue) - msgboxText = 'Error: new value must be numeric.'; - error(msgboxText) + msgboxText = 'Error: new value must be numeric.'; + error(msgboxText) else - if length(newvalue)~=1 - msgboxText = 'Error: new value must be a single value, either 0 or 1.'; - error(msgboxText) - end - if newvalue~=0 && newvalue~=1 - msgboxText = 'Error: new value must be a single value, either 0 or 1.'; - error(msgboxText) - end + if length(newvalue)~=1 + msgboxText = 'Error: new value must be a single value, either 0 or 1.'; + error(msgboxText) + end + if newvalue~=0 && newvalue~=1 + msgboxText = 'Error: new value must be a single value, either 0 or 1.'; + error(msgboxText) + end end if ischar(EEG.event(1).type) - msgboxText = 'Your event codes are not numeric.'; - error(msgboxText) + msgboxText = 'Your event codes are not numeric.'; + error(msgboxText) else - currentcodes = uint16([EEG.event.type]); %numeric codes + currentcodes = uint16([EEG.event.type]); %numeric codes end nevents = length(currentcodes); bitbase = dec2bin(0,16); @@ -85,9 +85,13 @@ for i=1:nevents if newvalue==0 % set to zero - EEG.event(i).type = double(bitand(currentcodes(i), bitcmp(bitbase,16))); + try %%GH June 2024 + EEG.event(i).type = double(bitand(currentcodes(i), bitcmp(bitbase,16))); + catch + EEG.event(i).type = double(bitand(currentcodes(i), bitcmp(bitbase,'uint16'))); + end else % set to one - EEG.event(i).type = double(bitor(currentcodes(i), bitbase)); + EEG.event(i).type = double(bitor(currentcodes(i), bitbase)); end end EEG = eeg_checkset( EEG, 'eventconsistency' ); diff --git a/functions/summary_rejectflags.m b/functions/summary_rejectflags.m index 08fa3ee2..a1e43ad0 100755 --- a/functions/summary_rejectflags.m +++ b/functions/summary_rejectflags.m @@ -1,12 +1,12 @@ % PURPOSE: summarizes marked flag for artifact detection % % FORMAT -% +% % histoflags = summary_rejectflags(EEG); -% +% % % *** This function is part of ERPLAB Toolbox *** -% Author: Javier Lopez-Calderon +% Author: Javier Lopez-Calderon % Center for Mind and Brain % University of California, Davis, % Davis, CA @@ -36,7 +36,7 @@ function histoflags = summary_rejectflags(EEG) if isempty(EEG.epoch) - error('ERPLAB: summary_rejectflags() only works with epoched dataset') + error('ERPLAB: summary_rejectflags() only works with epoched dataset') end ntrial = EEG.trials; @@ -44,40 +44,40 @@ oldflag = zeros(1,ntrial); for b=1:nbin - for i=1:ntrial - if length(EEG.epoch(i).eventlatency) == 1 - binix = [EEG.epoch(i).eventbini]; - if iscell(binix) - binix = cell2mat(binix); - end - if ismember(b, binix) - flagx = [EEG.epoch(i).eventflag]; - if iscell(flagx) - flagx = cell2mat(flagx); - end - oldflag(b,i) = flagx; - else - oldflag(b,i) =0; - end - elseif length(EEG.epoch(i).eventlatency) > 1 - indxtimelock = find(cell2mat(EEG.epoch(i).eventlatency) == 0,1,'first'); % catch zero-time locked type - if ismember(b, EEG.epoch(i).eventbini{indxtimelock}) - oldflag(b,i) = EEG.epoch(i).eventflag{indxtimelock}; - else - oldflag(b,i) =0; - end - else - errorm = 1; + for i=1:ntrial + if length(EEG.epoch(i).eventlatency) == 1 + binix = [EEG.epoch(i).eventbini]; + if iscell(binix) + binix = cell2mat(binix); + end + if ismember(b, binix) + flagx = [EEG.epoch(i).eventflag]; + if iscell(flagx) + flagx = cell2mat(flagx); end + oldflag(b,i) = flagx; + else + oldflag(b,i) =0; + end + elseif length(EEG.epoch(i).eventlatency) > 1 + indxtimelock = find(cell2mat(EEG.epoch(i).eventlatency) == 0,1,'first'); % catch zero-time locked type + if ismember(b, EEG.epoch(i).eventbini{indxtimelock}) + oldflag(b,i) = EEG.epoch(i).eventflag{indxtimelock}; + else + oldflag(b,i) =0; + end + else + errorm = 1; end + end end histoflags = zeros(1,16); flagbit = bitshift(1, 0:15); for b=1:nbin - for j=1:16 - C = bitand(flagbit(j), oldflag(b,:)); - histoflags(b,j) = nnz(C); - end + for j=1:16 + C = bitand(flagbit(j), oldflag(b,:)); + histoflags(b,j) = nnz(C); + end end diff --git a/images/EstudioLogo.jpg b/images/EstudioLogo.jpg new file mode 100644 index 00000000..37d891b5 Binary files /dev/null and b/images/EstudioLogo.jpg differ diff --git a/images/EstudioLogo.png b/images/EstudioLogo.png new file mode 100644 index 00000000..8299485a Binary files /dev/null and b/images/EstudioLogo.png differ diff --git a/pop_functions/pop_DQ_preavg.m b/pop_functions/pop_DQ_preavg.m index c7686e35..968a2288 100755 --- a/pop_functions/pop_DQ_preavg.m +++ b/pop_functions/pop_DQ_preavg.m @@ -1,4 +1,4 @@ -% Purpose: Outputs DQ Table on Epoched Dataset (not ERP) +% Purpose: Outputs DQ Table on Epoched Dataset (not ERP) % % Format : % @@ -11,16 +11,16 @@ % -function pop_DQ_preavg(ALLEEG, varargin) +function pop_DQ_preavg(ALLEEG, varargin) -%ERP = preloadERP; +%ERP = preloadERP; if nargin < 1 help pop_DQ_preavg return end -if isobject(ALLEEG) % eegobj +if isobject(ALLEEG) % eegobj whenEEGisanObject return end @@ -36,16 +36,16 @@ function pop_DQ_preavg(ALLEEG, varargin) end % read values in memory for this function - def = erpworkingmemory('pop_DQ_preavg'); + def = erpworkingmemory('pop_DQ_preavg'); % def{1} - dataset indx, def{2} - artcrit, def{3} - wavg, def{4} - stderror, def{5} - exclude boundaries, % def{6} - ERP type, def{7} - wintaper type, def{8} - wintaper function, - % def{9} - data quality flag, def{10} - DQ_spec_structure, + % def{9} - data quality flag, def{10} - DQ_spec_structure, % def{11} - DQ pre-avg flag, def {12} - DQ_custom_wins - - if isempty(def) || numel(def)~=12 + + if isempty(def) || numel(def)~=12 % Should not be empty, and have exactly 12 elements. Else, fallback to: - def = {1 1 1 1 1 0 0 [] 1 [] 1 0}; + def = {1 1 1 1 1 0 0 [] 1 [] 1 0}; end @@ -69,7 +69,7 @@ function pop_DQ_preavg(ALLEEG, varargin) answer = DQ_preavg(currdata, def, nepochperdata, timelimits); - + if isempty(answer) disp('User selected Cancel') return @@ -78,10 +78,10 @@ function pop_DQ_preavg(ALLEEG, varargin) if numel(setindex) > 1 disp('This tool cannot consider more than one .set file at a time!') - return + return end - + % % Artifact rejection criteria for averaging @@ -120,7 +120,7 @@ function pop_DQ_preavg(ALLEEG, varargin) % Write the analytic Standardized Measurment Error info DQ_flag = answer{9}; DQ_spec = answer{10}; - DQ_preavg_txt = answer{11}; + DQ_preavg_txt = answer{11}; DQcustom_wins = answer{12}; % store setting in erplab working memory @@ -150,28 +150,16 @@ function pop_DQ_preavg(ALLEEG, varargin) 'DQ_flag',DQ_flag,'DQ_spec',DQ_spec, 'DQ_preavg_txt', DQ_preavg_txt,'DQ_custom_wins', DQcustom_wins, 'History', ''); - pause(0.1); + pause(0.1); %Here, pass hidden ERP struct to DQTableGUI - ALLERP = []; - CURRENTPREAVG = 1; + ALLERP = []; + CURRENTPREAVG = 1; ERPpreavg.erpname = ALLEEG(setindex).setname; %setname instead of erpname in DQ Table - DQ_Table_GUI(ERPpreavg,ALLERP,CURRENTPREAVG,1); + DQ_Table_GUI(ERPpreavg,ALLERP,CURRENTPREAVG,1); end - - - - - - - - - - - - -end \ No newline at end of file +end \ No newline at end of file diff --git a/pop_functions/pop_ERP_simulation.m b/pop_functions/pop_ERP_simulation.m old mode 100644 new mode 100755 diff --git a/pop_functions/pop_artextval.m b/pop_functions/pop_artextval.m index 047102ce..5318d5e9 100755 --- a/pop_functions/pop_artextval.m +++ b/pop_functions/pop_artextval.m @@ -108,7 +108,7 @@ ampth = answer{2}; chanArray = unique_bc2(answer{3}); % avoids repeated channels lpfilt = answer{4}; - lpopt = answer{5} + lpopt = answer{5}; flag = answer{6}; viewer = answer{end}; diff --git a/pop_functions/pop_artinterp.m b/pop_functions/pop_artinterp.m index c17849a7..82fd6e4c 100755 --- a/pop_functions/pop_artinterp.m +++ b/pop_functions/pop_artinterp.m @@ -7,7 +7,7 @@ % INPUTS : % % EEG - input dataset -% +% % [EEG, com] = pop_artinterp(EEG, 'FlagToUse', replaceFlag, 'InterpMethod', interpolationMethod, ... % 'ChanToInterp', replaceChannelInd, ... % 'ChansToIgnore', ignoreChannels); @@ -20,14 +20,14 @@ % 'InterpMethod' - [string] method used for interpolation (default is 'spherical'). % 'invdist'/'v4' uses inverse distance on the scalp % 'spherical' uses superfast spherical interpolation. -% 'ChanToInterp' - [integer] Index of channel to interpolate. +% 'ChanToInterp' - [integer] Index of channel to interpolate. % 'ChansToIgnore' - [integer array] Do not include these electrodes % as input for interpolation. % 'InterpAnyChan' - default = 0; If 1, all channels that are flagged with artifacts % will be interpolated IF no more than THRESHOLD % percent of channels are flagged -% 'Threshold' - default = 10%; if greater than X% of channels are flagged, -% then interpolation routine will NOT work for that epoch +% 'Threshold' - default = 10%; if greater than X% of channels are flagged, +% then interpolation routine will NOT work for that epoch % % % OUTPUTS : @@ -73,112 +73,112 @@ function [EEG, com] = pop_artinterp(EEG, varargin) com = ''; if nargin<1 - help pop_artinterp - return + help pop_artinterp + return end if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if nargin==1 - serror = erplab_eegscanner(EEG, 'pop_artinterp', 2, 0, 1, 2, 1); - if serror - return - end - - dlg_title = {'Interpolate Flagged Artifact Epochs'}; - - %defaults - defx = {0, 'spherical',[],[],[],0,10}; - %first pos: no previous flag selected - %second pos: no previous method selected (default to 'spherical') - %third pos: no prev electrode selected (should agree with fourth pos) - %fourth pos: no prev "channel-label" selected (should agree with third pos) - %fifth pos: no prev "channels" to ignore - %sixth pos: set to 0 = "interpolate only one" electrode option - %seventh pos: set to 10% default threshold (of artifacts across - % electrode) for 'any electrode interpolation' option - %eigth pos: set [] default, for measurment channel rule - - %take previously selected electrodes and flags used from previous - % artinterp() usage? - def = erpworkingmemory('pop_artinterp'); - - if isempty(def) - def = defx; - else - %make sure that electrode number exists in current list of - %available channels - %def{1} = def{1}(ismember_bc2(def{1},1:EEG(1).nbchan)); - def{3} = def{3}(ismember_bc2(def{3},1:EEG(1).nbchan)); - end - - try - chanlabels = {EEG(1).chanlocs.labels}; %only works on single datasets - catch - chanlabels = []; - end - - - - histoflags = summary_rejectflags(EEG); - - %check currently activated flags - flagcheck = sum(histoflags); - active_flags = (flagcheck>1); - - % def{end} = active_flags; - - - % - % Call GUI - % - answer = artifactinterpGUI(dlg_title, def, defx, chanlabels, active_flags); - - if isempty(answer) - disp('User selected Cancel') - return - end - - replaceFlag = answer{1}; - interpolationMethod = answer{2}; - replaceChannelInd = answer{3}; - replaceChannelLabel = answer{4}; - ignoreChannels = unique_bc2(answer{5}); % avoids repeted channels - many_electrodes = answer{6}; - threshold_perc = answer{7}; - % measurement_chan = answer{8}; - - % displayEEG = answer{6}; %no display EEG for now - % viewer = answer{end}; %no viewer for Now - - viewer = 0; % no viewer - if viewer - viewstr = 'on'; - else - viewstr = 'off'; - end - if ~isempty(find(replaceFlag<1 | replaceFlag>16, 1)) - msgboxText{1} = 'ERROR, flag cannot be greater than 16 nor lesser than 1'; - title = 'ERPLAB: Flag input'; - errorfound(msgboxText, title); - return - end - erpworkingmemory('pop_artinterp', {answer{1} answer{2} answer{3} answer{4} answer{5} ... - answer{6}, answer{7}}); - - if length(EEG)==1 - EEG.setname = [EEG.setname '_arInterp']; %suggest a new name - end - - % - % Somersault - % - [EEG, com] = pop_artinterp(EEG, 'FlagToUse', replaceFlag, 'InterpMethod', interpolationMethod, ... - 'ChanToInterp', replaceChannelInd, 'ChansToIgnore', ignoreChannels, ... - 'InterpAnyChan', many_electrodes, 'Threshold',threshold_perc,... - 'Review', viewstr, 'History', 'gui'); + serror = erplab_eegscanner(EEG, 'pop_artinterp', 2, 0, 1, 2, 1); + if serror return + end + + dlg_title = {'Interpolate Flagged Artifact Epochs'}; + + %defaults + defx = {0, 'spherical',[],[],[],0,10}; + %first pos: no previous flag selected + %second pos: no previous method selected (default to 'spherical') + %third pos: no prev electrode selected (should agree with fourth pos) + %fourth pos: no prev "channel-label" selected (should agree with third pos) + %fifth pos: no prev "channels" to ignore + %sixth pos: set to 0 = "interpolate only one" electrode option + %seventh pos: set to 10% default threshold (of artifacts across + % electrode) for 'any electrode interpolation' option + %eigth pos: set [] default, for measurment channel rule + + %take previously selected electrodes and flags used from previous + % artinterp() usage? + def = erpworkingmemory('pop_artinterp'); + + if isempty(def) + def = defx; + else + %make sure that electrode number exists in current list of + %available channels + %def{1} = def{1}(ismember_bc2(def{1},1:EEG(1).nbchan)); + def{3} = def{3}(ismember_bc2(def{3},1:EEG(1).nbchan)); + end + + try + chanlabels = {EEG(1).chanlocs.labels}; %only works on single datasets + catch + chanlabels = []; + end + + + + histoflags = summary_rejectflags(EEG); + + %check currently activated flags + flagcheck = sum(histoflags); + active_flags = (flagcheck>1); + + % def{end} = active_flags; + + + % + % Call GUI + % + answer = artifactinterpGUI(dlg_title, def, defx, chanlabels, active_flags); + + if isempty(answer) + disp('User selected Cancel') + return + end + + replaceFlag = answer{1}; + interpolationMethod = answer{2}; + replaceChannelInd = answer{3}; + replaceChannelLabel = answer{4}; + ignoreChannels = unique_bc2(answer{5}); % avoids repeted channels + many_electrodes = answer{6}; + threshold_perc = answer{7}; + % measurement_chan = answer{8}; + + % displayEEG = answer{6}; %no display EEG for now + % viewer = answer{end}; %no viewer for Now + + viewer = 0; % no viewer + if viewer + viewstr = 'on'; + else + viewstr = 'off'; + end + if ~isempty(find(replaceFlag<1 | replaceFlag>16, 1)) + msgboxText{1} = 'ERROR, flag cannot be greater than 16 nor lesser than 1'; + title = 'ERPLAB: Flag input'; + errorfound(msgboxText, title); + return + end + erpworkingmemory('pop_artinterp', {answer{1} answer{2} answer{3} answer{4} answer{5} ... + answer{6}, answer{7}}); + + if length(EEG)==1 + EEG.setname = [EEG.setname '_arInterp']; %suggest a new name + end + + % + % Somersault + % + [EEG, com] = pop_artinterp(EEG, 'FlagToUse', replaceFlag, 'InterpMethod', interpolationMethod, ... + 'ChanToInterp', replaceChannelInd, 'ChansToIgnore', ignoreChannels, ... + 'InterpAnyChan', many_electrodes, 'Threshold',threshold_perc,... + 'Review', viewstr, 'History', 'gui'); + return end % @@ -193,14 +193,14 @@ t2 = single(EEG(1).xmax*1000); %p.addParamValue('Twindow', [t1 t2], @isnumeric); %p.addParamValue('Channels', 1:EEG(1).nbchan, @isnumeric); %all channels -p.addParamValue('FlagToUse', 0, @isnumeric); -p.addParamValue('InterpMethod', 'spherical', @ischar); +p.addParamValue('FlagToUse', 0, @isnumeric); +p.addParamValue('InterpMethod', 'spherical', @ischar); p.addParamValue('ChanToInterp', 0, @isnumeric); %%%%%%%%%%%%% <<<< %p.addParamValue('ChanLabel', 'none', @ischar); -p.addParamValue('ChansToIgnore', [], @isnumeric); +p.addParamValue('ChansToIgnore', [], @isnumeric); p.addParamValue('InterpAnyChan', 0,@isnumeric); -p.addParamValue('Threshold', 10, @isnumeric); %percentage value -%p.addParamValue('MeasurementChanIdx',[],@isnumeric); +p.addParamValue('Threshold', 10, @isnumeric); %percentage value +%p.addParamValue('MeasurementChanIdx',[],@isnumeric); p.addParamValue('Review', 'off', @ischar); % to open a window with the marked epochs %p.addParamValue('Flag', 1, @isnumeric); %param for things to-be flagged p.addParamValue('History', 'script', @ischar); % history from scripting @@ -209,37 +209,37 @@ replaceFlag = p.Results.FlagToUse; interpolationMethod = p.Results.InterpMethod; -replaceChannelInd = p.Results.ChanToInterp; +replaceChannelInd = p.Results.ChanToInterp; %replaceChannelLabel = p.Results.ChanLabel; -ignoreChannels = p.Results.ChansToIgnore; -many_electrodes = p.Results.InterpAnyChan; -threshold_perc = p.Results.Threshold; -%meas_chan = p.Results.MeasurementChanIdx; +ignoreChannels = p.Results.ChansToIgnore; +many_electrodes = p.Results.InterpAnyChan; +threshold_perc = p.Results.Threshold; +%meas_chan = p.Results.MeasurementChanIdx; %flag = p.Results.Flag; -displayEEG = p.Results.Review; +displayEEG = p.Results.Review; if strcmpi(p.Results.Review, 'on')% to open a window with the marked epochs - eprev = 1; + eprev = 1; else - eprev = 0; + eprev = 0; end if ~isempty(find(ignoreChannels<1 | ignoreChannels>EEG(1).nbchan, 1)) - error('ERPLAB says: error at pop_artstep(). Channel indices cannot be greater than EEG.nbchan') + error('ERPLAB says: error at pop_artstep(). Channel indices cannot be greater than EEG.nbchan') end if ~isempty(find(replaceFlag<1 | replaceFlag>16, 1)) - error('ERPLAB says: error at pop_artstep(). Flag cannot be greater than 16 or lesser than 1') + error('ERPLAB says: error at pop_artstep(). Flag cannot be greater than 16 or lesser than 1') end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end % @@ -258,25 +258,25 @@ -%% first, index the epochs to interpolate based on the flag used -ntrial = EEG.trials; %number of original trials -oldflag = zeros(1,ntrial); +%% first, index the epochs to interpolate based on the flag used +ntrial = EEG.trials; %number of original trials +oldflag = zeros(1,ntrial); for i = 1:ntrial if length(EEG.epoch(i).eventlatency) == 1 - flagx = [EEG.epoch(i).eventflag]; + flagx = [EEG.epoch(i).eventflag]; - if iscell(flagx) - flagx = cell2mat(flagx) + if iscell(flagx) + flagx = cell2mat(flagx); end oldflag(i) = flagx; - + elseif length(EEG.epoch(i).eventlatency) > 1 - indxtimelock = find(cell2mat(EEG.epoch(i).eventlatency) == 0,1,'first');% catch zero-time locked type - oldflag(i) = EEG.epoch(i).eventflag{indxtimelock}; - + indxtimelock = find(cell2mat(EEG.epoch(i).eventlatency) == 0,1,'first');% catch zero-time locked type + oldflag(i) = EEG.epoch(i).eventflag{indxtimelock}; + end @@ -285,43 +285,39 @@ % filter oldflag by specified flag flagbit = bitshift(1,0:15); -flagged_epochs = bitand(flagbit(replaceFlag), oldflag); +flagged_epochs = bitand(flagbit(replaceFlag), oldflag); epoch_ind = find(flagged_epochs); %list of index of epochs, filtered by specified flag, to interpolate -%% interpolate only the epochs with the specified flag -N_interpolate = numel(epoch_ind); - +%% interpolate only the epochs with the specified flag - -for e = 1:N_interpolate - - tmpEEG = EEG; %temp EEG struct - - - tmpEEG.data = tmpEEG.data(:,:,epoch_ind(e)); %index current epoch - tmpEEG.trials = 1; %update temp single trial EEG struct - all_chans = EEG.reject.rejmanualE(:,epoch_ind(e)); - - ignoreChannelsE = ignoreChannels; - chanlocs = tmpEEG.chanlocs; +if many_electrodes == 1 - %skip epoch if the channel to be interpolated is itself a not-real - %channel (i.e. no theta information) - nonemptychans = find(~cellfun('isempty', { chanlocs.theta })); + epoch_ind = find(flagged_epochs); %list of index of epochs, filtered by specified flag, to interpolate + %% interpolate only the epochs with the specified flag + N_interpolate = numel(epoch_ind); - - if many_electrodes == 1 + for e = 1:N_interpolate + + tmpEEG = EEG; %temp EEG struct + tmpEEG.data = tmpEEG.data(:,:,epoch_ind(e)); %index current epoch + tmpEEG.trials = 1; %update temp single trial EEG struct + all_chans = EEG.reject.rejmanualE(:,epoch_ind(e)); + ignoreChannelsE = ignoreChannels; + chanlocs = tmpEEG.chanlocs; + %skip epoch if the channel to be interpolated is itself a not-real + %channel (i.e. no theta information) + nonemptychans = find(~cellfun('isempty', { chanlocs.theta })); chans_to_interp = find(all_chans)'; - + %skip channels to be interpolated is itself a not-real %channel (i.e. no theta information) - [~,chan_ind ] = intersect_bc(chans_to_interp,nonemptychans); - chans_to_interp2 = chans_to_interp(chan_ind); + [~,chan_ind ] = intersect_bc(chans_to_interp,nonemptychans); + chans_to_interp2 = chans_to_interp(chan_ind); if isempty(chans_to_interp2) @@ -330,8 +326,6 @@ continue end - - %fix redundancies between chan_to_interp & ignore channels if any(ismember(chans_to_interp,ignoreChannels)) @@ -352,9 +346,6 @@ continue else - - - fprintf('\nInterpolating epoch #%s by flag %s \n', num2str(epoch_ind(e)), ... num2str(replaceFlag)); @@ -366,76 +357,91 @@ %reset flag at EEG.reject.manual EEG.reject.rejmanual(epoch_ind(e)) = 0; - - - - end - - - - else - %one electrode case - - %skip channels to be interpolated is itself a not-real - %channel (i.e. no theta information) - [~,chan_ind ] = intersect_bc(replaceChannelInd,nonemptychans); - replaceChannelInd2 = replaceChannelInd(chan_ind); - - if isempty(replaceChannelInd2) - fprintf('\nSkipping epoch #%s since the channel(s) #%i to be interpolated are not real channels (no channel location theta info)', ... - num2str(epoch_ind(e)), replaceChannelInd); - continue - end - - %fix redundancies between chan_to_interp & ignore channels - if ismember(replaceChannelInd,ignoreChannels) - ignoreChannelsE = setdiff(ignoreChannels, replaceChannelInd); - end - - %fix ignoreChannels to not include channels that are bad (unless it's the chosen channel)! - include_to_ignore = double(find(all_chans)'); + %re-add interpolated temp EEG epoch into original EEG + EEG.data(:,:,epoch_ind(e)) = tmpEEG.data; + end +else + epochrej1 = EEG.reject.rejmanualE(replaceChannelInd,:); + [~,epoch_ind1] = find(epochrej1==1); + epoch_ind= intersect(epoch_ind,epoch_ind1); + N_interpolate = numel(epoch_ind); + + for e = 1:N_interpolate + tmpEEG = EEG; %temp EEG struct + tmpEEG.data = tmpEEG.data(:,:,epoch_ind(e)); %index current epoch + tmpEEG.trials = 1; %update temp single trial EEG struct + all_chans = EEG.reject.rejmanualE(:,epoch_ind(e)); - if replaceChannelInd ~= include_to_ignore - ignoreChannelsE = cat(2,ignoreChannelsE, include_to_ignore); - end + ignoreChannelsE = ignoreChannels; + chanlocs = tmpEEG.chanlocs; - %adjust bad channel count with updated ignored channels - total_chans = numel(all_chans) - numel(ignoreChannelsE); + %skip epoch if the channel to be interpolated is itself a not-real + %channel (i.e. no theta information) + nonemptychans = find(~cellfun('isempty', { chanlocs.theta })); - - if sum(all_chans)/(total_chans) >= (threshold_perc/100) + %one electrode case + if EEG.reject.rejmanualE(replaceChannelInd,epoch_ind(e))==1%%GH May 2024 + %skip channels to be interpolated is itself a not-real + %channel (i.e. no theta information) + [~,chan_ind ] = intersect_bc(replaceChannelInd,nonemptychans); + replaceChannelInd2 = replaceChannelInd(chan_ind); - fprintf('\nSkipping epoch #%s by flag %s since amount of channels with artifact threshold %i percent exceeded\n', ... - num2str(epoch_ind(e)),num2str(replaceFlag), threshold_perc); + if isempty(replaceChannelInd2) + fprintf('\nSkipping epoch #%s since the channel(s) #%i to be interpolated are not real channels (no channel location theta info)', ... + num2str(epoch_ind(e)), replaceChannelInd); + continue + end - continue - else + %fix redundancies between chan_to_interp & ignore channels + if ismember(replaceChannelInd,ignoreChannels) + ignoreChannelsE = setdiff(ignoreChannels, replaceChannelInd); + end + + %fix ignoreChannels to not include channels that are bad (unless it's the chosen channel)! + include_to_ignore = double(find(all_chans)'); + + + if replaceChannelInd ~= include_to_ignore + ignoreChannelsE = cat(2,ignoreChannelsE, include_to_ignore); + end + %adjust bad channel count with updated ignored channels +% total_chans = numel(all_chans) - numel(ignoreChannelsE); + + + % if sum(all_chans)/(total_chans) >= (threshold_perc/100) + % fprintf('\nSkipping epoch #%s by flag %s since amount of channels with artifact threshold %i percent exceeded\n', ... + % num2str(epoch_ind(e)),num2str(replaceFlag), threshold_perc); + % continue + % else + % fprintf('\nInterpolating epoch #%s by flag %s \n', num2str(epoch_ind(e)), ... num2str(replaceFlag)); fprintf('\nFlag for epoch %s has been reset in EEG.rejmanual \n', num2str(epoch_ind(e))); - tmpEEG = erplab_interpolateElectrodes(tmpEEG, replaceChannelInd, ... ignoreChannelsE,interpolationMethod); - %reset flag at EEG.reject.manual - EEG.reject.rejmanual(epoch_ind(e)) = 0; + %reset flag at EEG.reject.manual%%GH May 2024 + EEG.reject.rejmanualE(replaceChannelInd,epoch_ind(e))=0; + [xpos,~] = find(EEG.reject.rejmanualE(:,epoch_ind(e))==1); + if isempty(xpos) + EEG.reject.rejmanual(epoch_ind(e)) = 0; + end + % end + + %re-add interpolated temp EEG epoch into original EEG + EEG.data(:,:,epoch_ind(e)) = tmpEEG.data; end - end - - - %re-add interpolated temp EEG epoch into original EEG - EEG.data(:,:,epoch_ind(e)) = tmpEEG.data; - end + % transfer the EEG.reject artifact marks to EVENTLIST EEG = pop_syncroartifacts(EEG, 'Direction','eeglab2erplab'); % GUI: 30-May-2023 21:02:55 @@ -443,8 +449,8 @@ fprintf('\n'); if N_interpolate == 0 + warning('on'); warning('No epochs were actually flagged, so no epochs were interpolated!'); - else % performance @@ -460,9 +466,9 @@ com = sprintf( '%s = pop_artinterp( %s ', inputname(1), inputname(1)); if many_electrodes idx= strcmp(fn,'ChanToInterp'); - fn(idx) = []; + fn(idx) = []; end - + for q=1:length(fn) fn2com = fn{q}; diff --git a/pop_functions/pop_basicfilter.m b/pop_functions/pop_basicfilter.m index 4590066e..a3fa71d1 100755 --- a/pop_functions/pop_basicfilter.m +++ b/pop_functions/pop_basicfilter.m @@ -76,9 +76,7 @@ function [EEG, com] = pop_basicfilter( EEG, chanArray, varargin) com = ''; if exist('filtfilt','file') ~= 2 - msgboxText = ['ERPLAB''s filtering functions require the Matlab Signal Processing Toolbox.' ... - 'You do not appear to have this toolbox installed. The Signal Processing Toolbox can be purchased from The Mathworks (but it may be included in your institution''s license for no additional cost).'... - 'If you do not know how to obtain or install it, please contact your system administrator.']; + msgboxText = 'cannot find the signal processing toolbox'; title = 'ERPLAB: pop_basicfilter() error'; errorfound(msgboxText, title); return diff --git a/pop_functions/pop_blcerp.m b/pop_functions/pop_blcerp.m index c14cb03f..cedef571 100755 --- a/pop_functions/pop_blcerp.m +++ b/pop_functions/pop_blcerp.m @@ -2,16 +2,16 @@ % % FORMAT : % -% ERP = pop_blcerp(ERP, blc) +% ERP = pop_blcerp(ERP, 'Baseline',blc) % % ERP - ERPLAB structure % blc - window for baseline correction in msec or either a string like 'pre', 'post', or 'all' % (strings with the baseline interval also works. e.g. '-300 100') % % Example : -% >> ERP = pop_blcerp( ERP , [-200 800], [-100 0]); -% >> ERP = pop_blcerp( ERP , [-200 800], '-100 0'); -% >> ERP = pop_blcerp( ERP , [-400 2000], 'post'); +% >> ERP = pop_blcerp( ERP , [-200 800], 'Baseline', [-100 0]); +% >> ERP = pop_blcerp( ERP , [-200 800], 'Baseline', '-100 0'); +% >> ERP = pop_blcerp( ERP , [-400 2000], 'Baseline', 'post'); % % INPUTS : % @@ -91,10 +91,13 @@ end blcorr = answer{1}; + ChanArray = answer{2}; + BinArray = answer{3}; % % Somersault % - [ERP, erpcom] = pop_blcerp(ERP, 'Baseline', blcorr, 'Saveas', 'on', 'History', 'gui'); + [ERP, erpcom] = pop_blcerp(ERP, 'Baseline', blcorr,'ChanArray',ChanArray,... + 'BinArray',BinArray,'Saveas', 'on', 'History', 'gui'); return end @@ -108,9 +111,22 @@ % option(s) p.addParamValue('Baseline', 'pre'); % erpset index or input file p.addParamValue('Saveas', 'off', @ischar); % 'on', 'off' +p.addParamValue('ChanArray', [], @isnumeric); +p.addParamValue('BinArray', [], @isnumeric); p.addParamValue('History', 'script', @ischar); % history from scripting p.parse(ERP, varargin{:}); +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; +end + + +BinArray = p.Results.BinArray; +if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = [1:ERP.nbin]; +end + @@ -192,6 +208,8 @@ ERPaux = ERP; % original ERP nbin = ERP.nbin; + + % % baseline correction 01-14-2009 % @@ -213,6 +231,18 @@ ERP.saved = 'no'; % erpcom = sprintf('%s = pop_blcerp( %s, %s);', inputname(1), inputname(1), blcorrcomm); +ChanArrayleft = setdiff([1:ERP.nchan],ChanArray);%% channles are not for baseline correction +if ~isempty(ChanArrayleft) + ERP.bindata(ChanArrayleft,:,:) = ERPaux.bindata(ChanArrayleft,:,:); +end + + +BinArrayleft = setdiff([1:ERP.nbin],BinArray);%% bins are not for baseline correction +if ~isempty(BinArrayleft) + ERP.bindata(:,:,BinArrayleft) = ERPaux.bindata(:,:,BinArrayleft); +end + + % % History % diff --git a/pop_functions/pop_creabasiceventlist.m b/pop_functions/pop_creabasiceventlist.m index 3b609ed4..15ff9d9d 100755 --- a/pop_functions/pop_creabasiceventlist.m +++ b/pop_functions/pop_creabasiceventlist.m @@ -65,88 +65,88 @@ function [EEG, com] = pop_creabasiceventlist(EEG, varargin) com = ''; if nargin < 1 - help pop_creabasiceventlist - return + help pop_creabasiceventlist + return end if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if nargin==1 - serror = erplab_eegscanner(EEG, 'pop_creabasiceventlist', 2, 0, 0, 0, 2); - if serror - return - end - if isfield(EEG(1).event, 'type') - if ~all(cellfun(@isnumeric, { EEG(1).event.type })) - msgboxText = ['Some or all of your events contain a text-based event label, '... - 'and not a numeric event code.\n\nERPLAB must have a numeric code '... - 'for every event (a text label can also be present). For labels such as "S14", '... - 'you can automatically create an equivalent numeric event code (e.g., 14) by '... - 'checking the box labeled "Create numeric equivalents of nonnumeric event codes '... - 'when possible" when creating the EventList.\n\nFor labels that cannot be automatically '... - 'converted (e.g., "RESP"), or for ambiguous cases (e.g., when you have both "S14" and '... - '"R14"), you can flexibly create numeric versions using the Advanced button at EVENTLIST GUI.\n']; - - title_msg = 'ERPLAB: Warning'; - %button = askquest(sprintf(msgboxText), title_msg); - button = askquestpoly(sprintf(msgboxText), title_msg, {'Continue'}); - if ~strcmpi(button,'Continue') - disp('User selected Cancel') - return - end - end - end - - def = erpworkingmemory('pop_creabasiceventlist'); - if isempty(def) - def = {'' 'boundary' -99 1 1}; - end - - % - % Call GUI - % - if length(EEG)>1 - multieeg = 1; % when multi eeg - else - multieeg = 0; % just single eeg - end - inputstrMat = creabasiceventlistGUI(def, multieeg); % GUI - - if isempty(inputstrMat) && ~strcmp(inputstrMat,'') + serror = erplab_eegscanner(EEG, 'pop_creabasiceventlist', 2, 0, 0, 0, 2); + if serror + return + end + if isfield(EEG(1).event, 'type') + if ~all(cellfun(@isnumeric, { EEG(1).event.type })) + msgboxText = ['Some or all of your events contain a text-based event label, '... + 'and not a numeric event code.\n\nERPLAB must have a numeric code '... + 'for every event (a text label can also be present). For labels such as "S14", '... + 'you can automatically create an equivalent numeric event code (e.g., 14) by '... + 'checking the box labeled "Create numeric equivalents of nonnumeric event codes '... + 'when possible" when creating the EventList.\n\nFor labels that cannot be automatically '... + 'converted (e.g., "RESP"), or for ambiguous cases (e.g., when you have both "S14" and '... + '"R14"), you can flexibly create numeric versions using the Advanced button at EVENTLIST GUI.\n']; + + title_msg = 'ERPLAB: Warning'; + %button = askquest(sprintf(msgboxText), title_msg); + button = askquestpoly(sprintf(msgboxText), title_msg, {'Continue'}); + if ~strcmpi(button,'Continue') disp('User selected Cancel') return - elseif strcmp(inputstrMat,'advanced') - %[EEG, com ] = pop_editeventlist(EEG, 'History', 'off'); - [EEG, com ] = pop_editeventlist(EEG); - return - end - - elname = inputstrMat{1}; - boundarystrcode = inputstrMat{2}; - newboundarynumcode = inputstrMat{3}; - rwwarn = inputstrMat{4}; - alphanum = inputstrMat{5}; - - erpworkingmemory('pop_creabasiceventlist', {elname, boundarystrcode, newboundarynumcode, rwwarn, alphanum}); - - if rwwarn==1 - striswarning = 'on'; - else - striswarning = 'off'; - end - if alphanum==1 - stralphanum = 'on'; - else - stralphanum = 'off'; - end - if length(EEG)==1 - EEG.setname = [EEG.setname '_elist']; %suggest a new name + end end - - [EEG, com] = pop_creabasiceventlist(EEG, 'Eventlist', elname, 'BoundaryString', boundarystrcode,... - 'BoundaryNumeric', newboundarynumcode,'Warning', striswarning, 'AlphanumericCleaning', stralphanum, 'History', 'gui'); + end + + def = erpworkingmemory('pop_creabasiceventlist'); + if isempty(def) + def = {'' 'boundary' -99 1 1}; + end + + % + % Call GUI + % + if length(EEG)>1 + multieeg = 1; % when multi eeg + else + multieeg = 0; % just single eeg + end + inputstrMat = creabasiceventlistGUI(def, multieeg); % GUI + + if isempty(inputstrMat) && ~strcmp(inputstrMat,'') + disp('User selected Cancel') + return + elseif strcmp(inputstrMat,'advanced') + %[EEG, com ] = pop_editeventlist(EEG, 'History', 'off'); + [EEG, com ] = pop_editeventlist(EEG); return + end + + elname = inputstrMat{1}; + boundarystrcode = inputstrMat{2}; + newboundarynumcode = inputstrMat{3}; + rwwarn = inputstrMat{4}; + alphanum = inputstrMat{5}; + + erpworkingmemory('pop_creabasiceventlist', {elname, boundarystrcode, newboundarynumcode, rwwarn, alphanum}); + + if rwwarn==1 + striswarning = 'on'; + else + striswarning = 'off'; + end + if alphanum==1 + stralphanum = 'on'; + else + stralphanum = 'off'; + end + if length(EEG)==1 + EEG.setname = [EEG.setname '_elist']; %suggest a new name + end + + [EEG, com] = pop_creabasiceventlist(EEG, 'Eventlist', elname, 'BoundaryString', boundarystrcode,... + 'BoundaryNumeric', newboundarynumcode,'Warning', striswarning, 'AlphanumericCleaning', stralphanum, 'History', 'gui'); + return end % @@ -173,49 +173,49 @@ newboundarynumcode_old = p.Results.Newboundary; % new numeric code for replacing string boundaries (old versions) if isempty(boundarystrcode_old) - boundarystrcode = p.Results.BoundaryString; % current string for boundaries + boundarystrcode = p.Results.BoundaryString; % current string for boundaries else - boundarystrcode = boundarystrcode_old; % current string for boundaries + boundarystrcode = boundarystrcode_old; % current string for boundaries end if isempty(newboundarynumcode_old) - newboundarynumcode = p.Results.BoundaryNumeric; % new numeric code for replacing string boundaries + newboundarynumcode = p.Results.BoundaryNumeric; % new numeric code for replacing string boundaries else - newboundarynumcode = newboundarynumcode_old; % new numeric code for replacing string boundaries - + newboundarynumcode = newboundarynumcode_old; % new numeric code for replacing string boundaries + end boundarystrcode = strtrim(boundarystrcode); boundarystrcode = regexprep(boundarystrcode, '''|"',''); if strcmpi(p.Results.Warning, 'on') - rwwarn = 1; + rwwarn = 1; else - rwwarn = 0; + rwwarn = 0; end if strcmpi(p.Results.AlphanumericCleaning, 'on') - alphanum = 1; + alphanum = 1; else - alphanum = 0; + alphanum = 0; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end % % process multiple datasets. Updated August 23, 2013 JLC % if length(EEG) > 1 - options1 = {'Eventlist', p.Results.Eventlist, 'BoundaryString', p.Results.BoundaryString,... - 'BoundaryNumeric', p.Results.BoundaryNumeric,'Warning', p.Results.Warning,... - 'AlphanumericCleaning', p.Results.AlphanumericCleaning, 'History', 'gui'}; - [ EEG, com ] = eeg_eval( 'pop_creabasiceventlist', EEG, 'warning', 'on', 'params', options1); - return; + options1 = {'Eventlist', p.Results.Eventlist, 'BoundaryString', p.Results.BoundaryString,... + 'BoundaryNumeric', p.Results.BoundaryNumeric,'Warning', p.Results.Warning,... + 'AlphanumericCleaning', p.Results.AlphanumericCleaning, 'History', 'gui'}; + [ EEG, com ] = eeg_eval( 'pop_creabasiceventlist', EEG, 'warning', 'on', 'params', options1); + return; end % @@ -225,108 +225,108 @@ auxEvent = EEG.event; if isfield(EEG, 'EVENTLIST') - auxEVENTLIST = EEG.EVENTLIST; % keep old EVENTLIST just in case - if rwwarn - if isfield(EEG.EVENTLIST, 'eventinfo') - if ~isempty(EEG.EVENTLIST.eventinfo) - if nargin==1 - question = ['dataset %s already has attached an EVENTLIST structure.\n'... - 'So, pop_creabasiceventlist() will totally overwrite it.\n'... - 'Do you want to continue anyway?']; - title = 'ERPLAB: binoperator, Overwriting Confirmation'; - button = askquest(sprintf(question, EEG.setname), title); - - if ~strcmpi(button,'yes') - disp('User selected Cancel') - return - end - else - fprintf('\n\nWARNING: Previous EVENTLIST structure will be overwritten.\n\n') - end - %if ischar(EEG.event(1).type) - % [ EEG.event.type ] = EEG.EVENTLIST.eventinfo.code; - %end - EEG.EVENTLIST = []; - end + auxEVENTLIST = EEG.EVENTLIST; % keep old EVENTLIST just in case + if rwwarn + if isfield(EEG.EVENTLIST, 'eventinfo') + if ~isempty(EEG.EVENTLIST.eventinfo) + if nargin==1 + question = ['dataset %s already has attached an EVENTLIST structure.\n'... + 'So, pop_creabasiceventlist() will totally overwrite it.\n'... + 'Do you want to continue anyway?']; + title = 'ERPLAB: binoperator, Overwriting Confirmation'; + button = askquest(sprintf(question, EEG.setname), title); + + if ~strcmpi(button,'yes') + disp('User selected Cancel') + return + end + else + fprintf('\n\nWARNING: Previous EVENTLIST structure will be overwritten.\n\n') end + %if ischar(EEG.event(1).type) + % [ EEG.event.type ] = EEG.EVENTLIST.eventinfo.code; + %end + EEG.EVENTLIST = []; + end end + end else - auxEVENTLIST = 'none'; + auxEVENTLIST = 'none'; end field2del = {'bepoch','bini','binlabel', 'code', 'codelabel','enable','flag','item'}; tf = ismember_bc2(field2del,fieldnames(EEG.event)'); if rwwarn && nnz(tf)>0 - question = ['The EEG.event field of %s contains subfield name(s) reserved for ERPLAB.\n\n'... - 'What would you like to do?\n\n']; - - BackERPLABcolor = [1 0.9 0.3]; % yellow - title = 'ERPLAB: pop_creabasiceventlist, Overwriting Confirmation'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question, EEG.setname), title,'Cancel','Overwrite them', 'Continue as it is', 'Overwrite them'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) - - if strcmpi(button,'Continue as it is') - fprintf('|WARNING: Fields found in EEG.event that has ERPLAB''s reserved names will not be overwritten.\n\n'); - elseif strcmpi(button,'Cancel') || strcmpi(button,'') - return - elseif strcmpi(button,'Overwrite them') - %bepoch bini binlabel codelabel duration enable flag item latency type urevent - EEG.event = rmfield(EEG.event, field2del(tf)); - fprintf('|WARNING: Fields found in EEG.event that has ERPLAB''s reserved names were overwritten.\n\n') - end + question = ['The EEG.event field of %s contains subfield name(s) reserved for ERPLAB.\n\n'... + 'What would you like to do?\n\n']; + + BackERPLABcolor = [1 0.9 0.3]; % yellow + title = 'ERPLAB: pop_creabasiceventlist, Overwriting Confirmation'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question, EEG.setname), title,'Cancel','Overwrite them', 'Continue as it is', 'Overwrite them'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + + if strcmpi(button,'Continue as it is') + fprintf('|WARNING: Fields found in EEG.event that has ERPLAB''s reserved names will not be overwritten.\n\n'); + elseif strcmpi(button,'Cancel') || strcmpi(button,'') + return + elseif strcmpi(button,'Overwrite them') + %bepoch bini binlabel codelabel duration enable flag item latency type urevent + EEG.event = rmfield(EEG.event, field2del(tf)); + fprintf('|WARNING: Fields found in EEG.event that has ERPLAB''s reserved names were overwritten.\n\n') + end end if alphanum==1 - alphanstr = 'on'; + alphanstr = 'on'; else - alphanstr = 'off'; + alphanstr = 'off'; end % Warning if rwwarn==0 - striswarning = 'off'; + striswarning = 'off'; else - striswarning = 'on'; + striswarning = 'on'; end % Send EVENTLIST to... if strcmp(elname,'') || strcmp(elname,'no') || strcmp(elname,'none') - stroption2do = 'EEG'; + stroption2do = 'EEG'; else - stroption2do = 'EEG&Text'; + stroption2do = 'EEG&Text'; end EEG = pop_editeventlist(EEG, 'SendEL2', stroption2do, 'ExportEL', elname,... - 'BoundaryString', boundarystrcode,'BoundaryNumeric', newboundarynumcode, 'Warning', striswarning,... - 'AlphanumericCleaning', alphanstr, 'History', 'off'); + 'BoundaryString', boundarystrcode,'BoundaryNumeric', newboundarynumcode, 'Warning', striswarning,... + 'AlphanumericCleaning', alphanstr, 'History', 'off'); EEG = pop_overwritevent(EEG, 'code', 'History', 'off'); if rwwarn - if ~all(cellfun(@isnumeric, { EEG.event.type })) - msgboxText = ['Some or all of your events still contain a text-based event label, '... - 'and not a numeric event code.\n\nERPLAB must have a numeric code '... - 'for every event (a text label can also be present). For labels such as "S14", '... - 'you can automatically create an equivalent numeric event code (e.g., 14) by '... - 'checking the box labeled "Create numeric equivalents of nonnumeric event codes '... - 'when possible" when creating the EventList.\n\nFor labels that cannot be automatically '... - 'converted (e.g., "RESP"), or for ambiguous cases (e.g., when you have both "S14" and '... - '"R14"), you can flexibly create numeric versions using the Advanced button at EVENTLIST GUI.\n\n'... - 'Would you like to continue anyway?']; - title_msg = 'ERPLAB: Warning'; - button = askquest(sprintf(msgboxText), title_msg); - - if ~strcmpi(button,'yes') - if isempty(auxEVENTLIST) || isstruct(auxEVENTLIST) - EEG.EVENTLIST = auxEVENTLIST; - else - EEG = rmfield(EEG, 'EVENTLIST'); - end - EEG.event = auxEvent; - disp('User selected Cancel') - return - end + if ~all(cellfun(@isnumeric, { EEG.event.type })) + msgboxText = ['Some or all of your events still contain a text-based event label, '... + 'and not a numeric event code.\n\nERPLAB must have a numeric code '... + 'for every event (a text label can also be present). For labels such as "S14", '... + 'you can automatically create an equivalent numeric event code (e.g., 14) by '... + 'checking the box labeled "Create numeric equivalents of nonnumeric event codes '... + 'when possible" when creating the EventList.\n\nFor labels that cannot be automatically '... + 'converted (e.g., "RESP"), or for ambiguous cases (e.g., when you have both "S14" and '... + '"R14"), you can flexibly create numeric versions using the Advanced button at EVENTLIST GUI.\n\n'... + 'Would you like to continue anyway?']; + title_msg = 'ERPLAB: Warning'; + button = askquest(sprintf(msgboxText), title_msg); + + if ~strcmpi(button,'yes') + if isempty(auxEVENTLIST) || isstruct(auxEVENTLIST) + EEG.EVENTLIST = auxEVENTLIST; + else + EEG = rmfield(EEG, 'EVENTLIST'); + end + EEG.event = auxEvent; + disp('User selected Cancel') + return end + end end % @@ -336,56 +336,56 @@ fn = fieldnames(p.Results); com = sprintf( '%s = pop_creabasiceventlist( %s ', inputname(1), inputname(1)); for q=1:length(fn) - fn2com = fn{q}; % get fieldname - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); % get content of current field - if ~isempty(fn2res) - if iscell(fn2res) - com = sprintf( '%s, ''%s'', {', com, fn2com); - for c=1:length(fn2res) - getcont = fn2res{c}; - if ischar(getcont) - fnformat = '''%s'''; - else - fnformat = '%s'; - getcont = num2str(getcont); - end - com = sprintf( [ '%s ' fnformat], com, getcont); - end - com = sprintf( '%s }', com); - else - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); - end - else - %if iscell(fn2res) - % fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - % fnformat = '{%s}'; - %else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - %end - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - end + fn2com = fn{q}; % get fieldname + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); % get content of current field + if ~isempty(fn2res) + if iscell(fn2res) + com = sprintf( '%s, ''%s'', {', com, fn2com); + for c=1:length(fn2res) + getcont = fn2res{c}; + if ischar(getcont) + fnformat = '''%s'''; + else + fnformat = '%s'; + getcont = num2str(getcont); + end + com = sprintf( [ '%s ' fnformat], com, getcont); + end + com = sprintf( '%s }', com); + else + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); + end + else + %if iscell(fn2res) + % fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + % fnformat = '{%s}'; + %else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + %end + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); end + end end + end end com = sprintf( '%s );', com); % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - otherwise %off or none - com = ''; + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + otherwise %off or none + com = ''; end @@ -395,6 +395,6 @@ prefunc = dbstack; nf = length(unique_bc2({prefunc.name})); if nf==1 - msg2end + msg2end end return \ No newline at end of file diff --git a/pop_functions/pop_currentsourcedensity.m b/pop_functions/pop_currentsourcedensity.m index 40f26ef5..1c4a327a 100755 --- a/pop_functions/pop_currentsourcedensity.m +++ b/pop_functions/pop_currentsourcedensity.m @@ -49,6 +49,11 @@ else isERP = 0; end +try + ERPtooltype = varargin{1};%%GH 2024 +catch + ERPtooltype = 'erplab'; +end % check input dataset try @@ -124,15 +129,19 @@ MapMontage(M) %%%changed by Guanghui August 10 2022 -csd_param = erpworkingmemory('csd_param'); -ERPtooltype = erpgettoolversion('tooltype'); if strcmpi(ERPtooltype,'EStudio') + csd_param = estudioworkingmemory('csd_param'); + if isempty(csd_param) + csd_param = [4,0.00001,10,1]; + estudioworkingmemory('csd_param',csd_param); + end csd_param(4) = 0; erpworkingmemory('csd_param',csd_param); csd_param = csd_param(1:3); savepref=0; else + csd_param = erpworkingmemory('csd_param'); [csd_param] = csd_generate; csd_param(4) = 1; erpworkingmemory('csd_param',csd_param); @@ -218,9 +227,15 @@ erpcom = 'pop_currentsourcedensity(EEG)'; end + +else%%GH Mar. 2024 + if isERP + EEG.bindata = csd_data; + erpcom = sprintf('%s=pop_currentsourcedensity(%s, %s);', 'ERP','ERP', ['"',varargin{1},'"']); + else + EEG.data = csd_data; + erpcom = sprintf('%s=pop_currentsourcedensity(%s, %s);', 'EEG','EEG', ['"',varargin{1},'"']); + end end - - -%eeglab redraw - +%eeglab redraw \ No newline at end of file diff --git a/pop_functions/pop_deleterpset.m b/pop_functions/pop_deleterpset.m index 20bbf243..81fe343f 100755 --- a/pop_functions/pop_deleterpset.m +++ b/pop_functions/pop_deleterpset.m @@ -27,65 +27,65 @@ function [ALLERP, erpcom] = pop_deleterpset(ALLERP, varargin) erpcom = ''; if nargin<1 - help pop_deleterpset + help pop_deleterpset end if nargin==1 - try - CURRENTERP = evalin('base', 'CURRENTERP'); - catch - CURRENTERP = 0; - end - if CURRENTERP == 0 - msgboxText = 'ERPsets menu is already empty...'; - title = 'ERPLAB: no erpset(s)'; - errorfound(msgboxText, title); - return - end - - prompt = {'Erpset(s) to clear:'}; - dlg_title = 'Delete erpset(s)'; - num_lines = 1; - def = {num2str(CURRENTERP)}; %01-13-2009 - - % - % open window - % - answer = inputvalue(prompt,dlg_title,num_lines,def); - - if isempty(answer) - disp('User selected Cancel') - return - end - - erpindex = str2num(answer{1}); - nerpset = length(ALLERP); - erpindex = unique_bc2(erpindex); - - if isempty(erpindex) - msgboxText = 'Wrong erpset index(es)'; - title = 'ERPLAB: unrecognizable erpset(s)'; - errorfound(msgboxText, title); - return - end - if max(erpindex)>nerpset || min(erpindex)<1 - erpm = findobj('tag', 'linerp'); - nerpmenu = length(erpm); - if max(erpindex)<=nerpmenu && nerpmenu>=1 && max(erpindex)>=1 - %... - else - msgboxText = ['Wrong erpset index(es)\n'... - 'Check your erpset menu or write length(ALLERP) at command window for comprobation']; - title = 'ERPLAB: pop_deleterpset not existing erpset(s)'; - errorfound(sprintf(msgboxText), title); - return - end - end - - % - % Somersault - % - [ALLERP, erpcom] = pop_deleterpset(ALLERP, 'Erpsets', erpindex, 'Saveas', 'on','History', 'gui'); + try + CURRENTERP = evalin('base', 'CURRENTERP'); + catch + CURRENTERP = 0; + end + if CURRENTERP == 0 + msgboxText = 'ERPsets menu is already empty...'; + title = 'ERPLAB: no erpset(s)'; + errorfound(msgboxText, title); return + end + + prompt = {'Erpset(s) to clear:'}; + dlg_title = 'Delete erpset(s)'; + num_lines = 1; + def = {num2str(CURRENTERP)}; %01-13-2009 + + % + % open window + % + answer = inputvalue(prompt,dlg_title,num_lines,def); + + if isempty(answer) + disp('User selected Cancel') + return + end + + erpindex = str2num(answer{1}); + nerpset = length(ALLERP); + erpindex = unique_bc2(erpindex); + + if isempty(erpindex) + msgboxText = 'Wrong erpset index(es)'; + title = 'ERPLAB: unrecognizable erpset(s)'; + errorfound(msgboxText, title); + return + end + if max(erpindex)>nerpset || min(erpindex)<1 + erpm = findobj('tag', 'linerp'); + nerpmenu = length(erpm); + if max(erpindex)<=nerpmenu && nerpmenu>=1 && max(erpindex)>=1 + %... + else + msgboxText = ['Wrong erpset index(es)\n'... + 'Check your erpset menu or write length(ALLERP) at command window for comprobation']; + title = 'ERPLAB: pop_deleterpset not existing erpset(s)'; + errorfound(sprintf(msgboxText), title); + return + end + end + + % + % Somersault + % + [ALLERP, erpcom] = pop_deleterpset(ALLERP, 'Erpsets', erpindex, 'Saveas', 'on','History', 'gui'); + return end % @@ -105,45 +105,45 @@ erpindex = p.Results.Erpsets; if strcmpi(p.Results.Warning,'on') - warnop = 1; + warnop = 1; else - warnop = 0; + warnop = 0; end if ismember_bc2({p.Results.Saveas}, {'on','yes'}) - issaveas = 1; + issaveas = 1; else - issaveas = 0; + issaveas = 0; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end nerpset = length(ALLERP); erpindex = unique_bc2(erpindex); if isempty(erpindex) - msgboxText = 'Wrong erpset index(es)'; - error(['ERPLAB says: ' msgboxText]) + msgboxText = 'Wrong erpset index(es)'; + error(['ERPLAB says: ' msgboxText]) end if max(erpindex)>nerpset || min(erpindex)<1 - msgboxText = 'Wrong erpset index(es)'; - error(['ERPLAB says: ' msgboxText]) + msgboxText = 'Wrong erpset index(es)'; + error(['ERPLAB says: ' msgboxText]) end detect = ~ismember_bc2(1:nerpset,erpindex); newindex = find(detect); if isempty(newindex) - ALLERP = []; + ALLERP = []; else - ALLERP = ALLERP(newindex); + ALLERP = ALLERP(newindex); end if issaveas - updatemenuerp(ALLERP, -1) - assignin('base','ALLERP',ALLERP); % save to workspace. Dec 5, 2012 + updatemenuerp(ALLERP, -1) + assignin('base','ALLERP',ALLERP); % save to workspace. Dec 5, 2012 end % erpcom = sprintf('ALLERP = pop_deleterpset( ALLERP, [%s]);', num2str(erpindex)); % @@ -153,61 +153,64 @@ fn = fieldnames(p.Results); erpcom = sprintf( '%s = pop_deleterpset( %s ', inputname(1), inputname(1) ); for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); - end - else - if iscell(fn2res) - if ischar([fn2res{:}]) - fn2resstr = sprintf('''%s'' ', fn2res{:}); - else - fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - end - fnformat = '{%s}'; - else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - end - if strcmpi(fn2com,'Criterion') - if p.Results.Criterion<100 - erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); - end - else - erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); - end - end + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + else + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + end end + end end erpcom = sprintf( '%s );', erpcom); % get history from script. ERP switch shist - case 1 % from GUI - displayEquiComERP(erpcom); - case 2 % from script - for i=1:length(ALLERP) - ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); - end - case 3 - % implicit - - %for i=1:length(ALLERP) - % ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); - %end - %fprintf('%%Equivalent command:\n%s\n\n', erpcom); - otherwise %off or none - erpcom = ''; + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for i=1:length(ALLERP) + ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); + end + case 3 + % implicit + + %for i=1:length(ALLERP) + % ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); + %end + %fprintf('%%Equivalent command:\n%s\n\n', erpcom); + otherwise %off or none + erpcom = ''; end % % Completion statement % msg2end -eeglab redraw +ERPtooltype = erpgettoolversion('tooltype'); +if ~strcmpi(ERPtooltype,'EStudio') + eeglab redraw +end return diff --git a/pop_functions/pop_eeglindetrend.m b/pop_functions/pop_eeglindetrend.m index b93f1ba4..f174f0b0 100755 --- a/pop_functions/pop_eeglindetrend.m +++ b/pop_functions/pop_eeglindetrend.m @@ -2,7 +2,7 @@ % % FORMAT : % -% >> EEG = pop_eeglindetrend( EEG, detwindow ); +% >> EEG = pop_eeglindetrend( EEG, 'Baseline',detwindow ); % % % INPUTS : @@ -17,8 +17,8 @@ % % EXAMPLE : % -% EEG = pop_eeglindetrend( EEG, 'pre'); -% EEG = pop_eeglindetrend( EEG, [-300 100]); +% EEG = pop_eeglindetrend( EEG, 'Baseline','pre'); +% EEG = pop_eeglindetrend( EEG, 'Baseline', [-300 100]); % % % See also blcerpGUI.m lindetrend.m @@ -51,65 +51,70 @@ % You should have received a copy of the GNU General Public License % along with this program. If not, see . -function [EEG, com] = pop_eeglindetrend( EEG, detwindow, varargin) +function [EEG, com] = pop_eeglindetrend( EEG, varargin) com = ''; if nargin < 1 - help pop_lindetrend - return + help pop_lindetrend + return end if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if nargin==1 - if isempty(EEG(1).data) - msgboxText = 'pop_lindetrend() cannot read an empty dataset!'; - title = 'ERPLAB: pop_lindetrend error'; - errorfound(msgboxText, title); - return - end - if isempty(EEG(1).epoch) - msgboxText = 'pop_lindetrend has been tested for epoched data only'; - title = 'ERPLAB: pop_lindetrend error'; - errorfound(msgboxText, title); - return - end - - def = erpworkingmemory('pop_eeglindetrend'); - if isempty(def) - def = 'pre'; - end - - % - % Call GUI - % - titlegui = 'Linear Detrend'; - answer = blcerpGUI(EEG(1), titlegui, def); % open GUI - if isempty(answer) - disp('User selected Cancel') - return - end - detwindow = answer{1}; - if ischar(detwindow) && strcmpi(detwindow, 'none') - disp('User selected Cancel') - return - end - if isempty(detwindow) - disp('User selected Cancel') - return - end - - erpworkingmemory('pop_eeglindetrend', detwindow); - - if length(EEG)==1 - EEG.setname = [EEG.setname '_ld']; % suggested name (si queris no mas!) - end - % - % Somersault - % - wchmsgonstr ='off'; %temporary - [EEG, com] = pop_eeglindetrend( EEG, detwindow, 'Warning', wchmsgonstr, 'History', 'gui'); + if isempty(EEG(1).data) + msgboxText = 'pop_lindetrend() cannot read an empty dataset!'; + title = 'ERPLAB: pop_lindetrend error'; + errorfound(msgboxText, title); return + end + if isempty(EEG(1).epoch) + msgboxText = 'pop_lindetrend has been tested for epoched data only'; + title = 'ERPLAB: pop_lindetrend error'; + errorfound(msgboxText, title); + return + end + + def = erpworkingmemory('pop_eeglindetrend'); + if isempty(def) + def = 'pre'; + end + + % + % Call GUI + % + titlegui = 'Linear Detrend'; + answer = blcerpGUI(EEG(1), titlegui, def); % open GUI + if isempty(answer) + disp('User selected Cancel') + return + end + detwindow = answer{1}; + if ischar(detwindow) && strcmpi(detwindow, 'none') + disp('User selected Cancel') + return + end + if isempty(detwindow) + disp('User selected Cancel') + return + end + + erpworkingmemory('pop_eeglindetrend', detwindow); + + if length(EEG)==1 + EEG.setname = [EEG.setname '_ld']; % suggested name (si queris no mas!) + end + + ChanArray = answer{2}; + + + % + % Somersault + % + wchmsgonstr ='off'; %temporary + [EEG, com] = pop_eeglindetrend( EEG, 'Baseline', detwindow,'ChanArray',ChanArray,... + 'Warning', wchmsgonstr, 'History', 'gui'); + return end % @@ -119,116 +124,135 @@ p.FunctionName = mfilename; p.CaseSensitive = false; p.addRequired('EEG'); -p.addRequired('detwindow'); % option(s) +p.addParamValue('Baseline', 'pre'); p.addParamValue('Warning', 'off', @ischar); +p.addParamValue('ChanArray', [], @isnumeric); % 'on', 'off' p.addParamValue('History', 'script', @ischar); % history from scripting -p.parse(EEG, detwindow, varargin{:}); +p.parse(EEG, varargin{:}); if strcmpi(p.Results.Warning,'on') - wchmsgon = 1; + wchmsgon = 1; else - wchmsgon = 0; + wchmsgon = 0; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>EEG.nbchan) || any(ChanArray(:)<1) + ChanArray = [1:EEG.nbchan]; +end + +detwindow = p.Results.Baseline; % in case of an error -if ischar(detwindow) && ~strcmpi(detwindow,'all') && ~strcmpi(detwindow,'pre') && ~strcmpi(detwindow,'post') - internum = str2num(detwindow); - if length(internum)~=2 - msgboxText = ['Unappropriated time range for detrending\n'... - 'lindetrend() was ended.\n']; - if shist == 1; % gui - title = 'ERPLAB: pop_eeglindetrend() error'; - errorfound(sprintf(msgboxText), title); - return - else - error('prog:input', msgboxText) - end +if ischar(detwindow) && ~strcmpi(detwindow,'all') && ~strcmpi(detwindow,'pre') && ~strcmpi(detwindow,'post') && ~strcmpi(detwindow,'none') + internum = str2num(detwindow); + if length(internum)~=2 + msgboxText = ['Unappropriated time range for detrending\n'... + 'lindetrend() was ended.\n']; + if shist == 1; % gui + title = 'ERPLAB: pop_eeglindetrend() error'; + errorfound(sprintf(msgboxText), title); + return + else + error('prog:input', msgboxText) end + end end % % process multiple datasets. Updated August 23, 2013 JLC % -options1 = {detwindow, 'Warning', p.Results.Warning, 'History', 'gui'}; +options1 = {'Baseline',detwindow,'ChanArray',ChanArray, 'Warning', p.Results.Warning, 'History', 'gui'}; +EEGaux = EEG; +ChanArrayleft = setdiff([1:EEG.nbchan],ChanArray); if length(EEG) > 1 - [ EEG, com ] = eeg_eval( 'pop_eeglindetrend', EEG, 'warning', 'on', 'params', options1); - return; + [ EEG, com ] = eeg_eval( 'pop_eeglindetrend', EEG, 'warning', 'on', 'params', options1); + if ~isempty(ChanArrayleft) + if length(EEG) > 1 + for Numofeeg = 1:length(EEG) + EEG(Numofeeg).data(ChanArrayleft,:,:) = EEGaux(Numofeeg).data(ChanArrayleft,:,:); + end + end + end + return; end; + + % % subroutine % EEG = lindetrend( EEG, detwindow); +if ~isempty(ChanArrayleft) + EEG.data(ChanArrayleft,:,:) = EEGaux.data(ChanArrayleft,:,:); +end + + % com = sprintf( '%s = pop_eeglindetrend( %s, ''%s'' );', inputname(1), inputname(1), detwindow); % % History % -skipfields = {'EEG', 'detwindow','Saveas','History'}; +skipfields = {'EEG','Saveas','History'}; fn = fieldnames(p.Results); -if isnumeric(detwindow) - dtwin = vect2colon(detwindow); -else - dtwin = ['''' detwindow '''']; -end -com = sprintf('%s = pop_eeglindetrend( %s, %s', inputname(1), inputname(1), dtwin); - + +com = sprintf('%s = pop_eeglindetrend( %s,', inputname(1), inputname(1)); + for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); - end - else - if iscell(fn2res) - if ischar([fn2res{:}]) - fn2resstr = sprintf('''%s'' ', fn2res{:}); - else - fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - end - fnformat = '{%s}'; - else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - end - if strcmpi(fn2com,'Criterion') - if p.Results.Criterion<100 - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - else - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - end + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); + end + else + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); end + end end + end end com = sprintf( '%s );', com); % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - otherwise %off or none - com = ''; + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + otherwise %off or none + com = ''; end % diff --git a/pop_functions/pop_eegtrim.m b/pop_functions/pop_eegtrim.m index cdf8e9ed..b5c2fa30 100755 --- a/pop_functions/pop_eegtrim.m +++ b/pop_functions/pop_eegtrim.m @@ -4,18 +4,18 @@ % % FORMAT: % EEG = pop_eegtrim(EEG, pre, post) -% +% % INPUT % % EEG - input dataset % pre - pre-stimulation window in ms (time left before the first event) % post - post-stimulation window in ms (time left after the last event) -% -% +% +% % OUTPUT % % EEG - trimmed continuous dataset () -% +% % Author: Javier Lopez-Calderon & Johanna Kreither % Center for Mind and Brain % University of California, Davis, @@ -25,39 +25,39 @@ function [EEG, com] = pop_eegtrim(EEG, pre, post, varargin) com = ''; if nargin<1 - help pop_eegtrim - return + help pop_eegtrim + return end if nargin==1 - serror = erplab_eegscanner(EEG, 'pop_creabasiceventlist', 2, 0, 0, 2, 2); % check for continuous dataset - if serror - return - end - def = erpworkingmemory('pop_eegtrim'); - - % - % Call GUI - % - answer = gui_eegtrim(def); - - if isempty(answer) - disp('User selected Cancel') - return - end - - pre = answer{1}; - post = answer{2}; - - erpworkingmemory('pop_eegtrim', {answer{1} answer{2}}); - if length(EEG)==1 - EEG.setname = [EEG.setname '_trim']; %suggest a new name - end - - % - % Somersault - % - [EEG, com] = pop_eegtrim(EEG, pre, post, 'History', 'gui'); - return + serror = erplab_eegscanner(EEG, 'pop_creabasiceventlist', 2, 0, 0, 2, 2); % check for continuous dataset + if serror + return + end + def = erpworkingmemory('pop_eegtrim'); + + % + % Call GUI + % + answer = gui_eegtrim(def); + + if isempty(answer) + disp('User selected Cancel') + return + end + + pre = answer{1}; + post = answer{2}; + + erpworkingmemory('pop_eegtrim', {answer{1} answer{2}}); + if length(EEG)==1 + EEG.setname = [EEG.setname '_trim']; %suggest a new name + end + + % + % Somersault + % + [EEG, com] = pop_eegtrim(EEG, pre, post, 'History', 'gui'); + return end % @@ -74,22 +74,22 @@ p.parse(EEG, pre, post, varargin{:}); if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end t1 = EEG.event(1).latency; if t1<=2 - t1 = EEG.event(2).latency; + t1 = EEG.event(2).latency; end t2 = EEG.event(end).latency; if t2>=EEG.pnts-2 - t2 = EEG.event(end-1).latency; + t2 = EEG.event(end-1).latency; end pnts = EEG.pnts; fs = EEG.srate; @@ -101,55 +101,55 @@ post2 = pnts; if pre2<1 - error('There is not enough samples to keep the pre-stimulation window.') + error('There is not enough samples to keep the pre-stimulation window.') end if post1>pnts - error('There is not enough samples to keep the post-stimulation window.') + error('There is not enough samples to keep the post-stimulation window.') end % trimming disp('Trimming data...') EEG = eeg_eegrej( EEG, [pre1 pre2;post1 post2]); -skipfields = {'EEG', 'History'}; +skipfields = {'EEG', 'History','pre','post'};%%GH Mar. 2024 fn = fieldnames(p.Results); com = sprintf( '%s = pop_eegtrim( %s, %g, %g ', inputname(1), inputname(1), pre, post); for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); - end - else - if iscell(fn2res) - fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - fnformat = '{%s}'; - else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - end - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); + end + else + if iscell(fn2res) + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; end + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); + end end + end end com = sprintf( '%s );', com); % get history from script switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - otherwise %off or none - com = ''; + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + otherwise %off or none + com = ''; end % diff --git a/pop_functions/pop_epoch2continuous.m b/pop_functions/pop_epoch2continuous.m old mode 100644 new mode 100755 index a24bd5b3..f6ac5170 --- a/pop_functions/pop_epoch2continuous.m +++ b/pop_functions/pop_epoch2continuous.m @@ -158,8 +158,7 @@ end -% com = sprintf('%s = pop_epoch2continuous(%s);', inputname(1), inputname(1)); -com = sprintf( '%s = pop_bdfrecovery( %s ', inputname(1), inputname(1) ); +com = sprintf( '%s = pop_epoch2continuous( %s ', inputname(1), inputname(1) ); skipfields = {'History'}; fn = fieldnames(p.Results); for q=1:length(fn) diff --git a/pop_functions/pop_eraseventcodes.m b/pop_functions/pop_eraseventcodes.m index 5e313d8d..42a8914e 100755 --- a/pop_functions/pop_eraseventcodes.m +++ b/pop_functions/pop_eraseventcodes.m @@ -95,7 +95,7 @@ errorfound(sprintf(msgboxText), title); return end - prompt = {'expression (>, < ==, ~=):'}; + prompt = {'expression (>, <, ==, ~=):'}; dlg_title = 'Input event-code condition to delete'; num_lines = 1; def = erpworkingmemory('pop_eraseventcodes'); diff --git a/pop_functions/pop_erplindetrend.m b/pop_functions/pop_erplindetrend.m index 706a7b60..6f233000 100755 --- a/pop_functions/pop_erplindetrend.m +++ b/pop_functions/pop_erplindetrend.m @@ -2,7 +2,7 @@ % % FORMAT : % -% ERP = pop_erplindetrend( ERP, detwindow ); +% ERP = pop_erplindetrend( ERP,'Baseline', detwindow ); % % INPUTS : % @@ -16,9 +16,9 @@ % % % EXAMPLE : -% ERP = pop_erplindetrend( ERP, 'post'); -% ERP = pop_erplindetrend( ERP, '0 798'); -% ERP = pop_erplindetrend( ERP, [0 798]); +% ERP = pop_erplindetrend( ERP, 'Baseline', 'post'); +% ERP = pop_erplindetrend( ERP,'Baseline', '0 798'); +% ERP = pop_erplindetrend( ERP, 'Baseline', [0 798]); % % See also blcerpGUI.m lindetrend.m % @@ -51,55 +51,57 @@ % You should have received a copy of the GNU General Public License % along with this program. If not, see . -function [ERP, erpcom] = pop_erplindetrend( ERP, detwindow, varargin) +function [ERP, erpcom] = pop_erplindetrend( ERP, varargin) erpcom = ''; if nargin < 1 - help pop_erplindetrend - return + help pop_erplindetrend + return end if isfield(ERP(1), 'datatype') - datatype = ERP.datatype; + datatype = ERP.datatype; else - datatype = 'ERP'; + datatype = 'ERP'; end if nargin==1 - title_msg = 'ERPLAB: pop_erplindetrend() error:'; - if isempty(ERP) - ERP = preloadERP; - if isempty(ERP) - msgboxText = 'No ERPset was found!'; - - errorfound(msgboxText, title_msg); - return - end - end - if ~strcmpi(datatype, 'ERP') - msgboxText = 'Cannot detrend Power Spectrum waveforms. Sorry'; + title_msg = 'ERPLAB: pop_erplindetrend() error:'; + if isempty(ERP) + ERP = preloadERP; + if isempty(ERP) + msgboxText = 'No ERPset was found!'; + errorfound(msgboxText, title_msg); return - end - def = erpworkingmemory('pop_erplindetrend'); - if isempty(def) - def = {'pre'}; - end - - % - % Call GUI - % - titlegui = 'Linear Detrend'; - answer = blcerpGUI(ERP, titlegui, def); - if isempty(answer) - disp('User selected Cancel') - return - end - detwindow = answer{1}; - erpworkingmemory('pop_erplindetrend', detwindow); - - % - % Somersault - % - [ERP, erpcom] = pop_erplindetrend(ERP, detwindow, 'Warning', 'on', 'Saveas', 'on','ErrorMsg', 'popup', 'History', 'gui'); - return + end + end + if ~strcmpi(datatype, 'ERP') + msgboxText = 'Cannot detrend Power Spectrum waveforms. Sorry'; + errorfound(msgboxText, title_msg); + return + end + def = erpworkingmemory('pop_erplindetrend'); + if isempty(def) + def = {'pre'}; + end + + % + % Call GUI + % + titlegui = 'Linear Detrend'; + answer = blcerpGUI(ERP, titlegui, def); + if isempty(answer) + disp('User selected Cancel') + return + end + detwindow = answer{1}; + erpworkingmemory('pop_erplindetrend', detwindow); + ChanArray = answer{2}; + BinArray = answer{3}; + % + % Somersault + % + [ERP, erpcom] = pop_erplindetrend(ERP,'Baseline', detwindow,'ChanArray',ChanArray,... + 'BinArray',BinArray, 'Warning', 'on', 'Saveas', 'on','ErrorMsg', 'popup', 'History', 'gui'); + return end % @@ -109,60 +111,76 @@ p.FunctionName = mfilename; p.CaseSensitive = false; p.addRequired('ERP'); -p.addRequired('detwindow'); % option(s) +p.addParamValue('Baseline', 'pre'); p.addParamValue('Warning', 'off', @ischar); +p.addParamValue('ChanArray', [], @isnumeric); +p.addParamValue('BinArray', [], @isnumeric); p.addParamValue('Saveas', 'off', @ischar); % 'on', 'off' p.addParamValue('ErrorMsg', 'cw', @ischar); % cw = command window p.addParamValue('History', 'script', @ischar); % history from scripting -p.parse(ERP, detwindow, varargin{:}); +p.parse(ERP, varargin{:}); if strcmpi(p.Results.Warning,'on') - wchmsgon = 1; + wchmsgon = 1; else - wchmsgon = 0; + wchmsgon = 0; end if ismember_bc2({p.Results.Saveas}, {'on','yes'}) - issaveas = 1; + issaveas = 1; else - issaveas = 0; + issaveas = 0; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end if strcmpi(p.Results.ErrorMsg,'popup') - errormsgtype = 1; % open popup window + errormsgtype = 1; % open popup window else - errormsgtype = 0; % error in red at command window + errormsgtype = 0; % error in red at command window end + + +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; +end + + +BinArray = p.Results.BinArray; +if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = [1:ERP.nbin]; +end +detwindow = p.Results.Baseline; + if ischar(detwindow) - if ~strcmpi(detwindow,'all') && ~strcmpi(detwindow,'pre') && ~strcmpi(detwindow,'post') - internum = str2num(detwindow); - if length(internum)~=2 - msgboxText = 'Wrong interval. Linear detrending will not be performed.'; - title = 'ERPLAB: pop_erplindetrend() error'; - errorfound(msgboxText, title); - return - end - detwindowstr = ['[ ' num2str(internum) ' ]']; - else - detwindowstr = ['''' detwindow '''']; - end -else - if length(detwindow)~=2 + if ~strcmpi(detwindow,'all') && ~strcmpi(detwindow,'pre') && ~strcmpi(detwindow,'post') && ~strcmpi(detwindow,'none') + internum = str2num(detwindow); + if length(internum)~=2 msgboxText = 'Wrong interval. Linear detrending will not be performed.'; title = 'ERPLAB: pop_erplindetrend() error'; errorfound(msgboxText, title); return - end - detwindowstr = ['[ ' num2str(detwindow) ' ]']; + end + detwindowstr = ['[ ' num2str(internum) ' ]']; + else + detwindowstr = ['''' detwindow '''']; + end +else + if length(detwindow)~=2 + msgboxText = 'Wrong interval. Linear detrending will not be performed.'; + title = 'ERPLAB: pop_erplindetrend() error'; + errorfound(msgboxText, title); + return + end + detwindowstr = ['[ ' num2str(detwindow) ' ]']; end ERPaux = ERP; @@ -172,42 +190,94 @@ % ERP = lindetrend( ERP, detwindow); + +ChanArrayleft = setdiff([1:ERP.nchan],ChanArray);%% channles are not for baseline correction +if ~isempty(ChanArrayleft) + ERP.bindata(ChanArrayleft,:,:) = ERPaux.bindata(ChanArrayleft,:,:); +end + + +BinArrayleft = setdiff([1:ERP.nbin],BinArray);%% channles are not for baseline correction +if ~isempty(BinArrayleft) + ERP.bindata(:,:,BinArrayleft) = ERPaux.bindata(:,:,BinArrayleft); +end + + % % Completion statement % msg2end ERP.saved = 'no'; -erpcom = sprintf( '%s = pop_erplindetrend( %s, %s );', inputname(1), inputname(1), detwindowstr); -if issaveas - [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); - if issave>0 - if issave==2 - erpcom = sprintf('%s\n%s', erpcom, erpcom_save); - msgwrng = '*** Your ERPset was saved on your hard drive.***'; - mcolor = [0 0 1]; + + +skipfields = {'ERP', 'History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_erplindetrend( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end else - msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; - mcolor = [1 0.52 0.2]; + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + else + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end end - else - ERP = ERPaux; - msgwrng = 'ERPLAB Warning: Your changes were not saved'; - mcolor = [1 0.22 0.2]; - end - try cprintf(mcolor, '%s\n\n', msgwrng);catch,fprintf('%s\n\n', msgwrng);end ; + end + end +end +erpcom = sprintf( '%s );', erpcom); + + +if issaveas + [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); + if issave>0 + if issave==2 + erpcom = sprintf('%s\n%s', erpcom, erpcom_save); + msgwrng = '*** Your ERPset was saved on your hard drive.***'; + mcolor = [0 0 1]; + else + msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; + mcolor = [1 0.52 0.2]; + end + else + ERP = ERPaux; + msgwrng = 'ERPLAB Warning: Your changes were not saved'; + mcolor = [1 0.22 0.2]; + end + try cprintf(mcolor, '%s\n\n', msgwrng);catch,fprintf('%s\n\n', msgwrng);end ; end % get history from script. ERP switch shist - case 1 % from GUI - displayEquiComERP(erpcom); - case 2 % from script - ERP = erphistory(ERP, [], erpcom, 1); - case 3 - % implicit - %ERP = erphistory(ERP, [], erpcom, 1); - %fprintf('%%Equivalent command:\n%s\n\n', erpcom); - otherwise %off or none - erpcom = ''; + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + ERP = erphistory(ERP, [], erpcom, 1); + case 3 + % implicit + %ERP = erphistory(ERP, [], erpcom, 1); + %fprintf('%%Equivalent command:\n%s\n\n', erpcom); + otherwise %off or none + erpcom = ''; end return diff --git a/pop_functions/pop_exporteegeventlist.m b/pop_functions/pop_exporteegeventlist.m index f23745df..d33b244c 100755 --- a/pop_functions/pop_exporteegeventlist.m +++ b/pop_functions/pop_exporteegeventlist.m @@ -52,154 +52,156 @@ function [EEG, com] = pop_exporteegeventlist(EEG, varargin) com = ''; if nargin < 1 - help pop_exporteegeventlist - return + help pop_exporteegeventlist + return end if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if length(EEG)>1 - msgboxText = 'Unfortunately, this function does not work with multiple datasets'; - title = 'ERPLAB: multiple inputs'; - errorfound(msgboxText, title); - return + msgboxText = 'Unfortunately, this function does not work with multiple datasets'; + title = 'ERPLAB: multiple inputs'; + errorfound(msgboxText, title); + return end if nargin==1 - if isempty(EEG) - msgboxText = 'pop_exporteegeventlist() error: cannot work with an empty dataset!'; - title = 'ERPLAB: No data'; - errorfound(msgboxText, title); - return - end - if isempty(EEG.data) - msgboxText = 'pop_exporteegeventlist() error: cannot work with an empty dataset!'; - title = 'ERPLAB: No data'; - errorfound(msgboxText, title); - return - end - if isfield(EEG, 'EVENTLIST') - if isempty(EEG.EVENTLIST) - msgboxText = ['EEG.EVENTLIST structure is empty.\n\n'... - 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; - title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; - errorfound(sprintf(msgboxText), title); - return - end - if isfield(EEG.EVENTLIST, 'eventinfo') - if isempty(EEG.EVENTLIST.eventinfo) - msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty.\n\n'... - 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; - title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; - errorfound(sprintf(msgboxText), title); - return - end - else - msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty.\n\n'... - 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; - title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; - errorfound(sprintf(msgboxText), title); - return - end - else - msgboxText = ['EEG.EVENTLIST structure is empty.\n\n'... - 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; - title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; - errorfound(sprintf(msgboxText), title); - return + if isempty(EEG) + msgboxText = 'pop_exporteegeventlist() error: cannot work with an empty dataset!'; + title = 'ERPLAB: No data'; + errorfound(msgboxText, title); + return + end + if isempty(EEG.data) + msgboxText = 'pop_exporteegeventlist() error: cannot work with an empty dataset!'; + title = 'ERPLAB: No data'; + errorfound(msgboxText, title); + return + end + if isfield(EEG, 'EVENTLIST') + if isempty(EEG.EVENTLIST) + msgboxText = ['EEG.EVENTLIST structure is empty.\n\n'... + 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; + title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; + errorfound(sprintf(msgboxText), title); + return end - if ~isfield(EEG.EVENTLIST, 'bdf') - msgboxText = ['EEG.EVENTLIST.bdf structure is empty.\n\n'... - 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; + if isfield(EEG.EVENTLIST, 'eventinfo') + if isempty(EEG.EVENTLIST.eventinfo) + msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty.\n\n'... + 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; errorfound(sprintf(msgboxText), title); return + end + else + msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty.\n\n'... + 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; + title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; + errorfound(sprintf(msgboxText), title); + return end + else + msgboxText = ['EEG.EVENTLIST structure is empty.\n\n'... + 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; + title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; + errorfound(sprintf(msgboxText), title); + return + end + if ~isfield(EEG.EVENTLIST, 'bdf') + msgboxText = ['EEG.EVENTLIST.bdf structure is empty.\n\n'... + 'Please, use ERPLAB --> EVENTLIST --> Create EEG EventList menu before exporting to text.']; + title = 'ERPLAB: pop_exporteegeventlist() error, EVENTLIST structure'; + errorfound(sprintf(msgboxText), title); + return + end + + % + % Save OUTPUT file + % + [fname, pathname,indx] = uiputfile({'*.txt';'*.xls,*.xlsx';'*.*'},'Save EVENTLIST file as');%%GH Mar 2024 + + if isequal(fname,0) + disp('User selected Cancel') + return + else + [xpath, fname, ext] = fileparts(fname); - % - % Save OUTPUT file - % - [fname, pathname] = uiputfile({'*.txt';'*.*'},'Save EVENTLIST file as'); - - if isequal(fname,0) - disp('User selected Cancel') - return + if indx==2 + ext = '.xls'; else - [xpath, fname, ext] = fileparts(fname); - - if ~strcmp(ext,'.txt') - ext = '.txt'; - end - - fname = [fname ext]; - elname = fullfile(pathname, fname); - disp(['For EVENTLIST output user selected ', elname]) + ext = '.txt'; end - % - % Somersault - % - [EEG, com] = pop_exporteegeventlist(EEG, 'Filename', elname, 'History', 'gui'); - return + fname = [fname ext]; + elname = fullfile(pathname, fname); + disp(['For EVENTLIST output user selected ', elname]) + end + + % + % Somersault + % + [EEG, com] = pop_exporteegeventlist(EEG, 'Filename', elname, 'History', 'gui'); + return end if nargin==2 - % - % Parsing inputs (versions<4.0) - % - p = inputParser; - p.FunctionName = mfilename; - p.CaseSensitive = false; - p.addRequired('EEG'); - p.addRequired('varargin'); - - % option(s) - p.addParamValue('History', 'script', @ischar); % history from scripting - p.parse(EEG, varargin{:}); - elname = varargin{:}; + % + % Parsing inputs (versions<4.0) + % + p = inputParser; + p.FunctionName = mfilename; + p.CaseSensitive = false; + p.addRequired('EEG'); + p.addRequired('varargin'); + + % option(s) + p.addParamValue('History', 'script', @ischar); % history from scripting + p.parse(EEG, varargin{:}); + elname = varargin{:}; else - % - % Parsing inputs - % - p = inputParser; - p.FunctionName = mfilename; - p.CaseSensitive = false; - p.addRequired('EEG'); - % option(s) - p.addParamValue('Filename', '', @ischar); % erpset index or input file - p.addParamValue('History', 'script', @ischar); % history from scripting - p.parse(EEG, varargin{:}); - elname = p.Results.Filename; + % + % Parsing inputs + % + p = inputParser; + p.FunctionName = mfilename; + p.CaseSensitive = false; + p.addRequired('EEG'); + % option(s) + p.addParamValue('Filename', '', @ischar); % erpset index or input file + p.addParamValue('History', 'script', @ischar); % history from scripting + p.parse(EEG, varargin{:}); + elname = p.Results.Filename; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end if isempty(EEG.data) - error('ERPLAB says: error at pop_exporteegeventlist(). cannot work with an empty dataset!') + error('ERPLAB says: error at pop_exporteegeventlist(). cannot work with an empty dataset!') end if isfield(EEG, 'EVENTLIST') - if isempty(EEG.EVENTLIST) - error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST structure is empty.'); - end - - if isfield(EEG.EVENTLIST, 'eventinfo') - if isempty(EEG.EVENTLIST.eventinfo) - error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST.eventinfo structure is empty.'); - end - else - error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST.eventinfo structure was not found.'); + if isempty(EEG.EVENTLIST) + error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST structure is empty.'); + end + + if isfield(EEG.EVENTLIST, 'eventinfo') + if isempty(EEG.EVENTLIST.eventinfo) + error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST.eventinfo structure is empty.'); end + else + error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST.eventinfo structure was not found.'); + end else - error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST structure was not found.'); + error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST structure was not found.'); end if ~isfield(EEG.EVENTLIST, 'bdf') - error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST.bdf structure was not found.'); + error('ERPLAB says: error at pop_exporteegeventlist(). EEG.EVENTLIST.bdf structure was not found.'); end @@ -208,7 +210,16 @@ % % subroutine % -creaeventlist(EEG, EVENTLIST, elname, 1); + + +%%GH Mar 2024 +[xpath, fname, ext] = fileparts(elname); + +if strcmpi(ext,'.txt') + creaeventlist(EEG, EVENTLIST, elname, 1); +else + f_creaeventlist_excel(EEG, EVENTLIST, elname, 1); +end % % History @@ -217,53 +228,53 @@ fn = fieldnames(p.Results); com = sprintf( '%s = pop_exporteegeventlist( %s ', inputname(1), inputname(1) ); for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); - end - else - if iscell(fn2res) - if ischar([fn2res{:}]) - fn2resstr = sprintf('''%s'' ', fn2res{:}); - else - fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - end - fnformat = '{%s}'; - else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - end - if strcmpi(fn2com,'Criterion') - if p.Results.Criterion<100 - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - else - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - end + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); + end + else + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); end + end end + end end com = sprintf( '%s );', com); % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - % EEG = erphistory(EEG, [], com, 1); - % fprintf('%%Equivalent command:\n%s\n\n', com); - otherwise %off or none - com = ''; + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + % EEG = erphistory(EEG, [], com, 1); + % fprintf('%%Equivalent command:\n%s\n\n', com); + otherwise %off or none + com = ''; end % diff --git a/pop_functions/pop_exporterpeventlist.m b/pop_functions/pop_exporterpeventlist.m index 17972003..a8893b1f 100755 --- a/pop_functions/pop_exporterpeventlist.m +++ b/pop_functions/pop_exporterpeventlist.m @@ -204,7 +204,14 @@ % % subroutine % +%%GH Mar 2024 +[xpath, fname, ext] = fileparts(elname); + +if strcmpi(ext,'.txt') exporterpeventlist(ERP, indexel, elname); +else + f_creaeventlist_excel(ERP, ERP.EVENTLIST, elname, 1); +end erpcom = sprintf( 'pop_exporterpeventlist(%s, %s, ''%s'');', inputname(1), num2str(indexel), elname); % get history from script. ERP switch shist diff --git a/pop_functions/pop_filterp.m b/pop_functions/pop_filterp.m index efdad214..17abfe55 100755 --- a/pop_functions/pop_filterp.m +++ b/pop_functions/pop_filterp.m @@ -94,13 +94,15 @@ return end nchan = ERP.nchan; - defx = {0 30 2 1:nchan 1 'butter' 0 []}; + nbin = ERP.nbin; + defx = {0 30 2 1:nchan 1 'butter' 0 [],1:nbin}; def = erpworkingmemory('pop_filterp'); if isempty(def) def = defx; else def{4} = def{4}(ismember_bc2(def{4},1:nchan)); + try def{9} = def{9}(ismember_bc2(def{9},1:nbin)); catch def{9} = 1:nbin; end end % @@ -117,13 +119,11 @@ hicutoff = answer{2}; % for low pass filter filterorder = answer{3}; chanArray = answer{4}; - filterallch = answer{5}; +% filterallch = answer{5}; fdesign = answer{6}; remove_dc = answer{7}; - - if filterallch - chanArray = 1:nchan; - end + binArray = answer{9}; + erpworkingmemory('pop_filterp', answer(:)'); @@ -155,11 +155,11 @@ else error('ERPLAB says: Invalid type of filter ') end - +% binArray = [1:ERP.nbin];%%GH Apr 2024 % % Somersault % - [ERP, erpcom] = pop_filterp( ERP, chanArray, 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... + [ERP, erpcom] = pop_filterp( ERP, chanArray, 'binArray',binArray,'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... 'Saveas', 'on', 'History', 'gui'); return end @@ -176,6 +176,7 @@ p.addParamValue('Filter', 'lowpass',@ischar); p.addParamValue('Design', 'butter', @ischar); p.addParamValue('Cutoff', 30, @isnumeric); +p.addParamValue('binArray', [], @isnumeric); p.addParamValue('Order', 2, @isnumeric); p.addParamValue('RemoveDC', 'off', @ischar); p.addParamValue('Saveas', 'off', @ischar); @@ -183,13 +184,20 @@ p.parse(ERP, chanArray, varargin{:}); + +binArray = p.Results.binArray;%%GH Apr 2024 +nbin = ERP(1).nbin; +if isempty(binArray) || any(binArray(:)>nbin) || any(binArray(:)<1) + binArray = [1:nbin]; +end + filtp = p.Results.Filter; fdesign = p.Results.Design; filco = p.Results.Cutoff; if ~strcmpi(datatype, 'ERP') - msgboxText = 'Cannot filter Power Spectrum waveforms!'; - error(msgboxText); + msgboxText = 'Cannot filter Power Spectrum waveforms!'; + error(msgboxText); end if strcmpi(filtp, 'lowpass') if length(filco)~=1 @@ -286,7 +294,7 @@ % % subroutine % -options = { chanArray, locutoff, hicutoff, filterorder, fdesignnum, remove_dc}; +options = { chanArray, locutoff, hicutoff, filterorder, fdesignnum, remove_dc,binArray}; ERPaux = ERP; % store original ERP ERP = filterp(ERP, options{:}); ERP.saved = 'no'; diff --git a/pop_functions/pop_gaverager.m b/pop_functions/pop_gaverager.m index c26d3c21..477e1ec3 100755 --- a/pop_functions/pop_gaverager.m +++ b/pop_functions/pop_gaverager.m @@ -318,7 +318,7 @@ end catch - warning('Dataquality measures not found in all these ERPsets. Setting DQ_flag = 0'); + warning('Data quality measures not found in all these ERPsets. Setting DQ_flag = 0'); DQ_flag = 0; end end diff --git a/pop_functions/pop_geterpvalues.m b/pop_functions/pop_geterpvalues.m index 7c5629ff..95224f0d 100755 --- a/pop_functions/pop_geterpvalues.m +++ b/pop_functions/pop_geterpvalues.m @@ -9,7 +9,7 @@ % pop_geterpvalues(filename, latency, binArray, chanArray, parameters); % % -% INPUTS : +% INPUTS: % % ALLERP - structure array of ERP structures (ERPsets) % To read the ERPset from a list in a text file, @@ -106,180 +106,182 @@ Amp = []; Lat = []; if nargin<1 - help pop_geterpvalues - return + help pop_geterpvalues + return end if nargin==1 % GUI - if isstruct(ALLERP) - if ~iserpstruct(ALLERP(1)); - ALLERP = []; - nbinx = 1; - nchanx = 1; - else - nbinx = ALLERP(1).nbin; - nchanx = ALLERP(1).nchan; - end - else - ALLERP = []; - nbinx = 1; - nchanx = 1; - end - cerpi = evalin('base', 'CURRENTERP'); % current erp index - def = erpworkingmemory('pop_geterpvalues'); - if isempty(def) - if isempty(ALLERP) - inp1 = 1; %from hard drive - erpset = []; - else - inp1 = 0; %from erpset menu - erpset = 1:length(ALLERP); - end - - def = {inp1 erpset '' 0 1:nbinx 1:nchanx 'instabl' 1 3 'pre' 0 1 5 0 0.5 0 0 0 '' 0 1}; - else - if ~isempty(ALLERP) - if isnumeric(def{2}) % JavierLC 11-17-11 - [uu, mm] = unique_bc2(def{2}, 'first'); - erpset_list_sorted = [def{2}(sort(mm))]; - %def{2} = def{2}(def{2}<=length(ALLERP)); - % non-empty check, axs jul17 - erpset_list = erpset_list_sorted(erpset_list_sorted<=length(ALLERP)); - if isempty(erpset_list) - % if nothing in list, just go with current - def{2} = cerpi; - else - % use JLC's sorting, iff not empty - def{2} = erpset_list; - end - - end - end - end - - % - % call GUI - % - instr = geterpvaluesGUI2(ALLERP, def, cerpi);% open a GUI - - if isempty(instr) - disp('User selected Cancel') - return - end - - optioni = instr{1}; %1 means from hard drive, 0 means from erpsets menu - erpset = instr{2}; - fname = instr{3}; - latency = instr{4}; - binArray = instr{5}; - chanArray = instr{6}; - moption = instr{7}; % option: type of measurement ---> instabl, meanbl, peakampbl, peaklatbl, area, areaz, or errorbl. - coi = instr{8}; - dig = instr{9}; - blc = instr{10}; - binlabop = instr{11}; % 0: bin number as bin label, 1: bin descriptor as bin label for table. - polpeak = instr{12}; % local peak polarity - sampeak = instr{13}; % number of samples (one-side) for local peak detection criteria - locpeakrep = instr{14}; % 1 abs peak , 0 Nan - frac = instr{15}; - fracmearep = instr{16}; % 1 zero , 0 Nan. Fractional area latency replacement - send2ws = instr{17}; % send measurements to workspace - appfile = instr{18}; % 1 means append file (it wont get into wmemory), 3 means call filter GUI - foutput = instr{19}; - mlabel = instr{20}; - inclate = instr{21}; % include used latency values for measurements like mean, peak, area... - intfactor = instr{22}; - viewmea = instr{23}; % viewer - peak_onset = instr{24}; % 1 for - - if optioni==1 % from files - filelist = erpset; - disp(['pop_geterpvalues(): For file-List, user selected ', filelist]) - fid_list = fopen( filelist ); - inputfnamex = textscan(fid_list, '%[^\n]','CommentStyle','#'); - inputfname = cellstr(char(inputfnamex{:})); - fclose(fid_list); - ALLERP = {ALLERP, filelist}; % truco - elseif optioni==2 % from current erpset (single) - erpset = cerpi; - else % from erpsets menu - %erpset = erpset; - end - if strcmpi(fname,'no_save.no_save') %|| strcmpi(fname,'no_save.viewer') - fnamer = ''; - else - fnamer = fname; - end - if send2ws - s2ws = 'on'; % send to workspace + if isstruct(ALLERP) + if ~iserpstruct(ALLERP(1)); + ALLERP = []; + nbinx = 1; + nchanx = 1; else - s2ws = 'off'; - end - if viewmea - vmstr = 'on'; % open viewer + nbinx = ALLERP(1).nbin; + nchanx = ALLERP(1).nchan; + end + else + ALLERP = []; + nbinx = 1; + nchanx = 1; + end + cerpi = evalin('base', 'CURRENTERP'); % current erp index + def = erpworkingmemory('pop_geterpvalues'); + if isempty(def) + if isempty(ALLERP) + inp1 = 1; %from hard drive + erpset = []; else - vmstr = 'off'; + inp1 = 0; %from erpset menu + erpset = 1:length(ALLERP); end - erpworkingmemory('pop_geterpvalues', {optioni, erpset, fnamer, latency,... - binArray, chanArray, moption, coi, dig, blc, binlabop, polpeak,... - sampeak, locpeakrep, frac, fracmearep, send2ws, foutput, mlabel,... - inclate, intfactor, peak_onset}); - - if binlabop==0 - binlabopstr = 'off'; - else - binlabopstr = 'on'; - end - if polpeak==0 - polpeakstr = 'negative'; - else - polpeakstr = 'positive'; - end - if locpeakrep==0 - locpeakrepstr = 'NaN'; - else - locpeakrepstr = 'absolute'; - end - if fracmearep==0 % Fractional area latency replacement - fracmearepstr = 'NaN'; - else - if ismember_bc2({moption}, {'fareatlat', 'fninteglat','fareaplat','fareanlat'}) - fracmearepstr = 'errormsg'; + def = {inp1 erpset '' 0 1:nbinx 1:nchanx 'instabl' 1 3 'pre' 0 1 5 0 0.5 0 0 0 '' 0 1}; + else + if ~isempty(ALLERP) + if isnumeric(def{2}) % JavierLC 11-17-11 + [uu, mm] = unique_bc2(def{2}, 'first'); + erpset_list_sorted = [def{2}(sort(mm))]; + %def{2} = def{2}(def{2}<=length(ALLERP)); + % non-empty check, axs jul17 + erpset_list = erpset_list_sorted(erpset_list_sorted<=length(ALLERP)); + if isempty(erpset_list) + % if nothing in list, just go with current + def{2} = cerpi; else - fracmearepstr = 'absolute'; + % use JLC's sorting, iff not empty + def{2} = erpset_list; end - end - if appfile - appfstr = 'on'; - else - appfstr = 'off'; - end - if foutput % 1 means "long format"; 0 means "wide format" - foutputstr = 'long'; - else - foutputstr = 'wide'; - end - if inclate - inclatestr = 'yes'; - else - inclatestr = 'no'; - end - - % - % Somersault - % - - %latency, binArray, chanArray, erpset, moption, coi, dig, blc, binlabopstr, polpeakstr, sampeak, locpeakrepstr, fname, s2ws, appfstr, foutputstr, frac, mlabel, fracmearepstr, inclatestr, intfactor, vmstr - - [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP, latency, binArray, chanArray, 'Erpsets', erpset, 'Measure',... - moption, 'Component', coi, 'Resolution', dig, 'Baseline', blc, 'Binlabel', binlabopstr, 'Peakpolarity',... - polpeakstr, 'Neighborhood', sampeak, 'Peakreplace', locpeakrepstr, 'Filename', fname, 'Warning','on',... - 'SendtoWorkspace', s2ws, 'Append', appfstr, 'FileFormat', foutputstr,'Afraction', frac, 'Mlabel', mlabel,... - 'Fracreplace', fracmearepstr,'IncludeLat', inclatestr, 'InterpFactor', intfactor, 'Viewer', vmstr,... - 'PeakOnset',peak_onset,'History', 'gui'); - - pause(0.1) + + end + end + end + + % + % call GUI + % + instr = geterpvaluesGUI2(ALLERP, def, cerpi);% open a GUI + + if isempty(instr) + disp('User selected Cancel') return + end + + optioni = instr{1}; %1 means from hard drive, 0 means from erpsets menu + erpset = instr{2}; + fname = instr{3}; + latency = instr{4}; + binArray = instr{5}; + chanArray = instr{6}; + moption = instr{7}; % option: type of measurement ---> instabl, meanbl, peakampbl, peaklatbl, area, areaz, or errorbl. + coi = instr{8}; + dig = instr{9}; + blc = instr{10}; + binlabop = instr{11}; % 0: bin number as bin label, 1: bin descriptor as bin label for table. + polpeak = instr{12}; % local peak polarity + sampeak = instr{13}; % number of samples (one-side) for local peak detection criteria + locpeakrep = instr{14}; % 1 abs peak , 0 Nan + frac = instr{15}; + fracmearep = instr{16}; % 1 zero , 0 Nan. Fractional area latency replacement + send2ws = instr{17}; % send measurements to workspace + appfile = instr{18}; % 1 means append file (it wont get into wmemory), 3 means call filter GUI + foutput = instr{19}; + mlabel = instr{20}; + inclate = instr{21}; % include used latency values for measurements like mean, peak, area... + intfactor = instr{22}; + viewmea = instr{23}; % viewer + peak_onset = instr{24}; % 1 for + + if optioni==1 % from files + filelist = erpset; + disp(['pop_geterpvalues(): For file-List, user selected ', filelist]) + fid_list = fopen( filelist ); + inputfnamex = textscan(fid_list, '%[^\n]','CommentStyle','#'); + inputfname = cellstr(char(inputfnamex{:})); + fclose(fid_list); + ALLERP = {ALLERP, filelist}; % truco + elseif optioni==2 % from current erpset (single) + erpset = cerpi; + else % from erpsets menu + %erpset = erpset; + end + if strcmpi(fname,'no_save.no_save') %|| strcmpi(fname,'no_save.viewer') + fnamer = ''; + else + fnamer = fname; + end + if send2ws + s2ws = 'on'; % send to workspace + else + s2ws = 'off'; + end + if viewmea + vmstr = 'on'; % open viewer + else + vmstr = 'off'; + end + + erpworkingmemory('pop_geterpvalues', {optioni, erpset, fnamer, latency,... + binArray, chanArray, moption, coi, dig, blc, binlabop, polpeak,... + sampeak, locpeakrep, frac, fracmearep, send2ws, foutput, mlabel,... + inclate, intfactor, peak_onset}); + + if binlabop==0 + binlabopstr = 'off'; + else + binlabopstr = 'on'; + end + if polpeak==0 + polpeakstr = 'negative'; + else + polpeakstr = 'positive'; + end + if locpeakrep==0 + locpeakrepstr = 'NaN'; + elseif locpeakrep==-1 + locpeakrepstr = 'errormsg';%%GH May 2024 + else + locpeakrepstr = 'absolute'; + end + if fracmearep==0 % Fractional area latency replacement + fracmearepstr = 'NaN'; + else + if ismember_bc2({moption}, {'fareatlat', 'fninteglat','fareaplat','fareanlat'}) + fracmearepstr = 'errormsg'; + else + fracmearepstr = 'absolute'; + end + end + if appfile + appfstr = 'on'; + else + appfstr = 'off'; + end + if foutput % 1 means "long format"; 0 means "wide format" + foutputstr = 'long'; + else + foutputstr = 'wide'; + end + if inclate + inclatestr = 'yes'; + else + inclatestr = 'no'; + end + + % + % Somersault + % + + %latency, binArray, chanArray, erpset, moption, coi, dig, blc, binlabopstr, polpeakstr, sampeak, locpeakrepstr, fname, s2ws, appfstr, foutputstr, frac, mlabel, fracmearepstr, inclatestr, intfactor, vmstr + + [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP, latency, binArray, chanArray, 'Erpsets', erpset, 'Measure',... + moption, 'Component', coi, 'Resolution', dig, 'Baseline', blc, 'Binlabel', binlabopstr, 'Peakpolarity',... + polpeakstr, 'Neighborhood', sampeak, 'Peakreplace', locpeakrepstr, 'Filename', fname, 'Warning','on',... + 'SendtoWorkspace', s2ws, 'Append', appfstr, 'FileFormat', foutputstr,'Afraction', frac, 'Mlabel', mlabel,... + 'Fracreplace', fracmearepstr,'IncludeLat', inclatestr, 'InterpFactor', intfactor, 'Viewer', vmstr,... + 'PeakOnset',peak_onset,'History', 'gui'); + + pause(0.1) + return end % @@ -320,27 +322,27 @@ p.parse(ALLERP, latency, binArray, chanArray, varargin{:}); if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end % % Measurement types % meacell = {'instabl', 'meanbl', 'peakampbl', 'peaklatbl', 'fpeaklat',... - 'areat', 'areap', 'arean','areazt','areazp','areazn','fareatlat',... - 'fareaplat','fninteglat','fareanlat', 'ninteg','nintegz' }; + 'areat', 'areap', 'arean','areazt','areazp','areazn','fareatlat',... + 'fareaplat','fninteglat','fareanlat', 'ninteg','nintegz' }; measurearray = {'Instantaneous amplitude','Mean amplitude between two fixed latencies',... - 'Peak amplitude','Peak latency','Fractional Peak latency',... - 'Numerical integration/Area between two fixed latencies',... - 'Numerical integration/Area between two (automatically detected) zero-crossing latencies'... - 'Fractional Area latency', ''}; + 'Peak amplitude','Peak latency','Fractional Peak latency',... + 'Numerical integration/Area between two fixed latencies',... + 'Numerical integration/Area between two (automatically detected) zero-crossing latencies'... + 'Fractional Area latency', ''}; % % Get inputs @@ -349,66 +351,66 @@ cond1 = iserpstruct(ALLERP); cond2 = isnumeric(erpsetArray); if isempty(latency) - latency = 0; -end -if cond1 && cond2 % either from GUI or script, when ALLERP exist and erpset indices were specified - if isempty(erpsetArray) - erpsetArray =1:length(ALLERP); - elseif erpsetArray==0 - try - erpsetArray = evalin('base', 'CURRENTERP'); % current erp index - catch - erpsetArray = length(ALLERP); - end - + latency = 0; +end +if cond1 && cond2 % either from GUI or script, when ALLERP exist and erpset indices were specified + if isempty(erpsetArray) + erpsetArray =1:length(ALLERP); + elseif erpsetArray==0 + try + erpsetArray = evalin('base', 'CURRENTERP'); % current erp index + catch + erpsetArray = length(ALLERP); end - nfile = length(erpsetArray); - optioni = 0; % from erpset menu or ALLERP struct - if isempty(binArray) % JLC - binArray = 1:min([ALLERP(erpsetArray).nbin]); - end - if isempty(chanArray) - chanArray = 1:min([ALLERP(erpsetArray).nchan]); - end + end + nfile = length(erpsetArray); + optioni = 0; % from erpset menu or ALLERP struct + + if isempty(binArray) % JLC + binArray = 1:min([ALLERP(erpsetArray).nbin]); + end + if isempty(chanArray) + chanArray = 1:min([ALLERP(erpsetArray).nchan]); + end else - filelist = ''; - optioni = 1; % from file - if iscell(ALLERP) % from the GUI, when ALLERP exist and user picks a list up as well - filelist = ALLERP{2}; - ALLERP = ALLERP{1}; - elseif ischar(ALLERP) % from script, when user picks a list. - filelist = ALLERP; - end - if isempty(binArray) % JLC - binArray = 1; - end - if isempty(chanArray) - chanArray = 1; - end - if ~iscell(filelist) && ~isempty(filelist) - disp(['For file-List, user selected ', filelist]) - fid_list = fopen( filelist ); - inputfnamex = textscan(fid_list, '%[^\n]','CommentStyle','#'); - inputfname = cellstr(char(inputfnamex{:})); - nfile = length(inputfname); - fclose(fid_list); - elseif ~isempty(filelist) && iscell(filelist) - inputfname = filelist; - nfile = length(inputfname); - else - error('ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ') - end - if isempty(erpsetArray) - erpsetArray =1:nfile; - elseif erpsetArray==0 - try - erpsetArray = evalin('base', 'CURRENTERP'); % current erp index - catch - erpsetArray = nfile; - end - + filelist = ''; + optioni = 1; % from file + if iscell(ALLERP) % from the GUI, when ALLERP exist and user picks a list up as well + filelist = ALLERP{2}; + ALLERP = ALLERP{1}; + elseif ischar(ALLERP) % from script, when user picks a list. + filelist = ALLERP; + end + if isempty(binArray) % JLC + binArray = 1; + end + if isempty(chanArray) + chanArray = 1; + end + if ~iscell(filelist) && ~isempty(filelist) + disp(['For file-List, user selected ', filelist]) + fid_list = fopen( filelist ); + inputfnamex = textscan(fid_list, '%[^\n]','CommentStyle','#'); + inputfname = cellstr(char(inputfnamex{:})); + nfile = length(inputfname); + fclose(fid_list); + elseif ~isempty(filelist) && iscell(filelist) + inputfname = filelist; + nfile = length(inputfname); + else + error('ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ') + end + if isempty(erpsetArray) + erpsetArray =1:nfile; + elseif erpsetArray==0 + try + erpsetArray = evalin('base', 'CURRENTERP'); % current erp index + catch + erpsetArray = nfile; end + + end end fname = p.Results.Filename; @@ -420,72 +422,75 @@ mlabel = strrep(mlabel, ' ', '_'); if ~isempty(frac) - if frac<0 || frac>1 - error('ERPLAB says: error at pop_geterpvalues(). Fractional area value must be between 0 and 1') - end + if frac<0 || frac>1 + error('ERPLAB says: error at pop_geterpvalues(). Fractional area value must be between 0 and 1') + end end if ischar(localrep) - lr = str2num(localrep); - if isempty(lr) - if strcmpi(localrep,'absolute') - locpeakrep = 1; - else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' localrep]) - end + lr = str2num(localrep); + if isempty(lr) + if strcmpi(localrep,'absolute') + locpeakrep = 1; + elseif strcmpi(localrep,'error') || strcmpi(localrep,'errormsg') %%GH May 2024 + locpeakrep = 2; % shows error message. Stop measuring. else - if isnan(lr) - locpeakrep = 0; - else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' localrep]) - end + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' localrep]) end -else - if isnan(localrep) - locpeakrep = 0; + else + if isnan(lr) + locpeakrep = 0; + else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' num2str(localrep(1))]) + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' localrep]) end + end +else + if isnan(localrep) + locpeakrep = 0; + else + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' num2str(localrep(1))]) + end end if ischar(fraclocalrep) - flr = str2num(fraclocalrep); - if isempty(flr) - if strcmpi(fraclocalrep,'absolute') - fracmearep = 1; - elseif strcmpi(fraclocalrep,'error') || strcmpi(fraclocalrep,'errormsg') - fracmearep = 2; % shows error message. Stop measuring. - else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' fraclocalrep]) - end + flr = str2num(fraclocalrep); + if isempty(flr) + if strcmpi(fraclocalrep,'absolute') + fracmearep = 1; + elseif strcmpi(fraclocalrep,'error') || strcmpi(fraclocalrep,'errormsg') + fracmearep = 2; % shows error message. Stop measuring. else - if isnan(flr) - fracmearep = 0; - else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' fraclocalrep]) - end + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' fraclocalrep]) end -else - if isnan(fraclocalrep) - fracmearep = 0; + else + if isnan(flr) + fracmearep = 0; else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' num2str(fraclocalrep(1))]) + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' fraclocalrep]) end + end +else + if isnan(fraclocalrep) + fracmearep = 0; + else + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' num2str(fraclocalrep(1))]) + end end sampeak = p.Results.Neighborhood; % samples around the peak if strcmpi(p.Results.Peakpolarity, 'positive') - polpeak = 1; % positive + polpeak = 1; % positive elseif strcmpi(p.Results.Peakpolarity, 'negative') - polpeak = 0; + polpeak = 0; else - error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' p.Results.Peakpolarity]); + error(['ERPLAB says: error at pop_geterpvalues(). Unrecognizable input ' p.Results.Peakpolarity]); end if strcmpi(p.Results.Binlabel, 'on') - binlabop = 1; % bin descriptor as bin label for table + binlabop = 1; % bin descriptor as bin label for table elseif strcmpi(p.Results.Binlabel, 'off') - binlabop = 0; % bin# as bin label for table + binlabop = 0; % bin# as bin label for table else - error(['ERPLAB says: Unrecognizable input ' p.Results.Binlabel]); + error(['ERPLAB says: Unrecognizable input ' p.Results.Binlabel]); end blc = p.Results.Baseline; @@ -496,422 +501,435 @@ peak_onset = p.Results.PeakOnset; if isempty(moption) - error('ERPLAB says: User must specify a type of measurement.') + error('ERPLAB says: User must specify a type of measurement.') end if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}); - if length(latency)~=1 - error(['ERPLAB says: ' moption ' only needs 1 latency value.']) - end + if length(latency)~=1 + error(['ERPLAB says: ' moption ' only needs 1 latency value.']) + end else - if length(latency)~=2 - error(['ERPLAB says: ' moption ' needs 2 latency values.']) - else - if latency(1)>=latency(2) - msgboxText = ['For latency range, lower time limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; - title = 'ERPLAB: pop_geterpvalues() inputs'; - errorfound(sprintf(msgboxText), title); - return - end - end + if length(latency)~=2 + error(['ERPLAB says: ' moption ' needs 2 latency values.']) + else + if latency(1)>=latency(2) + msgboxText = ['For latency range, lower time limit must be on the left.\n'... + 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; + title = 'ERPLAB: pop_geterpvalues() inputs'; + errorfound(sprintf(msgboxText), title); + return + end + end end if strcmpi(p.Results.Warning, 'on') - menup = 1; % enable warning message + menup = 1; % enable warning message else - menup = 0; + menup = 0; end if strcmpi(p.Results.SendtoWorkspace, 'on') - send2ws = 1; % send to workspace + send2ws = 1; % send to workspace else - send2ws = 0; + send2ws = 0; end if strcmpi(p.Results.Viewer, 'on') - viewmea = 1; % open viewer + viewmea = 1; % open viewer else - viewmea = 0; + viewmea = 0; end if strcmpi(p.Results.Append, 'on') - appendfile = 1; + appendfile = 1; else - appendfile = 0; + appendfile = 0; end if strcmpi(p.Results.FileFormat, 'long') - foutput = 1; % 1 means "long format"; 0 means "wide format" + foutput = 1; % 1 means "long format"; 0 means "wide format" else - foutput = 0; + foutput = 0; end if strcmpi(p.Results.IncludeLat, 'yes') || strcmpi(p.Results.IncludeLat, 'on') - inclate = 1; + inclate = 1; else - inclate = 0; + inclate = 0; end intfactor = p.Results.InterpFactor; if ~ismember_bc2({moption}, meacell); - msgboxText = [moption ' is not a valid option for pop_geterpvalues!']; - if shist == 1; % gui - title = 'ERPLAB: pop_geterpvalues wrong inputs'; - errorfound(msgboxText, title); - return - else - error(msgboxText) - end + msgboxText = [moption ' is not a valid option for pop_geterpvalues!']; + if shist == 1; % gui + title = 'ERPLAB: pop_geterpvalues wrong inputs'; + errorfound(msgboxText, title); + return + else + error(msgboxText) + end end if ischar(blc) - blcorrstr = ['''' blc '''' ]; + blcorrstr = ['''' blc '''' ]; else - blcorrstr = ['[' num2str(blc) ']']; + blcorrstr = ['[' num2str(blc) ']']; end if ~viewmea - [pathtest, filtest, ext] = fileparts(fname); + [pathtest, filtest, ext] = fileparts(fname); + + if isempty(filtest) + error('File name is empty.') + end + if strcmpi(ext,'.xls') + fprintf('\nWARNING:\n'); + title = 'ERPLAB: WARNING, pop_geterpvalues() export to Excel' ; + question = ['Sorry. Export to Excel is not longer supported by ERPLAB.\n\n'... + 'Do you want to continue anyway using a text file instead?']; + button = askquest(sprintf(question), title); - if isempty(filtest) - error('File name is empty.') - end - if strcmpi(ext,'.xls') - fprintf('\nWARNING:\n'); - title = 'ERPLAB: WARNING, pop_geterpvalues() export to Excel' ; - question = ['Sorry. Export to Excel is not longer supported by ERPLAB.\n\n'... - 'Do you want to continue anyway using a text file instead?']; - button = askquest(sprintf(question), title); - - if ~strcmpi(button,'yes') - disp('User selected Cancel') - return - end - if strcmp(pathtest,'') - pathtest = cd; - end - ext = '.txt'; - fname = fullfile(pathtest, [filtest ext]); - fprintf('\nOutput file will have extension %s\n', ext); - exceloption = 0; - send_to_file = 1; - % if ispc - % exceloption = 1; - % fprintf('\nOutput will be a Microsoft Excel spreadsheet file'); - % warning off MATLAB:xlswrite:AddSheet - % if strcmp(pathtest,'') - % pathtest = cd; - % fname = fullfile(pathtest, [filtest ext]); - % end - % else - % fprintf('\nWARNING:\n'); - % title = 'ERPLAB: WARNING, pop_geterpvalues() export to Excel' ; - % question = ['The full functionality of XLSWRITE depends on the ability '... - % 'to instantiate Microsoft Excel as a COM server.\n\n'... - % 'COM is a technology developed for Windows platforms and, '... - % 'at the current ERPLAB version, is not available for non-Windows machines\n\n'... - % 'Do you want to continue anyway with a text file instead?']; - % button = askquest(sprintf(question), title); - % - % if ~strcmpi(button,'yes') - % disp('User selected Cancel') - % return - % end - % if strcmp(pathtest,'') - % pathtest = cd; - % end - % ext = '.txt'; - % fname = fullfile(pathtest, [filtest ext]); - % fprintf('\nOutput file will have extension %s\n', ext); - % exceloption = 0; - % end - % send_to_file = 1; - elseif strcmpi(ext,'.no_save') - send_to_file = 0; - elseif strcmpi(ext,'.viewer') % temporary - send_to_file = 0; - else - exceloption = 0; - if strcmp(pathtest,'') - pathtest = cd; - end - if ~strcmpi(ext,'.txt')&& ~strcmpi(ext,'.dat') - ext = '.txt'; - fname = fullfile(pathtest, [filtest ext]); - end - fprintf('\nOutput file will have extension %s\n', ext); - send_to_file = 1; - end -else + if ~strcmpi(button,'yes') + disp('User selected Cancel') + return + end + if strcmp(pathtest,'') + pathtest = cd; + end + ext = '.txt'; + fname = fullfile(pathtest, [filtest ext]); + fprintf('\nOutput file will have extension %s\n', ext); + exceloption = 0; + send_to_file = 1; + % if ispc + % exceloption = 1; + % fprintf('\nOutput will be a Microsoft Excel spreadsheet file'); + % warning off MATLAB:xlswrite:AddSheet + % if strcmp(pathtest,'') + % pathtest = cd; + % fname = fullfile(pathtest, [filtest ext]); + % end + % else + % fprintf('\nWARNING:\n'); + % title = 'ERPLAB: WARNING, pop_geterpvalues() export to Excel' ; + % question = ['The full functionality of XLSWRITE depends on the ability '... + % 'to instantiate Microsoft Excel as a COM server.\n\n'... + % 'COM is a technology developed for Windows platforms and, '... + % 'at the current ERPLAB version, is not available for non-Windows machines\n\n'... + % 'Do you want to continue anyway with a text file instead?']; + % button = askquest(sprintf(question), title); + % + % if ~strcmpi(button,'yes') + % disp('User selected Cancel') + % return + % end + % if strcmp(pathtest,'') + % pathtest = cd; + % end + % ext = '.txt'; + % fname = fullfile(pathtest, [filtest ext]); + % fprintf('\nOutput file will have extension %s\n', ext); + % exceloption = 0; + % end + % send_to_file = 1; + elseif strcmpi(ext,'.no_save') send_to_file = 0; + elseif strcmpi(ext,'.viewer') % temporary + send_to_file = 0; + else + exceloption = 0; + if strcmp(pathtest,'') + pathtest = cd; + end + if ~strcmpi(ext,'.txt')&& ~strcmpi(ext,'.dat') + ext = '.txt'; + fname = fullfile(pathtest, [filtest ext]); + end + fprintf('\nOutput file will have extension %s\n', ext); + send_to_file = 1; + end +else + send_to_file = 0; end fprintf('\nBaseline period = %s will be used for measurements\n\n', blcorrstr); if optioni==1 % from files - erpsetArray = 1:nfile; % JLC. Sept 2012 + erpsetArray = 1:nfile; % JLC. Sept 2012 end conti = 1; Lat = {[]}; for k=1:nfile - if optioni==1 % from files - filex = load(inputfname{k}, '-mat'); - ERP = filex.ERP; - [ERP, conti, serror] = olderpscan(ERP, menup); - if viewmea==1 && conti==1 && serror==0 - if k==1 - ALLERPX = buildERPstruct([]); % auxiliar ALLERP - end - ALLERPX(k) = ERP; - end - else % from erpsets - ERP = ALLERP(erpsetArray(k)); - [ERP, conti, serror] = olderpscan(ERP, menup); - end - if conti==0 - break - end - if serror ==1 - kindex = k; - kname = ERP.erpname; - break - end - if k==1 - n1bin = ERP.nbin; - n1chan = ERP.nchan; - n1bdesc = ERP.bindescr; - - if isempty(binArray) % JLC - binArray = 1:n1bin; - end - if isempty(chanArray) - chanArray = 1:n1chan; - end - Amp = zeros(length(binArray), length(chanArray), nfile); - else - if ERP.nbin~=n1bin - serror = 2; - break - end - if ismember_bc2(0,ismember(lower(ERP.bindescr), lower(n1bdesc))) % May 25, 2010 - serror = 3; - break - end - end + if optioni==1 % from files + filex = load(inputfname{k}, '-mat'); + ERP = filex.ERP; + [ERP, conti, serror] = olderpscan(ERP, menup); + if viewmea==1 && conti==1 && serror==0 + if k==1 + ALLERPX = buildERPstruct([]); % auxiliar ALLERP + end + ALLERPX(k) = ERP; + end + else % from erpsets + ERP = ALLERP(erpsetArray(k)); + [ERP, conti, serror] = olderpscan(ERP, menup); + end + if conti==0 + break + end + if serror ==1 + kindex = k; + kname = ERP.erpname; + break + end + if k==1 + n1bin = ERP.nbin; + n1chan = ERP.nchan; + n1bdesc = ERP.bindescr; - datatype = checkdatatype(ERP); - if ~strcmpi(datatype, 'ERP') && ismember(moption, {'areazt','areazp','areazn', 'nintegz'} ) - error('This type of measurement (automatic area/integration) is not allowed for Power Spectrum data '); + if isempty(binArray) % JLC + binArray = 1:n1bin; end - - % - % subroutine - % - % - % Get measurements - % - fprintf('Taking measurements across ERPset #%g...\n', erpsetArray(k)) - - if inclate || viewmea % JLC. Sept 2012 - [A, lat4mea] = geterpvalues(ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor,peak_onset); + if isempty(chanArray) + chanArray = 1:n1chan; + end + Amp = zeros(length(binArray), length(chanArray), nfile); + else + if ERP.nbin~=n1bin + serror = 2; + break + end + if ismember_bc2(0,ismember(lower(ERP.bindescr), lower(n1bdesc))) % May 25, 2010 + serror = 3; + break + end + end + + datatype = checkdatatype(ERP); + if ~strcmpi(datatype, 'ERP') && ismember(moption, {'areazt','areazp','areazn', 'nintegz'} ) + error('This type of measurement (automatic area/integration) is not allowed for Power Spectrum data '); + end + + % + % subroutine + % + % + % Get measurements + % + fprintf('Taking measurements across ERPset #%g...\n', erpsetArray(k)) + + if inclate || viewmea % JLC. Sept 2012 + [A, lat4mea] = geterpvalues(ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor,peak_onset); + else + %ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor + A = geterpvalues(ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor,peak_onset); + lat4mea = []; + end + + % + % + % en vez de abortar la lectura de valores debido a un error, es mejor llenar con NAN y seguir midiendo la sgte medida.... + % Cambiar los "breaks"! + % + + if isempty(A) && viewmea==0 + errmsg = 'Empty outcome.'; + serror = 4; + break + elseif ischar(A) && viewmea==0 + errmsg = A; + serror = 4; + break + elseif (isempty(A) || ischar(A)) && viewmea==1 + if isempty(lat4mea) + A = NaN(length(binArray), length(chanArray)); % for viewer, when measurement was not possible. + lat4mea = {latency(1)}; else - %ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor - A = geterpvalues(ERP, latency, binArray, chanArray, moption, blc, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor,peak_onset); - lat4mea = []; - end - - % - % - % en vez de abortar la lectura de valores debido a un error, es mejor llenar con NAN y seguir midiendo la sgte medida.... - % Cambiar los "breaks"! - % - - if isempty(A) && viewmea==0 - errmsg = 'Empty outcome.'; - serror = 4; - break - elseif ischar(A) && viewmea==0 - errmsg = A; - serror = 4; - break - elseif (isempty(A) || ischar(A)) && viewmea==1 - if isempty(lat4mea) - A = NaN(length(binArray), length(chanArray)); % for viewer, when measurement was not possible. - lat4mea = {latency(1)}; - else - errmsg = A; - serror = 4; - break - end - %lat4mea = {}; - %[lat4mea{1:length(binArray),1:length(chanArray)}] = deal(latency); % specified latency(ies) for getting measurements. - %lat4mea = {latency(1)}; - end - - % - % Store values - % - Amp(:,:,k) = A; % bin x channel x erpset - Lat{:,:,k} = lat4mea; % bin x channel x erpset - - if send_to_file && ~viewmea - if exceloption - % - % Excel - % - exportvalues2xls(ERP, {A}, binArray,chanArray, 0, moption, fname, k+appendfile) - else - % - % Text - % - % (ERP, values, binArray, chanArray, fname, dig, ncall, binlabop, formatout, mlabel, lat4mea) - exportvaluesV2(ERP, {A}, binArray, chanArray, fname, dig, k+appendfile, binlabop, foutput, mlabel, lat4mea) - end - - prew = 'Additionally, m'; + errmsg = A; + serror = 4; + break + end + %lat4mea = {}; + %[lat4mea{1:length(binArray),1:length(chanArray)}] = deal(latency); % specified latency(ies) for getting measurements. + %lat4mea = {latency(1)}; + end + + % + % Store values + % + Amp(:,:,k) = A; % bin x channel x erpset + Lat{:,:,k} = lat4mea; % bin x channel x erpset + + if send_to_file && ~viewmea + if exceloption + % + % Excel + % + exportvalues2xls(ERP, {A}, binArray,chanArray, 0, moption, fname, k+appendfile) else - prew = 'M'; + % + % Text + % + % (ERP, values, binArray, chanArray, fname, dig, ncall, binlabop, formatout, mlabel, lat4mea) + exportvaluesV2(ERP, {A}, binArray, chanArray, fname, dig, k+appendfile, binlabop, foutput, mlabel, lat4mea) end + + prew = 'Additionally, m'; + else + prew = 'M'; + end end % % Errors % if conti==0 - return + return end + +ERPtooltype = erpgettoolversion('tooltype');%%GH May 2024 + if serror~=0 - switch serror - case 1 - msgboxText = sprintf('A problem was found at ERPset %s (%gth).', kname, kindex); - case 2 - msgboxText = ['Number of bins is different across datasets .\n'... - 'You must use ERPset related to the same experiment.']; - case 3 - msgboxText = ['The bin description set among datasets is different.\n'... - 'You must use ERPset related to the same experiment.']; - case 4 - msgboxText = errmsg ; + switch serror + case 1 + msgboxText = sprintf('A problem was found at ERPset %s (%gth).', kname, kindex); + case 2 + msgboxText = ['Number of bins is different across datasets .\n'... + 'You must use ERPset related to the same experiment.']; + case 3 + msgboxText = ['The bin description set among datasets is different.\n'... + 'You must use ERPset related to the same experiment.']; + case 4 + + switch moption%%GH May 2024 + case {'fareanlat','fareaplat','peakampbl','peaklatbl','fpeaklat'} + msgboxText = [errmsg,', erpset',num2str(k) ]; otherwise - msgboxText = 'Sorry, something went wrong.'; - end - if shist == 1; % gui - tittle = 'ERPLAB: geterpvalues() error:'; - errorfound(sprintf(msgboxText), tittle); - [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP); - pause(0.1) - return - else - error('Error:measurements', msgboxText) + msgboxText = errmsg ; + end + otherwise + msgboxText = 'Sorry, something went wrong.'; + end + if shist == 1; % gui + tittle = 'ERPLAB: geterpvalues() error:'; + errorfound(sprintf(msgboxText), tittle); + if strcmpi(ERPtooltype,'ERPLAB')%%GH May 2024 + [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP); end + pause(0.1) + return + else + error('Error:measurements', msgboxText) + end end % % Send measurements to workspace (from GUI) % if send2ws==1 - assignin('base','ERP_MEASURES', Amp); - fprintf('\n%seasured values were sent to Workspace as ERP_MEASURES.\n', prew); + assignin('base','ERP_MEASURES', Amp); + fprintf('\n%seasured values were sent to Workspace as ERP_MEASURES.\n', prew); end % % Open Viewer ******** % if viewmea==1 - comme = ''; - switch moption - case 'instabl' - moptionstr = measurearray{1}; - case 'meanbl' - moptionstr = measurearray{2}; - case 'peakampbl' - moptionstr = measurearray{3}; - if polpeak - comme = ', positive'; - else - comme = ', negative'; - end - case 'peaklatbl' - moptionstr = measurearray{4}; - if polpeak - comme = ', positive'; - else - comme = ', negative'; - end - case 'fpeaklat' - moptionstr = measurearray{5}; - if polpeak - comme = ', positive'; - else - comme = ', negative'; - end - case {'areat', 'areap', 'arean', 'ninteg'} - moptionstr = measurearray{6}; - if strcmpi(moption, 'areat') - comme = ', total'; - elseif strcmpi(moption, 'areap') - comme = ', positive'; - elseif strcmpi(moption, 'arean') - comme = ', negative'; - else - comme = '. Integral'; - end - case {'areazt','areazp','areazn', 'nintegz'} - moptionstr = measurearray{7}; - if strcmpi(moption, 'areazt') - comme = ', total'; - elseif strcmpi(moption, 'areazp') - comme = ', positive'; - elseif strcmpi(moption, 'areazn') - comme = ', negative'; - else - comme = '. Integral'; - end - case {'fareatlat', 'fareaplat','fninteglat','fareanlat', } - moptionstr = measurearray{8}; - if strcmpi(moption, 'fareatlat') - comme = ', total'; - elseif strcmpi(moption, 'fareaplat') - comme = ', positive'; - elseif strcmpi(moption, 'fareanlat') - comme = ', negative'; - else - comme = '. Integral'; - end - otherwise - return - end - - moptionstr = [moptionstr comme]; - moreoptions = {blc, moption, moptionstr, dig, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor}; - - % - % Call Viewer GUI - % - if optioni==1 % from files - mout = meaviewerGUI(ALLERPX, {Amp, Lat, binArray, chanArray, erpsetArray, latency, moreoptions}); - clear ALLERPX % auxiliar ALLERP - else - mout = meaviewerGUI(ALLERP, {Amp, Lat, binArray, chanArray, erpsetArray, latency, moreoptions}); - end - if ~isempty(mout) && iscell(mout) - %try - latfromviewer = mout{2}; - %catch - %end - if ~isempty(latfromviewer) - - if isnan(latfromviewer)% when viewer is open from plotted figure - return - end - - def = erpworkingmemory('pop_geterpvalues'); - def{4} = latfromviewer; - erpworkingmemory('pop_geterpvalues', def); - end - [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP); - pause(0.1) - return - elseif isnan(mout) % when viewer is open from plotted figure - return - else - disp('User selected Cancel') + comme = ''; + switch moption + case 'instabl' + moptionstr = measurearray{1}; + case 'meanbl' + moptionstr = measurearray{2}; + case 'peakampbl' + moptionstr = measurearray{3}; + if polpeak + comme = ', positive'; + else + comme = ', negative'; + end + case 'peaklatbl' + moptionstr = measurearray{4}; + if polpeak + comme = ', positive'; + else + comme = ', negative'; + end + case 'fpeaklat' + moptionstr = measurearray{5}; + if polpeak + comme = ', positive'; + else + comme = ', negative'; + end + case {'areat', 'areap', 'arean', 'ninteg'} + moptionstr = measurearray{6}; + if strcmpi(moption, 'areat') + comme = ', total'; + elseif strcmpi(moption, 'areap') + comme = ', positive'; + elseif strcmpi(moption, 'arean') + comme = ', negative'; + else + comme = '. Integral'; + end + case {'areazt','areazp','areazn', 'nintegz'} + moptionstr = measurearray{7}; + if strcmpi(moption, 'areazt') + comme = ', total'; + elseif strcmpi(moption, 'areazp') + comme = ', positive'; + elseif strcmpi(moption, 'areazn') + comme = ', negative'; + else + comme = '. Integral'; + end + case {'fareatlat', 'fareaplat','fninteglat','fareanlat', } + moptionstr = measurearray{8}; + if strcmpi(moption, 'fareatlat') + comme = ', total'; + elseif strcmpi(moption, 'fareaplat') + comme = ', positive'; + elseif strcmpi(moption, 'fareanlat') + comme = ', negative'; + else + comme = '. Integral'; + end + otherwise + return + end + + moptionstr = [moptionstr comme]; + moreoptions = {blc, moption, moptionstr, dig, coi, polpeak, sampeak, locpeakrep, frac, fracmearep, intfactor}; + + % + % Call Viewer GUI + % + if optioni==1 % from files + mout = meaviewerGUI(ALLERPX, {Amp, Lat, binArray, chanArray, erpsetArray, latency, moreoptions}); + clear ALLERPX % auxiliar ALLERP + else + mout = meaviewerGUI(ALLERP, {Amp, Lat, binArray, chanArray, erpsetArray, latency, moreoptions}); + end + if ~isempty(mout) && iscell(mout) + %try + latfromviewer = mout{2}; + %catch + %end + if ~isempty(latfromviewer) + + if isnan(latfromviewer)% when viewer is open from plotted figure return + end + + def = erpworkingmemory('pop_geterpvalues'); + def{4} = latfromviewer; + erpworkingmemory('pop_geterpvalues', def); + end + if strcmpi(ERPtooltype,'ERPLAB')%%GH May 2024 + [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP); end + pause(0.1) + return + elseif isnan(mout) % when viewer is open from plotted figure + return + else + disp('User selected Cancel') + return + end end @@ -934,57 +952,57 @@ skipfields = {'ALLERP', 'latency', 'binArray','chanArray', 'Component', 'Warning','History'}; if isstruct(ALLERP) && optioni~=1 % from files - if length(erpsetArray)==1 && erpsetArray==1 - DATIN = 'ERP'; - skipfields = [skipfields, 'Erpsets']; - else - DATIN = inputname(1); - end -else - %DATIN = ['''' ALLERP '''']; - DATIN = sprintf('''%s''', filelist); + if length(erpsetArray)==1 && erpsetArray==1 + DATIN = 'ERP'; skipfields = [skipfields, 'Erpsets']; + else + DATIN = inputname(1); + end +else + %DATIN = ['''' ALLERP '''']; + DATIN = sprintf('''%s''', filelist); + skipfields = [skipfields, 'Erpsets']; end if ~ismember_bc2({moption}, {'peakampbl', 'peaklatbl', 'fpeaklat'}) % JLC. 08/22/13 - skipfields = [skipfields {'Neighborhood', 'Peakpolarity', 'Peakreplace'}]; + skipfields = [skipfields {'Neighborhood', 'Peakpolarity', 'Peakreplace'}]; end if strcmpi(fname,'no_save.no_save') || strcmpi(fname,'tempofile.txt') - skipfields = [skipfields {'Filename'}]; + skipfields = [skipfields {'Filename'}]; end fn = fieldnames(p.Results); erpcom = sprintf( 'ALLERP = pop_geterpvalues( %s, %s, %s, %s ', DATIN, latencystr, binArraystr, chanArraystr); for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') && ~strcmpi(fn2res,'no') - erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); - end - else - erpcom = sprintf( '%s, ''%s'', %s', erpcom, fn2com, vect2colon(fn2res,'Repeat','on')); - end + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') && ~strcmpi(fn2res,'no') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); end + else + erpcom = sprintf( '%s, ''%s'', %s', erpcom, fn2com, vect2colon(fn2res,'Repeat','on')); + end end + end end erpcom = sprintf( '%s );', erpcom); % get history from script. ERP switch shist - case 1 % from GUI - displayEquiComERP(erpcom); - case 2 % from script - for i=1:length(ALLERP) - ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); - end - case 3 - % implicit - %for i=1:length(ALLERP) - % ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); - %end - %fprintf('%%Equivalent command:\n%s\n\n', erpcom); - otherwise %off or none - erpcom = ''; - return + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for i=1:length(ALLERP) + ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); + end + case 3 + % implicit + %for i=1:length(ALLERP) + % ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); + %end + %fprintf('%%Equivalent command:\n%s\n\n', erpcom); + otherwise %off or none + erpcom = ''; + return end return diff --git a/pop_functions/pop_importeegeventlist.m b/pop_functions/pop_importeegeventlist.m index 9d4703c3..0570ee66 100755 --- a/pop_functions/pop_importeegeventlist.m +++ b/pop_functions/pop_importeegeventlist.m @@ -54,68 +54,68 @@ function [EEG, com] = pop_importeegeventlist(EEG, ELfullname, varargin) com = ''; if nargin < 1 - help pop_importeegeventlist - return + help pop_importeegeventlist + return end if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if nargin==1 - if length(EEG)>1 - msgboxText = 'Unfortunately, this function does not work with multiple datasets'; - title = 'ERPLAB: multiple inputs'; - errorfound(msgboxText, title); - return - end - if isempty(EEG) - msgboxText = 'pop_importeegeventlist() error: cannot work with an empty dataset!'; - title = 'ERPLAB: pop_importeegeventlist() error'; - errorfound(msgboxText, title); - return - end - if isempty(EEG.data) - msgboxText = 'pop_importeegeventlist() cannot work with an empty dataset!'; - title = 'ERPLAB: pop_importeegeventlist() error'; - errorfound(msgboxText, title); - return - end - if ~isempty(EEG.epoch) - msgboxText = 'pop_importeegeventlist() has been tested for continuous data only.'; - title = 'ERPLAB: pop_importeegeventlist Permission denied'; - errorfound(msgboxText, title); - return - end - [filename,pathname] = uigetfile({'*.*';'*.txt'},'Select a EVENTLIST file'); - ELfullname = fullfile(pathname, filename); - - if isequal(filename,0) - disp('User selected Cancel') - return - else - disp(['For read an EVENTLIST, user selected ', ELfullname]) - end - - question = ['Do you want to replace your EEG.EVENTLIST field with this file?\n\n'... - ' (YES: replace) (NO: sent EVENTLIST to workspace)']; - title = 'ERPLAB: Confirmation'; - button = askquest(sprintf(question), title); - - if strcmpi(button,'yes') - repEL = 'on'; - elseif strcmpi(button,'no') - repEL = 'off'; - else - disp('User selected Cancel') - return - end - - % - % Somersault - % - EEG.setname = [EEG.setname '_impel']; %suggest a new name (Imported Event List) - [EEG, com] = pop_importeegeventlist(EEG, ELfullname, 'ReplaceEventList', repEL, 'History', 'gui'); + if length(EEG)>1 + msgboxText = 'Unfortunately, this function does not work with multiple datasets'; + title = 'ERPLAB: multiple inputs'; + errorfound(msgboxText, title); + return + end + if isempty(EEG) + msgboxText = 'pop_importeegeventlist() error: cannot work with an empty dataset!'; + title = 'ERPLAB: pop_importeegeventlist() error'; + errorfound(msgboxText, title); + return + end + if isempty(EEG.data) + msgboxText = 'pop_importeegeventlist() cannot work with an empty dataset!'; + title = 'ERPLAB: pop_importeegeventlist() error'; + errorfound(msgboxText, title); return + end + if ~isempty(EEG.epoch) + msgboxText = 'pop_importeegeventlist() has been tested for continuous data only.'; + title = 'ERPLAB: pop_importeegeventlist Permission denied'; + errorfound(msgboxText, title); + return + end + [filename,pathname] = uigetfile({'*.txt';'*.xls,*.xlsx';'*.*'},'Select a EVENTLIST file'); + ELfullname = fullfile(pathname, filename); + + if isequal(filename,0) + disp('User selected Cancel') + return + else + disp(['For read an EVENTLIST, user selected ', ELfullname]) + end + + question = ['Do you want to replace your EEG.EVENTLIST field with this file?\n\n'... + ' (YES: replace) (NO: sent EVENTLIST to workspace)']; + title = 'ERPLAB: Confirmation'; + button = askquest(sprintf(question), title); + + if strcmpi(button,'yes') + repEL = 'on'; + elseif strcmpi(button,'no') + repEL = 'off'; + else + disp('User selected Cancel') + return + end + + % + % Somersault + % + EEG.setname = [EEG.setname '_impel']; %suggest a new name (Imported Event List) + [EEG, com] = pop_importeegeventlist(EEG, ELfullname, 'ReplaceEventList', repEL, 'History', 'gui'); + return end % @@ -134,134 +134,138 @@ p.parse(EEG, ELfullname, varargin{:}); if length(EEG)>1 - msgboxText = 'Unfortunately, this function does not work with multiple datasets'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'Unfortunately, this function does not work with multiple datasets'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if isempty(EEG) - msgboxText = 'pop_importeegeventlist() error: cannot work with an empty dataset!'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'pop_importeegeventlist() error: cannot work with an empty dataset!'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if isempty(EEG.data) - msgboxText = 'pop_importeegeventlist() cannot work with an empty dataset!'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'pop_importeegeventlist() cannot work with an empty dataset!'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if ~isempty(EEG.epoch) - msgboxText = 'pop_importeegeventlist() has been tested for continuous data only.'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'pop_importeegeventlist() has been tested for continuous data only.'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if strcmpi(p.Results.ReplaceEventList,'on') - repEL = 1; + repEL = 1; else - repEL = 0; + repEL = 0; end if strcmpi(p.Results.Warning, 'on') - rwwarn = 1; + rwwarn = 1; else - rwwarn = 0; + rwwarn = 0; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end % % subroutine % -[EEG, EVENTLIST] = readeventlist(EEG, ELfullname); -[pathstr, filename, ext] = fileparts(ELfullname); +[pathstr, filename, ext] = fileparts(ELfullname);%%GH Mar 2024 +if strcmpi(ext,'.txt') + [EEG, EVENTLIST] = readeventlist(EEG, ELfullname); +else + [EEG, EVENTLIST] = f_readeventlist_excel(EEG, ELfullname); +end if repEL - if ~isempty(EVENTLIST) - EEG = pasteeventlist(EEG, EVENTLIST, 1); % joints both structs - EEG = pop_overwritevent(EEG, 'code'); - EEG.EVENTLIST = []; - [EEG, EVENTLIST] = creaeventlist(EEG, EVENTLIST, [filename '_new_' num2str((datenum(datestr(now))*1e10)) '.txt'], 0); - EEG = pasteeventlist(EEG, EVENTLIST, 1); % joints both structs - - disp('EVENTLIST was added to the current EEG structure') - else - EEG.EVENTLIST = []; - [EEG, EVENTLIST] = creaeventlist(EEG, EVENTLIST, [filename '_new_' num2str((datenum(datestr(now))*1e10)) '.txt'], 1); - EEG = pasteeventlist(EEG, EVENTLIST, 1); % joints both structs - end - - % - % History - % - skipfields = {'EEG', 'ELfullname','History'}; - fn = fieldnames(p.Results); + if ~isempty(EVENTLIST) + EEG = pasteeventlist(EEG, EVENTLIST, 1); % joints both structs + EEG = pop_overwritevent(EEG, 'code'); + EEG.EVENTLIST = []; + [EEG, EVENTLIST] = creaeventlist(EEG, EVENTLIST, [filename '_new_' num2str((datenum(datestr(now))*1e10)) '.txt'], 0); + EEG = pasteeventlist(EEG, EVENTLIST, 1); % joints both structs - com = sprintf('%s = pop_importeegeventlist( %s, ''%s'' ', inputname(1), inputname(1), ELfullname); - - for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); - end - else - if iscell(fn2res) - if ischar([fn2res{:}]) - fn2resstr = sprintf('''%s'' ', fn2res{:}); - else - fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - end - fnformat = '{%s}'; - else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - end - if strcmpi(fn2com,'Criterion') - if p.Results.Criterion<100 - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - else - com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); - end - end + disp('EVENTLIST was added to the current EEG structure') + else + EEG.EVENTLIST = []; + [EEG, EVENTLIST] = creaeventlist(EEG, EVENTLIST, [filename '_new_' num2str((datenum(datestr(now))*1e10)) '.txt'], 1); + EEG = pasteeventlist(EEG, EVENTLIST, 1); % joints both structs + end + + % + % History + % + skipfields = {'EEG', 'ELfullname','History'}; + fn = fieldnames(p.Results); + + com = sprintf('%s = pop_importeegeventlist( %s, ''%s'' ', inputname(1), inputname(1), ELfullname); + + for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + com = sprintf( '%s, ''%s'', ''%s''', com, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); end + else + com = sprintf( ['%s, ''%s'', ' fnformat], com, fn2com, fn2resstr); + end end + end end - com = sprintf( '%s );', com); - - % com = sprintf( '%s = pop_importeegeventlist( %s, ''%s'', %s );', inputname(1), inputname(1),... - % ELfullname, num2str(repEL)); - % % get history from script - % if shist - % EEG = erphistory(EEG, [], com, 1); - % else - % com = sprintf('%s %% %s', com, datestr(now)); - % end + end + com = sprintf( '%s );', com); + + % com = sprintf( '%s = pop_importeegeventlist( %s, ''%s'', %s );', inputname(1), inputname(1),... + % ELfullname, num2str(repEL)); + % % get history from script + % if shist + % EEG = erphistory(EEG, [], com, 1); + % else + % com = sprintf('%s %% %s', com, datestr(now)); + % end else - filenamex = regexprep(filename, ' ', '_'); - assignin('base',filenamex,EVENTLIST); - disp(['EVENTLIST was added to WORKSPACE as ' filenamex] ) + filenamex = regexprep(filename, ' ', '_'); + assignin('base',filenamex,EVENTLIST); + disp(['EVENTLIST was added to WORKSPACE as ' filenamex] ) end % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - %EEG = erphistory(EEG, [], com, 1); - %fprintf('%%Equivalent command:\n%s\n\n', erpcom); - otherwise %off or none - com = ''; - return + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + %EEG = erphistory(EEG, [], com, 1); + %fprintf('%%Equivalent command:\n%s\n\n', erpcom); + otherwise %off or none + com = ''; + return end % diff --git a/pop_functions/pop_importerpeventlist.m b/pop_functions/pop_importerpeventlist.m index 99786fff..51930ea9 100755 --- a/pop_functions/pop_importerpeventlist.m +++ b/pop_functions/pop_importerpeventlist.m @@ -59,54 +59,54 @@ function [ERP, erpcom] = pop_importerpeventlist(ERP, ELfullname, varargin) erpcom = ''; if nargin < 1 - help pop_importerpeventlist - return + help pop_importerpeventlist + return end if isempty(ERP) - msgboxText = 'pop_importerpeventlist() cannot work with an empty erpset!'; - title = 'ERPLAB: pop_importerpeventlist() error'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_importerpeventlist() cannot work with an empty erpset!'; + title = 'ERPLAB: pop_importerpeventlist() error'; + errorfound(msgboxText, title); + return end if isempty(ERP.bindata) - msgboxText = 'pop_importerpeventlist() cannot work with an empty erpset!'; - title = 'ERPLAB: pop_importerpeventlist() error'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_importerpeventlist() cannot work with an empty erpset!'; + title = 'ERPLAB: pop_importerpeventlist() error'; + errorfound(msgboxText, title); + return end if nargin==1 - % - % Call GUI - % - answer = eventlist2erpGUI(ERP); - - if isempty(answer) - disp('User selected Cancel') - return - end - - ELfullname = answer{1}; - repEL = answer{2}; - indexel = answer{3}; - - if repEL==0 - repEL = 'replaceall'; - elseif repEL==1 - repEL = 'replace'; - elseif repEL==2 - repEL = 'append'; - else - disp('User selected Cancel') - return - end - - ERP.erpname = [ERP.erpname '_impel']; %suggest a new name (Imported Event List) - - % - % Somersault - % - [ERP, erpcom] = pop_importerpeventlist(ERP, ELfullname, 'ReplaceEventList', repEL, 'EventListIndex', indexel, 'Saveas', 'on', 'History', 'gui'); + % + % Call GUI + % + answer = eventlist2erpGUI(ERP); + + if isempty(answer) + disp('User selected Cancel') + return + end + + ELfullname = answer{1}; + repEL = answer{2}; + indexel = answer{3}; + + if repEL==0 + repEL = 'replaceall'; + elseif repEL==1 + repEL = 'replace'; + elseif repEL==2 + repEL = 'append'; + else + disp('User selected Cancel') return + end + + ERP.erpname = [ERP.erpname '_impel']; %suggest a new name (Imported Event List) + + % + % Somersault + % + [ERP, erpcom] = pop_importerpeventlist(ERP, ELfullname, 'ReplaceEventList', repEL, 'EventListIndex', indexel, 'Saveas', 'on', 'History', 'gui'); + return end % @@ -129,59 +129,66 @@ indexel = p.Results.EventListIndex; if strcmpi(p.Results.ReplaceEventList,'replaceall') - repEL = 0; + repEL = 0; elseif strcmpi(p.Results.ReplaceEventList,'replace') - repEL = 1; + repEL = 1; elseif strcmpi(p.Results.ReplaceEventList,'append') - repEL = 2; + repEL = 2; else - error('ERPLAB says: Invalid value for "ReplaceEventList"') + error('ERPLAB says: Invalid value for "ReplaceEventList"') end if strcmpi(p.Results.Warning, 'on') - rwwarn = 1; + rwwarn = 1; else - rwwarn = 0; + rwwarn = 0; end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end if ismember_bc2({p.Results.Saveas}, {'on','yes'}) - issaveas = 1; + issaveas = 1; else - issaveas = 0; + issaveas = 0; end ERPaux = ERP; % % subroutine % -[ERP, EVENTLIST, serror] = importerpeventlist(ERP, ELfullname); +[pathstr, filename, ext] = fileparts(ELfullname);%%GH Mar 2024 +if strcmpi(ext,'.txt') + [ERP, EVENTLIST, serror] = importerpeventlist(ERP, ELfullname); +else + [ERP1, EVENTLIST] = f_readeventlist_excel(ERP, ELfullname); + ERP.EVENTLIST.eventinfo = EVENTLIST.eventinfo; + serror = 0; +end if serror==1 - return + return end % [pathstr, filename, ext] = fileparts(ELfullname); %#ok if repEL==0 % make #1 - ERP.EVENTLIST = []; - ERP = pasteeventlist(ERP, EVENTLIST, 1); + ERP.EVENTLIST = []; + ERP = pasteeventlist(ERP, EVENTLIST, 1); elseif repEL==1 % replace - ERP = pasteeventlist(ERP, EVENTLIST, 1, indexel); + ERP = pasteeventlist(ERP, EVENTLIST, 1, indexel); elseif repEL==2 % append - nelnext = length(ERP.EVENTLIST)+1; - ERP = pasteeventlist(ERP, EVENTLIST, 1, nelnext); + nelnext = length(ERP.EVENTLIST)+1; + ERP = pasteeventlist(ERP, EVENTLIST, 1, nelnext); else - ERP = pasteeventlist(ERP, EVENTLIST, 0); - %filenamex = regexprep(filename, ' ', '_'); - %assignin('base',filenamex,EVENTLIST); - %disp(['EVENTLIST was added to WORKSPACE as ' filenamex] ) - return + ERP = pasteeventlist(ERP, EVENTLIST, 0); + %filenamex = regexprep(filename, ' ', '_'); + %assignin('base',filenamex,EVENTLIST); + %disp(['EVENTLIST was added to WORKSPACE as ' filenamex] ) + return end ERP.saved = 'no'; @@ -192,70 +199,70 @@ fn = fieldnames(p.Results); erpcom = sprintf( '%s = pop_importerpeventlist( %s, "%s" ', inputname(1), inputname(1), ELfullname); for q=1:length(fn) - fn2com = fn{q}; - if ~ismember_bc2(fn2com, skipfields) - fn2res = p.Results.(fn2com); - if ~isempty(fn2res) - if ischar(fn2res) - if ~strcmpi(fn2res,'off') - erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); - end - else - if iscell(fn2res) - if ischar([fn2res{:}]) - fn2resstr = sprintf('''%s'' ', fn2res{:}); - else - fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); - end - fnformat = '{%s}'; - else - fn2resstr = vect2colon(fn2res, 'Sort','on'); - fnformat = '%s'; - end - if strcmpi(fn2com,'Criterion') - if p.Results.Criterion<100 - erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); - end - else - erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); - end - end + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + else + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + end end + end end erpcom = sprintf( '%s );', erpcom); -if issaveas - [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); - if issave>0 - % generate text command - if issave==2 - erpcom = sprintf('%s\n%s', erpcom, erpcom_save); - msgwrng = '*** Your ERPset was saved on your hard drive.***'; - else - msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; - end - fprintf('\n%s\n\n', msgwrng) - try cprintf([0 0 1], 'COMPLETE\n\n');catch,fprintf('COMPLETE\n\n');end ; - else - ERP = ERPaux; - msgwrng = 'ERPLAB Warning: Your changes were not saved'; - try cprintf([1 0.52 0.2], '%s\n\n', msgwrng);catch,fprintf('%s\n\n', msgwrng);end ; - end +if issaveas + [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); + if issave>0 + % generate text command + if issave==2 + erpcom = sprintf('%s\n%s', erpcom, erpcom_save); + msgwrng = '*** Your ERPset was saved on your hard drive.***'; + else + msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; + end + fprintf('\n%s\n\n', msgwrng) + try cprintf([0 0 1], 'COMPLETE\n\n');catch,fprintf('COMPLETE\n\n');end ; + else + ERP = ERPaux; + msgwrng = 'ERPLAB Warning: Your changes were not saved'; + try cprintf([1 0.52 0.2], '%s\n\n', msgwrng);catch,fprintf('%s\n\n', msgwrng);end ; + end end % get history from script. ERP switch shist - case 1 % from GUI - displayEquiComERP(erpcom); - case 2 % from script - ERP = erphistory(ERP, [], erpcom, 1); - case 3 - % implicit - % ERP = erphistory(ERP, [], erpcom, 1); - % fprintf('%%Equivalent command:\n%s\n\n', erpcom); - otherwise %off or none - erpcom = ''; - return + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + ERP = erphistory(ERP, [], erpcom, 1); + case 3 + % implicit + % ERP = erphistory(ERP, [], erpcom, 1); + % fprintf('%%Equivalent command:\n%s\n\n', erpcom); + otherwise %off or none + erpcom = ''; + return end % % Completion statement diff --git a/pop_functions/pop_remove_response_mistakes.m b/pop_functions/pop_remove_response_mistakes.m index 3e5aa916..8dae7042 100755 --- a/pop_functions/pop_remove_response_mistakes.m +++ b/pop_functions/pop_remove_response_mistakes.m @@ -12,8 +12,10 @@ end EEG = remove_response_mistakes(EEG,stim_codes,resp_codes,1); - -[ALLEEG,EEG] = pop_newset(ALLEEG,EEG,CURRENTSET); - -hist_com = ['[ALLEEG EEG] = pop_remove_response_mistakes(ALLEEG, EEG, CURRENTSET, ' num2str(stim_codes) ',' num2str(resp_codes) ]; +ERPtooltype = erpgettoolversion('tooltype'); +if ~strcmpi(ERPtooltype,'estudio') + [ALLEEG,EEG] = pop_newset(ALLEEG,EEG,CURRENTSET); +end +stim_codesstr = vect2colon(stim_codes);resp_codesstr = vect2colon(resp_codes); +hist_com = ['[ALLEEG EEG] = pop_remove_response_mistakes(ALLEEG, EEG, CURRENTSET,', stim_codesstr, ',',resp_codesstr,');' ]; diff --git a/pop_functions/pop_squeezevents.m b/pop_functions/pop_squeezevents.m index 30617952..9134d843 100755 --- a/pop_functions/pop_squeezevents.m +++ b/pop_functions/pop_squeezevents.m @@ -47,38 +47,38 @@ function [EEG, com] = pop_squeezevents(EEG, varargin) com = ''; if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if isempty(EEG(1)) - msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; - title = 'ERPLAB: pop_squeezevents Permission denied'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; + title = 'ERPLAB: pop_squeezevents Permission denied'; + errorfound(msgboxText, title); + return end if ~isempty(EEG(1).epoch) - msgboxText = 'pop_squeezevents() has been tested for continuous data only.'; - title = 'ERPLAB: pop_squeezevents Permission denied'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_squeezevents() has been tested for continuous data only.'; + title = 'ERPLAB: pop_squeezevents Permission denied'; + errorfound(msgboxText, title); + return end if isempty(EEG(1).data) - msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; - title = 'ERPLAB: pop_squeezevents Permission denied'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; + title = 'ERPLAB: pop_squeezevents Permission denied'; + errorfound(msgboxText, title); + return end if isempty(EEG(1).event) - msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; - title = 'ERPLAB: pop_squeezevents Permission denied'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; + title = 'ERPLAB: pop_squeezevents Permission denied'; + errorfound(msgboxText, title); + return end if isempty([EEG(1).event.type]) - msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; - title = 'ERPLAB: pop_squeezevents Permission denied'; - errorfound(msgboxText, title); - return + msgboxText = 'pop_squeezevents() cannot work with an empty dataset.'; + title = 'ERPLAB: pop_squeezevents Permission denied'; + errorfound(msgboxText, title); + return end p = inputParser; @@ -89,41 +89,58 @@ p.parse(EEG, varargin{:}); if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end % % process multiple datasets April 13, 2011 JLC % if length(EEG) > 1 - [EEG, com ] = eeg_eval( 'pop_squeezevents', EEG, 'warning', 'on'); - return; + [EEG, com ] = eeg_eval( 'pop_squeezevents', EEG, 'warning', 'on'); + return; end - +%%for events squeezevents(EEG.event); + +%%for bins if exist---Jan 09 2024 GH +if isfield(EEG,'EVENTLIST') && ~isempty(EEG.EVENTLIST) + if ~isempty(EEG.EVENTLIST.trialsperbin) + for jjj = 1:length(EEG.EVENTLIST.eventinfo) + eventbini(jjj,1) = EEG.EVENTLIST.eventinfo(jjj).bini; + end + if any(eventbini(:)>0) + fprintf('\n\n**Below is the number and description of each bin:\n\n') + for ii = 1:numel(EEG.EVENTLIST.trialsperbin) + fprintf(['bin',32,num2str(ii),', #',32,num2str(EEG.EVENTLIST.trialsperbin(ii)),',',32,EEG.EVENTLIST.bdf(ii).description,'\n']) + end + end + end +end%%change end + + com = sprintf( 'pop_squeezevents(%s);', inputname(1)); % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - % EEG = erphistory(EEG, [], com, 1); - % fprintf('%%Equivalent command:\n%s\n\n', com); - otherwise %off or none - com = ''; - return + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + % EEG = erphistory(EEG, [], com, 1); + % fprintf('%%Equivalent command:\n%s\n\n', com); + otherwise %off or none + com = ''; + return end % diff --git a/pop_functions/pop_summary_AR_eeg_detection.m b/pop_functions/pop_summary_AR_eeg_detection.m index c31f03c5..40e32a7c 100755 --- a/pop_functions/pop_summary_AR_eeg_detection.m +++ b/pop_functions/pop_summary_AR_eeg_detection.m @@ -52,74 +52,80 @@ rej = []; histoflags = []; if nargin<1 - help pop_summary_AR_eeg_detection - return + help pop_summary_AR_eeg_detection + return end if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if nargin==1 - if length(EEG)>1 - msgboxText = 'Unfortunately, pop_summary_AR_eeg_detection() does not work with multiple datasets'; - title = 'ERPLAB: multiple inputs'; - errorfound(msgboxText, title); - return - end - if isempty(EEG.epoch) - msgboxText = 'pop_summary_AR_eeg_detection() only works with epoched dataset.'; - title = 'ERPLAB: pop_summary_AR_eeg_detection'; - errorfound(sprintf(msgboxText), title); - return - end - - BackERPLABcolor = [1 0.9 0.3]; % ERPLAB main window background - question = 'In order to see your summary, what would you like to do?'; + if length(EEG)>1 + msgboxText = 'Unfortunately, pop_summary_AR_eeg_detection() does not work with multiple datasets'; + title = 'ERPLAB: multiple inputs'; + errorfound(msgboxText, title); + return + end + if isempty(EEG.epoch) + msgboxText = 'pop_summary_AR_eeg_detection() only works with epoched dataset.'; + title = 'ERPLAB: pop_summary_AR_eeg_detection'; + errorfound(sprintf(msgboxText), title); + return + end + + BackERPLABcolor = [1 0.9 0.3]; % ERPLAB main window background + question = 'In order to see your summary, what would you like to do?'; + + if isempty(EEG.setname)%%changed by GH Sep. 2023 title = 'Artifact detection summary'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(question, title,'Save in a file','Show at Command Window', 'Cancel','Show at Command Window'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) + else + title = ['Artifact detection summary for ',EEG.setname]; + end + + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(question, title,'Save in a file','Show at Command Window', 'Cancel','Show at Command Window'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor) + + if strcmpi(button,'Show at Command Window') + fullname = ''; + elseif strcmpi(button,'Save in a file') - if strcmpi(button,'Show at Command Window') - fullname = ''; - elseif strcmpi(button,'Save in a file') - - % - % Save OUTPUT file - % - [filename, filepath, filterindex] = uiputfile({'*.txt';'*.dat';'*.*'},'Save Artifact Detection Summary as', ['AR_summary_' EEG.setname]); + % + % Save OUTPUT file + % + [filename, filepath, filterindex] = uiputfile({'*.txt';'*.dat';'*.*'},'Save Artifact Detection Summary as', ['AR_summary_' EEG.setname]); + + if isequal(filename,0) + disp('User selected Cancel') + return + else + [px, fname, ext] = fileparts(filename); + + if strcmp(ext,'') - if isequal(filename,0) - disp('User selected Cancel') - return + if filterindex==1 || filterindex==3 + ext = '.txt'; else - [px, fname, ext] = fileparts(filename); - - if strcmp(ext,'') - - if filterindex==1 || filterindex==3 - ext = '.txt'; - else - ext = '.dat'; - end - end - - fname = [ fname ext]; - fullname = fullfile(filepath, fname); - disp(['For saving artifact detection summary, user selected
' fullname '']) - + ext = '.dat'; end - elseif strcmpi(button,'Cancel') || strcmpi(button,'') - disp('User selected Cancel') - return + end + + fname = [ fname ext]; + fullname = fullfile(filepath, fname); + disp(['For saving artifact detection summary, user selected ' fullname '']) + end - - % - % Somersault - % - [EEG, tprej, acce, rej, histoflags, com] = pop_summary_AR_eeg_detection(EEG, fullname, 'History', 'gui'); + elseif strcmpi(button,'Cancel') || strcmpi(button,'') + disp('User selected Cancel') return + end + + % + % Somersault + % + [EEG, tprej, acce, rej, histoflags, com] = pop_summary_AR_eeg_detection(EEG, fullname, 'History', 'gui'); + return end % @@ -135,30 +141,30 @@ p.parse(EEG, fullname, varargin{:}); if length(EEG)>1 - msgboxText = 'Unfortunately, pop_summary_AR_eeg_detection() does not work with multiple datasets'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'Unfortunately, pop_summary_AR_eeg_detection() does not work with multiple datasets'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if isempty(EEG.epoch) - msgboxText = 'pop_summary_AR_eeg_detection() only works with epoched dataset.'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'pop_summary_AR_eeg_detection() only works with epoched dataset.'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end if isempty(strtrim(fullname)) - fidsumm = 1; % to command window + fidsumm = 1; % to command window else - if strcmpi(strtrim(fullname), 'none') - fidsumm = -99; - else - fidsumm = fopen( fullname , 'w'); % to a file - end + if strcmpi(strtrim(fullname), 'none') + fidsumm = -99; + else + fidsumm = fopen( fullname , 'w'); % to a file + end end F = fieldnames(EEG.reject); @@ -170,66 +176,66 @@ histT = zeros(1, EEG.trials); for i=1:nfield - fieldnameE = char(sfields2{i}); - fieldnameT = char(rfields{i}); - - if ~isempty(EEG.reject.(fieldnameE)) - histE = histE | [EEG.reject.(fieldnameE)]; %electrodes - histT = histT | [EEG.reject.(fieldnameT)]; %trials (epochs) - end + fieldnameE = char(sfields2{i}); + fieldnameT = char(rfields{i}); + + if ~isempty(EEG.reject.(fieldnameE)) + histE = histE | [EEG.reject.(fieldnameE)]; %electrodes + histT = histT | [EEG.reject.(fieldnameT)]; %trials (epochs) + end end nbin = EEG.EVENTLIST.nbin; Sumbin = zeros(1,nbin); for i=1:nbin - for j=1:EEG.trials - if length(EEG.epoch(j).eventlatency) == 1 - binix = [EEG.epoch(j).eventbini]; - if iscell(binix) - binix = cell2mat(binix); - end - if ismember(i, binix) - Sumbin(i) = Sumbin(i) + histT(j); - end - elseif length(EEG.epoch(j).eventlatency) > 1 - indxtimelock = find(cell2mat(EEG.epoch(j).eventlatency) == 0,1,'first'); % catch zero-time locked type, - if ismember(i, EEG.epoch(j).eventbini{indxtimelock}) - Sumbin(i) = Sumbin(i) + histT(j); - end - end + for j=1:EEG.trials + if length(EEG.epoch(j).eventlatency) == 1 + binix = [EEG.epoch(j).eventbini]; + if iscell(binix) + binix = cell2mat(binix); + end + if ismember(i, binix) + Sumbin(i) = Sumbin(i) + histT(j); + end + elseif length(EEG.epoch(j).eventlatency) > 1 + indxtimelock = find(cell2mat(EEG.epoch(j).eventlatency) == 0,1,'first'); % catch zero-time locked type, + if ismember(i, EEG.epoch(j).eventbini{indxtimelock}) + Sumbin(i) = Sumbin(i) + histT(j); + end end + end end histoflags = summary_rejectflags(EEG); if fidsumm~=-99 - % - % Table - % - hdr = {'Bin' '#(%) accepted' '#(%) rejected' '# F2' '# F3' '# F4' '# F5' '# F6' '# F7' '# F8' }; - fprintf(fidsumm, '%s %15s %15s %7s %7s %7s %7s %7s %7s %7s\n', hdr{:}); + % + % Table + % + hdr = {'Bin' '#(%) accepted' '#(%) rejected' '# F2' '# F3' '# F4' '# F5' '# F6' '# F7' '# F8' }; + fprintf(fidsumm, '%s %15s %15s %7s %7s %7s %7s %7s %7s %7s\n', hdr{:}); end acce = zeros(1,nbin); rej = zeros(1,nbin); for i=1:nbin - rej(i) = Sumbin(i) ; - acce(i) = EEG.EVENTLIST.trialsperbin(i)-rej(i); - - if EEG.EVENTLIST.trialsperbin(i) ~= 0 - pacce = (acce(i)/EEG.EVENTLIST.trialsperbin(i))*100; - paccestr = sprintf('%.1f', pacce); - prej = (rej(i)/EEG.EVENTLIST.trialsperbin(i))*100; - prejstr = sprintf('%.1f', prej); - else - paccestr = 'error'; - prejstr = 'error'; - end - if fidsumm~=-99 - fprintf(fidsumm, '%3g %6g(%5s) %8g(%5s) %7g %7g %7g %7g %7g %7g %7g\n', i,acce(i), paccestr, rej(i), prejstr, histoflags(i,2:8)); - end + rej(i) = Sumbin(i) ; + acce(i) = EEG.EVENTLIST.trialsperbin(i)-rej(i); + + if EEG.EVENTLIST.trialsperbin(i) ~= 0 + pacce = (acce(i)/EEG.EVENTLIST.trialsperbin(i))*100; + paccestr = sprintf('%.1f', pacce); + prej = (rej(i)/EEG.EVENTLIST.trialsperbin(i))*100; + prejstr = sprintf('%.1f', prej); + else + paccestr = 'error'; + prejstr = 'error'; + end + if fidsumm~=-99 + fprintf(fidsumm, '%3g %6g(%5s) %8g(%5s) %7g %7g %7g %7g %7g %7g %7g\n', i,acce(i), paccestr, rej(i), prejstr, histoflags(i,2:8)); + end end trej = sum(Sumbin); @@ -240,29 +246,29 @@ tprejstr = sprintf('%.1f', tprej); thistoflags = sum(histoflags,1); if fidsumm~=-99 - fprintf(fidsumm, [repmat('_',1,100) '\n']); - fprintf(fidsumm, 'Total %5g(%5s) %8g(%5s) %7g %7g %7g %7g %7g %7g %7g\n', tacce, tpaccestr, trej, tprejstr, thistoflags(2:8)); - fprintf(fidsumm, '\n'); + fprintf(fidsumm, [repmat('_',1,100) '\n']); + fprintf(fidsumm, 'Total %5g(%5s) %8g(%5s) %7g %7g %7g %7g %7g %7g %7g\n', tacce, tpaccestr, trej, tprejstr, thistoflags(2:8)); + fprintf(fidsumm, '\n'); end if fidsumm>1 - fclose(fidsumm); - com = sprintf('EEG = pop_summary_AR_eeg_detection(EEG, ''%s'');', fullname); + fclose(fidsumm); + com = sprintf('EEG = pop_summary_AR_eeg_detection(EEG, ''%s'');', fullname); else - com = sprintf('[EEG, tprej, acce, rej, histoflags ] = pop_summary_AR_eeg_detection(EEG,''none'');'); + com = sprintf('[EEG, tprej, acce, rej, histoflags ] = pop_summary_AR_eeg_detection(EEG,''none'');'); end % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - otherwise %off or none - com = ''; - return + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + otherwise %off or none + com = ''; + return end % diff --git a/pop_functions/pop_summary_AR_erp_detection.m b/pop_functions/pop_summary_AR_erp_detection.m index 69cbb978..d2900b04 100755 --- a/pop_functions/pop_summary_AR_erp_detection.m +++ b/pop_functions/pop_summary_AR_erp_detection.m @@ -84,7 +84,7 @@ oldcolor = get(0,'DefaultUicontrolBackgroundColor'); set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) button = questdlg(question, title,'Save in a file','Show at Command Window', 'Cancel','Show at Command Window'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor) + set(0,'DefaultUicontrolBackgroundColor',oldcolor); if strcmpi(button,'Show at Command Window') fullname = ''; @@ -184,6 +184,9 @@ % Table % if fidsumm~=-99 + fprintf(fidsumm, ['\n',repmat('_',1,100) '\n']); + fprintf(fidsumm, ['ERP Name:',32,ERP.erpname '\n']); + fprintf(fidsumm, [repmat('_',1,100) '\n']); hdr = {'Bin' '#(%) accepted' '#(%) rejected' '# F2' '# F3' '# F4' '# F5' '# F6' '# F7' '# F8' }; fprintf(fidsumm, '%s %15s %15s %7s %7s %7s %7s %7s %7s %7s\n', hdr{:}); end diff --git a/pop_functions/pop_syncroartifacts.m b/pop_functions/pop_syncroartifacts.m index 519b76f5..be3d3210 100755 --- a/pop_functions/pop_syncroartifacts.m +++ b/pop_functions/pop_syncroartifacts.m @@ -14,7 +14,7 @@ % 'Direction' 'erplab2eeglab' - erplab to eeglab synchro % 'eeglab2erplab' - eeglab to erplab synchro % 'bidirectional' - (default) both -% +% % OUTPUTS % % EEG - updated epoched dataset @@ -56,46 +56,46 @@ com = ''; if isobject(EEG) % eegobj - whenEEGisanObject % calls a script for showing an error window - return + whenEEGisanObject % calls a script for showing an error window + return end if nargin==1 - serror = erplab_eegscanner(EEG, 'pop_syncroartifacts', 2, 0, 1, 2, 1); - if serror - return - end - - % - % Call GUI - % - direction = synchroartifactsGUI; - % direction = 1; % erplab to eeglab synchro - % direction = 2; % eeglab to erplab synchro - % direction = 3; % both - % direction = 0; % none - if isempty(direction) - disp('User selected Cancel') - return - end - if direction==1 % erplab to eeglab synchro - dircom = 'erplab2eeglab'; - elseif direction==2 %eeglab to erplab synchro - dircom = 'eeglab2erplab'; - elseif direction==3 % both - dircom = 'bidirectional'; - else - dircom = 'none'; - end - if length(EEG)==1 - EEG.setname = [EEG.setname '_synctrej']; %suggest a new name - end - - % - % Somersault - % - [EEG, com] = pop_syncroartifacts(EEG, 'Direction', dircom, 'History', 'gui'); - pause(0.1); + serror = erplab_eegscanner(EEG, 'pop_syncroartifacts', 2, 0, 1, 2, 1); + if serror + return + end + + % + % Call GUI + % + direction = synchroartifactsGUI; + % direction = 1; % erplab to eeglab synchro + % direction = 2; % eeglab to erplab synchro + % direction = 3; % both + % direction = 0; % none + if isempty(direction) + disp('User selected Cancel') return + end + if direction==1 % erplab to eeglab synchro + dircom = 'erplab2eeglab'; + elseif direction==2 %eeglab to erplab synchro + dircom = 'eeglab2erplab'; + elseif direction==3 % both + dircom = 'bidirectional'; + else + dircom = 'none'; + end + if length(EEG)==1 + EEG.setname = [EEG.setname '_synctrej']; %suggest a new name + end + + % + % Somersault + % + [EEG, com] = pop_syncroartifacts(EEG, 'Direction', dircom, 'History', 'gui'); + pause(0.1); + return end % @@ -110,22 +110,22 @@ p.parse(EEG, varargin{:}); if strcmpi(p.Results.History,'implicit') - shist = 3; % implicit + shist = 3; % implicit elseif strcmpi(p.Results.History,'script') - shist = 2; % script + shist = 2; % script elseif strcmpi(p.Results.History,'gui') - shist = 1; % gui + shist = 1; % gui else - shist = 0; % off + shist = 0; % off end % % process multiple datasets. Updated August 23, 2013 JLC % if length(EEG) > 1 - options1 = {'Direction', p.Results.Direction, 'History', 'gui'}; - [ EEG, com ] = eeg_eval( 'pop_syncroartifacts', EEG, 'warning', 'on', 'params', options1); - return; + options1 = {'Direction', p.Results.Direction, 'History', 'gui'}; + [ EEG, com ] = eeg_eval( 'pop_syncroartifacts', EEG, 'warning', 'on', 'params', options1); + return; end %erplab_eegscanner(EEG, funcname, chckmultieeg, chckemptyeeg, chckepocheeg, chcknoevents, chckeventlist, varargin) @@ -133,20 +133,20 @@ if strcmpi(p.Results.Direction,'no') || strcmpi(p.Results.Direction,'none') - direction = 0; + direction = 0; elseif strcmpi(p.Results.Direction,'erplab2eeglab') - direction = 1; + direction = 1; elseif strcmpi(p.Results.Direction,'eeglab2erplab') - direction = 2; + direction = 2; elseif strcmpi(p.Results.Direction,'bidirectional') - direction = 3; + direction = 3; else - msgboxText = 'ERPLAB says: Invalid synchronization direction parameter.'; - error('prog:input', ['ERPLAB says: ' msgboxText]); + msgboxText = 'ERPLAB says: Invalid synchronization direction parameter.'; + error('prog:input', ['ERPLAB says: ' msgboxText]); end if direction==0 - fprintf('User decided not to synchronize.\n'); - return + fprintf('User decided not to synchronize.\n'); + return end % @@ -154,46 +154,46 @@ % isRT = 1; % there is RT info by default if ~isfield(EEG.EVENTLIST.bdf, 'rt') - isRT = 0; % no RT info + isRT = 0; % no RT info else - valid_rt = nnz(~cellfun(@isempty,{EEG.EVENTLIST.bdf.rt})); - if valid_rt==0 - isRT = 0; % no RT info - end + valid_rt = nnz(~cellfun(@isempty,{EEG.EVENTLIST.bdf.rt})); + if valid_rt==0 + isRT = 0; % no RT info + end end % % Synchronization % if direction==1 % erplab to eeglab synchro - EEG = synchroner1(EEG); + EEG = synchroner1(EEG); elseif direction==2 %eeglab to erplab synchro - EEG = synchroner2(EEG, isRT); + EEG = synchroner2(EEG, isRT); elseif direction==3 % both - %EEG = synchroner1(EEG); - %EEG = synchroner2(EEG, isRT); - EEG = synchroner3(EEG, isRT); + %EEG = synchroner1(EEG); + %EEG = synchroner2(EEG, isRT); + EEG = synchroner3(EEG, isRT); else - fprintf('no synchronization.\n'); + fprintf('no synchronization.\n'); end com = sprintf( '%s = pop_syncroartifacts(%s, %s);', inputname(1), inputname(1), num2str(direction)); % get history from script. EEG switch shist - case 1 % from GUI - com = sprintf('%s %% GUI: %s', com, datestr(now)); - %fprintf('%%Equivalent command:\n%s\n\n', com); - displayEquiComERP(com); - case 2 % from script - EEG = erphistory(EEG, [], com, 1); - case 3 - % implicit - % EEG = erphistory(EEG, [], com, 1); - % fprintf('%%Equivalent command:\n%s\n\n', com); - otherwise %off or none - com = ''; - return + case 1 % from GUI + com = sprintf('%s %% GUI: %s', com, datestr(now)); + %fprintf('%%Equivalent command:\n%s\n\n', com); + displayEquiComERP(com); + case 2 % from script + EEG = erphistory(EEG, [], com, 1); + case 3 + % implicit + % EEG = erphistory(EEG, [], com, 1); + % fprintf('%%Equivalent command:\n%s\n\n', com); + otherwise %off or none + com = ''; + return end % @@ -213,33 +213,39 @@ fprintf('---------------------------------------------------------\n\n'); nepoch = EEG.trials; for i=1:nepoch - cflag = EEG.epoch(i).eventflag; % flag(s) from event(s) within this epoch - if iscell(cflag) - %cflag = cell2mat(cflag); - cflag = uint16([cflag{:}]); % giving some problems with uint16 type of flags - end - laten = EEG.epoch(i).eventlatency;% latency(ies) from event(s) within this epoch - if iscell(laten) - laten = cell2mat(laten); + cflag = EEG.epoch(i).eventflag; % flag(s) from event(s) within this epoch + if iscell(cflag) + %cflag = cell2mat(cflag); + cflag = uint16([cflag{:}]); % giving some problems with uint16 type of flags + end + laten = EEG.epoch(i).eventlatency;% latency(ies) from event(s) within this epoch + if iscell(laten) + laten = cell2mat(laten); + end + + indxtimelock = find(laten == 0,1,'first'); % catch zero-time locked code position, + flag = cflag(indxtimelock); + + %sum(bitget(flag, 1:8))>0; + if sum(bitget(flag, 1:8))>0 + if ~isempty(EEG.reject.rejmanual)%%GH Jun 2024 + if EEG.reject.rejmanual(i)==0 + EEG.reject.rejmanual(i) = 1; % marks epoch with artifact + %EEG.reject.rejmanualE(chanArray(ch), i) = 1; % marks channel with artifact + iflag = find(bitget(flag,1:8)); + fprintf('Epoch # %g was marked due to flag(s) # %s was(were) set for its home item.\n',i, num2str(iflag)); + end + end - - indxtimelock = find(laten == 0,1,'first'); % catch zero-time locked code position, - flag = cflag(indxtimelock); - - %sum(bitget(flag, 1:8))>0; - if sum(bitget(flag, 1:8))>0 - if EEG.reject.rejmanual(i)==0 - EEG.reject.rejmanual(i) = 1; % marks epoch with artifact - %EEG.reject.rejmanualE(chanArray(ch), i) = 1; % marks channel with artifact - iflag = find(bitget(flag,1:8)); - fprintf('Epoch # %g was marked due to flag(s) # %s was(were) set for its home item.\n',i, num2str(iflag)); - end - else - if EEG.reject.rejmanual(i)==1 - EEG.reject.rejmanual(i)=0; - fprintf('The mark at epoch # %g was removed due to no set flag was found at its home item.\n',i); - end + else + if ~isempty(EEG.reject.rejmanual)%%GH Jun 2024 + if EEG.reject.rejmanual(i)==1 + EEG.reject.rejmanual(i)=0; + fprintf('The mark at epoch # %g was removed due to no set flag was found at its home item.\n',i); + end + end + end end % @@ -250,22 +256,28 @@ fprintf('---------------------------------------------------------\n\n'); nitem = length(EEG.EVENTLIST.eventinfo); for i=1:nitem - flag = EEG.EVENTLIST.eventinfo(i).flag; - bepoch = EEG.EVENTLIST.eventinfo(i).bepoch; - if bepoch>0 - if sum(bitget(flag, 1:8))>0 - if EEG.reject.rejmanual(bepoch)==0 - EEG.reject.rejmanual(bepoch) = 1; % marks epoch with artifact - iflag = find(bitget(flag,1:8)); - fprintf('Epoch # %g was marked due to flag(s) # %s was(were) set for item # %g.\n',bepoch, num2str(iflag), i); - end - else - if EEG.reject.rejmanual(bepoch)==1 - EEG.reject.rejmanual(bepoch)=0; - fprintf('The mark at epoch # %g was removed due to no set flag was found at item # %g.\n', bepoch, i); - end + flag = EEG.EVENTLIST.eventinfo(i).flag; + bepoch = EEG.EVENTLIST.eventinfo(i).bepoch; + if bepoch>0 + if sum(bitget(flag, 1:8))>0 + if ~isempty(EEG.reject.rejmanual)%%GH Jun 2024 + if EEG.reject.rejmanual(bepoch)==0 + EEG.reject.rejmanual(bepoch) = 1; % marks epoch with artifact + iflag = find(bitget(flag,1:8)); + fprintf('Epoch # %g was marked due to flag(s) # %s was(were) set for item # %g.\n',bepoch, num2str(iflag), i); end + + end + else + if ~isempty(EEG.reject.rejmanual)%%GH Jun 2024 + if EEG.reject.rejmanual(bepoch)==1 + EEG.reject.rejmanual(bepoch)=0; + fprintf('The mark at epoch # %g was removed due to no set flag was found at item # %g.\n', bepoch, i); + end + + end end + end end fprintf('\nEEG.reject.rejmanual(i) was synchronized according to EEG.epoch(i).eventflag values.\n') return @@ -287,9 +299,9 @@ indx = []; for i=1:length(arfields) - if ~isempty(EEG.reject.(arfields{i})) - indx = [indx i]; - end + if ~isempty(EEG.reject.(arfields{i})) + indx = [indx i]; + end end fprintf('\n---------------------------------------------------------\n'); @@ -299,23 +311,23 @@ selarfields = arfields(indx); % not empty EEGLAB's artifact rejection fields nsarf = length(selarfields); for i=1:ntrial; - r = zeros(1,nsarf); - for j=1:nsarf - r(j) = EEG.reject.(selarfields{j})(i); - end - if nnz(r)>0 - EEG = markartifacts(EEG, 1, [], [], i, isRT, 1); - else - EEG = markartifacts(EEG, 0, [], [], i, isRT, 1); % JLC Sept 1, 2012 - end + r = zeros(1,nsarf); + for j=1:nsarf + r(j) = EEG.reject.(selarfields{j})(i); + end + if nnz(r)>0 + EEG = markartifacts(EEG, 1, [], [], i, isRT, 1); + else + EEG = markartifacts(EEG, 0, [], [], i, isRT, 1); % JLC Sept 1, 2012 + end end fprintf('\nFlag 1 was marked at EEG.EVENTLIST.eventinfo and EEG.epoch, according to EEG.reject.{ar_tool}.\n'); if isRT - fprintf('For reaction time filtering, EEG.EVENTLIST.bdf was synchronized with artifact detection info as well.\n\n'); + fprintf('For reaction time filtering, EEG.EVENTLIST.bdf was synchronized with artifact detection info as well.\n\n'); else - fprintf('EEG.EVENTLIST.bdf was not synchronized due to reaction time measurement was not found in this dataset.\n\n'); + fprintf('EEG.EVENTLIST.bdf was not synchronized due to reaction time measurement was not found in this dataset.\n\n'); end return @@ -344,9 +356,9 @@ indx = []; for i=1:length(arfields) - if ~isempty(EEG.reject.(arfields{i})) - indx = [indx i]; - end + if ~isempty(EEG.reject.(arfields{i})) + indx = [indx i]; + end end fprintf('\n---------------------------------------------------------\n'); @@ -378,25 +390,25 @@ fprintf('---------------------------------------------------------\n\n'); for qEpoch=1:nepoch - cflag = EEG.epoch(qEpoch).eventflag; % flag(s) from event(s) within this epoch - if iscell(cflag) - %cflag = cell2mat(cflag); - cflag = uint16([cflag{:}]); % giving some problems with uint16 type of flags - end - laten = EEG.epoch(qEpoch).eventlatency;% latency(ies) from event(s) within this epoch - if iscell(laten) - laten = cell2mat(laten); - end - - indxtimelock = find(laten == 0,1,'first'); % catch zero-time locked code position, - flag = cflag(indxtimelock); - - if sum(bitget(flag, 1:8))>0 && EEG.reject.rejmanual(qEpoch) == 0 - EEG.reject.rejmanual(qEpoch) = 1; % % marks epoch with artifact only if flag is marked (no unmarking) - %EEG.reject.rejmanualE(chanArray(ch), qEpoch) = 1; % marks channel with artifact - iflag = find(bitget(flag,1:8)); - fprintf('Epoch # %g was marked due to flag(s) # %s was(were) set for its home item.\n',qEpoch, num2str(iflag)); - end + cflag = EEG.epoch(qEpoch).eventflag; % flag(s) from event(s) within this epoch + if iscell(cflag) + %cflag = cell2mat(cflag); + cflag = uint16([cflag{:}]); % giving some problems with uint16 type of flags + end + laten = EEG.epoch(qEpoch).eventlatency;% latency(ies) from event(s) within this epoch + if iscell(laten) + laten = cell2mat(laten); + end + + indxtimelock = find(laten == 0,1,'first'); % catch zero-time locked code position, + flag = cflag(indxtimelock); + + if sum(bitget(flag, 1:8))>0 && EEG.reject.rejmanual(qEpoch) == 0 + EEG.reject.rejmanual(qEpoch) = 1; % % marks epoch with artifact only if flag is marked (no unmarking) + %EEG.reject.rejmanualE(chanArray(ch), qEpoch) = 1; % marks channel with artifact + iflag = find(bitget(flag,1:8)); + fprintf('Epoch # %g was marked due to flag(s) # %s was(were) set for its home item.\n',qEpoch, num2str(iflag)); + end end % diff --git a/studio_functions/.txt b/studio_functions/.txt new file mode 100644 index 00000000..93380506 --- /dev/null +++ b/studio_functions/.txt @@ -0,0 +1,1028 @@ +# Non-editable header begin -------------------------------------------------------------------------------- +# +# data format...............: continuous +# setname...................: 1_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new +# filename..................: 1_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new.set +# filepath..................: /Users/gzhang/Documents/Demo data/EEGsets/EEG set/ +# nchan.....................: 30 +# pnts......................: 155648 +# srate.....................: 256 +# nevents...................: 1002 +# generated by (bdf)........: +# generated by (set)........: 1_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new +# reported in ..............: +# prog Version..............: 11.0 +# creation date.............: 25-Apr-2024 14:39:36 +# user Account..............: +# +# Non-editable header end -------------------------------------------------------------------------------- + + + + +# item bepoch ecode label onset diff dura b_flags a_flags enable bin +# (sec) (msec) (msec) (binary) (binary) + + +1 0 1 "" 12.0752 0.00 0.0 00000000 00000000 1 [ ] +2 0 180 "" 15.1162 3041.02 0.0 00000000 00000000 1 [ ] +3 0 180 "" 15.7129 596.68 0.0 00000000 00000000 1 [ ] +4 0 180 "" 16.3330 620.12 0.0 00000000 00000000 1 [ ] +5 0 180 "" 16.9170 583.98 0.0 00000000 00000000 1 [ ] +6 0 180 "" 17.4834 566.41 0.0 00000000 00000000 1 [ ] +7 0 180 "" 18.1064 623.05 0.0 00000000 00000000 1 [ ] +8 0 180 "" 18.6465 540.04 0.0 00000000 00000000 1 [ ] +9 0 180 "" 19.2734 626.95 0.0 00000000 00000000 1 [ ] +10 0 180 "" 19.9033 629.88 0.0 00000000 00000000 1 [ ] +11 0 180 "" 20.4336 530.27 0.0 00000000 00000000 1 [ ] +12 0 180 "" 20.9932 559.57 0.0 00000000 00000000 1 [ ] +13 0 180 "" 21.5801 586.91 0.0 00000000 00000000 1 [ ] +14 0 180 "" 22.1895 609.38 0.0 00000000 00000000 1 [ ] +15 0 180 "" 22.7793 589.84 0.0 00000000 00000000 1 [ ] +16 0 180 "" 23.3398 560.55 0.0 00000000 00000000 1 [ ] +17 0 80 "" 23.8965 556.64 0.0 00000000 00000000 1 [ ] +18 0 80 "" 24.5264 629.88 0.0 00000000 00000000 1 [ ] +19 0 80 "" 25.1465 620.12 0.0 00000000 00000000 1 [ ] +20 0 80 "" 25.7568 610.35 0.0 00000000 00000000 1 [ ] +21 0 80 "" 26.3701 613.28 0.0 00000000 00000000 1 [ ] +22 0 80 "" 26.9160 545.90 0.0 00000000 00000000 1 [ ] +23 0 70 "" 27.5361 620.12 0.0 00000000 00000000 1 [ ] +24 0 80 "" 28.1533 617.19 0.0 00000000 00000000 1 [ ] +25 0 80 "" 28.7500 596.68 0.0 00000000 00000000 1 [ ] +26 0 80 "" 29.3799 629.88 0.0 00000000 00000000 1 [ ] +27 0 80 "" 29.9629 583.01 0.0 00000000 00000000 1 [ ] +28 0 80 "" 30.5830 620.12 0.0 00000000 00000000 1 [ ] +29 0 80 "" 31.1494 566.41 0.0 00000000 00000000 1 [ ] +30 0 80 "" 31.6934 543.95 0.0 00000000 00000000 1 [ ] +31 0 80 "" 32.3232 629.88 0.0 00000000 00000000 1 [ ] +32 0 80 "" 32.9365 613.28 0.0 00000000 00000000 1 [ ] +33 0 80 "" 33.4893 552.73 0.0 00000000 00000000 1 [ ] +34 0 70 "" 34.0527 563.48 0.0 00000000 00000000 1 [ ] +35 0 80 "" 34.6260 573.24 0.0 00000000 00000000 1 [ ] +36 0 70 "" 35.1797 553.71 0.0 00000000 00000000 1 [ ] +37 0 80 "" 35.7998 620.12 0.0 00000000 00000000 1 [ ] +38 0 80 "" 36.3691 569.34 0.0 00000000 00000000 1 [ ] +39 0 70 "" 36.9863 617.19 0.0 00000000 00000000 1 [ ] +40 0 80 "" 37.5664 580.08 0.0 00000000 00000000 1 [ ] +41 0 80 "" 38.1357 569.34 0.0 00000000 00000000 1 [ ] +42 0 80 "" 38.7725 636.72 0.0 00000000 00000000 1 [ ] +43 0 80 "" 39.4023 629.88 0.0 00000000 00000000 1 [ ] +44 0 80 "" 39.9658 563.48 0.0 00000000 00000000 1 [ ] +45 0 80 "" 40.5361 570.31 0.0 00000000 00000000 1 [ ] +46 0 80 "" 41.0996 563.48 0.0 00000000 00000000 1 [ ] +47 0 80 "" 41.6426 542.97 0.0 00000000 00000000 1 [ ] +48 0 80 "" 42.2197 577.15 0.0 00000000 00000000 1 [ ] +49 0 70 "" 42.8262 606.45 0.0 00000000 00000000 1 [ ] +50 0 80 "" 43.4023 576.17 0.0 00000000 00000000 1 [ ] +51 0 70 "" 43.9727 570.31 0.0 00000000 00000000 1 [ ] +52 0 80 "" 44.5391 566.41 0.0 00000000 00000000 1 [ ] +53 0 80 "" 45.0762 537.11 0.0 00000000 00000000 1 [ ] +54 0 80 "" 45.6826 606.45 0.0 00000000 00000000 1 [ ] +55 0 80 "" 46.2227 540.04 0.0 00000000 00000000 1 [ ] +56 0 80 "" 46.8330 610.35 0.0 00000000 00000000 1 [ ] +57 0 70 "" 47.4863 653.32 0.0 00000000 00000000 1 [ ] +58 0 80 "" 48.0791 592.77 0.0 00000000 00000000 1 [ ] +59 0 80 "" 48.6689 589.84 0.0 00000000 00000000 1 [ ] +60 0 80 "" 49.2793 610.35 0.0 00000000 00000000 1 [ ] +61 0 80 "" 49.8193 540.04 0.0 00000000 00000000 1 [ ] +62 0 80 "" 50.3691 549.80 0.0 00000000 00000000 1 [ ] +63 0 80 "" 50.9092 540.04 0.0 00000000 00000000 1 [ ] +64 0 80 "" 51.4922 583.01 0.0 00000000 00000000 1 [ ] +65 0 80 "" 52.0859 593.75 0.0 00000000 00000000 1 [ ] +66 0 80 "" 52.6689 583.01 0.0 00000000 00000000 1 [ ] +67 0 70 "" 53.2422 573.24 0.0 00000000 00000000 1 [ ] +68 0 80 "" 53.8721 629.88 0.0 00000000 00000000 1 [ ] +69 0 80 "" 54.4795 607.42 0.0 00000000 00000000 1 [ ] +70 0 70 "" 55.0557 576.17 0.0 00000000 00000000 1 [ ] +71 0 80 "" 55.6025 546.88 0.0 00000000 00000000 1 [ ] +72 0 80 "" 56.1455 542.97 0.0 00000000 00000000 1 [ ] +73 0 80 "" 56.6924 546.88 0.0 00000000 00000000 1 [ ] +74 0 80 "" 57.2422 549.80 0.0 00000000 00000000 1 [ ] +75 0 80 "" 57.7920 549.80 0.0 00000000 00000000 1 [ ] +76 0 80 "" 58.3359 543.95 0.0 00000000 00000000 1 [ ] +77 0 80 "" 58.8955 559.57 0.0 00000000 00000000 1 [ ] +78 0 80 "" 59.5186 623.05 0.0 00000000 00000000 1 [ ] +79 0 80 "" 60.1191 600.59 0.0 00000000 00000000 1 [ ] +80 0 80 "" 60.6758 556.64 0.0 00000000 00000000 1 [ ] +81 0 70 "" 61.2256 549.80 0.0 00000000 00000000 1 [ ] +82 0 80 "" 61.8320 606.45 0.0 00000000 00000000 1 [ ] +83 0 80 "" 62.4326 600.59 0.0 00000000 00000000 1 [ ] +84 0 80 "" 63.0557 623.05 0.0 00000000 00000000 1 [ ] +85 0 80 "" 63.6357 580.08 0.0 00000000 00000000 1 [ ] +86 0 70 "" 64.2588 623.05 0.0 00000000 00000000 1 [ ] +87 0 80 "" 64.8359 577.15 0.0 00000000 00000000 1 [ ] +88 0 70 "" 65.3818 545.90 0.0 00000000 00000000 1 [ ] +89 0 80 "" 65.9219 540.04 0.0 00000000 00000000 1 [ ] +90 0 80 "" 66.4893 567.38 0.0 00000000 00000000 1 [ ] +91 0 80 "" 67.1152 625.98 0.0 00000000 00000000 1 [ ] +92 0 80 "" 67.7393 624.02 0.0 00000000 00000000 1 [ ] +93 0 70 "" 68.3789 639.65 0.0 00000000 00000000 1 [ ] +94 0 80 "" 68.9756 596.68 0.0 00000000 00000000 1 [ ] +95 0 70 "" 69.5557 580.08 0.0 00000000 00000000 1 [ ] +96 0 80 "" 70.1221 566.41 0.0 00000000 00000000 1 [ ] +97 0 80 "" 70.7451 623.05 0.0 00000000 00000000 1 [ ] +98 0 70 "" 71.3350 589.84 0.0 00000000 00000000 1 [ ] +99 0 80 "" 71.8955 560.55 0.0 00000000 00000000 1 [ ] +100 0 70 "" 72.4883 592.77 0.0 00000000 00000000 1 [ ] +101 0 80 "" 73.0957 607.42 0.0 00000000 00000000 1 [ ] +102 0 70 "" 73.6621 566.41 0.0 00000000 00000000 1 [ ] +103 0 80 "" 74.2490 586.91 0.0 00000000 00000000 1 [ ] +104 0 80 "" 74.8457 596.68 0.0 00000000 00000000 1 [ ] +105 0 80 "" 75.3887 542.97 0.0 00000000 00000000 1 [ ] +106 0 80 "" 75.9355 546.88 0.0 00000000 00000000 1 [ ] +107 0 80 "" 76.5557 620.12 0.0 00000000 00000000 1 [ ] +108 0 80 "" 77.1816 625.98 0.0 00000000 00000000 1 [ ] +109 0 80 "" 77.7256 543.95 0.0 00000000 00000000 1 [ ] +110 0 80 "" 78.2715 545.90 0.0 00000000 00000000 1 [ ] +111 0 80 "" 78.8486 577.15 0.0 00000000 00000000 1 [ ] +112 0 80 "" 79.4648 616.21 0.0 00000000 00000000 1 [ ] +113 0 80 "" 80.0684 603.52 0.0 00000000 00000000 1 [ ] +114 0 80 "" 80.6123 543.95 0.0 00000000 00000000 1 [ ] +115 0 80 "" 81.2354 623.05 0.0 00000000 00000000 1 [ ] +116 0 80 "" 81.8623 626.95 0.0 00000000 00000000 1 [ ] +117 0 80 "" 82.4453 583.01 0.0 00000000 00000000 1 [ ] +118 0 80 "" 83.0723 626.95 0.0 00000000 00000000 1 [ ] +119 0 70 "" 83.6289 556.64 0.0 00000000 00000000 1 [ ] +120 0 80 "" 84.1787 549.80 0.0 00000000 00000000 1 [ ] +121 0 80 "" 84.8047 625.98 0.0 00000000 00000000 1 [ ] +122 0 80 "" 85.3721 567.38 0.0 00000000 00000000 1 [ ] +123 0 80 "" 85.9785 606.45 0.0 00000000 00000000 1 [ ] +124 0 80 "" 86.6084 629.88 0.0 00000000 00000000 1 [ ] +125 0 70 "" 87.2119 603.52 0.0 00000000 00000000 1 [ ] +126 0 80 "" 87.7783 566.41 0.0 00000000 00000000 1 [ ] +127 0 70 "" 88.3818 603.52 0.0 00000000 00000000 1 [ ] +128 0 80 "" 88.9688 586.91 0.0 00000000 00000000 1 [ ] +129 0 70 "" 89.5420 573.24 0.0 00000000 00000000 1 [ ] +130 0 80 "" 90.1016 559.57 0.0 00000000 00000000 1 [ ] +131 0 80 "" 90.7383 636.72 0.0 00000000 00000000 1 [ ] +132 0 80 "" 91.3682 629.88 0.0 00000000 00000000 1 [ ] +133 0 80 "" 91.9785 610.35 0.0 00000000 00000000 1 [ ] +134 0 80 "" 92.5879 609.38 0.0 00000000 00000000 1 [ ] +135 0 80 "" 93.1514 563.48 0.0 00000000 00000000 1 [ ] +136 0 80 "" 93.7520 600.59 0.0 00000000 00000000 1 [ ] +137 0 70 "" 94.3418 589.84 0.0 00000000 00000000 1 [ ] +138 0 80 "" 94.9053 563.48 0.0 00000000 00000000 1 [ ] +139 0 80 "" 95.5215 616.21 0.0 00000000 00000000 1 [ ] +140 0 80 "" 96.0752 553.71 0.0 00000000 00000000 1 [ ] +141 0 80 "" 96.6914 616.21 0.0 00000000 00000000 1 [ ] +142 0 80 "" 97.2480 556.64 0.0 00000000 00000000 1 [ ] +143 0 80 "" 97.7910 542.97 0.0 00000000 00000000 1 [ ] +144 0 80 "" 98.3779 586.91 0.0 00000000 00000000 1 [ ] +145 0 80 "" 98.9180 540.04 0.0 00000000 00000000 1 [ ] +146 0 80 "" 99.4648 546.88 0.0 00000000 00000000 1 [ ] +147 0 80 "" 100.0645 599.61 0.0 00000000 00000000 1 [ ] +148 0 70 "" 100.6582 593.75 0.0 00000000 00000000 1 [ ] +149 0 80 "" 101.2510 592.77 0.0 00000000 00000000 1 [ ] +150 0 80 "" 101.8652 614.26 0.0 00000000 00000000 1 [ ] +151 0 80 "" 102.4014 536.13 0.0 00000000 00000000 1 [ ] +152 0 70 "" 102.9883 586.91 0.0 00000000 00000000 1 [ ] +153 0 80 "" 103.5576 569.34 0.0 00000000 00000000 1 [ ] +154 0 80 "" 104.1084 550.78 0.0 00000000 00000000 1 [ ] +155 0 80 "" 104.6611 552.73 0.0 00000000 00000000 1 [ ] +156 0 80 "" 105.2783 617.19 0.0 00000000 00000000 1 [ ] +157 0 70 "" 105.8711 592.77 0.0 00000000 00000000 1 [ ] +158 0 80 "" 106.4248 553.71 0.0 00000000 00000000 1 [ ] +159 0 70 "" 106.9580 533.20 0.0 00000000 00000000 1 [ ] +160 0 80 "" 107.5576 599.61 0.0 00000000 00000000 1 [ ] +161 0 80 "" 108.1016 543.95 0.0 00000000 00000000 1 [ ] +162 0 80 "" 108.6816 580.08 0.0 00000000 00000000 1 [ ] +163 0 80 "" 109.2812 599.61 0.0 00000000 00000000 1 [ ] +164 0 80 "" 109.8408 559.57 0.0 00000000 00000000 1 [ ] +165 0 80 "" 110.4043 563.48 0.0 00000000 00000000 1 [ ] +166 0 70 "" 111.0010 596.68 0.0 00000000 00000000 1 [ ] +167 0 80 "" 111.5742 573.24 0.0 00000000 00000000 1 [ ] +168 0 70 "" 112.1680 593.75 0.0 00000000 00000000 1 [ ] +169 0 80 "" 112.7275 559.57 0.0 00000000 00000000 1 [ ] +170 0 70 "" 113.2676 540.04 0.0 00000000 00000000 1 [ ] +171 0 80 "" 113.8545 586.91 0.0 00000000 00000000 1 [ ] +172 0 70 "" 114.4346 580.08 0.0 00000000 00000000 1 [ ] +173 0 80 "" 115.0781 643.55 0.0 00000000 00000000 1 [ ] +174 0 80 "" 115.6445 566.41 0.0 00000000 00000000 1 [ ] +175 0 80 "" 116.2344 589.84 0.0 00000000 00000000 1 [ ] +176 0 70 "" 116.7744 540.04 0.0 00000000 00000000 1 [ ] +177 0 80 "" 117.3740 599.61 0.0 00000000 00000000 1 [ ] +178 0 80 "" 117.9277 553.71 0.0 00000000 00000000 1 [ ] +179 0 80 "" 118.4873 559.57 0.0 00000000 00000000 1 [ ] +180 0 80 "" 119.0713 583.98 0.0 00000000 00000000 1 [ ] +181 0 70 "" 119.6182 546.88 0.0 00000000 00000000 1 [ ] +182 0 80 "" 120.2080 589.84 0.0 00000000 00000000 1 [ ] +183 0 80 "" 120.8477 639.65 0.0 00000000 00000000 1 [ ] +184 0 70 "" 121.4814 633.79 0.0 00000000 00000000 1 [ ] +185 0 80 "" 122.0439 562.50 0.0 00000000 00000000 1 [ ] +186 0 80 "" 122.6875 643.55 0.0 00000000 00000000 1 [ ] +187 0 70 "" 123.2842 596.68 0.0 00000000 00000000 1 [ ] +188 0 80 "" 123.9238 639.65 0.0 00000000 00000000 1 [ ] +189 0 80 "" 124.4678 543.95 0.0 00000000 00000000 1 [ ] +190 0 80 "" 125.0811 613.28 0.0 00000000 00000000 1 [ ] +191 0 80 "" 125.7109 629.88 0.0 00000000 00000000 1 [ ] +192 0 80 "" 126.3340 623.05 0.0 00000000 00000000 1 [ ] +193 0 80 "" 126.8838 549.80 0.0 00000000 00000000 1 [ ] +194 0 80 "" 127.4307 546.88 0.0 00000000 00000000 1 [ ] +195 0 80 "" 128.0537 623.05 0.0 00000000 00000000 1 [ ] +196 0 70 "" 128.6543 600.59 0.0 00000000 00000000 1 [ ] +197 0 80 "" 129.1904 536.13 0.0 00000000 00000000 1 [ ] +198 0 70 "" 129.8145 624.02 0.0 00000000 00000000 1 [ ] +199 0 80 "" 130.3809 566.41 0.0 00000000 00000000 1 [ ] +200 0 70 "" 130.9609 580.08 0.0 00000000 00000000 1 [ ] +201 0 80 "" 131.5342 573.24 0.0 00000000 00000000 1 [ ] +202 0 80 "" 132.0811 546.88 0.0 00000000 00000000 1 [ ] +203 0 80 "" 132.6406 559.57 0.0 00000000 00000000 1 [ ] +204 0 70 "" 133.2637 623.05 0.0 00000000 00000000 1 [ ] +205 0 80 "" 133.8770 613.28 0.0 00000000 00000000 1 [ ] +206 0 80 "" 134.4609 583.98 0.0 00000000 00000000 1 [ ] +207 0 70 "" 135.0508 589.84 0.0 00000000 00000000 1 [ ] +208 0 80 "" 135.6270 576.17 0.0 00000000 00000000 1 [ ] +209 0 80 "" 136.2676 640.62 0.0 00000000 00000000 1 [ ] +210 0 80 "" 136.8838 616.21 0.0 00000000 00000000 1 [ ] +211 0 80 "" 137.4941 610.35 0.0 00000000 00000000 1 [ ] +212 0 80 "" 138.0840 589.84 0.0 00000000 00000000 1 [ ] +213 0 80 "" 138.6709 586.91 0.0 00000000 00000000 1 [ ] +214 0 80 "" 139.2070 536.13 0.0 00000000 00000000 1 [ ] +215 0 80 "" 139.8203 613.28 0.0 00000000 00000000 1 [ ] +216 0 80 "" 140.4502 629.88 0.0 00000000 00000000 1 [ ] +217 0 80 "" 141.0605 610.35 0.0 00000000 00000000 1 [ ] +218 0 80 "" 141.6377 577.15 0.0 00000000 00000000 1 [ ] +219 0 70 "" 142.2168 579.10 0.0 00000000 00000000 1 [ ] +220 0 80 "" 142.7637 546.88 0.0 00000000 00000000 1 [ ] +221 0 70 "" 143.3574 593.75 0.0 00000000 00000000 1 [ ] +222 0 80 "" 143.9434 585.94 0.0 00000000 00000000 1 [ ] +223 0 80 "" 144.4971 553.71 0.0 00000000 00000000 1 [ ] +224 0 80 "" 145.0840 586.91 0.0 00000000 00000000 1 [ ] +225 0 70 "" 145.7002 616.21 0.0 00000000 00000000 1 [ ] +226 0 80 "" 146.2734 573.24 0.0 00000000 00000000 1 [ ] +227 0 70 "" 146.8643 590.82 0.0 00000000 00000000 1 [ ] +228 0 80 "" 147.4307 566.41 0.0 00000000 00000000 1 [ ] +229 0 80 "" 148.0137 583.01 0.0 00000000 00000000 1 [ ] +230 0 70 "" 148.6201 606.45 0.0 00000000 00000000 1 [ ] +231 0 80 "" 149.1738 553.71 0.0 00000000 00000000 1 [ ] +232 0 80 "" 149.7266 552.73 0.0 00000000 00000000 1 [ ] +233 0 70 "" 150.3135 586.91 0.0 00000000 00000000 1 [ ] +234 0 80 "" 150.8506 537.11 0.0 00000000 00000000 1 [ ] +235 0 80 "" 151.4238 573.24 0.0 00000000 00000000 1 [ ] +236 0 80 "" 151.9766 552.73 0.0 00000000 00000000 1 [ ] +237 0 80 "" 152.6074 630.86 0.0 00000000 00000000 1 [ ] +238 0 80 "" 153.2207 613.28 0.0 00000000 00000000 1 [ ] +239 0 70 "" 153.8438 623.05 0.0 00000000 00000000 1 [ ] +240 0 80 "" 154.4766 632.81 0.0 00000000 00000000 1 [ ] +241 0 80 "" 155.0498 573.24 0.0 00000000 00000000 1 [ ] +242 0 80 "" 155.6865 636.72 0.0 00000000 00000000 1 [ ] +243 0 70 "" 156.3066 620.12 0.0 00000000 00000000 1 [ ] +244 0 80 "" 156.8740 567.38 0.0 00000000 00000000 1 [ ] +245 0 70 "" 157.5068 632.81 0.0 00000000 00000000 1 [ ] +246 0 80 "" 158.0771 570.31 0.0 00000000 00000000 1 [ ] +247 0 80 "" 158.6299 552.73 0.0 00000000 00000000 1 [ ] +248 0 80 "" 159.2168 586.91 0.0 00000000 00000000 1 [ ] +249 0 80 "" 159.8604 643.55 0.0 00000000 00000000 1 [ ] +250 0 80 "" 160.4600 599.61 0.0 00000000 00000000 1 [ ] +251 0 70 "" 161.0664 606.45 0.0 00000000 00000000 1 [ ] +252 0 80 "" 161.6299 563.48 0.0 00000000 00000000 1 [ ] +253 0 70 "" 162.2568 626.95 0.0 00000000 00000000 1 [ ] +254 0 80 "" 162.8896 632.81 0.0 00000000 00000000 1 [ ] +255 0 70 "" 163.4570 567.38 0.0 00000000 00000000 1 [ ] +256 0 80 "" 164.0566 599.61 0.0 00000000 00000000 1 [ ] +257 0 80 "" 164.6367 580.08 0.0 00000000 00000000 1 [ ] +258 0 80 "" 165.2100 573.24 0.0 00000000 00000000 1 [ ] +259 0 80 "" 165.7930 583.01 0.0 00000000 00000000 1 [ ] +260 0 80 "" 166.3730 580.08 0.0 00000000 00000000 1 [ ] +261 0 80 "" 166.9268 553.71 0.0 00000000 00000000 1 [ ] +262 0 80 "" 167.5068 580.08 0.0 00000000 00000000 1 [ ] +263 0 70 "" 168.1201 613.28 0.0 00000000 00000000 1 [ ] +264 0 80 "" 168.6865 566.41 0.0 00000000 00000000 1 [ ] +265 0 80 "" 169.2363 549.80 0.0 00000000 00000000 1 [ ] +266 0 80 "" 169.8535 617.19 0.0 00000000 00000000 1 [ ] +267 0 70 "" 170.4902 636.72 0.0 00000000 00000000 1 [ ] +268 0 80 "" 171.0596 569.34 0.0 00000000 00000000 1 [ ] +269 0 80 "" 171.6768 617.19 0.0 00000000 00000000 1 [ ] +270 0 80 "" 172.3037 626.95 0.0 00000000 00000000 1 [ ] +271 0 80 "" 172.8633 559.57 0.0 00000000 00000000 1 [ ] +272 0 80 "" 173.4531 589.84 0.0 00000000 00000000 1 [ ] +273 0 70 "" 174.0166 563.48 0.0 00000000 00000000 1 [ ] +274 0 80 "" 174.5830 566.41 0.0 00000000 00000000 1 [ ] +275 0 80 "" 175.1699 586.91 0.0 00000000 00000000 1 [ ] +276 0 80 "" 175.7266 556.64 0.0 00000000 00000000 1 [ ] +277 0 80 "" 176.2695 542.97 0.0 00000000 00000000 1 [ ] +278 0 80 "" 176.8936 624.02 0.0 00000000 00000000 1 [ ] +279 0 70 "" 177.5000 606.45 0.0 00000000 00000000 1 [ ] +280 0 80 "" 178.0898 589.84 0.0 00000000 00000000 1 [ ] +281 0 80 "" 178.7197 629.88 0.0 00000000 00000000 1 [ ] +282 0 70 "" 179.2930 573.24 0.0 00000000 00000000 1 [ ] +283 0 80 "" 179.8867 593.75 0.0 00000000 00000000 1 [ ] +284 0 70 "" 180.4434 556.64 0.0 00000000 00000000 1 [ ] +285 0 80 "" 181.0029 559.57 0.0 00000000 00000000 1 [ ] +286 0 80 "" 181.5664 563.48 0.0 00000000 00000000 1 [ ] +287 0 80 "" 182.1826 616.21 0.0 00000000 00000000 1 [ ] +288 0 70 "" 182.7959 613.28 0.0 00000000 00000000 1 [ ] +289 0 80 "" 183.3760 580.08 0.0 00000000 00000000 1 [ ] +290 0 80 "" 183.9893 613.28 0.0 00000000 00000000 1 [ ] +291 0 80 "" 184.6133 624.02 0.0 00000000 00000000 1 [ ] +292 0 70 "" 185.1895 576.17 0.0 00000000 00000000 1 [ ] +293 0 80 "" 185.7900 600.59 0.0 00000000 00000000 1 [ ] +294 0 80 "" 186.3564 566.41 0.0 00000000 00000000 1 [ ] +295 0 80 "" 186.9795 623.05 0.0 00000000 00000000 1 [ ] +296 0 70 "" 187.5859 606.45 0.0 00000000 00000000 1 [ ] +297 0 80 "" 188.2129 626.95 0.0 00000000 00000000 1 [ ] +298 0 70 "" 188.8359 623.05 0.0 00000000 00000000 1 [ ] +299 0 80 "" 189.3828 546.88 0.0 00000000 00000000 1 [ ] +300 0 80 "" 189.9463 563.48 0.0 00000000 00000000 1 [ ] +301 0 70 "" 190.5430 596.68 0.0 00000000 00000000 1 [ ] +302 0 80 "" 191.1631 620.12 0.0 00000000 00000000 1 [ ] +303 0 80 "" 191.8027 639.65 0.0 00000000 00000000 1 [ ] +304 0 70 "" 192.3965 593.75 0.0 00000000 00000000 1 [ ] +305 0 80 "" 192.9766 580.08 0.0 00000000 00000000 1 [ ] +306 0 80 "" 193.5996 623.05 0.0 00000000 00000000 1 [ ] +307 0 80 "" 194.1758 576.17 0.0 00000000 00000000 1 [ ] +308 0 80 "" 194.7490 573.24 0.0 00000000 00000000 1 [ ] +309 0 80 "" 195.3057 556.64 0.0 00000000 00000000 1 [ ] +310 0 80 "" 195.9160 610.35 0.0 00000000 00000000 1 [ ] +311 0 80 "" 196.5430 626.95 0.0 00000000 00000000 1 [ ] +312 0 80 "" 197.1289 585.94 0.0 00000000 00000000 1 [ ] +313 0 80 "" 197.7227 593.75 0.0 00000000 00000000 1 [ ] +314 0 70 "" 198.3262 603.52 0.0 00000000 00000000 1 [ ] +315 0 80 "" 198.9355 609.38 0.0 00000000 00000000 1 [ ] +316 0 80 "" 199.5527 617.19 0.0 00000000 00000000 1 [ ] +317 0 70 "" 200.1289 576.17 0.0 00000000 00000000 1 [ ] +318 0 80 "" 200.7627 633.79 0.0 00000000 00000000 1 [ ] +319 0 70 "" 201.3027 540.04 0.0 00000000 00000000 1 [ ] +320 0 80 "" 201.9092 606.45 0.0 00000000 00000000 1 [ ] +321 0 70 "" 202.4756 566.41 0.0 00000000 00000000 1 [ ] +322 0 80 "" 203.0762 600.59 0.0 00000000 00000000 1 [ ] +323 0 80 "" 203.6924 616.21 0.0 00000000 00000000 1 [ ] +324 0 80 "" 204.3457 653.32 0.0 00000000 00000000 1 [ ] +325 0 80 "" 204.9658 620.12 0.0 00000000 00000000 1 [ ] +326 0 80 "" 205.6025 636.72 0.0 00000000 00000000 1 [ ] +327 0 70 "" 206.2061 603.52 0.0 00000000 00000000 1 [ ] +328 0 80 "" 206.8057 599.61 0.0 00000000 00000000 1 [ ] +329 0 70 "" 207.3623 556.64 0.0 00000000 00000000 1 [ ] +330 0 80 "" 207.9922 629.88 0.0 00000000 00000000 1 [ ] +331 0 70 "" 208.5625 570.31 0.0 00000000 00000000 1 [ ] +332 0 80 "" 209.1162 553.71 0.0 00000000 00000000 1 [ ] +333 0 70 "" 209.6787 562.50 0.0 00000000 00000000 1 [ ] +334 0 80 "" 210.3096 630.86 0.0 00000000 00000000 1 [ ] +335 0 80 "" 210.9355 625.98 0.0 00000000 00000000 1 [ ] +336 0 80 "" 211.4922 556.64 0.0 00000000 00000000 1 [ ] +337 0 80 "" 212.1162 624.02 0.0 00000000 00000000 1 [ ] +338 0 80 "" 212.6729 556.64 0.0 00000000 00000000 1 [ ] +339 0 80 "" 213.2588 585.94 0.0 00000000 00000000 1 [ ] +340 0 80 "" 213.8828 624.02 0.0 00000000 00000000 1 [ ] +341 0 80 "" 214.4453 562.50 0.0 00000000 00000000 1 [ ] +342 0 80 "" 215.0723 626.95 0.0 00000000 00000000 1 [ ] +343 0 80 "" 215.6494 577.15 0.0 00000000 00000000 1 [ ] +344 0 80 "" 216.2061 556.64 0.0 00000000 00000000 1 [ ] +345 0 80 "" 216.7627 556.64 0.0 00000000 00000000 1 [ ] +346 0 80 "" 217.3057 542.97 0.0 00000000 00000000 1 [ ] +347 0 70 "" 217.9521 646.48 0.0 00000000 00000000 1 [ ] +348 0 80 "" 218.5322 580.08 0.0 00000000 00000000 1 [ ] +349 0 80 "" 219.0791 546.88 0.0 00000000 00000000 1 [ ] +350 0 80 "" 219.6660 586.91 0.0 00000000 00000000 1 [ ] +351 0 70 "" 220.2090 542.97 0.0 00000000 00000000 1 [ ] +352 0 80 "" 220.8223 613.28 0.0 00000000 00000000 1 [ ] +353 0 80 "" 221.4121 589.84 0.0 00000000 00000000 1 [ ] +354 0 80 "" 222.0322 620.12 0.0 00000000 00000000 1 [ ] +355 0 80 "" 222.6084 576.17 0.0 00000000 00000000 1 [ ] +356 0 80 "" 223.1758 567.38 0.0 00000000 00000000 1 [ ] +357 0 80 "" 223.7959 620.12 0.0 00000000 00000000 1 [ ] +358 0 80 "" 224.4053 609.38 0.0 00000000 00000000 1 [ ] +359 0 80 "" 224.9424 537.11 0.0 00000000 00000000 1 [ ] +360 0 80 "" 225.5283 585.94 0.0 00000000 00000000 1 [ ] +361 0 80 "" 226.0820 553.71 0.0 00000000 00000000 1 [ ] +362 0 80 "" 226.7090 626.95 0.0 00000000 00000000 1 [ ] +363 0 80 "" 227.2988 589.84 0.0 00000000 00000000 1 [ ] +364 0 80 "" 227.9258 626.95 0.0 00000000 00000000 1 [ ] +365 0 80 "" 228.5352 609.38 0.0 00000000 00000000 1 [ ] +366 0 80 "" 229.1016 566.41 0.0 00000000 00000000 1 [ ] +367 0 80 "" 229.6885 586.91 0.0 00000000 00000000 1 [ ] +368 0 80 "" 230.2617 573.24 0.0 00000000 00000000 1 [ ] +369 0 80 "" 230.8320 570.31 0.0 00000000 00000000 1 [ ] +370 0 80 "" 231.4082 576.17 0.0 00000000 00000000 1 [ ] +371 0 70 "" 232.0186 610.35 0.0 00000000 00000000 1 [ ] +372 0 80 "" 232.5850 566.41 0.0 00000000 00000000 1 [ ] +373 0 80 "" 233.2021 617.19 0.0 00000000 00000000 1 [ ] +374 0 80 "" 233.7549 552.73 0.0 00000000 00000000 1 [ ] +375 0 80 "" 234.3320 577.15 0.0 00000000 00000000 1 [ ] +376 0 70 "" 234.9424 610.35 0.0 00000000 00000000 1 [ ] +377 0 80 "" 235.5352 592.77 0.0 00000000 00000000 1 [ ] +378 0 80 "" 236.1123 577.15 0.0 00000000 00000000 1 [ ] +379 0 80 "" 236.6953 583.01 0.0 00000000 00000000 1 [ ] +380 0 70 "" 237.2822 586.91 0.0 00000000 00000000 1 [ ] +381 0 80 "" 237.8418 559.57 0.0 00000000 00000000 1 [ ] +382 0 80 "" 238.3848 542.97 0.0 00000000 00000000 1 [ ] +383 0 80 "" 239.0020 617.19 0.0 00000000 00000000 1 [ ] +384 0 80 "" 239.5547 552.73 0.0 00000000 00000000 1 [ ] +385 0 80 "" 240.1582 603.52 0.0 00000000 00000000 1 [ ] +386 0 70 "" 240.7188 560.55 0.0 00000000 00000000 1 [ ] +387 0 80 "" 241.2783 559.57 0.0 00000000 00000000 1 [ ] +388 0 80 "" 241.8682 589.84 0.0 00000000 00000000 1 [ ] +389 0 80 "" 242.4980 629.88 0.0 00000000 00000000 1 [ ] +390 0 80 "" 243.0684 570.31 0.0 00000000 00000000 1 [ ] +391 0 80 "" 243.6748 606.45 0.0 00000000 00000000 1 [ ] +392 0 70 "" 244.2188 543.95 0.0 00000000 00000000 1 [ ] +393 0 80 "" 244.8350 616.21 0.0 00000000 00000000 1 [ ] +394 0 70 "" 245.4150 580.08 0.0 00000000 00000000 1 [ ] +395 0 80 "" 246.0088 593.75 0.0 00000000 00000000 1 [ ] +396 0 80 "" 246.6445 635.74 0.0 00000000 00000000 1 [ ] +397 0 80 "" 247.1885 543.95 0.0 00000000 00000000 1 [ ] +398 0 80 "" 247.7852 596.68 0.0 00000000 00000000 1 [ ] +399 0 80 "" 248.3779 592.77 0.0 00000000 00000000 1 [ ] +400 0 80 "" 249.0146 636.72 0.0 00000000 00000000 1 [ ] +401 0 80 "" 249.5645 549.80 0.0 00000000 00000000 1 [ ] +402 0 80 "" 250.1250 560.55 0.0 00000000 00000000 1 [ ] +403 0 80 "" 250.7148 589.84 0.0 00000000 00000000 1 [ ] +404 0 80 "" 251.2920 577.15 0.0 00000000 00000000 1 [ ] +405 0 80 "" 251.8379 545.90 0.0 00000000 00000000 1 [ ] +406 0 80 "" 252.4150 577.15 0.0 00000000 00000000 1 [ ] +407 0 80 "" 253.0381 623.05 0.0 00000000 00000000 1 [ ] +408 0 80 "" 253.5645 526.37 0.0 00000000 00000000 1 [ ] +409 0 80 "" 254.1582 593.75 0.0 00000000 00000000 1 [ ] +410 0 80 "" 254.7383 580.08 0.0 00000000 00000000 1 [ ] +411 0 80 "" 255.3418 603.52 0.0 00000000 00000000 1 [ ] +412 0 80 "" 255.9180 576.17 0.0 00000000 00000000 1 [ ] +413 0 80 "" 256.4746 556.64 0.0 00000000 00000000 1 [ ] +414 0 70 "" 257.0449 570.31 0.0 00000000 00000000 1 [ ] +415 0 80 "" 257.6113 566.41 0.0 00000000 00000000 1 [ ] +416 0 80 "" 258.2080 596.68 0.0 00000000 00000000 1 [ ] +417 0 70 "" 258.7578 549.80 0.0 00000000 00000000 1 [ ] +418 0 80 "" 259.3545 596.68 0.0 00000000 00000000 1 [ ] +419 0 80 "" 259.9814 626.95 0.0 00000000 00000000 1 [ ] +420 0 80 "" 260.5713 589.84 0.0 00000000 00000000 1 [ ] +421 0 80 "" 261.1543 583.01 0.0 00000000 00000000 1 [ ] +422 0 70 "" 261.7744 620.12 0.0 00000000 00000000 1 [ ] +423 0 80 "" 262.3984 624.02 0.0 00000000 00000000 1 [ ] +424 0 80 "" 263.0244 625.98 0.0 00000000 00000000 1 [ ] +425 0 70 "" 263.6611 636.72 0.0 00000000 00000000 1 [ ] +426 0 80 "" 264.1943 533.20 0.0 00000000 00000000 1 [ ] +427 0 70 "" 264.7314 537.11 0.0 00000000 00000000 1 [ ] +428 0 80 "" 265.2783 546.88 0.0 00000000 00000000 1 [ ] +429 0 80 "" 265.8516 573.24 0.0 00000000 00000000 1 [ ] +430 0 80 "" 266.4443 592.77 0.0 00000000 00000000 1 [ ] +431 0 80 "" 266.9941 549.80 0.0 00000000 00000000 1 [ ] +432 0 80 "" 267.6377 643.55 0.0 00000000 00000000 1 [ ] +433 0 70 "" 268.2549 617.19 0.0 00000000 00000000 1 [ ] +434 0 80 "" 268.8613 606.45 0.0 00000000 00000000 1 [ ] +435 0 70 "" 269.4443 583.01 0.0 00000000 00000000 1 [ ] +436 0 80 "" 269.9941 549.80 0.0 00000000 00000000 1 [ ] +437 0 80 "" 270.5908 596.68 0.0 00000000 00000000 1 [ ] +438 0 80 "" 271.2109 620.12 0.0 00000000 00000000 1 [ ] +439 0 80 "" 271.7510 540.04 0.0 00000000 00000000 1 [ ] +440 0 80 "" 272.2949 543.95 0.0 00000000 00000000 1 [ ] +441 0 80 "" 272.9414 646.48 0.0 00000000 00000000 1 [ ] +442 0 80 "" 273.5312 589.84 0.0 00000000 00000000 1 [ ] +443 0 80 "" 274.0840 552.73 0.0 00000000 00000000 1 [ ] +444 0 80 "" 274.6514 567.38 0.0 00000000 00000000 1 [ ] +445 0 80 "" 275.2373 585.94 0.0 00000000 00000000 1 [ ] +446 0 70 "" 275.8145 577.15 0.0 00000000 00000000 1 [ ] +447 0 80 "" 276.4209 606.45 0.0 00000000 00000000 1 [ ] +448 0 80 "" 277.0479 626.95 0.0 00000000 00000000 1 [ ] +449 0 80 "" 277.6572 609.38 0.0 00000000 00000000 1 [ ] +450 0 80 "" 278.2578 600.59 0.0 00000000 00000000 1 [ ] +451 0 70 "" 278.8672 609.38 0.0 00000000 00000000 1 [ ] +452 0 80 "" 279.4512 583.98 0.0 00000000 00000000 1 [ ] +453 0 70 "" 280.0244 573.24 0.0 00000000 00000000 1 [ ] +454 0 80 "" 280.6514 626.95 0.0 00000000 00000000 1 [ ] +455 0 70 "" 281.2744 623.05 0.0 00000000 00000000 1 [ ] +456 0 80 "" 281.9180 643.55 0.0 00000000 00000000 1 [ ] +457 0 70 "" 282.4805 562.50 0.0 00000000 00000000 1 [ ] +458 0 80 "" 283.0674 586.91 0.0 00000000 00000000 1 [ ] +459 0 80 "" 283.6973 629.88 0.0 00000000 00000000 1 [ ] +460 0 80 "" 284.3037 606.45 0.0 00000000 00000000 1 [ ] +461 0 80 "" 284.9238 620.12 0.0 00000000 00000000 1 [ ] +462 0 80 "" 285.5273 603.52 0.0 00000000 00000000 1 [ ] +463 0 80 "" 286.1172 589.84 0.0 00000000 00000000 1 [ ] +464 0 80 "" 286.7246 607.42 0.0 00000000 00000000 1 [ ] +465 0 80 "" 287.3477 623.05 0.0 00000000 00000000 1 [ ] +466 0 80 "" 287.8877 540.04 0.0 00000000 00000000 1 [ ] +467 0 80 "" 288.4346 546.88 0.0 00000000 00000000 1 [ ] +468 0 80 "" 288.9941 559.57 0.0 00000000 00000000 1 [ ] +469 0 70 "" 289.5938 599.61 0.0 00000000 00000000 1 [ ] +470 0 80 "" 290.2275 633.79 0.0 00000000 00000000 1 [ ] +471 0 80 "" 290.8174 589.84 0.0 00000000 00000000 1 [ ] +472 0 80 "" 291.3945 577.15 0.0 00000000 00000000 1 [ ] +473 0 80 "" 291.9902 595.70 0.0 00000000 00000000 1 [ ] +474 0 80 "" 292.5742 583.98 0.0 00000000 00000000 1 [ ] +475 0 80 "" 293.1904 616.21 0.0 00000000 00000000 1 [ ] +476 0 80 "" 293.8008 610.35 0.0 00000000 00000000 1 [ ] +477 0 80 "" 294.4209 620.12 0.0 00000000 00000000 1 [ ] +478 0 70 "" 295.0469 625.98 0.0 00000000 00000000 1 [ ] +479 0 80 "" 295.6143 567.38 0.0 00000000 00000000 1 [ ] +480 0 70 "" 296.1709 556.64 0.0 00000000 00000000 1 [ ] +481 0 80 "" 296.7939 623.05 0.0 00000000 00000000 1 [ ] +482 0 80 "" 297.4238 629.88 0.0 00000000 00000000 1 [ ] +483 0 80 "" 297.9873 563.48 0.0 00000000 00000000 1 [ ] +484 0 70 "" 298.5977 610.35 0.0 00000000 00000000 1 [ ] +485 0 80 "" 299.2305 632.81 0.0 00000000 00000000 1 [ ] +486 0 70 "" 299.7705 540.04 0.0 00000000 00000000 1 [ ] +487 0 80 "" 300.3672 596.68 0.0 00000000 00000000 1 [ ] +488 0 80 "" 300.9434 576.17 0.0 00000000 00000000 1 [ ] +489 0 80 "" 301.5010 557.62 0.0 00000000 00000000 1 [ ] +490 0 70 "" 302.0508 549.80 0.0 00000000 00000000 1 [ ] +491 0 80 "" 302.5908 540.04 0.0 00000000 00000000 1 [ ] +492 0 70 "" 303.1973 606.45 0.0 00000000 00000000 1 [ ] +493 0 80 "" 303.8271 629.88 0.0 00000000 00000000 1 [ ] +494 0 80 "" 304.4434 616.21 0.0 00000000 00000000 1 [ ] +495 0 70 "" 304.9902 546.88 0.0 00000000 00000000 1 [ ] +496 0 80 "" 305.5605 570.31 0.0 00000000 00000000 1 [ ] +497 0 80 "" 306.1436 583.01 0.0 00000000 00000000 1 [ ] +498 0 80 "" 306.6807 537.11 0.0 00000000 00000000 1 [ ] +499 0 80 "" 307.2539 573.24 0.0 00000000 00000000 1 [ ] +500 0 80 "" 307.8467 592.77 0.0 00000000 00000000 1 [ ] +501 0 80 "" 308.4102 563.48 0.0 00000000 00000000 1 [ ] +502 0 80 "" 309.0137 603.52 0.0 00000000 00000000 1 [ ] +503 0 80 "" 309.5938 580.08 0.0 00000000 00000000 1 [ ] +504 0 80 "" 310.1465 552.73 0.0 00000000 00000000 1 [ ] +505 0 80 "" 310.6768 530.27 0.0 00000000 00000000 1 [ ] +506 0 70 "" 311.2471 570.31 0.0 00000000 00000000 1 [ ] +507 0 80 "" 311.8672 620.12 0.0 00000000 00000000 1 [ ] +508 0 80 "" 312.4199 552.73 0.0 00000000 00000000 1 [ ] +509 0 70 "" 312.9873 567.38 0.0 00000000 00000000 1 [ ] +510 0 80 "" 313.6006 613.28 0.0 00000000 00000000 1 [ ] +511 0 80 "" 314.2100 609.38 0.0 00000000 00000000 1 [ ] +512 0 80 "" 314.7773 567.38 0.0 00000000 00000000 1 [ ] +513 0 70 "" 315.3340 556.64 0.0 00000000 00000000 1 [ ] +514 0 80 "" 315.9199 585.94 0.0 00000000 00000000 1 [ ] +515 0 80 "" 316.4600 540.04 0.0 00000000 00000000 1 [ ] +516 0 80 "" 317.0166 556.64 0.0 00000000 00000000 1 [ ] +517 0 80 "" 317.6465 629.88 0.0 00000000 00000000 1 [ ] +518 0 80 "" 318.2471 600.59 0.0 00000000 00000000 1 [ ] +519 0 80 "" 318.8203 573.24 0.0 00000000 00000000 1 [ ] +520 0 80 "" 319.4131 592.77 0.0 00000000 00000000 1 [ ] +521 0 80 "" 320.0098 596.68 0.0 00000000 00000000 1 [ ] +522 0 80 "" 320.6035 593.75 0.0 00000000 00000000 1 [ ] +523 0 80 "" 321.1738 570.31 0.0 00000000 00000000 1 [ ] +524 0 70 "" 321.8037 629.88 0.0 00000000 00000000 1 [ ] +525 0 80 "" 322.3633 559.57 0.0 00000000 00000000 1 [ ] +526 0 80 "" 322.9834 620.12 0.0 00000000 00000000 1 [ ] +527 0 80 "" 323.5898 606.45 0.0 00000000 00000000 1 [ ] +528 0 80 "" 324.1934 603.52 0.0 00000000 00000000 1 [ ] +529 0 80 "" 324.7598 566.41 0.0 00000000 00000000 1 [ ] +530 0 80 "" 325.3867 626.95 0.0 00000000 00000000 1 [ ] +531 0 80 "" 325.9697 583.01 0.0 00000000 00000000 1 [ ] +532 0 80 "" 326.5635 593.75 0.0 00000000 00000000 1 [ ] +533 0 80 "" 327.1270 563.48 0.0 00000000 00000000 1 [ ] +534 0 80 "" 327.7002 573.24 0.0 00000000 00000000 1 [ ] +535 0 80 "" 328.2568 556.64 0.0 00000000 00000000 1 [ ] +536 0 70 "" 328.8301 573.24 0.0 00000000 00000000 1 [ ] +537 0 80 "" 329.3799 549.80 0.0 00000000 00000000 1 [ ] +538 0 80 "" 329.9531 573.24 0.0 00000000 00000000 1 [ ] +539 0 70 "" 330.5996 646.48 0.0 00000000 00000000 1 [ ] +540 0 80 "" 331.1836 583.98 0.0 00000000 00000000 1 [ ] +541 0 70 "" 331.7598 576.17 0.0 00000000 00000000 1 [ ] +542 0 80 "" 332.3428 583.01 0.0 00000000 00000000 1 [ ] +543 0 80 "" 332.9365 593.75 0.0 00000000 00000000 1 [ ] +544 0 80 "" 333.5303 593.75 0.0 00000000 00000000 1 [ ] +545 0 80 "" 334.1436 613.28 0.0 00000000 00000000 1 [ ] +546 0 70 "" 334.7363 592.77 0.0 00000000 00000000 1 [ ] +547 0 80 "" 335.3496 613.28 0.0 00000000 00000000 1 [ ] +548 0 80 "" 335.9268 577.15 0.0 00000000 00000000 1 [ ] +549 0 80 "" 336.5068 580.08 0.0 00000000 00000000 1 [ ] +550 0 80 "" 337.1094 602.54 0.0 00000000 00000000 1 [ ] +551 0 80 "" 337.6797 570.31 0.0 00000000 00000000 1 [ ] +552 0 80 "" 338.2832 603.52 0.0 00000000 00000000 1 [ ] +553 0 80 "" 338.9062 623.05 0.0 00000000 00000000 1 [ ] +554 0 80 "" 339.5361 629.88 0.0 00000000 00000000 1 [ ] +555 0 80 "" 340.1465 610.35 0.0 00000000 00000000 1 [ ] +556 0 80 "" 340.7363 589.84 0.0 00000000 00000000 1 [ ] +557 0 80 "" 341.2930 556.64 0.0 00000000 00000000 1 [ ] +558 0 80 "" 341.8730 580.08 0.0 00000000 00000000 1 [ ] +559 0 80 "" 342.4531 580.08 0.0 00000000 00000000 1 [ ] +560 0 80 "" 343.0000 546.88 0.0 00000000 00000000 1 [ ] +561 0 80 "" 343.6367 636.72 0.0 00000000 00000000 1 [ ] +562 0 80 "" 344.2334 596.68 0.0 00000000 00000000 1 [ ] +563 0 70 "" 344.8594 625.98 0.0 00000000 00000000 1 [ ] +564 0 80 "" 345.4697 610.35 0.0 00000000 00000000 1 [ ] +565 0 80 "" 346.0928 623.05 0.0 00000000 00000000 1 [ ] +566 0 70 "" 346.7031 610.35 0.0 00000000 00000000 1 [ ] +567 0 80 "" 347.3066 603.52 0.0 00000000 00000000 1 [ ] +568 0 80 "" 347.8594 552.73 0.0 00000000 00000000 1 [ ] +569 0 70 "" 348.4727 613.28 0.0 00000000 00000000 1 [ ] +570 0 80 "" 349.0830 610.35 0.0 00000000 00000000 1 [ ] +571 0 80 "" 349.6924 609.38 0.0 00000000 00000000 1 [ ] +572 0 80 "" 350.2725 580.08 0.0 00000000 00000000 1 [ ] +573 0 80 "" 350.8965 624.02 0.0 00000000 00000000 1 [ ] +574 0 80 "" 351.5225 625.98 0.0 00000000 00000000 1 [ ] +575 0 80 "" 352.1260 603.52 0.0 00000000 00000000 1 [ ] +576 0 80 "" 352.7393 613.28 0.0 00000000 00000000 1 [ ] +577 0 80 "" 353.3564 617.19 0.0 00000000 00000000 1 [ ] +578 0 80 "" 353.9932 636.72 0.0 00000000 00000000 1 [ ] +579 0 80 "" 354.6025 609.38 0.0 00000000 00000000 1 [ ] +580 0 80 "" 355.1963 593.75 0.0 00000000 00000000 1 [ ] +581 0 80 "" 355.7529 556.64 0.0 00000000 00000000 1 [ ] +582 0 80 "" 356.3125 559.57 0.0 00000000 00000000 1 [ ] +583 0 80 "" 356.9355 623.05 0.0 00000000 00000000 1 [ ] +584 0 80 "" 357.4795 543.95 0.0 00000000 00000000 1 [ ] +585 0 80 "" 358.0293 549.80 0.0 00000000 00000000 1 [ ] +586 0 80 "" 358.5693 540.04 0.0 00000000 00000000 1 [ ] +587 0 70 "" 359.1592 589.84 0.0 00000000 00000000 1 [ ] +588 0 80 "" 359.7021 542.97 0.0 00000000 00000000 1 [ ] +589 0 70 "" 360.2959 593.75 0.0 00000000 00000000 1 [ ] +590 0 80 "" 360.8496 553.71 0.0 00000000 00000000 1 [ ] +591 0 80 "" 361.4395 589.84 0.0 00000000 00000000 1 [ ] +592 0 70 "" 362.0029 563.48 0.0 00000000 00000000 1 [ ] +593 0 80 "" 362.6357 632.81 0.0 00000000 00000000 1 [ ] +594 0 80 "" 363.1855 549.80 0.0 00000000 00000000 1 [ ] +595 0 80 "" 363.7988 613.28 0.0 00000000 00000000 1 [ ] +596 0 70 "" 364.3457 546.88 0.0 00000000 00000000 1 [ ] +597 0 80 "" 364.9395 593.75 0.0 00000000 00000000 1 [ ] +598 0 80 "" 365.5156 576.17 0.0 00000000 00000000 1 [ ] +599 0 80 "" 366.1426 626.95 0.0 00000000 00000000 1 [ ] +600 0 70 "" 366.7129 570.31 0.0 00000000 00000000 1 [ ] +601 0 80 "" 367.3154 602.54 0.0 00000000 00000000 1 [ ] +602 0 80 "" 367.9492 633.79 0.0 00000000 00000000 1 [ ] +603 0 80 "" 368.5762 626.95 0.0 00000000 00000000 1 [ ] +604 0 80 "" 369.1729 596.68 0.0 00000000 00000000 1 [ ] +605 0 80 "" 369.7061 533.20 0.0 00000000 00000000 1 [ ] +606 0 80 "" 370.2490 542.97 0.0 00000000 00000000 1 [ ] +607 0 80 "" 370.7959 546.88 0.0 00000000 00000000 1 [ ] +608 0 70 "" 371.4326 636.72 0.0 00000000 00000000 1 [ ] +609 0 80 "" 372.0557 623.05 0.0 00000000 00000000 1 [ ] +610 0 70 "" 372.6455 589.84 0.0 00000000 00000000 1 [ ] +611 0 80 "" 373.1787 533.20 0.0 00000000 00000000 1 [ ] +612 0 80 "" 373.7793 600.59 0.0 00000000 00000000 1 [ ] +613 0 80 "" 374.3555 576.17 0.0 00000000 00000000 1 [ ] +614 0 80 "" 374.9756 620.12 0.0 00000000 00000000 1 [ ] +615 0 80 "" 375.5654 589.84 0.0 00000000 00000000 1 [ ] +616 0 80 "" 376.1455 580.08 0.0 00000000 00000000 1 [ ] +617 0 80 "" 376.7520 606.45 0.0 00000000 00000000 1 [ ] +618 0 80 "" 377.2959 543.95 0.0 00000000 00000000 1 [ ] +619 0 80 "" 377.8389 542.97 0.0 00000000 00000000 1 [ ] +620 0 80 "" 378.4756 636.72 0.0 00000000 00000000 1 [ ] +621 0 80 "" 379.1191 643.55 0.0 00000000 00000000 1 [ ] +622 0 70 "" 379.7188 599.61 0.0 00000000 00000000 1 [ ] +623 0 80 "" 380.3389 620.12 0.0 00000000 00000000 1 [ ] +624 0 80 "" 380.9355 596.68 0.0 00000000 00000000 1 [ ] +625 0 80 "" 381.5283 592.77 0.0 00000000 00000000 1 [ ] +626 0 80 "" 382.1221 593.75 0.0 00000000 00000000 1 [ ] +627 0 80 "" 382.7285 606.45 0.0 00000000 00000000 1 [ ] +628 0 80 "" 383.3389 610.35 0.0 00000000 00000000 1 [ ] +629 0 70 "" 383.9287 589.84 0.0 00000000 00000000 1 [ ] +630 0 80 "" 384.4951 566.41 0.0 00000000 00000000 1 [ ] +631 0 80 "" 385.0918 596.68 0.0 00000000 00000000 1 [ ] +632 0 80 "" 385.7256 633.79 0.0 00000000 00000000 1 [ ] +633 0 80 "" 386.3516 625.98 0.0 00000000 00000000 1 [ ] +634 0 80 "" 386.9385 586.91 0.0 00000000 00000000 1 [ ] +635 0 70 "" 387.5586 620.12 0.0 00000000 00000000 1 [ ] +636 0 80 "" 388.1953 636.72 0.0 00000000 00000000 1 [ ] +637 0 80 "" 388.7822 586.91 0.0 00000000 00000000 1 [ ] +638 0 80 "" 389.4189 636.72 0.0 00000000 00000000 1 [ ] +639 0 70 "" 389.9648 545.90 0.0 00000000 00000000 1 [ ] +640 0 80 "" 390.5850 620.12 0.0 00000000 00000000 1 [ ] +641 0 80 "" 391.1621 577.15 0.0 00000000 00000000 1 [ ] +642 0 70 "" 391.7891 626.95 0.0 00000000 00000000 1 [ ] +643 0 80 "" 392.4053 616.21 0.0 00000000 00000000 1 [ ] +644 0 70 "" 392.9717 566.41 0.0 00000000 00000000 1 [ ] +645 0 80 "" 393.5254 553.71 0.0 00000000 00000000 1 [ ] +646 0 70 "" 394.1387 613.28 0.0 00000000 00000000 1 [ ] +647 0 80 "" 394.7217 583.01 0.0 00000000 00000000 1 [ ] +648 0 80 "" 395.2783 556.64 0.0 00000000 00000000 1 [ ] +649 0 80 "" 395.8281 549.80 0.0 00000000 00000000 1 [ ] +650 0 70 "" 396.4082 580.08 0.0 00000000 00000000 1 [ ] +651 0 80 "" 396.9854 577.15 0.0 00000000 00000000 1 [ ] +652 0 80 "" 397.6221 636.72 0.0 00000000 00000000 1 [ ] +653 0 80 "" 398.1680 545.90 0.0 00000000 00000000 1 [ ] +654 0 80 "" 398.7285 560.55 0.0 00000000 00000000 1 [ ] +655 0 80 "" 399.2920 563.48 0.0 00000000 00000000 1 [ ] +656 0 80 "" 399.9082 616.21 0.0 00000000 00000000 1 [ ] +657 0 80 "" 400.5381 629.88 0.0 00000000 00000000 1 [ ] +658 0 80 "" 401.1582 620.12 0.0 00000000 00000000 1 [ ] +659 0 80 "" 401.7314 573.24 0.0 00000000 00000000 1 [ ] +660 0 80 "" 402.3516 620.12 0.0 00000000 00000000 1 [ ] +661 0 80 "" 402.9648 613.28 0.0 00000000 00000000 1 [ ] +662 0 80 "" 403.5820 617.19 0.0 00000000 00000000 1 [ ] +663 0 80 "" 404.1816 599.61 0.0 00000000 00000000 1 [ ] +664 0 80 "" 404.7783 596.68 0.0 00000000 00000000 1 [ ] +665 0 70 "" 405.3418 563.48 0.0 00000000 00000000 1 [ ] +666 0 80 "" 405.9414 599.61 0.0 00000000 00000000 1 [ ] +667 0 80 "" 406.5020 560.55 0.0 00000000 00000000 1 [ ] +668 0 80 "" 407.1182 616.21 0.0 00000000 00000000 1 [ ] +669 0 70 "" 407.7178 599.61 0.0 00000000 00000000 1 [ ] +670 0 80 "" 408.2744 556.64 0.0 00000000 00000000 1 [ ] +671 0 80 "" 408.8750 600.59 0.0 00000000 00000000 1 [ ] +672 0 80 "" 409.4678 592.77 0.0 00000000 00000000 1 [ ] +673 0 80 "" 410.0283 560.55 0.0 00000000 00000000 1 [ ] +674 0 80 "" 410.6211 592.77 0.0 00000000 00000000 1 [ ] +675 0 80 "" 411.1816 560.55 0.0 00000000 00000000 1 [ ] +676 0 80 "" 411.7520 570.31 0.0 00000000 00000000 1 [ ] +677 0 80 "" 412.2910 539.06 0.0 00000000 00000000 1 [ ] +678 0 70 "" 412.8516 560.55 0.0 00000000 00000000 1 [ ] +679 0 80 "" 413.4248 573.24 0.0 00000000 00000000 1 [ ] +680 0 80 "" 413.9746 549.80 0.0 00000000 00000000 1 [ ] +681 0 80 "" 414.5811 606.45 0.0 00000000 00000000 1 [ ] +682 0 80 "" 415.2178 636.72 0.0 00000000 00000000 1 [ ] +683 0 80 "" 415.7881 570.31 0.0 00000000 00000000 1 [ ] +684 0 80 "" 416.4111 623.05 0.0 00000000 00000000 1 [ ] +685 0 80 "" 416.9785 567.38 0.0 00000000 00000000 1 [ ] +686 0 80 "" 417.5684 589.84 0.0 00000000 00000000 1 [ ] +687 0 80 "" 418.1113 542.97 0.0 00000000 00000000 1 [ ] +688 0 70 "" 418.7217 610.35 0.0 00000000 00000000 1 [ ] +689 0 80 "" 419.3047 583.01 0.0 00000000 00000000 1 [ ] +690 0 80 "" 419.8984 593.75 0.0 00000000 00000000 1 [ ] +691 0 70 "" 420.5117 613.28 0.0 00000000 00000000 1 [ ] +692 0 80 "" 421.0615 549.80 0.0 00000000 00000000 1 [ ] +693 0 70 "" 421.6846 623.05 0.0 00000000 00000000 1 [ ] +694 0 80 "" 422.2480 563.48 0.0 00000000 00000000 1 [ ] +695 0 70 "" 422.8115 563.48 0.0 00000000 00000000 1 [ ] +696 0 80 "" 423.3975 585.94 0.0 00000000 00000000 1 [ ] +697 0 70 "" 423.9580 560.55 0.0 00000000 00000000 1 [ ] +698 0 80 "" 424.5713 613.28 0.0 00000000 00000000 1 [ ] +699 0 80 "" 425.1982 626.95 0.0 00000000 00000000 1 [ ] +700 0 70 "" 425.7676 569.34 0.0 00000000 00000000 1 [ ] +701 0 80 "" 426.3877 620.12 0.0 00000000 00000000 1 [ ] +702 0 80 "" 426.9980 610.35 0.0 00000000 00000000 1 [ ] +703 0 80 "" 427.5576 559.57 0.0 00000000 00000000 1 [ ] +704 0 80 "" 428.1377 580.08 0.0 00000000 00000000 1 [ ] +705 0 80 "" 428.7480 610.35 0.0 00000000 00000000 1 [ ] +706 0 80 "" 429.3242 576.17 0.0 00000000 00000000 1 [ ] +707 0 80 "" 429.9414 617.19 0.0 00000000 00000000 1 [ ] +708 0 80 "" 430.5674 625.98 0.0 00000000 00000000 1 [ ] +709 0 80 "" 431.1377 570.31 0.0 00000000 00000000 1 [ ] +710 0 80 "" 431.7646 626.95 0.0 00000000 00000000 1 [ ] +711 0 80 "" 432.3877 623.05 0.0 00000000 00000000 1 [ ] +712 0 80 "" 432.9443 556.64 0.0 00000000 00000000 1 [ ] +713 0 70 "" 433.5312 586.91 0.0 00000000 00000000 1 [ ] +714 0 80 "" 434.1113 580.08 0.0 00000000 00000000 1 [ ] +715 0 80 "" 434.7373 625.98 0.0 00000000 00000000 1 [ ] +716 0 70 "" 435.3076 570.31 0.0 00000000 00000000 1 [ ] +717 0 80 "" 435.8848 577.15 0.0 00000000 00000000 1 [ ] +718 0 70 "" 436.4512 566.41 0.0 00000000 00000000 1 [ ] +719 0 80 "" 437.0146 563.48 0.0 00000000 00000000 1 [ ] +720 0 80 "" 437.6113 596.68 0.0 00000000 00000000 1 [ ] +721 0 80 "" 438.1572 545.90 0.0 00000000 00000000 1 [ ] +722 0 70 "" 438.7979 640.62 0.0 00000000 00000000 1 [ ] +723 0 80 "" 439.3477 549.80 0.0 00000000 00000000 1 [ ] +724 0 80 "" 439.8975 549.80 0.0 00000000 00000000 1 [ ] +725 0 70 "" 440.5381 640.62 0.0 00000000 00000000 1 [ ] +726 0 80 "" 441.1475 609.38 0.0 00000000 00000000 1 [ ] +727 0 80 "" 441.7812 633.79 0.0 00000000 00000000 1 [ ] +728 0 80 "" 442.3711 589.84 0.0 00000000 00000000 1 [ ] +729 0 70 "" 442.9277 556.64 0.0 00000000 00000000 1 [ ] +730 0 80 "" 443.4873 559.57 0.0 00000000 00000000 1 [ ] +731 0 80 "" 444.0771 589.84 0.0 00000000 00000000 1 [ ] +732 0 80 "" 444.6504 573.24 0.0 00000000 00000000 1 [ ] +733 0 70 "" 445.2578 607.42 0.0 00000000 00000000 1 [ ] +734 0 80 "" 445.8574 599.61 0.0 00000000 00000000 1 [ ] +735 0 70 "" 446.4678 610.35 0.0 00000000 00000000 1 [ ] +736 0 80 "" 447.0205 552.73 0.0 00000000 00000000 1 [ ] +737 0 80 "" 447.5605 540.04 0.0 00000000 00000000 1 [ ] +738 0 80 "" 448.1172 556.64 0.0 00000000 00000000 1 [ ] +739 0 80 "" 448.6777 560.55 0.0 00000000 00000000 1 [ ] +740 0 70 "" 449.3242 646.48 0.0 00000000 00000000 1 [ ] +741 0 80 "" 449.9404 616.21 0.0 00000000 00000000 1 [ ] +742 0 80 "" 450.5537 613.28 0.0 00000000 00000000 1 [ ] +743 0 80 "" 451.1436 589.84 0.0 00000000 00000000 1 [ ] +744 0 80 "" 451.6973 553.71 0.0 00000000 00000000 1 [ ] +745 0 70 "" 452.2910 593.75 0.0 00000000 00000000 1 [ ] +746 0 80 "" 452.8271 536.13 0.0 00000000 00000000 1 [ ] +747 0 80 "" 453.4307 603.52 0.0 00000000 00000000 1 [ ] +748 0 80 "" 453.9736 542.97 0.0 00000000 00000000 1 [ ] +749 0 80 "" 454.5508 577.15 0.0 00000000 00000000 1 [ ] +750 0 80 "" 455.1738 623.05 0.0 00000000 00000000 1 [ ] +751 0 80 "" 455.7910 617.19 0.0 00000000 00000000 1 [ ] +752 0 80 "" 456.3242 533.20 0.0 00000000 00000000 1 [ ] +753 0 80 "" 456.8975 573.24 0.0 00000000 00000000 1 [ ] +754 0 80 "" 457.5039 606.45 0.0 00000000 00000000 1 [ ] +755 0 80 "" 458.1270 623.05 0.0 00000000 00000000 1 [ ] +756 0 70 "" 458.6934 566.41 0.0 00000000 00000000 1 [ ] +757 0 80 "" 459.2969 603.52 0.0 00000000 00000000 1 [ ] +758 0 80 "" 459.8740 577.15 0.0 00000000 00000000 1 [ ] +759 0 80 "" 460.4072 533.20 0.0 00000000 00000000 1 [ ] +760 0 70 "" 460.9570 549.80 0.0 00000000 00000000 1 [ ] +761 0 80 "" 461.5605 603.52 0.0 00000000 00000000 1 [ ] +762 0 70 "" 462.1572 596.68 0.0 00000000 00000000 1 [ ] +763 0 80 "" 462.7969 639.65 0.0 00000000 00000000 1 [ ] +764 0 80 "" 463.3633 566.41 0.0 00000000 00000000 1 [ ] +765 0 80 "" 463.9404 577.15 0.0 00000000 00000000 1 [ ] +766 0 80 "" 464.4873 546.88 0.0 00000000 00000000 1 [ ] +767 0 80 "" 465.0469 559.57 0.0 00000000 00000000 1 [ ] +768 0 80 "" 465.6533 606.45 0.0 00000000 00000000 1 [ ] +769 0 80 "" 466.2568 603.52 0.0 00000000 00000000 1 [ ] +770 0 70 "" 466.8672 610.35 0.0 00000000 00000000 1 [ ] +771 0 80 "" 467.5039 636.72 0.0 00000000 00000000 1 [ ] +772 0 70 "" 468.0605 556.64 0.0 00000000 00000000 1 [ ] +773 0 80 "" 468.6807 620.12 0.0 00000000 00000000 1 [ ] +774 0 80 "" 469.2705 589.84 0.0 00000000 00000000 1 [ ] +775 0 80 "" 469.8369 566.41 0.0 00000000 00000000 1 [ ] +776 0 70 "" 470.4404 603.52 0.0 00000000 00000000 1 [ ] +777 0 80 "" 471.0000 559.57 0.0 00000000 00000000 1 [ ] +778 0 70 "" 471.6104 610.35 0.0 00000000 00000000 1 [ ] +779 0 80 "" 472.1533 542.97 0.0 00000000 00000000 1 [ ] +780 0 70 "" 472.6865 533.20 0.0 00000000 00000000 1 [ ] +781 0 80 "" 473.2334 546.88 0.0 00000000 00000000 1 [ ] +782 0 70 "" 473.7969 563.48 0.0 00000000 00000000 1 [ ] +783 0 80 "" 474.4033 606.45 0.0 00000000 00000000 1 [ ] +784 0 80 "" 475.0039 600.59 0.0 00000000 00000000 1 [ ] +785 0 70 "" 475.6133 609.38 0.0 00000000 00000000 1 [ ] +786 0 80 "" 476.2305 617.19 0.0 00000000 00000000 1 [ ] +787 0 80 "" 476.8633 632.81 0.0 00000000 00000000 1 [ ] +788 0 80 "" 477.5000 636.72 0.0 00000000 00000000 1 [ ] +789 0 80 "" 478.0771 577.15 0.0 00000000 00000000 1 [ ] +790 0 80 "" 478.6934 616.21 0.0 00000000 00000000 1 [ ] +791 0 80 "" 479.2969 603.52 0.0 00000000 00000000 1 [ ] +792 0 80 "" 479.8867 589.84 0.0 00000000 00000000 1 [ ] +793 0 80 "" 480.5166 629.88 0.0 00000000 00000000 1 [ ] +794 0 80 "" 481.1035 586.91 0.0 00000000 00000000 1 [ ] +795 0 80 "" 481.6904 586.91 0.0 00000000 00000000 1 [ ] +796 0 80 "" 482.2236 533.20 0.0 00000000 00000000 1 [ ] +797 0 80 "" 482.7803 556.64 0.0 00000000 00000000 1 [ ] +798 0 80 "" 483.3369 556.64 0.0 00000000 00000000 1 [ ] +799 0 80 "" 483.9336 596.68 0.0 00000000 00000000 1 [ ] +800 0 80 "" 484.5264 592.77 0.0 00000000 00000000 1 [ ] +801 0 80 "" 485.0664 540.04 0.0 00000000 00000000 1 [ ] +802 0 80 "" 485.6768 610.35 0.0 00000000 00000000 1 [ ] +803 0 80 "" 486.3262 649.41 0.0 00000000 00000000 1 [ ] +804 0 70 "" 486.8701 543.95 0.0 00000000 00000000 1 [ ] +805 0 80 "" 487.4795 609.38 0.0 00000000 00000000 1 [ ] +806 0 80 "" 488.0400 560.55 0.0 00000000 00000000 1 [ ] +807 0 80 "" 488.6729 632.81 0.0 00000000 00000000 1 [ ] +808 0 70 "" 489.2402 567.38 0.0 00000000 00000000 1 [ ] +809 0 80 "" 489.7861 545.90 0.0 00000000 00000000 1 [ ] +810 0 70 "" 490.3633 577.15 0.0 00000000 00000000 1 [ ] +811 0 80 "" 490.9961 632.81 0.0 00000000 00000000 1 [ ] +812 0 70 "" 491.5693 573.24 0.0 00000000 00000000 1 [ ] +813 0 80 "" 492.1396 570.31 0.0 00000000 00000000 1 [ ] +814 0 80 "" 492.7529 613.28 0.0 00000000 00000000 1 [ ] +815 0 70 "" 493.3135 560.55 0.0 00000000 00000000 1 [ ] +816 0 80 "" 493.8936 580.08 0.0 00000000 00000000 1 [ ] +817 0 80 "" 494.4600 566.41 0.0 00000000 00000000 1 [ ] +818 0 70 "" 495.0830 623.05 0.0 00000000 00000000 1 [ ] +819 0 80 "" 495.6826 599.61 0.0 00000000 00000000 1 [ ] +820 0 80 "" 496.2900 607.42 0.0 00000000 00000000 1 [ ] +821 0 70 "" 496.8594 569.34 0.0 00000000 00000000 1 [ ] +822 0 80 "" 497.5059 646.48 0.0 00000000 00000000 1 [ ] +823 0 80 "" 498.0566 550.78 0.0 00000000 00000000 1 [ ] +824 0 80 "" 498.6631 606.45 0.0 00000000 00000000 1 [ ] +825 0 80 "" 499.2998 636.72 0.0 00000000 00000000 1 [ ] +826 0 70 "" 499.8564 556.64 0.0 00000000 00000000 1 [ ] +827 0 80 "" 500.4893 632.81 0.0 00000000 00000000 1 [ ] +828 0 80 "" 501.0566 567.38 0.0 00000000 00000000 1 [ ] +829 0 70 "" 501.5967 540.04 0.0 00000000 00000000 1 [ ] +830 0 80 "" 502.1826 585.94 0.0 00000000 00000000 1 [ ] +831 0 80 "" 502.7861 603.52 0.0 00000000 00000000 1 [ ] +832 0 70 "" 503.3857 599.61 0.0 00000000 00000000 1 [ ] +833 0 80 "" 504.0098 624.02 0.0 00000000 00000000 1 [ ] +834 0 80 "" 504.5732 563.48 0.0 00000000 00000000 1 [ ] +835 0 80 "" 505.1328 559.57 0.0 00000000 00000000 1 [ ] +836 0 70 "" 505.6924 559.57 0.0 00000000 00000000 1 [ ] +837 0 80 "" 506.2861 593.75 0.0 00000000 00000000 1 [ ] +838 0 80 "" 506.9092 623.05 0.0 00000000 00000000 1 [ ] +839 0 80 "" 507.4561 546.88 0.0 00000000 00000000 1 [ ] +840 0 80 "" 508.0557 599.61 0.0 00000000 00000000 1 [ ] +841 0 80 "" 508.5957 540.04 0.0 00000000 00000000 1 [ ] +842 0 70 "" 509.1865 590.82 0.0 00000000 00000000 1 [ ] +843 0 80 "" 509.8125 625.98 0.0 00000000 00000000 1 [ ] +844 0 70 "" 510.4160 603.52 0.0 00000000 00000000 1 [ ] +845 0 80 "" 510.9961 580.08 0.0 00000000 00000000 1 [ ] +846 0 80 "" 511.5498 553.71 0.0 00000000 00000000 1 [ ] +847 0 70 "" 512.1631 613.28 0.0 00000000 00000000 1 [ ] +848 0 80 "" 512.7764 613.28 0.0 00000000 00000000 1 [ ] +849 0 70 "" 513.3662 589.84 0.0 00000000 00000000 1 [ ] +850 0 80 "" 513.9824 616.21 0.0 00000000 00000000 1 [ ] +851 0 80 "" 514.5488 566.41 0.0 00000000 00000000 1 [ ] +852 0 70 "" 515.1162 567.38 0.0 00000000 00000000 1 [ ] +853 0 80 "" 515.7295 613.28 0.0 00000000 00000000 1 [ ] +854 0 70 "" 516.3330 603.52 0.0 00000000 00000000 1 [ ] +855 0 80 "" 516.9092 576.17 0.0 00000000 00000000 1 [ ] +856 0 80 "" 517.5195 610.35 0.0 00000000 00000000 1 [ ] +857 0 80 "" 518.1328 613.28 0.0 00000000 00000000 1 [ ] +858 0 80 "" 518.7588 625.98 0.0 00000000 00000000 1 [ ] +859 0 80 "" 519.3691 610.35 0.0 00000000 00000000 1 [ ] +860 0 70 "" 519.9062 537.11 0.0 00000000 00000000 1 [ ] +861 0 80 "" 520.4395 533.20 0.0 00000000 00000000 1 [ ] +862 0 80 "" 521.0654 625.98 0.0 00000000 00000000 1 [ ] +863 0 70 "" 521.6025 537.11 0.0 00000000 00000000 1 [ ] +864 0 80 "" 522.1855 583.01 0.0 00000000 00000000 1 [ ] +865 0 80 "" 522.7920 606.45 0.0 00000000 00000000 1 [ ] +866 0 70 "" 523.3691 577.15 0.0 00000000 00000000 1 [ ] +867 0 80 "" 523.9688 599.61 0.0 00000000 00000000 1 [ ] +868 0 70 "" 524.5625 593.75 0.0 00000000 00000000 1 [ ] +869 0 80 "" 525.1729 610.35 0.0 00000000 00000000 1 [ ] +870 0 70 "" 525.7461 573.24 0.0 00000000 00000000 1 [ ] +871 0 80 "" 526.2920 545.90 0.0 00000000 00000000 1 [ ] +872 0 80 "" 526.9229 630.86 0.0 00000000 00000000 1 [ ] +873 0 80 "" 527.5293 606.45 0.0 00000000 00000000 1 [ ] +874 0 80 "" 528.1328 603.52 0.0 00000000 00000000 1 [ ] +875 0 80 "" 528.7119 579.10 0.0 00000000 00000000 1 [ ] +876 0 80 "" 529.3428 630.86 0.0 00000000 00000000 1 [ ] +877 0 80 "" 529.9053 562.50 0.0 00000000 00000000 1 [ ] +878 0 80 "" 530.5059 600.59 0.0 00000000 00000000 1 [ ] +879 0 80 "" 531.0586 552.73 0.0 00000000 00000000 1 [ ] +880 0 70 "" 531.6758 617.19 0.0 00000000 00000000 1 [ ] +881 0 80 "" 532.2188 542.97 0.0 00000000 00000000 1 [ ] +882 0 80 "" 532.8193 600.59 0.0 00000000 00000000 1 [ ] +883 0 80 "" 533.3555 536.13 0.0 00000000 00000000 1 [ ] +884 0 80 "" 533.8818 526.37 0.0 00000000 00000000 1 [ ] +885 0 80 "" 534.4658 583.98 0.0 00000000 00000000 1 [ ] +886 0 80 "" 535.0322 566.41 0.0 00000000 00000000 1 [ ] +887 0 80 "" 535.6055 573.24 0.0 00000000 00000000 1 [ ] +888 0 80 "" 536.2393 633.79 0.0 00000000 00000000 1 [ ] +889 0 80 "" 536.8252 585.94 0.0 00000000 00000000 1 [ ] +890 0 70 "" 537.4092 583.98 0.0 00000000 00000000 1 [ ] +891 0 80 "" 538.0459 636.72 0.0 00000000 00000000 1 [ ] +892 0 80 "" 538.5918 545.90 0.0 00000000 00000000 1 [ ] +893 0 80 "" 539.1426 550.78 0.0 00000000 00000000 1 [ ] +894 0 80 "" 539.7324 589.84 0.0 00000000 00000000 1 [ ] +895 0 80 "" 540.3584 625.98 0.0 00000000 00000000 1 [ ] +896 0 70 "" 540.9756 617.19 0.0 00000000 00000000 1 [ ] +897 0 80 "" 541.5518 576.17 0.0 00000000 00000000 1 [ ] +898 0 80 "" 542.0791 527.34 0.0 00000000 00000000 1 [ ] +899 0 80 "" 542.6152 536.13 0.0 00000000 00000000 1 [ ] +900 0 80 "" 543.2021 586.91 0.0 00000000 00000000 1 [ ] +901 0 70 "" 543.7852 583.01 0.0 00000000 00000000 1 [ ] +902 0 80 "" 544.3555 570.31 0.0 00000000 00000000 1 [ ] +903 0 80 "" 544.9053 549.80 0.0 00000000 00000000 1 [ ] +904 0 70 "" 545.5254 620.12 0.0 00000000 00000000 1 [ ] +905 0 80 "" 546.1484 623.05 0.0 00000000 00000000 1 [ ] +906 0 80 "" 546.7490 600.59 0.0 00000000 00000000 1 [ ] +907 0 80 "" 547.3818 632.81 0.0 00000000 00000000 1 [ ] +908 0 80 "" 547.9756 593.75 0.0 00000000 00000000 1 [ ] +909 0 80 "" 548.5586 583.01 0.0 00000000 00000000 1 [ ] +910 0 80 "" 549.1123 553.71 0.0 00000000 00000000 1 [ ] +911 0 70 "" 549.6689 556.64 0.0 00000000 00000000 1 [ ] +912 0 80 "" 550.2920 623.05 0.0 00000000 00000000 1 [ ] +913 0 80 "" 550.8584 566.41 0.0 00000000 00000000 1 [ ] +914 0 80 "" 551.4287 570.31 0.0 00000000 00000000 1 [ ] +915 0 70 "" 552.0088 580.08 0.0 00000000 00000000 1 [ ] +916 0 80 "" 552.6484 639.65 0.0 00000000 00000000 1 [ ] +917 0 80 "" 553.2451 596.68 0.0 00000000 00000000 1 [ ] +918 0 80 "" 553.8682 623.05 0.0 00000000 00000000 1 [ ] +919 0 80 "" 554.4453 577.15 0.0 00000000 00000000 1 [ ] +920 0 80 "" 555.0420 596.68 0.0 00000000 00000000 1 [ ] +921 0 80 "" 555.5752 533.20 0.0 00000000 00000000 1 [ ] +922 0 80 "" 556.1748 599.61 0.0 00000000 00000000 1 [ ] +923 0 70 "" 556.7881 613.28 0.0 00000000 00000000 1 [ ] +924 0 80 "" 557.3848 596.68 0.0 00000000 00000000 1 [ ] +925 0 80 "" 557.9648 580.08 0.0 00000000 00000000 1 [ ] +926 0 70 "" 558.5420 577.15 0.0 00000000 00000000 1 [ ] +927 0 80 "" 559.1387 596.68 0.0 00000000 00000000 1 [ ] +928 0 70 "" 559.6914 552.73 0.0 00000000 00000000 1 [ ] +929 0 80 "" 560.2451 553.71 0.0 00000000 00000000 1 [ ] +930 0 70 "" 560.8086 563.48 0.0 00000000 00000000 1 [ ] +931 0 80 "" 561.3516 542.97 0.0 00000000 00000000 1 [ ] +932 0 80 "" 562.0049 653.32 0.0 00000000 00000000 1 [ ] +933 0 80 "" 562.5820 577.15 0.0 00000000 00000000 1 [ ] +934 0 80 "" 563.1650 583.01 0.0 00000000 00000000 1 [ ] +935 0 80 "" 563.7783 613.28 0.0 00000000 00000000 1 [ ] +936 0 80 "" 564.4150 636.72 0.0 00000000 00000000 1 [ ] +937 0 70 "" 565.0283 613.28 0.0 00000000 00000000 1 [ ] +938 0 80 "" 565.6514 623.05 0.0 00000000 00000000 1 [ ] +939 0 80 "" 566.1953 543.95 0.0 00000000 00000000 1 [ ] +940 0 70 "" 566.7852 589.84 0.0 00000000 00000000 1 [ ] +941 0 80 "" 567.3320 546.88 0.0 00000000 00000000 1 [ ] +942 0 80 "" 567.8750 542.97 0.0 00000000 00000000 1 [ ] +943 0 80 "" 568.4150 540.04 0.0 00000000 00000000 1 [ ] +944 0 70 "" 568.9580 542.97 0.0 00000000 00000000 1 [ ] +945 0 80 "" 569.5146 556.64 0.0 00000000 00000000 1 [ ] +946 0 80 "" 570.1445 629.88 0.0 00000000 00000000 1 [ ] +947 0 80 "" 570.7412 596.68 0.0 00000000 00000000 1 [ ] +948 0 80 "" 571.3379 596.68 0.0 00000000 00000000 1 [ ] +949 0 80 "" 571.9551 617.19 0.0 00000000 00000000 1 [ ] +950 0 80 "" 572.5576 602.54 0.0 00000000 00000000 1 [ ] +951 0 80 "" 573.1514 593.75 0.0 00000000 00000000 1 [ ] +952 0 80 "" 573.7451 593.75 0.0 00000000 00000000 1 [ ] +953 0 70 "" 574.2881 542.97 0.0 00000000 00000000 1 [ ] +954 0 80 "" 574.8682 580.08 0.0 00000000 00000000 1 [ ] +955 0 70 "" 575.4883 620.12 0.0 00000000 00000000 1 [ ] +956 0 80 "" 576.0811 592.77 0.0 00000000 00000000 1 [ ] +957 0 80 "" 576.6211 540.04 0.0 00000000 00000000 1 [ ] +958 0 70 "" 577.1680 546.88 0.0 00000000 00000000 1 [ ] +959 0 80 "" 577.7148 546.88 0.0 00000000 00000000 1 [ ] +960 0 80 "" 578.3145 599.61 0.0 00000000 00000000 1 [ ] +961 0 80 "" 578.8613 546.88 0.0 00000000 00000000 1 [ ] +962 0 80 "" 579.4912 629.88 0.0 00000000 00000000 1 [ ] +963 0 80 "" 580.0547 563.48 0.0 00000000 00000000 1 [ ] +964 0 70 "" 580.6777 623.05 0.0 00000000 00000000 1 [ ] +965 0 80 "" 581.2842 606.45 0.0 00000000 00000000 1 [ ] +966 0 80 "" 581.8779 593.75 0.0 00000000 00000000 1 [ ] +967 0 80 "" 582.4277 549.80 0.0 00000000 00000000 1 [ ] +968 0 80 "" 583.0078 580.08 0.0 00000000 00000000 1 [ ] +969 0 70 "" 583.5713 563.48 0.0 00000000 00000000 1 [ ] +970 0 80 "" 584.1143 542.97 0.0 00000000 00000000 1 [ ] +971 0 80 "" 584.7109 596.68 0.0 00000000 00000000 1 [ ] +972 0 70 "" 585.3311 620.12 0.0 00000000 00000000 1 [ ] +973 0 80 "" 585.9414 610.35 0.0 00000000 00000000 1 [ ] +974 0 80 "" 586.5146 573.24 0.0 00000000 00000000 1 [ ] +975 0 70 "" 587.1074 592.77 0.0 00000000 00000000 1 [ ] +976 0 80 "" 587.6875 580.08 0.0 00000000 00000000 1 [ ] +977 0 80 "" 588.2715 583.98 0.0 00000000 00000000 1 [ ] +978 0 80 "" 588.8379 566.41 0.0 00000000 00000000 1 [ ] +979 0 80 "" 589.3848 546.88 0.0 00000000 00000000 1 [ ] +980 0 80 "" 589.9814 596.68 0.0 00000000 00000000 1 [ ] +981 0 80 "" 590.5742 592.77 0.0 00000000 00000000 1 [ ] +982 0 80 "" 591.1914 617.19 0.0 00000000 00000000 1 [ ] +983 0 80 "" 591.8008 609.38 0.0 00000000 00000000 1 [ ] +984 0 80 "" 592.3877 586.91 0.0 00000000 00000000 1 [ ] +985 0 80 "" 593.0205 632.81 0.0 00000000 00000000 1 [ ] +986 0 80 "" 593.6309 610.35 0.0 00000000 00000000 1 [ ] +987 0 80 "" 594.2539 623.05 0.0 00000000 00000000 1 [ ] +988 0 80 "" 594.8174 563.48 0.0 00000000 00000000 1 [ ] +989 0 70 "" 595.4346 617.19 0.0 00000000 00000000 1 [ ] +990 0 80 "" 596.0439 609.38 0.0 00000000 00000000 1 [ ] +991 0 80 "" 596.6074 563.48 0.0 00000000 00000000 1 [ ] +992 0 80 "" 597.1777 570.31 0.0 00000000 00000000 1 [ ] +993 0 80 "" 597.7441 566.41 0.0 00000000 00000000 1 [ ] +994 0 80 "" 598.3047 560.55 0.0 00000000 00000000 1 [ ] +995 0 70 "" 598.9072 602.54 0.0 00000000 00000000 1 [ ] +996 0 80 "" 599.5371 629.88 0.0 00000000 00000000 1 [ ] +997 0 80 "" 600.1104 573.24 0.0 00000000 00000000 1 [ ] +998 0 80 "" 600.6943 583.98 0.0 00000000 00000000 1 [ ] +999 0 80 "" 601.3145 620.12 0.0 00000000 00000000 1 [ ] +1000 0 80 "" 601.9375 623.05 0.0 00000000 00000000 1 [ ] +1001 0 70 "" 602.5039 566.41 0.0 00000000 00000000 1 [ ] +1002 0 1 "" 605.8389 3334.96 0.0 00000000 00000000 1 [ ] diff --git a/studio_functions/Functions/EStudio/EEG Tab/EStudio_EEG_Tab.m b/studio_functions/Functions/EStudio/EEG Tab/EStudio_EEG_Tab.m new file mode 100755 index 00000000..65b63746 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/EStudio_EEG_Tab.m @@ -0,0 +1,172 @@ +%%This function is to create EEG Tab + + +% Author: Guanghui Zhang & Steve J. Luck +% Center for Mind and Brain +% University of California, Davis +% Davis, CA +% Aug. 2023 + + + +function EStudio_gui_erp_totl = EStudio_EEG_Tab(EStudio_gui_erp_totl,ColorB_def) + +if isempty(ColorB_def) + ColorB_def = [0.7020 0.77 0.85]; +end + +%% Arrange the main interface for ERP panel (Tab3) +EStudio_gui_erp_totl.eegViewBox = uix.VBox('Parent', EStudio_gui_erp_totl.tabEEG,'BackgroundColor',ColorB_def); +EStudio_gui_erp_totl.eegViewPanel = uix.BoxPanel('Parent', EStudio_gui_erp_totl.eegViewBox,'TitleColor',ColorB_def,'ForegroundColor','k');% +EStudio_gui_erp_totl.eegViewContainer = uicontainer('Parent', EStudio_gui_erp_totl.eegViewPanel); + +EStudio_gui_erp_totl.eegpanelscroll = uix.ScrollingPanel('Parent', EStudio_gui_erp_totl.tabEEG); +set(EStudio_gui_erp_totl.eegpanelscroll,'BackgroundColor',ColorB_def); +% + Adjust the main layout +set( EStudio_gui_erp_totl.tabEEG, 'Widths', [-4, 300]); % Viewpanel and settings panel + +%%-------------------------function panels--------------------------------- +EStudio_gui_erp_totl.eegpanel_fonts = f_get_default_fontsize(); + +EStudio_gui_erp_totl.eegsettingLayout = uiextras.VBox('Parent', EStudio_gui_erp_totl.eegpanelscroll,'BackgroundColor',ColorB_def); + +% + Create the settings window panels for ERP panel +EStudio_gui_erp_totl.eegpanel{1} = f_EEG_eeg_sets_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(1) = 300; +EStudio_gui_erp_totl.eegpanel{2} = f_EEG_IC_channel_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(2) = 320; +EStudio_gui_erp_totl.eegpanel{3} = f_EEG_Plot_setting_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(3) = 290; +EStudio_gui_erp_totl.eegpanel{4} = f_EEG_edit_channel_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(4) = 170; +disp('EEG Tab: Launching EEGsets, Channel and IC Selection, Plot Settings, Edit/Delete Channels & Locations,...'); +EStudio_gui_erp_totl.eegpanel{5} = f_EEG_interpolate_chan_epoch_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(5) = 290; +EStudio_gui_erp_totl.eegpanel{6} = f_EEG_chanoperation_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(6) = 330; +EStudio_gui_erp_totl.eegpanel{7} = f_EEG_informtion_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(7) = 410; +EStudio_gui_erp_totl.eegpanel{8} = f_EEG_resample_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(8) = 215; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Interpolate Channels, Channel Operations, EEG & Bin Information, Sampling Rate & Epoch,...']); +EStudio_gui_erp_totl.eegpanel{9} = f_EEG_events_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(9) = 430; +EStudio_gui_erp_totl.eegpanel{10} = f_EEG_filtering_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(10) = 245; +EStudio_gui_erp_totl.eegpanel{11} = f_EEG_eeglabtool_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(11) = 210; +EStudio_gui_erp_totl.eegpanel{12} = f_EEG_eeglabica_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(12) = 250; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'EventList, Filtering, EEGLAB Tools (only for one selected dataset), EEGLAB ICA (only for one selected dataset),...']); +EStudio_gui_erp_totl.eegpanel{13} = f_EEG_event2bin_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(13) = 200; +EStudio_gui_erp_totl.eegpanel{14} = f_EEG_binepoch_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(14) = 160; +EStudio_gui_erp_totl.eegpanel{15} = f_EEG_arf_det_segmt_conus_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(15) = 290; +EStudio_gui_erp_totl.eegpanel{16} = f_EEG_arf_det_conus_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(16) = 470; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Assign Events to Bins (BINLISTER), Extract Bin-Based Epochs (Continuous EEG), Delete Time Segments (Continuous EEG), Reject Artifactual Time Segments (Continuous EEG),...']); +EStudio_gui_erp_totl.eegpanel{17} = f_EEG_shift_eventcode_conus_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(17) = 200; +EStudio_gui_erp_totl.eegpanel{18} = f_EEG_dq_fre_conus_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(18) = 290; +EStudio_gui_erp_totl.eegpanel{19} = f_EEG_arf_det_epoch_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(19) = 380; +EStudio_gui_erp_totl.eegpanel{20} = f_EEG_arf_sumop_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(20) = 160; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Shift Event Codes (Continuous EEG), Spectral Data Quality (Continuous EEG), Artifact Detection (Epoched EEG), Artifact Info & Tools (Epoched EEG),...']); +EStudio_gui_erp_totl.eegpanel{21} = f_EEG_baselinecorr_detrend_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(21) = 220; +EStudio_gui_erp_totl.eegpanel{22} = f_EEG_dq_epoch_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(22) = 240; +EStudio_gui_erp_totl.eegpanel{23} = f_EEG_avg_erp_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(23) = 300; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Baseline Correction & Linear Detrend (Epoched EEG), Compute Data Quality Metrics (Epoched EEG), Compute Averaged ERPs (Epoched EEG),...']); +EStudio_gui_erp_totl.eegpanel{24} = f_EEG_CSD_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(24) = 190; +EStudio_gui_erp_totl.eegpanel{25} = f_EEG_utilities_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(25) = 190; +EStudio_gui_erp_totl.eegpanel{26} = f_EEG_history_GUI(EStudio_gui_erp_totl.eegsettingLayout,EStudio_gui_erp_totl.eegpanel_fonts); +EStudio_gui_erp_totl.eegpanelSizes(26) = 300; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Convert Voltage to CSD, EEG Utilities, and History panels.']); + +set(EStudio_gui_erp_totl.eegsettingLayout, 'Heights', EStudio_gui_erp_totl.eegpanelSizes); +EStudio_gui_erp_totl.eegpanelscroll.Heights = sum(EStudio_gui_erp_totl.eegpanelSizes); + +%% Hook up the minimize callback and IsMinimized +set( EStudio_gui_erp_totl.eegpanel{1}, 'MinimizeFcn', {@nMinimize, 1} ); +set( EStudio_gui_erp_totl.eegpanel{2}, 'MinimizeFcn', {@nMinimize, 2} ); +set( EStudio_gui_erp_totl.eegpanel{3}, 'MinimizeFcn', {@nMinimize, 3} ); +set( EStudio_gui_erp_totl.eegpanel{4}, 'MinimizeFcn', {@nMinimize, 4} ); +set( EStudio_gui_erp_totl.eegpanel{5}, 'MinimizeFcn', {@nMinimize, 5} ); +set( EStudio_gui_erp_totl.eegpanel{6}, 'MinimizeFcn', {@nMinimize, 6} ); +set( EStudio_gui_erp_totl.eegpanel{7}, 'MinimizeFcn', {@nMinimize, 7} ); +set( EStudio_gui_erp_totl.eegpanel{8}, 'MinimizeFcn', {@nMinimize, 8} ); +set( EStudio_gui_erp_totl.eegpanel{9}, 'MinimizeFcn', {@nMinimize, 9} ); +set( EStudio_gui_erp_totl.eegpanel{10}, 'MinimizeFcn', {@nMinimize, 10} ); +set( EStudio_gui_erp_totl.eegpanel{11}, 'MinimizeFcn', {@nMinimize, 11} ); +set( EStudio_gui_erp_totl.eegpanel{12}, 'MinimizeFcn', {@nMinimize, 12} ); +set( EStudio_gui_erp_totl.eegpanel{13}, 'MinimizeFcn', {@nMinimize, 13} ); +set( EStudio_gui_erp_totl.eegpanel{14}, 'MinimizeFcn', {@nMinimize, 14} ); +set( EStudio_gui_erp_totl.eegpanel{15}, 'MinimizeFcn', {@nMinimize, 15} ); +set( EStudio_gui_erp_totl.eegpanel{16}, 'MinimizeFcn', {@nMinimize, 16} ); +set( EStudio_gui_erp_totl.eegpanel{17}, 'MinimizeFcn', {@nMinimize, 17} ); +set( EStudio_gui_erp_totl.eegpanel{18}, 'MinimizeFcn', {@nMinimize, 18} ); +set( EStudio_gui_erp_totl.eegpanel{19}, 'MinimizeFcn', {@nMinimize, 19} ); +set( EStudio_gui_erp_totl.eegpanel{20}, 'MinimizeFcn', {@nMinimize, 20} ); +set( EStudio_gui_erp_totl.eegpanel{21}, 'MinimizeFcn', {@nMinimize, 21} ); +set( EStudio_gui_erp_totl.eegpanel{22}, 'MinimizeFcn', {@nMinimize, 22} ); +set( EStudio_gui_erp_totl.eegpanel{23}, 'MinimizeFcn', {@nMinimize, 23} ); +set( EStudio_gui_erp_totl.eegpanel{24}, 'MinimizeFcn', {@nMinimize, 24} ); +set( EStudio_gui_erp_totl.eegpanel{25}, 'MinimizeFcn', {@nMinimize, 25} ); +set( EStudio_gui_erp_totl.eegpanel{26}, 'MinimizeFcn', {@nMinimize, 26} ); +%%shrinking Panels 4-26 to just their title-bar +whichpanel = [4:26]; +for Numofpanel = 1:length(whichpanel) + minned = EStudio_gui_erp_totl.eegpanel{whichpanel(Numofpanel)}.IsMinimized; + szs = get( EStudio_gui_erp_totl.eegsettingLayout, 'Sizes' ); + if minned + set( EStudio_gui_erp_totl.eegpanel{whichpanel(Numofpanel)}, 'IsMinimized', false); + szs(whichpanel(Numofpanel)) = EStudio_gui_erp_totl.eegpanelSizes(whichpanel(Numofpanel)); + else + set( EStudio_gui_erp_totl.eegpanel{whichpanel(Numofpanel)}, 'IsMinimized', true); + szs(whichpanel(Numofpanel)) = 25; + end + set( EStudio_gui_erp_totl.eegsettingLayout, 'Sizes', szs ); + EStudio_gui_erp_totl.eegpanelscroll.Heights = sum(szs); +end %% End for shrinking panels 4-23 + +%% + Create the view +peeg = EStudio_gui_erp_totl.eegViewContainer; +EStudio_gui_erp_totl.eegViewAxes = uiextras.HBox( 'Parent', peeg,'BackgroundColor',ColorB_def); +end + + +function nMinimize( eventSource, eventData, whichpanel ) %#ok +global EStudio_gui_erp_totl; + +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.7020 0.77 0.85]; +end +minned = EStudio_gui_erp_totl.eegpanel{whichpanel}.IsMinimized; +szs = get( EStudio_gui_erp_totl.eegsettingLayout, 'Sizes' ); +if minned + set( EStudio_gui_erp_totl.eegpanel{whichpanel}, 'IsMinimized', false); + szs(whichpanel) = EStudio_gui_erp_totl.eegpanelSizes(whichpanel); +else + set( EStudio_gui_erp_totl.eegpanel{whichpanel}, 'IsMinimized', true); + szs(whichpanel) = 25; +end +set( EStudio_gui_erp_totl.eegsettingLayout, 'Sizes', szs ,'BackgroundColor',ColorB_def); +EStudio_gui_erp_totl.eegpanelscroll.Heights = sum(szs); +set(EStudio_gui_erp_totl.eegpanelscroll,'BackgroundColor',ColorB_def); +end % nMinimize diff --git a/studio_functions/Functions/EStudio/EEG Tab/f_check_eegtab_panelchanges.m b/studio_functions/Functions/EStudio/EEG Tab/f_check_eegtab_panelchanges.m new file mode 100755 index 00000000..9463d918 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/f_check_eegtab_panelchanges.m @@ -0,0 +1,181 @@ +function [messgStr,eegpanelIndex]= f_check_eegtab_panelchanges() + +messgStr = ''; +eegpanelIndex = 0; + +MyViewer_eegset = estudioworkingmemory('EEGTab_eegset'); +if ~isempty(MyViewer_eegset) && MyViewer_eegset==1 + messgStr = char( 'Changes on "EEGsets" have not been applied'); + eegpanelIndex =100; + return; +end + + +MyViewer_chanic = estudioworkingmemory('EEGTab_chanic'); +if ~isempty(MyViewer_chanic) && MyViewer_chanic==1 + messgStr = char( 'Changes on "Channel and IC Selection" have not been applied'); + eegpanelIndex =1; + return; +end + + +MyViewer_plotset = estudioworkingmemory('EEGTab_plotset'); +if ~isempty(MyViewer_plotset) && MyViewer_plotset==1 + messgStr = char( 'Changes on "Plot Settings" have not been applied'); + eegpanelIndex =2; + return; +end + +%%filtering +MyViewer_filter = estudioworkingmemory('EEGTab_filter'); +if ~isempty(MyViewer_filter) && MyViewer_filter==1 + messgStr = char( 'Changes on "Filtering" have not been applied'); + eegpanelIndex =3; + return; +end + +%%Channel operations +MyViewer_chanop = estudioworkingmemory('EEGTab_chanop'); +if ~isempty(MyViewer_chanop) && MyViewer_chanop==1 + messgStr = char( 'Changes on "Channel Operations" have not been applied'); + eegpanelIndex =4; + return; +end + +%%Assign events to bins +MyViewer_event2bin = estudioworkingmemory('EEGTab_event2bin'); +if ~isempty(MyViewer_event2bin) && MyViewer_event2bin==1 + messgStr = char( 'Changes on "Assign Events to Bins (BINLISTER)" have not been applied'); + eegpanelIndex =5; + return; +end + + +%%Bin-based epoch +MyViewer_binepoch = estudioworkingmemory('EEGTab_binepoch'); +if ~isempty(MyViewer_binepoch) && MyViewer_binepoch==1 + messgStr = char( 'Changes on "Extract Bin-Based Epochs (Continuous EEG)" have not been applied'); + eegpanelIndex =6; + return; +end + + +%%edit chan +%%Bin-based epoch +MyViewer_editchan = estudioworkingmemory('EEGTab_editchan'); +if ~isempty(MyViewer_editchan) && MyViewer_editchan==1 + messgStr = char( 'Changes on "Edit Channel Info" have not been applied'); + eegpanelIndex =7; + return; +end + + + +%%interpolate +MyViewer_interpolatechan = estudioworkingmemory('EEGTab_interpolated_chan_epoch'); +if ~isempty(MyViewer_interpolatechan) && MyViewer_interpolatechan==1 + messgStr = char( 'Changes on "Interpolate Channels" have not been applied'); + eegpanelIndex =8; + return; +end + +%%detect artifact for epoched EEG +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_detect_arts_epoch'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Artifact Detection (Epoched EEG)" have not been applied'); + eegpanelIndex =9; + return; +end + + + +%%detect artifact for continuous EEG +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_detect_arts_conus'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Delete Time Segments (Continuous EEG)" have not been applied'); + eegpanelIndex =10; + return; +end + + +%%delete time segements +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_detect_segmt_conus'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Reject Artifactual Time Segments (Continuous EEG)" have not been applied'); + eegpanelIndex =11; + return; +end + + + +%%Shift Event Codes for Continuous EEG +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_shiftcodes_conus'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Shift Event Codes (Continuous EEG)" have not been applied'); + eegpanelIndex =12; + return; +end + + + +%%Remove response mistakes for Continuous EEG +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_rmresposmistak_conus'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Remove Response Errors (Continuous EEG)" have not been applied'); + eegpanelIndex =13; + return; +end + + +%%spectral data quality +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_dq_fre_conus'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Spectral Data Quality (Continuous EEG)" have not been applied'); + eegpanelIndex =14; + return; +end + + +%%linear detrend +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_baseline_detrend'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Baseline Correction & Linear Detrend (Epoched EEG)" have not been applied'); + eegpanelIndex =15; + return; +end + +%%data quality for epoched eeg +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_dq_epoch'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Data Quality Metrics (Epoched EEG)" have not been applied'); + eegpanelIndex =16; + return; +end + +%%compute averaged ERP +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_avg_erp'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Compute Averaged ERPs (Epoched EEG)" have not been applied'); + eegpanelIndex =17; + return; +end + +%%compute averaged ERP +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_resample'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Sampling Rate & Epoch" have not been applied'); + eegpanelIndex =18; + return; +end + + + +MyViewer_detectartepoch = estudioworkingmemory('EEGTab_csd'); +if ~isempty(MyViewer_detectartepoch) && MyViewer_detectartepoch==1 + messgStr = char( 'Changes on "Convert voltage to CSD" have not been applied'); + eegpanelIndex =19; + return; +end + + +return; diff --git a/studio_functions/Functions/EStudio/EEG Tab/f_eeg_read_chan_IC_names.m b/studio_functions/Functions/EStudio/EEG Tab/f_eeg_read_chan_IC_names.m new file mode 100755 index 00000000..69856d17 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/f_eeg_read_chan_IC_names.m @@ -0,0 +1,57 @@ + + + +function [AllStr,chanName,ICName] = f_eeg_read_chan_IC_names(chanlocs,ChanArray,ICArray,channeLabel) +chanName = ''; +ICName = ''; +AllStr = ''; +if isempty(chanlocs) && isempty(ChanArray) + return; +end + +if ~isempty(ChanArray) + if ~isempty(chanlocs) && channeLabel==1 + if any(ChanArray(:)>length(chanlocs) ) + ChanArray = [1:length(chanlocs)]; + end + chanlocs = chanlocs(ChanArray); + tmplocs = readlocs(chanlocs); + chanName = { tmplocs.labels }; + for ii = 1:length(chanName) + chanName{1,ii}= sprintf(chanName{1,ii},'_','\_'); + chanName{1,ii} = strcat(num2str(ChanArray(ii)),'.',32,chanName{1,ii}); + end + elseif (isempty(chanlocs) || channeLabel==0) && ~isempty(ChanArray) + count = 0; + for ii = ChanArray + count = count +1; + chanName{count,1} = ['Chan',32,num2str(ii)]; + end + end +end +AllStr = chanName; +chanName = char(chanName); +%%IC names +if isempty(ICArray) + AllStr = char(AllStr); + return; +end +count = 0; +for ii = ICArray + count = count +1; + ICName{count,1} = ['IC',32,num2str(ii)]; +end + +if isempty(AllStr) + AllStr = char(ICName); +else + count = 0; + for ii = ICArray + count = count +1; + AllStr{length(AllStr)+1} = ['IC',32,num2str(ii)]; + end + +end +AllStr = char(AllStr); +ICName = char(ICName); +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/f_get_default_fontsize.m b/studio_functions/Functions/EStudio/EEG Tab/f_get_default_fontsize.m old mode 100644 new mode 100755 similarity index 54% rename from studio_functions/Functions/EStudio/f_get_default_fontsize.m rename to studio_functions/Functions/EStudio/EEG Tab/f_get_default_fontsize.m index bb0af327..3e611376 --- a/studio_functions/Functions/EStudio/f_get_default_fontsize.m +++ b/studio_functions/Functions/EStudio/EEG Tab/f_get_default_fontsize.m @@ -1,5 +1,10 @@ +%%This function is to set the default fontsize for ERP wave viewer on different platforms - +%Author: Guanghui ZHANG && Steve Luck +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +% 2023 function FonsizeDefault = f_get_default_fontsize() @@ -9,7 +14,7 @@ FonsizeDefault = 12; elseif isunix % Code to run on Linux platform - FonsizeDefault = 9; + FonsizeDefault = 8.5; elseif ispc % Code to run on Windows platform FonsizeDefault = 9; diff --git a/studio_functions/Functions/EStudio/EEG Tab/f_ploteeg.m b/studio_functions/Functions/EStudio/EEG Tab/f_ploteeg.m new file mode 100644 index 00000000..0050aaa3 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/f_ploteeg.m @@ -0,0 +1,71 @@ + +%%This function is to manually detect segememnts with artifats for +%%continuous or epoched EEG + + +% FORMAT : [EEG, eegcom] = f_ploteeg(EEG,mflag) + +%INPUTS: +% +% EEG - structure array of EEG structures (EEGsets) +% mflag - flag value between 1 to 8 to be marked when an artifact is +% found.(1 value) for epoched EEG + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Apr. 2024 + + + + +function [EEG, eegcom] = f_ploteeg(EEG,mflag) +eegcom = ''; +if nargin < 1 + help f_ploteeg + return +end + +if nargin < 2 + mflag=1; +end + + +if isempty(EEG) + msgboxText = 'Cannot handle an empty EEGset'; + title = 'ERPLAB: f_ploteeg() error'; + errorfound(msgboxText, title); + return +end +if isempty(EEG(1).data) + msgboxText = 'Cannot handle an empty EEGset'; + title = 'ERPLAB: f_ploteeg() error'; + errorfound(msgboxText, title); + return +end + +if length(EEG)>1 + msgboxText = 'Cannot handle multiple eegsets!'; + title = 'ERPLAB: f_ploteeg() error'; + errorfound(msgboxText, title); + return +end + +app = feval('EEG_select_segement_artifact_GUI',EEG,1,mflag); +waitfor(app,'Finishbutton',1); +try + EEG = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave +catch + EEG = []; + return; +end + + +eegcom = '[EEG, eegcom] = f_ploteeg(EEG);'; +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/f_ploteegwave.m b/studio_functions/Functions/EStudio/EEG Tab/f_ploteegwave.m new file mode 100644 index 00000000..8eb1f9d3 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/f_ploteegwave.m @@ -0,0 +1,952 @@ +%%This is subfunction of the pop_ploteegset.m that is used to plot EEG wave + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% August 2023 + + +function errmeg = f_ploteegwave(EEG,ChanArray,ICArray,Winlength,... + AmpScale,ChanLabel,Submean,EventOnset,StackFlag,NormFlag,Startimes,... + AmpIC,bufftobo,FigOutpos,FigureName) + +errmeg = []; + +if nargin<1 + help f_ploteegwave; + return +end + +if isempty(EEG) + errmeg = 'EEG is empty'; + return; +end +%%selected channels +nbchan = EEG.nbchan; +if nargin<2 + ChanArray = 1:nbchan; +end +if ~isempty(ChanArray) &&( min(ChanArray(:)) >nbchan || max(ChanArray(:))> nbchan|| min(ChanArray(:))<=0) + ChanArray = 1:nbchan; +end + +%%selected ICs +if nargin<3 + ICArray = []; +end +if isempty(EEG.icachansind) + ICArray = []; +else + nIC = numel(EEG.icachansind); + if ~isempty(ICArray) + if min(ICArray(:))>nIC || max(ICArray(:)) > nIC || min(ICArray(:))<=0 + ICArray = []; + end + end +end + + +%%Time range that is to display (1s or 5s)? +if nargin<4 + Winlength=5; +end +if isempty(Winlength) || numel(Winlength)~=1 || min(Winlength(:))<=0 + Winlength=5; +end + +%%Vertical scale? +if nargin<5 + AmpScale = 50; +end +if isempty(AmpScale) || numel(AmpScale)~=1 || AmpScale==0 + AmpScale = 50; +end +OldAmpScale = AmpScale; + +%%channe labels (name or number) +if nargin<6 + ChanLabel = 1; +end +if ~isempty(ChanLabel) && numel(ChanLabel)~=1 + ChanLabel = ChanLabel(1); +end +if isempty(ChanLabel) || numel(ChanLabel)~=1 || (ChanLabel~=0 && ChanLabel~=1) + ChanLabel = 1; +end + +%%remove DC? +if nargin<7 + Submean = 0; +end +if ~isempty(Submean) && numel(Submean)~=1 + Submean = Submean(1); +end +if isempty(Submean) || numel(Submean)~=1 || (Submean~=0 && Submean~=1) + Submean = 0; +end + + +%%Display events? +if nargin<8 + EventOnset = 1; +end +if ~isempty(EventOnset) && numel(EventOnset)~=1 + EventOnset = EventOnset(1); +end +if isempty(EventOnset) || numel(EventOnset)~=1 || (EventOnset~=0 && EventOnset~=1) + EventOnset = 1; +end + + +%%Stack? +if nargin<9 + StackFlag = 0; +end +if ~isempty(StackFlag) && numel(StackFlag)~=1 + StackFlag = StackFlag(1); +end +if isempty(StackFlag) || numel(StackFlag)~=1 || (StackFlag~=0&&StackFlag~=1) + StackFlag = 0; +end + +%%Norm? +if nargin<10 + NormFlag = 0; +end +if ~isempty(NormFlag) && numel(NormFlag)~=1 + NormFlag = NormFlag(1); +end +if isempty(NormFlag) ||numel(NormFlag)~=1 || (NormFlag~=0 && NormFlag~=1) + NormFlag = 0; +end + +%%start time for the displayed data +if nargin < 11 + if ndims(EEG.data) ==3 + Startimes=1; + else + Startimes=0; + end +end +[ChanNum,Allsamples,tmpnb] = size(EEG.data); +Allsamples = Allsamples*tmpnb; +if ndims(EEG.data) > 2 + multiplier = size(EEG.data,2); +else + multiplier = EEG.srate; +end + +if isempty(Startimes) || Startimes<0 || Startimes>(ceil((Allsamples-1)/multiplier)-Winlength) + if ndims(EEG.data) ==3 + Startimes=1; + else + Startimes=0; + end +end + +%%VERTICAL SCALE for ICs +if nargin<12 + AmpIC = 20; +end + +if isempty(AmpIC) || numel(AmpIC)~=1 || AmpIC<=0 + AmpIC = 20; +end +OldAmpIC = AmpIC; + + +%%buffer at top and bottom +if nargin<13 + bufftobo = 100; +end +if isempty(bufftobo) || numel(bufftobo)~=1 || any(bufftobo(:)<=0) + bufftobo = 100; +end + + + + +if nargin <14 + FigOutpos = []; +end +if numel(FigOutpos)~=2 + FigOutpos = []; +end + +if nargin<15 + FigureName = ''; +end + +if isempty(FigureName) + FigureName ='none'; +end + +if isempty(EEG.setname) || strcmp(EEG.setname,'') + EEG.setname = 'still_not_saved!'; +end +if isempty(EEG.setname) + fname = 'none'; +else + [pathstr, fname, ext] = fileparts(EEG.setname); +end + +% FigbgColor = [1 1 1]; +extfig =''; +[pathstrfig, FigureName, extfig] = fileparts(FigureName) ; + +if isempty(FigureName) + fig_gui= figure('Name',['<< ' fname ' >> '],... + 'NumberTitle','on','color',[1 1 1]); + % fig_gui_wave = subplot(Numrows+1,1,[2:Numrows+1]); + hbig= axes('Parent',fig_gui,'Box','on','FontWeight','normal', 'XTick', [], 'YTick', []); + hold on +end + +if ~isempty(FigureName) + fig_gui= figure('Name',['<< ' FigureName ' >> '],... + 'NumberTitle','on','color',[1 1 1]); + hbig= axes('Parent',fig_gui,'Color','none','Box','on','FontWeight','normal', 'XTick', [], 'YTick', []); + hold on; +end +% drawnow; +try + Pos = hbig.Position; + hbig.Position = [Pos(1)*0.5,Pos(2)*0.95,Pos(3)*1.15,Pos(4)*0.95]; + outerpos = fig_gui.OuterPosition; + higpos = hbig.Position; + set(fig_gui,'outerposition',[1,1,(1.1/higpos(3))*FigOutpos(1) (1.1/higpos(4))*FigOutpos(2)]) +catch + set(fig_gui,'outerposition',get(0,'screensize'));%%Maximum figure +end + +if ~isempty(extfig) + set(fig_gui,'visible','off'); +end +set(fig_gui, 'Renderer', 'painters');%%vector figure + + +%%determine the time range that will be dispalyed +lowlim = round(Startimes*multiplier+1); +highlim = round(min((Startimes+Winlength)*multiplier+1,Allsamples)); + + +%%--------------------prepare event array if any -------------------------- +Events = EEG.event; +if ~isempty(Events) + if ~isfield(Events, 'type') || ~isfield(Events, 'latency'), Events = []; end +end +if ~isempty(Events) + if ischar(Events(1).type) + [Eventtypes tmpind indexcolor] = unique_bc({Events.type}); % indexcolor countinas the event type + else [Eventtypes tmpind indexcolor] = unique_bc([ Events.type ]); + end + Eventcolors = { 'r', [0 0.8 0], 'm', 'c', 'k', 'b', [0 0.8 0] }; + Eventstyle = { '-' '-' '-' '-' '-' '-' '-' '--' '--' '--' '--' '--' '--' '--'}; + Eventwidths = [ 2.5 1 ]; + Eventtypecolors = Eventcolors(mod([1:length(Eventtypes)]-1 ,length(Eventcolors))+1); + Eventcolors = Eventcolors(mod(indexcolor-1 ,length(Eventcolors))+1); + Eventtypestyle = Eventstyle (mod([1:length(Eventtypes)]-1 ,length(Eventstyle))+1); + Eventstyle = Eventstyle (mod(indexcolor-1 ,length(Eventstyle))+1); + + % for width, only boundary events have width 2 (for the line) + % ----------------------------------------------------------- + indexwidth = ones(1,length(Eventtypes))*2; + if iscell(Eventtypes) + for index = 1:length(Eventtypes) + if strcmpi(Eventtypes{index}, 'boundary'), indexwidth(index) = 1; end + end + else + % if option_boundary99 + % indexwidth = [ Eventtypes == -99 ]; + % end + end + Eventtypewidths = Eventwidths (mod(indexwidth([1:length(Eventtypes)])-1 ,length(Eventwidths))+1); + Eventwidths = Eventwidths (mod(indexwidth(indexcolor)-1 ,length(Eventwidths))+1); + + % latency and duration of events + % ------------------------------ + Eventlatencies = [ Events.latency ]+1; + if isfield(Events, 'duration') + durations = { Events.duration }; + durations(cellfun(@isempty, durations)) = { NaN }; + Eventlatencyend = Eventlatencies + [durations{:}]+1; + else Eventlatencyend = []; + end + % EventOnset = 1; +end + +if isempty(Events) + EventOnset = 0; +end + +chanNum = numel(ChanArray); + +%%-------------------------------IC and original data---------------------- +dataica = []; chaNum = 0; +if ~isempty(ICArray) + ICdispFlag=1; + if ~isempty(EEG.icaweights) && ~isempty(ICArray)%%pop_eegplot from eeglab + tmpdata = eeg_getdatact(EEG, 'component', [1:size(EEG.icaweights,1)]); + try + dataica = tmpdata(ICArray,:); + catch + dataica = tmpdata(:,:); + ICArray = [1:size(tmpdata,1)]; + end + end +else + ICdispFlag=0; +end + +if ~isempty(ChanArray) + EEGdispFlag=1; + dataeeg = EEG.data(ChanArray,:); + chaNum = numel(ChanArray); +else + dataeeg =[]; + EEGdispFlag=0; + chaNum = 0; +end + +%%---------------------------Normalize------------------------------------- +if NormFlag==1 + %%Norm for origanal + % data2 = []; + if ~isempty(dataeeg) + datastd = std(dataeeg(:,1:min(1000,Allsamples)),[],2);% + for i = 1:size(dataeeg,1) + dataeeg(i,:,:) = dataeeg(i,:,:)/datastd(i); + % if ~isempty(data2) + % data2(i,:,:) = data2(i,:,:)*datastd(i); + % end + end + end + + %%norm for IC data + if ~isempty(dataica) + dataicstd = std(dataica(:,1:min(1000,Allsamples)),[],2); + for i = 1:size(dataica,1) + dataica(i,:,:) = dataica(i,:,:)/dataicstd(i); + % if ~isempty(data2) + % data2(i,:,:) = data2(i,:,:)*dataicstd(i); + % end + end + end +end + +% Removing DC for IC data? +% ------------------------- +meandataica =[];ICNum = 0; +if ICdispFlag==1 + if ~isempty(EEG.icaweights) && ~isempty(ICArray) && ~isempty(dataica)%%pop_eegplot from eeglab + switch Submean % subtract the mean ? + case 1 + meandataica = mean(dataica(:,lowlim:highlim)'); + if any(isnan(meandataica)) + meandataica = nan_mean(dataica(:,lowlim:highlim)'); + end + otherwise, meandataica = zeros(1,numel(ICArray)); + end + end + ICNum = numel(ICArray); +else + ICNum = 0; +end + +% Removing DC for original data? +% ------------------------- +meandata = []; +if EEGdispFlag==1 && ~isempty(dataeeg) + switch Submean % subtract the mean ? + case 1 + meandata = mean(dataeeg(:,lowlim:highlim)'); + if any(isnan(meandata)) + meandata = nan_mean(dataeeg(:,lowlim:highlim)'); + end + otherwise, meandata = zeros(1,numel(ChanArray)); + end +end + +PlotNum = chaNum+ICNum; +if chaNum==0 && ICNum==0 + Ampscold = 0*[1:PlotNum]'; + if StackFlag==1 + Ampsc = 0*[1:PlotNum]'; + else + Ampsc = Ampscold; + end + AmpScaleold = 0; + ylims = [0 (PlotNum+1)*AmpScale]; + data = [dataeeg;dataica]; + meandata = [meandata,meandataica]; +elseif ICNum==0 && chaNum~=0 + Ampscold = AmpScale*[1:PlotNum]'; + if StackFlag==1 + Ampsc = ((Ampscold(end)+AmpScale)/2)*ones(1,PlotNum)'; + else + Ampsc = Ampscold; + end + AmpScaleold = AmpScale; + ylims = [AmpScale*(100-bufftobo)/100 PlotNum*AmpScale+AmpScale*bufftobo/100]; + data = [dataeeg;dataica]; + meandata = [meandata,meandataica]; +elseif ICNum~=0 && chaNum==0 + Ampscold = AmpIC*[1:PlotNum]'; + if StackFlag==1 + Ampsc = ((Ampscold(end)+AmpIC)/2)*ones(1,PlotNum)'; + else + Ampsc = Ampscold; + end + ylims = [AmpIC*(100-bufftobo)/100 PlotNum*AmpIC+AmpIC*bufftobo/100]; + AmpScaleold = AmpIC; + data = [dataeeg;dataica]; + meandata = [meandata,meandataica]; + AmpICNew = AmpIC; +elseif ICNum~=0 && chaNum~=0 + AmpICNew = (AmpScale*chaNum+AmpScale/2)/ICNum; + Ampscold1 = AmpICNew*[1:ICNum]'; + Ampscold2 = Ampscold1(end)+AmpScale/2+AmpScale*[1:chaNum]'; + Ampscold = [Ampscold1;Ampscold2]; + if StackFlag==1 + Ampsc = [(Ampscold1(end)/2)*ones(ICNum,1);((Ampscold2(end)+AmpScale+Ampscold2(1)+AmpIC)/2)*ones(chaNum,1)]; + else + Ampsc = Ampscold; + end + AmpScaleold = AmpScale; + ylims = [AmpICNew*(100-bufftobo)/100 Ampscold(end)+AmpScale*bufftobo/100]; + data = [dataeeg;(AmpICNew/AmpIC)*dataica]; + meandata = [meandata,(AmpICNew/AmpIC)*meandataica]; +end + + +Colorgbwave = []; +%%set the wave color for each channel +if ~isempty(data) + ColorNamergb = roundn([255 0 7;186 85 255;255 192 0;0 238 237;0 78 255;0 197 0]/255,-3); + Colorgb_chan = []; + if ~isempty(ChanArray) + chanNum = numel(ChanArray); + if chanNum<=6 + Colorgb_chan = ColorNamergb(1:chanNum,:); + else + jj = floor(chanNum/6); + Colorgb_chan = []; + for ii = 1:jj + Colorgb_chan = [Colorgb_chan; ColorNamergb]; + end + if jj*6~=chanNum + Colorgb_chan = [Colorgb_chan; ColorNamergb(1:chanNum-jj*6,:)]; + end + end + end + + %%colors for ICs + % Coloricrgb = roundn([211,211,211;169,169,16;128,128,128]/255,-3);three levels for gray + Coloricrgb = roundn([180 0 0;127 68 127;228 88 44;15 175 175;0 0 0;9 158 74]/255,-3); + Colorgb_IC = []; + if ~isempty(ICArray) + ICNum = numel(ICArray); + if ICNum<7 + Colorgb_IC = Coloricrgb(1:ICNum,:); + else + jj = floor(ICNum/6); + for ii = 1:jj + Colorgb_IC = [Colorgb_IC; Coloricrgb]; + end + + if jj*6~=ICNum + Colorgb_IC = [Colorgb_IC; Coloricrgb(1:ICNum-jj*6,:)]; + end + + end + end + Colorgbwave = [Colorgb_chan;Colorgb_IC]; +end + + +PlotNum =0; +if ICdispFlag==1 && EEGdispFlag==1 + if ~isempty(EEG.icaweights) && ~isempty(ICArray) + PlotNum = chanNum +numel(ICArray); + else + PlotNum = chanNum; + end +elseif ICdispFlag==0 && EEGdispFlag==1 + PlotNum = chanNum; +elseif ICdispFlag==1 && EEGdispFlag==0 + if ~isempty(EEG.icaweights) && ~isempty(ICArray) + PlotNum = numel(ICArray); + end +end +%% +EventOnsetdur =1; +Trialstag = size(EEG.data,2); +GapSize = ceil(numel([lowlim:highlim])/40); +if GapSize<=2 + GapSize=5; +end +% ------------------------------------------------------------------------- +% -------------------------draw events if any------------------------------ +% ------------------------------------------------------------------------- + +FonsizeDefault = f_get_default_fontsize(); +if isempty(FonsizeDefault) || numel(FonsizeDefault)~=1|| any(FonsizeDefault(:)<=0) + FonsizeDefault=10; +end + +if EventOnset==1 && ~isempty(data) + MAXEVENTSTRING = 75; + if MAXEVENTSTRING<0 + MAXEVENTSTRING = 0; + elseif MAXEVENTSTRING>75 + MAXEVENTSTRING=75; + end + % AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100]; + % + + % find event to plot + % ------------------ + event2plot = find ( Eventlatencies >=lowlim & Eventlatencies <= highlim ); + if ~isempty(Eventlatencyend) + event2plot2 = find ( Eventlatencyend >= lowlim & Eventlatencyend <= highlim ); + event2plot3 = find ( Eventlatencies < lowlim & Eventlatencyend > highlim ); + event2plot = setdiff(union(event2plot, event2plot2), event2plot3); + end + for index = 1:length(event2plot) + %Just repeat for the first one + if index == 1 + EVENTFONT = [' \fontsize{',num2str(FonsizeDefault),'} ']; + end + + % draw latency line + % ----------------- + if ndims(EEG.data)==2 + tmplat = Eventlatencies(event2plot(index))-lowlim-1; + else + % ----------------- + tmptaglat = [lowlim:highlim]; + tmpind = find(mod(tmptaglat-1,Trialstag) == 0); + tmpind = setdiff(tmpind,[1,numel(tmptaglat)]); + alltaglat = setdiff(tmptaglat(tmpind),[1,tmptaglat(end)]); + %%add gap between epochs if any + if ~isempty(tmpind) && ~isempty(alltaglat) %%two or multiple epochs were displayed + if length(alltaglat)==1 + if Eventlatencies(event2plot(index)) >= alltaglat + Singlat = Eventlatencies(event2plot(index))+GapSize; + else + Singlat = Eventlatencies(event2plot(index)); + end + else + if Eventlatencies(event2plot(index)) < alltaglat(1)%%check the first epoch + Singlat = Eventlatencies(event2plot(index)); + else%%the other epochs + for ii = 2:length(alltaglat) + if Eventlatencies(event2plot(index)) >= alltaglat(ii-1) && Eventlatencies(event2plot(index)) < alltaglat(ii) + Singlat = Eventlatencies(event2plot(index))+GapSize*(ii-1); + break; + elseif Eventlatencies(event2plot(index)) >= alltaglat(end) %%check the last epoch + Singlat = Eventlatencies(event2plot(index))+GapSize*length(alltaglat); + break; + end + end + end + end + tmplat = Singlat-lowlim;%%adjust the latency if any + else%%within one epoch + tmplat = Eventlatencies(event2plot(index))-lowlim;%-1; + end + + end + tmph = plot(hbig, [ tmplat tmplat ], ylims, 'color', Eventcolors{ event2plot(index) }, ... + 'linestyle', Eventstyle { event2plot(index) }, ... + 'linewidth', Eventwidths( event2plot(index) ) ); + + % schtefan: add Event types text above event latency line + % ------------------------------------------------------- + evntxt = strrep(num2str(Events(event2plot(index)).type),'_','-'); + if length(evntxt)>MAXEVENTSTRING, evntxt = [ evntxt(1:MAXEVENTSTRING-1) '...' ]; end % truncate + try, + if tmplat>=0 + tmph2 = text(hbig, [tmplat], ylims(2)-0.005, [EVENTFONT evntxt], ... + 'color', Eventcolors{ event2plot(index) }, ... + 'horizontalalignment', 'left',... + 'rotation',90,'FontSize',FonsizeDefault); + end + catch, end + + % draw duration is not 0 + % ---------------------- + % if EventOnsetdur && ~isempty(Eventlatencyend) ... + % && Eventwidths( event2plot(index) ) ~= 2.5 % do not plot length of boundary events + % tmplatend = Eventlatencyend(event2plot(index))-lowlim-1; + % if tmplatend ~= 0 + % tmplim = ylims; + % tmpcol = Eventcolors{ event2plot(index) }; + % h = patch(hbig, [ tmplat tmplatend tmplatend tmplat ], ... + % [ tmplim(1) tmplim(1) tmplim(2) tmplim(2) ], ... + % tmpcol ); % this argument is color + % set(h, 'EdgeColor', 'none') + % end + % end + end +else % JavierLC + MAXEVENTSTRING = 10; % default + % AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100]; +end + + +if StackFlag==1 + AmpScale=0; +end +DEFAULT_GRID_SPACING =Winlength/5; + +% ------------------------------------------------------------------------- +% -----------------draw EEG wave if any------------------------------------ +% ------------------------------------------------------------------------- +leftintv = []; +%%Plot continuous EEG +tmpcolor = [ 0 0 0.4 ]; +if EEG.trials==1 + if ~isempty(data) && PlotNum~=0 + + for ii = size(data,1):-1:1 + try + plot(hbig, (data(ii,lowlim:highlim)+ Ampsc(size(data,1)-ii+1)-meandata(ii))' , ... + 'color', Colorgbwave(ii,:), 'clipping','on','LineWidth',0.5);%% + catch + plot(hbig, (data(ii,lowlim:highlim)+ Ampsc(size(data,1)-ii+1)-meandata(ii))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',0.5);%% + end + end + set(hbig,'TickDir', 'in','LineWidth',1); + %%xtick + AmpScale = OldAmpScale; + set(hbig, 'Xlim',[1 Winlength*multiplier+1],... + 'XTick',[1:multiplier*DEFAULT_GRID_SPACING:Winlength*multiplier+1]); + set(hbig, 'XTickLabel', num2str((Startimes:DEFAULT_GRID_SPACING:Startimes+Winlength)'),'FontSize',FonsizeDefault); + %% + %%-----------------plot scale------------------ + leftintv = Winlength*multiplier+1; + else + set(hbig, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); + end +end + +%%------------------------------plot single-trial EEG---------------------- +%%Thanks for the eeglab developers so that we can borrow their codes +isfreq = 0; +Limits = [EEG.times(1),EEG.times(end)]; +Srate = EEG.srate; +Freqlimits = []; +if EEG.trials>1 + if ~isempty(data) && PlotNum~=0 + + % plot trial limits + % ----------------- + tmptag = [lowlim:highlim]; + tmpind = find(mod(tmptag-1,Trialstag) == 0); + % for index = tmpind + % plot(ax0, [tmptag(index)-lowlim tmptag(index)-lowlim], [0 1], 'b--'); + % end + alltag = tmptag(tmpind); + if isempty(tmpind) + epochNum = 0; + else + epochNum = numel(setdiff(tmpind,[0 1 numel(tmptag)])); + end + % compute epoch number + % -------------- + alltag1 = alltag; + if ~isempty(tmpind) + tagnum = (alltag1-1)/Trialstag+1; + for ii = 1:numel(tmpind) + alltag1(ii) = alltag1(ii)+(ii-1)*GapSize; + end + % set(hbig1,'XTickLabel', tagnum,'YTickLabel', [],... + % 'Xlim',[1 (Winlength*multiplier+epochNum*GapSize)],... + % 'XTick',alltag-lowlim+Trialstag/2, 'YTick',[],'xaxislocation', 'top'); + for ii = 1:numel(tagnum) + text(hbig, [alltag1(ii)-lowlim+Trialstag/2],ylims(2)+1.1, [32,num2str(tagnum(ii))], ... + 'color', 'k','FontSize',FonsizeDefault, ... + 'horizontalalignment', 'left','rotation',90); %% + set(hbig,'Xlim',[1 (Winlength*multiplier+epochNum*GapSize)]); + end + end + + %%add the gap between epochs if any + Epochintv = []; + + if ~isempty(tmpind) + if (numel(tmpind)==1 && tmpind(end) == numel(tmptag)) || (numel(tmpind)==1 && tmpind(1) == 1) + dataplot = data(:,lowlim:highlim); + Epochintv(1,1) =1; + Epochintv(1,2) =numel(lowlim:highlim); + else + tmpind = unique(setdiff([0,tmpind, numel(tmptag)],1)); + dataplotold = data(:,lowlim:highlim); + dataplot_new = []; + for ii = 2:numel(tmpind) + GapLeft = tmpind(ii-1)+1; + GapRight = tmpind(ii); + if GapLeft<1 + GapLeft =1; + end + if GapRight > numel(tmptag) + GapRight = numel(tmptag); + end + dataplot_new = [dataplot_new,dataplotold(:,GapLeft:GapRight),nan(size(dataplotold,1),GapSize)]; + Epochintv(ii-1,1) = GapLeft+(ii-2)*GapSize; + Epochintv(ii-1,2) = GapRight+(ii-2)*GapSize; + end + if ~isempty(dataplot_new) + dataplot = dataplot_new; + else + dataplot = dataplotold; + end + end + end + + %%-----------plot background color for trias with artifact--------- + %%highlight waves with labels + Value_adjust = floor(Startimes+1); + if Value_adjust<1 + Value_adjust=1; + end + tagnum = unique([Value_adjust,tagnum]); + + try trialsMakrs = EEG.reject.rejmanual(tagnum);catch trialsMakrs = zeros(1,numel(tagnum)) ; end + try trialsMakrschan = EEG.reject.rejmanualE(:,tagnum);catch trialsMakrschan = zeros(EEG.nbchan,numel(tagnum)) ; end + tmpcolsbgc = [1 1 0.783]; + if ~isempty(Epochintv) %%&& chaNum~=0 + for jj = 1:size(Epochintv,1) + [xpos,~]=find(trialsMakrschan(:,jj)==1); + if jj<= numel(trialsMakrs) && ~isempty(xpos) + if trialsMakrs(jj)==1 + patch(hbig,[Epochintv(jj,1),Epochintv(jj,2),Epochintv(jj,2),Epochintv(jj,1)],... + [ylims(1),ylims(1),ylims(end),ylims(end)],tmpcolsbgc,'EdgeColor','none','FaceAlpha',.5); + %%highlight the wave if the channels that were + %%marked as artifacts + if chaNum~=0 + ChanArray = reshape(ChanArray,1,numel(ChanArray)); + [~,ypos1]=find(ChanArray==xpos); + if ~isempty(ypos1) + for kk = 1:numel(ypos1) + dataChan = nan(1,size(dataplot,2)); + dataChan (Epochintv(jj,1):Epochintv(jj,2)) = dataplot(ypos1(kk),Epochintv(jj,1):Epochintv(jj,2)); + dataChan1= nan(1,size(dataplot,2)); + dataChan1 (1,Epochintv(jj,1):Epochintv(jj,1)) = dataplot(ypos1(kk),Epochintv(jj,1):Epochintv(jj,1)); + try + plot(hbig, (dataChan+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))', ... + 'color', Colorgbwave(ypos1(kk),:), 'clipping','on','LineWidth',1.5);%% + plot(hbig, (dataChan1+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))' , ... + 'color', Colorgbwave(ypos1(kk),:), 'clipping','on','LineWidth',1.5,'Marker' ,'s','MarkerSize',8,... + 'MarkerEdgeColor',Colorgbwave(ypos1(kk),:),'MarkerFaceColor',Colorgbwave(ypos1(kk),:));%% + catch + plot(hbig, (dataChan+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',1.5);%% + plot(hbig, (dataChan1+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',1.5,'Marker' ,'s','MarkerSize',8,... + 'MarkerEdgeColor',Colorgbwave(ypos1(kk),:),'MarkerFaceColor',Colorgbwave(ypos1(kk),:));%% + end + end + end + end + end + end + end + end + + for ii = size(dataplot,1):-1:1 + try + plot(hbig, (dataplot(ii,:)+ Ampsc(size(dataplot,1)-ii+1)-meandata(ii))', ... + 'color', Colorgbwave(ii,:), 'clipping','on','LineWidth',0.5);%% + catch + plot(hbig, (dataplot(ii,:)+ Ampsc(size(dataplot,1)-ii+1)-meandata(ii))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',0.5);%% + end + end + + %------------------------Xticks------------------------------------ + tagpos = []; + tagtext = []; + if ~isempty(alltag) + alltag = [alltag(1)-Trialstag alltag alltag(end)+Trialstag]; % add border trial limits + else + alltag = [ floor(lowlim/Trialstag)*Trialstag ceil(highlim/Trialstag)*Trialstag ]+1; + end + + nbdiv = 20/Winlength; % approximative number of divisions + divpossible = [ 100000./[1 2 4 5] 10000./[1 2 4 5] 1000./[1 2 4 5] 100./[1 2 4 5 10 20]]; % possible increments + [tmp indexdiv] = min(abs(nbdiv*divpossible-(Limits(2)-Limits(1)))); % closest possible increment + incrementpoint = divpossible(indexdiv)/1000*Srate; + + % tag zero below is an offset used to be sure that 0 is included + % in the absicia of the data epochs + if Limits(2) < 0, tagzerooffset = (Limits(2)-Limits(1))/1000*Srate+1; + else tagzerooffset = -Limits(1)/1000*Srate; + end + if tagzerooffset < 0, tagzerooffset = 0; end + + for i=1:length(alltag)-1 + if ~isempty(tagpos) && tagpos(end)-alltag(i)<2*incrementpoint/3 + tagpos = tagpos(1:end-1); + end + if ~isempty(Freqlimits) + tagpos = [ tagpos linspace(alltag(i),alltag(i+1)-1, nbdiv) ]; + else + if tagzerooffset ~= 0 + tmptagpos = [alltag(i)+tagzerooffset:-incrementpoint:alltag(i)]; + else + tmptagpos = []; + end + tagpos = [ tagpos [tmptagpos(end:-1:2) alltag(i)+tagzerooffset:incrementpoint:(alltag(i+1)-1)]]; + end + end + + % find corresponding epochs + % ------------------------- + if ~isfreq + tmplimit = Limits; + tpmorder = 1E-3; + else + tmplimit =Freqlimits; + tpmorder = 1; + end + tagtext = eeg_point2lat(tagpos, floor((tagpos)/Trialstag)+1, Srate, tmplimit,tpmorder); + + %%adjust xticks + EpochFlag = floor((tagpos)/Trialstag)+1;%% + + EpochFlag = reshape(EpochFlag,1,numel(EpochFlag)); + xtickstr = tagpos-lowlim+1; + [xpos,ypos] = find(xtickstr>0); + if ~isempty(ypos) + EpochFlag =EpochFlag(ypos); + xtickstr = xtickstr(ypos); + tagtext = tagtext(ypos); + end + + EpochFlagunique =unique(setdiff(EpochFlag,0)); + if numel(EpochFlagunique)~=1 + for ii = 2:numel(EpochFlagunique) + [xpos,ypos]= find(EpochFlag==EpochFlagunique(ii)); + if ~isempty(ypos) + xtickstr(ypos) = xtickstr(ypos)+(EpochFlagunique(ii)-EpochFlagunique(1))*GapSize;%*(1000/Srate); + end + end + end + set(hbig,'XTickLabel', tagtext,... + 'Xlim',[1 (Winlength*multiplier+epochNum*GapSize)],... + 'XTick',xtickstr,... + 'FontWeight','normal',... + 'xaxislocation', 'bottom','FontSize',FonsizeDefault); + XTickLabel = cellstr(hbig.XTickLabel); + for Numofxtick = 1:length(XTickLabel) + if strcmpi(XTickLabel{Numofxtick,:},'-0') + XTickLabel{Numofxtick} = '0'; + end + end + set(hbig,'XTickLabel',XTickLabel); + %% + %%-----------------plot scale------------------ + leftintv = (Winlength*multiplier+epochNum*GapSize); + else + set(hbig, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); + end +end + +%% +%%-----------------plot y scale------------------ +if ~isempty(data) && PlotNum~=0 && ~isempty(leftintv) + ytick_bottom = hbig.TickLength(1)*diff(hbig.XLim); + leftintv = leftintv+ytick_bottom*2.5; + rightintv = leftintv; + if ICdispFlag~=0 + line(hbig,[leftintv,rightintv],[ylims(1) AmpICNew+ylims(1)],'color','k','LineWidth',1, 'clipping','off'); + line(hbig,[leftintv-ytick_bottom,rightintv+ytick_bottom],[ylims(1) ylims(1)],'color','k','LineWidth',1, 'clipping','off'); + line(hbig,[leftintv-ytick_bottom,rightintv+ytick_bottom],[AmpICNew+ylims(1) AmpICNew+ylims(1)],'color','k','LineWidth',1, 'clipping','off'); + text(hbig,leftintv,((ylims(2)-ylims(1))/43+AmpICNew+ylims(1)), [num2str(AmpIC),32,'\muV'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + text(hbig,leftintv,((ylims(2)-ylims(1))/20+AmpICNew+ylims(1)), ['ICs'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + end + if EEGdispFlag~=0 + line(hbig,[leftintv,rightintv],[ylims(end)-OldAmpScale ylims(end)],'color','k','LineWidth',1, 'clipping','off'); + line(hbig,[leftintv-ytick_bottom,rightintv+ytick_bottom],[ylims(end)-OldAmpScale ylims(end)-OldAmpScale],'color','k','LineWidth',1, 'clipping','off'); + line(hbig,[leftintv-ytick_bottom,rightintv+ytick_bottom],[ylims(end) ylims(end)],'color','k','LineWidth',1, 'clipping','off'); + text(hbig,leftintv,(ylims(2)-ylims(1))/43+ylims(end), [num2str(OldAmpScale),32,'\muV'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + text(hbig,leftintv,(ylims(2)-ylims(1))/20+ylims(end), ['Chans'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + end + + + %%ytick ticklabels + if chaNum==0 + ChanArray = []; + end + set(hbig, 'ylim',[ylims(1) ylims(end)],'YTick',[ylims(1) Ampscold']); + [YLabels,chaName,ICName] = f_eeg_read_chan_IC_names(EEG.chanlocs,ChanArray,ICArray,ChanLabel); + YLabels = flipud(char(YLabels,'')); + set(hbig,'YTickLabel',cellstr(YLabels),... + 'TickLength',[.005 .005],... + 'Color','none',... + 'XColor','k',... + 'YColor','k',... + 'FontWeight','normal',... + 'TickDir', 'in',... + 'LineWidth',0.5,'FontSize',FonsizeDefault);%%,'HorizontalAlignment','center' + count=0; + for ii = length(hbig.YTickLabel):-1:2 + count = count+1; + hbig.YTickLabel{ii} = ['\color[rgb]{',num2str(Colorgbwave(count,:)),'}', strrep(hbig.YTickLabel{ii},'_','\_')]; + end +end + +set(gcf,'color',[1 1 1]); +prePaperType = get(fig_gui,'PaperType'); +prePaperUnits = get(fig_gui,'PaperUnits'); +preUnits = get(fig_gui,'Units'); +prePaperPosition = get(fig_gui,'PaperPosition'); +prePaperSize = get(fig_gui,'PaperSize'); +% Make changing paper type possible +set(fig_gui,'PaperType',''); + +% Set units to all be the same +set(fig_gui,'PaperUnits','inches'); +set(fig_gui,'Units','inches'); +% Set the page size and position to match the figure's dimensions +paperPosition = get(fig_gui,'PaperPosition'); +position = get(fig_gui,'Position'); +set(fig_gui,'PaperPosition',[0,0,position(3:4)]); +set(fig_gui,'PaperSize',position(3:4)); + +%%save figure with different formats +if ~isempty(extfig) + [C_style,IA_style] = ismember_bc2(extfig,{'.pdf','.svg','.jpg','.png','.tif','.bmp','.eps'}); + figFileName = fullfile(pathstrfig,FigureName); + try + switch IA_style + case 1 + print(fig_gui,'-dpdf',figFileName); + case 2 + print(fig_gui,'-dsvg',figFileName); + case 3 + print(fig_gui,'-djpeg',figFileName); + case 4 + print(fig_gui,'-dpng',figFileName); + + case 5 + print(fig_gui,'-dtiff',figFileName); + case 6 + print(fig_gui,'-dbmp',figFileName); + case 7 + print(fig_gui,'-depsc',figFileName); + otherwise + print(fig_gui,'-dpdf',figFileName); + end + catch + print(fig_gui,'-dpdf',figFileName); + end +end +return; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/f_preparms_eegwaviewer.m b/studio_functions/Functions/EStudio/EEG Tab/f_preparms_eegwaviewer.m new file mode 100755 index 00000000..d1ede027 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/f_preparms_eegwaviewer.m @@ -0,0 +1,269 @@ +%%this function is used to call back the parameters for plotting EEG wave + +% *** This function is part of EStudio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2023 && 2024 + +function OutputViewerpareeg = f_preparms_eegwaviewer(EEG,matlabfig,History,figureName) + +OutputViewerpareeg = ''; +if nargin<1 + help f_preparms_eegwaviewer(); + return +end +if isempty(EEG) + disp('f_preparms_eegwaviewer(): EEG is empty'); + return; +end + +if nargin<3 + History = 'gui'; +end + +if nargin <2 + matlabfig=1; +end +if nargin <4 + figureName = ''; +end + +%%channel array and IC array +%channels +ChanArray = estudioworkingmemory('EEG_ChanArray'); +nbchan = EEG.nbchan; +if isempty(ChanArray) || any(ChanArray(:)>nbchan) || any(ChanArray(:)<=0) + ChanArray = 1:nbchan; + estudioworkingmemory('EEG_ChanArray',ChanArray); +end + +EEG_plotset = estudioworkingmemory('EEG_plotset'); +ChanArray = reshape(ChanArray,1,[]); +try + chanOrder = EEG_plotset{10}; + if chanOrder==2 + if isfield(EEG,'chanlocs') && ~isempty(EEG.chanlocs) + chanindexnew = f_estudio_chan_frontback_left_right(EEG.chanlocs(ChanArray)); + if ~isempty(chanindexnew) + ChanArray = ChanArray(chanindexnew); + end + end + elseif chanOrder==3 + [eloc, labels, theta, radius, indices] = readlocs(EEG.chanlocs); + chanorders = EEG_plotset{11}; + chanorderindex = chanorders{1}; + chanorderindex1 = unique(chanorderindex,'stable'); + chanorderlabels = chanorders{2}; + [C,IA]= ismember_bc2(chanorderlabels,labels); + Chanlanelsinst = labels(ChanArray); + if ~any(IA==0) && numel(chanorderindex1) == length(labels) + [C,IA1]= ismember_bc2(Chanlanelsinst,chanorderlabels); + [C,IA2]= ismember_bc2(Chanlanelsinst,labels); + ChanArray = IA1(IA2); + end + end +catch +end + + +%%ICs +ICArray = estudioworkingmemory('EEG_ICArray'); +if isempty(EEG.icachansind) + ICArray = []; + estudioworkingmemory('EEG_ICArray',[]); +else + nIC = numel(EEG.icachansind); + if isempty(ICArray) || any(ICArray(:)>nIC) || any(ICArray(:)<=0) + ICArray = []; + estudioworkingmemory('EEG_ICArray',ICArray); + end +end + +%%Plot setting +EEG_plotset = estudioworkingmemory('EEG_plotset'); +if isempty(EEG_plotset) + EEGdisp = 1; + ICdisp = 0; + Winlength = 5;%%in second + AmpScale = 50; + ChanLabel = 1; + Submean=0; + EventOnset = 1; + StackFlag = 0; + NormFlag = 0; + AmpScale_ic=20; + buffer_topo_bottom = 100; +else + %%diaply original data? + try + EEGdisp = EEG_plotset{1}; + catch + EEGdisp = 1; + end + if isempty(EEGdisp) || (EEGdisp~=0 && EEGdisp~=1) + EEGdisp = 1; + end + + %%display ICs? + try + ICdisp = EEG_plotset{2}; + catch + ICdisp = 0; + end + if isempty(ICdisp) || (ICdisp~=0 && ICdisp~=1) + ICdisp = 0; + end + + %%Time range? + try + Winlength = EEG_plotset{3}; + catch + Winlength = 5; + end + if isempty(Winlength) || numel(Winlength)~=1 || min(Winlength(:))<=0 + Winlength=5; + end + + + %%Vertical scale for original data? + try + AmpScale = EEG_plotset{4}; + catch + AmpScale = 50; + end + if isempty(AmpScale) || numel(AmpScale)~=1 || AmpScale<=0 + AmpScale = 50; + end + + %%Vertical scale for IC data? + try + AmpScale_ic = EEG_plotset{5}; + catch + AmpScale_ic = 20; + end + if isempty(AmpScale_ic) || numel(AmpScale_ic)~=1 || AmpScale_ic<=0 + AmpScale_ic = 20; + end + + %%Channel labels? (1 is name, 0 is number) + try + ChanLabel = EEG_plotset{5}; + catch + ChanLabel = 1; + end + if isempty(ChanLabel) || numel(ChanLabel)~=1 || (ChanLabel~=0 && ChanLabel~=1) + ChanLabel = 1; + end + + %%Remove DC? (1 is "Yes", 0 is "no") + try + Submean = EEG_plotset{6}; + catch + Submean = 0; + end + if isempty(Submean) || numel(Submean)~=1 || (Submean~=0 && Submean~=1) + Submean = 0; + end + + %%Display events? + try + EventOnset = EEG_plotset{7}; + catch + EventOnset = 1; + end + if isempty(EventOnset) || numel(EventOnset)~=1 || (EventOnset~=0 && EventOnset~=1) + EventOnset = 1; + end + + + %%Stack? + try + StackFlag = EEG_plotset{8}; + catch + StackFlag = 0; + end + if isempty(StackFlag) || numel(StackFlag)~=1 || (StackFlag~=0&&StackFlag~=1) + StackFlag = 0; + end + + %%Norm? + try + NormFlag = EEG_plotset{9}; + catch + NormFlag = 0; + end + if isempty(NormFlag) ||numel(NormFlag)~=1 || (NormFlag~=0 && NormFlag~=1) + NormFlag = 0; + end + + %%buffer at top and bottom + try + buffer_topo_bottom = EEG_plotset{12}; + catch + buffer_topo_bottom=100; + end + if isempty(buffer_topo_bottom) || numel(buffer_topo_bottom)~=1 || any(buffer_topo_bottom(:)<=0) + buffer_topo_bottom=100; + end +end + + +%%Start time to display +Startimes = estudioworkingmemory('Startimes'); +[chaNum,sampleNum,trialNum]=size(EEG.data); +Frames = sampleNum*trialNum; +if EEG.trials>1 % time in second or in trials + multiplier = size(EEG.data,2); +else + multiplier = EEG.srate; +end + +StartimesMax = max(0,ceil((Frames-1)/multiplier)-Winlength); +if ndims(EEG.data)==3 + Startimes=Startimes-1; +end +if isempty(Startimes) || numel(Startimes)~=1 || Startimes<0 ||Startimes>StartimesMax + Startimes=0; + estudioworkingmemory('Startimes',Startimes); +end + +figSize = estudioworkingmemory('egfigsize'); +if isempty(figSize) + figSize = []; +end +if ICdisp==0 + ICArray = []; +end +if isempty(ICArray) + ICdisp=0; +end + + +if matlabfig==1 + if EEGdisp==0 + ChanArray = []; + end + [EEG, eegcom] = pop_ploteegset(EEG,'ChanArray',ChanArray,'ICArray',ICArray,'Winlength',Winlength,'bufftobo',buffer_topo_bottom,... + 'Ampchan',AmpScale,'ChanLabel',ChanLabel,'Submean',Submean,'EventOnset',EventOnset,'Ampic',AmpScale_ic,... + 'StackFlag',StackFlag,'NormFlag',NormFlag,'Startimes',Startimes,'figureName',figureName,'figSize',figSize,'History',History); +else + OutputViewerpareeg{1} = ChanArray; + OutputViewerpareeg{2} = ICArray; + OutputViewerpareeg{3} =EEGdisp; + OutputViewerpareeg{4} =ICdisp; + OutputViewerpareeg{5} =Winlength; + OutputViewerpareeg{6} =AmpScale; + OutputViewerpareeg{7} =ChanLabel; + OutputViewerpareeg{8} =Submean; + OutputViewerpareeg{9} = EventOnset; + OutputViewerpareeg{10} =StackFlag; + OutputViewerpareeg{11} =NormFlag; + OutputViewerpareeg{12} =Startimes; + OutputViewerpareeg{13} = AmpScale_ic; + OutputViewerpareeg{14} = buffer_topo_bottom; + OutputViewerpareeg{15} = figSize; +end + +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/f_redrawEEG_Wave_Viewer.m b/studio_functions/Functions/EStudio/EEG Tab/f_redrawEEG_Wave_Viewer.m new file mode 100644 index 00000000..82dae362 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/f_redrawEEG_Wave_Viewer.m @@ -0,0 +1,1984 @@ +%PURPOSE : Plot EEG waves within one axes as EEGLAB + +% Author: Guanghui Zhang & Steve J. Luck +% Center for Mind and Brain +% University of California, Davis +% Davis, CA +% 2023 + + + +function f_redrawEEG_Wave_Viewer(Axesreset) + +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +addlistener(observe_EEGDAT,'eeg_panel_change_message',@eeg_panel_change_message); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); + + +if nargin>2 + help f_redrawEEG_Wave_Viewer; + return; +end +if nargin<1 + Axesreset=0; +end + +if isempty(observe_EEGDAT.EEG) + Startimes = 0; +else + Startimes= estudioworkingmemory('Startimes'); + if isempty(Startimes) || min(Startimes)<0 + Startimes = 0; + end + EEG_plotset = estudioworkingmemory('EEG_plotset'); + try + Winlength = EEG_plotset{3}; + catch + Winlength = 5; + end + + [chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); + Frames = sampleNum*trialNum; + if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier = size(observe_EEGDAT.EEG.data,2); + else + multiplier = observe_EEGDAT.EEG.srate; + end + if isempty(Winlength)|| Winlength<0 || (Winlength>floor(Frames/observe_EEGDAT.EEG.srate)) + Winlength = 5; + end + StartimesMax = max(0,ceil((Frames-1)/multiplier)-Winlength); + if observe_EEGDAT.EEG.trials>1 + StartimesMax =StartimesMax+1; + end + if Startimes > StartimesMax + Startimes = StartimesMax; + end +end +if ~isempty(observe_EEGDAT.EEG) + if observe_EEGDAT.EEG.trials>1 && Startimes ==0%%for epoched EEG, it should be from the first epoch + Startimes=1; + end +end +estudioworkingmemory('Startimes',Startimes); + +%%Selected EEGsets from memory file +EEGset_selected = estudioworkingmemory('EEGArray'); +if ~isempty(observe_EEGDAT.ALLEEG) && ~isempty(observe_EEGDAT.EEG) + if isempty(EEGset_selected) || min(EEGset_selected(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGset_selected(:))>length(observe_EEGDAT.ALLEEG) + EEGset_selected = length(observe_EEGDAT.ALLEEG) ; + estudioworkingmemory('EEGArray',EEGset_selected); + observe_EEGDAT.CURRENTSET = EEGset_selected; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(EEGset_selected); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','ALLEEG', observe_EEGDAT.ALLEEG); + assignin('base','CURRENTSET', observe_EEGDAT.CURRENTSET); + end + [xpos,ypos] = find(EEGset_selected==observe_EEGDAT.CURRENTSET); + if ~isempty(ypos) + pagecurrentNum = ypos; + pageNum = numel(EEGset_selected); + PageStr = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET).setname; + else + pageNum=1; + pagecurrentNum=1; + PageStr = observe_EEGDAT.EEG.setname; + end + Enableflag = 'on'; +else + pageNum=1; + pagecurrentNum=1; + PageStr = 'No EEG was loaded'; + Enableflag = 'off'; +end + +EEG_autoplot = EStudio_gui_erp_totl.EEG_autoplot; + +EStudio_gui_erp_totl.eegpageinfo_text.String=['Page',32,num2str(pagecurrentNum),'/',num2str(pageNum),':',PageStr]; +EStudio_gui_erp_totl.eegpageinfo_minus.Callback=@page_minus; +set(EStudio_gui_erp_totl.eegpageinfo_edit,'String',num2str(pagecurrentNum),'Enable','on'); +if EEG_autoplot ==0 + EStudio_gui_erp_totl.eegpageinfo_text.String='Plotting is disabled, to enable it, please go to "Plotting Options" at the bottom of the plotting area to active it.'; + Enableflag = 'off'; +end +EStudio_gui_erp_totl.eegpageinfo_edit.Callback=@page_edit; +EStudio_gui_erp_totl.eegpageinfo_plus.Callback=@page_plus; +if pageNum ==1 + Enable_minus = 'off'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [1 1 1]; + Enable_minus_BackgroundColor = [0 0 0]; +else + if pagecurrentNum ==1 + Enable_minus = 'off'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [0 0 0]; + elseif pagecurrentNum == pageNum + Enable_minus = 'on'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [0 0 0]; + Enable_minus_BackgroundColor = [0 1 0]; + else + Enable_minus = 'on'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [0 1 0]; + end +end + +if ~isempty(observe_EEGDAT.ALLEEG) && ~isempty(observe_EEGDAT.EEG) && EEG_autoplot==0 + Enable_minus = 'off'; + Enable_plus = 'off'; + EStudio_gui_erp_totl.eegpageinfo_edit.Enable = 'off'; +end + +%%----Processing for label ICs or using IClabel +EEGUpdate = estudioworkingmemory('EEGUpdate'); +if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); +end +if EEGUpdate==1 + Enableflag = 'off'; + Enable_minus = 'off'; + Enable_plus = 'off'; + EStudio_gui_erp_totl.eegpageinfo_edit.Enable = 'off'; +end + + +EStudio_gui_erp_totl.eegpageinfo_minus.Enable = Enable_minus; +EStudio_gui_erp_totl.eegpageinfo_plus.Enable = Enable_plus; +EStudio_gui_erp_totl.eegpageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; +EStudio_gui_erp_totl.eegpageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; +set(EStudio_gui_erp_totl.eegpageinfo_box, 'Sizes', [-1 70 50 70] ); +set(EStudio_gui_erp_totl.eeg_zoom_in_large,'Callback',@zoomin_large,'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_in_fivesmall,'Callback',@zoomin_fivesmall,'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_in_small,'Callback',@zoomin_small,'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_edit,'String',num2str(Startimes),'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_edit,'Callback',@zoomedit,'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_out_small,'Callback',@zoomout_small,'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_out_fivelarge,'Callback',@zoomout_fivelarge,'Enable',Enableflag); +set(EStudio_gui_erp_totl.eeg_zoom_out_large,'Callback',@zoomout_large,'Enable',Enableflag); +if ~isempty(observe_EEGDAT.ALLEEG) && ~isempty(observe_EEGDAT.EEG) + set(EStudio_gui_erp_totl.popmemu_eeg,'Callback',@popmemu_eeg,'Enable','on','String',... + {'Plotting Options','Automatic Plotting','Window Size','Show Command','Save Figure as','Create Static/Exportable Plot'}); +else + set(EStudio_gui_erp_totl.popmemu_eeg,'Callback',@popmemu_eeg,'Enable','on','String',{'Plotting Options','Automatic Plotting','Window Size'}); +end +popmemu_eeg = EStudio_gui_erp_totl.popmemu_eeg.String; +if EEG_autoplot==1 + popmemu_eeg{2} = 'Automatic Plotting: On'; +else + popmemu_eeg{2} = 'Automatic Plotting: Off'; +end +EStudio_gui_erp_totl.popmemu_eeg.String=popmemu_eeg; + + +set(EStudio_gui_erp_totl.eeg_reset,'Callback',@eeg_paras_reset,'Enable','on'); +set(EStudio_gui_erp_totl.eeg_plot_button_title, 'Sizes', [10 40 40 40 40 40 40 40 -1 150 50 5]); + +if ~isempty(observe_EEGDAT.ALLEEG) && ~isempty(observe_EEGDAT.EEG) && EEG_autoplot==1 + EEG = observe_EEGDAT.EEG; + OutputViewereegpar = f_preparms_eegwaviewer(EEG,0); + % %%Plot the eeg waves + if ~isempty(OutputViewereegpar) + EStudio_gui_erp_totl = f_plotviewereegwave(EEG,OutputViewereegpar{1},OutputViewereegpar{2},... + OutputViewereegpar{3},OutputViewereegpar{4},OutputViewereegpar{5},... + OutputViewereegpar{6},OutputViewereegpar{7},OutputViewereegpar{8},... + OutputViewereegpar{9},OutputViewereegpar{10},OutputViewereegpar{11},... + OutputViewereegpar{12},OutputViewereegpar{13},OutputViewereegpar{14},EStudio_gui_erp_totl,Axesreset); + else + return; + end +end + +if isempty(observe_EEGDAT.EEG) || EEG_autoplot==0 + EStudio_gui_erp_totl.myeegviewer = axes('Parent', EStudio_gui_erp_totl.eegViewAxes,'Color','none','Box','on','FontWeight','normal'); + hold(EStudio_gui_erp_totl.myeegviewer,'on'); + set(EStudio_gui_erp_totl.myeegviewer, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); +else +end +EStudio_gui_erp_totl.eegplotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high +EStudio_gui_erp_totl.eegplotgrid.Heights(3) = 5; +EStudio_gui_erp_totl.eegplotgrid.Heights(4) = 30; % set the second element (x axis) to 30px high +EStudio_gui_erp_totl.eegplotgrid.Heights(5) = 30; % set the second element (x axis) to 30px high +end % redrawDemo + +%%------------------------------------------------------------------------- +%%-----------------------------Subfunctions-------------------------------- +%%------------------------------------------------------------------------- + +function popmemu_eeg(Source,~) +global EStudio_gui_erp_totl; +Value = Source.Value; +if Value==2 + app = feval('EStudio_plot_set_waves',EStudio_gui_erp_totl.EEG_autoplot,1); + waitfor(app,'Finishbutton',1); + try + plotSet = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.01); %wait for app to leave + catch + return; + end + if isempty(plotSet)||numel(plotSet)~=1 || (plotSet~=0&&plotSet~=1) + plotSet=1; + end + popmemu_eegString = EStudio_gui_erp_totl.popmemu_eeg.String; + if plotSet==1 + popmemu_eegString{2} = 'Automatic Plotting: On'; + else + popmemu_eegString{2} = 'Automatic Plotting: Off'; + end + EStudio_gui_erp_totl.popmemu_eeg.String=popmemu_eegString; + EStudio_gui_erp_totl.EEG_autoplot = plotSet; + f_redrawEEG_Wave_Viewer(); +elseif Value==3 + EStudiowinsize(); +elseif Value==4 + Show_command(); +elseif Value==5 + figure_saveas(); +elseif Value==6 + figure_out(); +end +Source.Value=1; +end + + +%%--------------------Setting for EStudio window size---------------------- +function EStudiowinsize(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +try + ScreenPos= EStudio_gui_erp_totl.ScreenPos; +catch + ScreenPos = get( 0, 'Screensize' ); +end +try + New_pos = EStudio_gui_erp_totl.Window.Position; +catch + return; +end +try + New_posin = estudioworkingmemory('EStudioScreenPos'); +catch + New_posin = [75,75]; +end +if isempty(New_posin) ||numel(New_posin)~=2 + New_posin = [75,75]; +end +New_posin(2) = abs(New_posin(2)); + +app = feval('EStudio_pos_gui',New_posin); +waitfor(app,'Finishbutton',1); +try + New_pos1 = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.01); %wait for app to leave +catch + return; +end +try New_pos1(2) = abs(New_pos1(2));catch; end; + +if isempty(New_pos1) || numel(New_pos1)~=2 + estudioworkingmemory('f_EEG_proces_messg',['The defined Window Size for EStudio is invalid and it must be two numbers']); + observe_EEGDAT.eeg_panel_message =4; + return; +end +estudioworkingmemory('EStudioScreenPos',New_pos1); +try + POS4 = (New_pos1(2)-New_posin(2))/100; + new_pos =[New_pos(1),New_pos(2)-ScreenPos(4)*POS4,ScreenPos(3)*New_pos1(1)/100,ScreenPos(4)*New_pos1(2)/100]; + if new_pos(2) < -abs(new_pos(4))%%if + + end + set(EStudio_gui_erp_totl.Window, 'Position', new_pos); +catch + estudioworkingmemory('f_EEG_proces_messg',['The defined Window Size for EStudio is invalid and it must be two numbers']); + observe_EEGDAT.eeg_panel_message =4; + set(EStudio_gui_erp_totl.Window, 'Position', [0 0 0.75*ScreenPos(3) 0.75*ScreenPos(4)]); + estudioworkingmemory('EStudioScreenPos',[75 75]); +end +f_redrawEEG_Wave_Viewer(); +f_redrawERP(); +EStudio_gui_erp_totl.context_tabs.TabSize = (new_pos(3)-20)/2; +end + + +%%------------------set to 0---------------------------------------- +function zoomin_large(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +if isempty(observe_EEGDAT.EEG) + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; + +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + Startimes =1; +else + Startimes = 0; +end +EStudio_gui_erp_totl.eeg_zoom_edit.String =num2str(Startimes); +estudioworkingmemory('Startimes',Startimes); +f_redrawEEG_Wave_Viewer(1); +end + + +%%reduce the start time of the displayed EEG +function zoomin_fivesmall(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +if isempty(observe_EEGDAT.EEG) + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end +[chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); +Frames = sampleNum*trialNum; +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); +else + multiplier_winleg = observe_EEGDAT.EEG.srate; +end +if isempty(Winlength)|| Winlength<0 || Winlength>floor(Frames/multiplier_winleg) + Winlength = 5; + EEG_plotset{3} = 5; +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +Startimesdef = str2num(EStudio_gui_erp_totl.eeg_zoom_edit.String); +if ~isempty(Startimesdef) && isnumeric(Startimesdef) && numel(Startimesdef)==1 && Startimesdef>=0 +else + Startimesdef = 0; + EStudio_gui_erp_totl.eeg_zoom_edit.String = '0'; +end + +Startimes = Startimesdef-fastif(Winlength>=5, round(5*Winlength), 5*Winlength); +if Startimes<0 + if observe_EEGDAT.EEG.trials>1 + Startimes=1; + else + Startimes=0; + end +end + +estudioworkingmemory('Startimes',Startimes); +EStudio_gui_erp_totl.eeg_zoom_edit.String =num2str(Startimes); +f_redrawEEG_Wave_Viewer(1); +end + + +%%prev time period +function zoomin_small(~,~) + +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +if isempty(observe_EEGDAT.EEG) + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; + +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end +[chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); +Frames = sampleNum*trialNum; +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); +else + multiplier_winleg = observe_EEGDAT.EEG.srate; +end +if isempty(Winlength)|| Winlength<0 || Winlength>floor(Frames/multiplier_winleg) + Winlength = 5; + EEG_plotset{3} = 5; +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +Startimesdef = str2num(EStudio_gui_erp_totl.eeg_zoom_edit.String); +if ~isempty(Startimesdef) && isnumeric(Startimesdef) && numel(Startimesdef)==1 && Startimesdef>=0 +else + Startimesdef = 0; + EStudio_gui_erp_totl.eeg_zoom_edit.String = '0'; +end + +Startimes = Startimesdef-fastif(Winlength>=5, round(Winlength), Winlength); +if Startimes<0 + if observe_EEGDAT.EEG.trials>1 + Startimes=1; + else + Startimes=0; + end +end + +estudioworkingmemory('Startimes',Startimes); +EStudio_gui_erp_totl.eeg_zoom_edit.String =num2str(Startimes); +f_redrawEEG_Wave_Viewer(1); +end + + +%%Editing the start the time for the displayed EEG data +function zoomedit(Source,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +if isempty(observe_EEGDAT.EEG) + Source.String ='0'; + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; + +Startimes = str2num(EStudio_gui_erp_totl.eeg_zoom_edit.String); +if isempty(Startimes) + Startimes = 0; + Source.String = '0'; + MessageViewer= char(strcat('Start time for the displayed EEG should be a number')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=4; +end +if numel(Startimes)~=1 + Startimes = Startimes(1); +end + + +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end +[chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); +Frames = sampleNum*trialNum; +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier = size(observe_EEGDAT.EEG.data,2); + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); +else + multiplier = observe_EEGDAT.EEG.srate; + multiplier_winleg = observe_EEGDAT.EEG.srate; +end + +if isempty(Winlength)|| Winlength<0 || (Winlength>floor(Frames/multiplier_winleg)) + Winlength = 5; + EEG_plotset{3} = 5; +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +if ndims(observe_EEGDAT.EEG.data) ==3 + Startimes = Startimes-1; +end +Startimes = max(0,min(Startimes,ceil((Frames-1)/multiplier)-Winlength)); +if ndims(observe_EEGDAT.EEG.data) ==3 + Startimes = Startimes+1; +end +Source.String = num2str(Startimes); + + +estudioworkingmemory('Startimes',Startimes); +f_redrawEEG_Wave_Viewer(1); +end + + + + +%%-------------------% > add one second for displayed EEG------------------ +function zoomout_small(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end +if isempty(observe_EEGDAT.EEG) + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; + +[chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); +Frames = sampleNum*trialNum; +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier = size(observe_EEGDAT.EEG.data,2); + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); +else + multiplier = observe_EEGDAT.EEG.srate; + multiplier_winleg = multiplier; +end + +if isempty(Winlength)|| Winlength<0 || Winlength>floor(Frames/multiplier_winleg) + Winlength = 5; + EEG_plotset{3} = 5; +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +Startimesdef = str2num(EStudio_gui_erp_totl.eeg_zoom_edit.String); +if ~isempty(Startimesdef) && isnumeric(Startimesdef) && numel(Startimesdef)==1 && Startimesdef>=0 +else + Startimesdef = 0; +end + +Startimes = Startimesdef+fastif(Winlength>=5, round(Winlength), Winlength); %%> add one second +if Startimes<0 + Startimes=0; +end + +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end + +if isempty(Winlength)|| Winlength<0 || (Winlength>floor(Frames/multiplier_winleg)) + Winlength = floor(Frames/multiplier_winleg); + EEG_plotset{3} = floor(Frames/multiplier_winleg); +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +StartimesMax = max(0,ceil((Frames-1)/multiplier)-Winlength); +if ndims(observe_EEGDAT.EEG.data)==3 + StartimesMax = StartimesMax+1; +end +if Startimes>StartimesMax + Startimes=StartimesMax; +end +EStudio_gui_erp_totl.eeg_zoom_edit.String = num2str(Startimes); + +estudioworkingmemory('Startimes',Startimes); +f_redrawEEG_Wave_Viewer(1); + +end + + +function zoomout_fivelarge(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end +if isempty(observe_EEGDAT.EEG) + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; + +[chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); +Frames = sampleNum*trialNum; +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier = size(observe_EEGDAT.EEG.data,2); + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); +else + multiplier = observe_EEGDAT.EEG.srate; + multiplier_winleg = multiplier; +end + +if isempty(Winlength)|| Winlength<0 || Winlength>floor(Frames/multiplier_winleg) + Winlength = 5; + EEG_plotset{3} = 5; +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +Startimesdef = str2num(EStudio_gui_erp_totl.eeg_zoom_edit.String); +if ~isempty(Startimesdef) && isnumeric(Startimesdef) && numel(Startimesdef)==1 && Startimesdef>=0 +else + Startimesdef = 0; +end + +Startimes = Startimesdef+fastif(Winlength>=5, round(5*Winlength), 5*Winlength); %%> add one second +if Startimes<0 + Startimes=0; +end + +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end + +if isempty(Winlength)|| Winlength<0 || (Winlength>floor(Frames/multiplier_winleg)) + Winlength = floor(Frames/multiplier_winleg); + EEG_plotset{3} = floor(Frames/multiplier_winleg); +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +StartimesMax = max(0,ceil((Frames-1)/multiplier)-Winlength); +if ndims(observe_EEGDAT.EEG.data)==3 + StartimesMax = StartimesMax+1; +end +if Startimes>StartimesMax + Startimes=StartimesMax; +end +EStudio_gui_erp_totl.eeg_zoom_edit.String = num2str(Startimes); + +estudioworkingmemory('Startimes',Startimes); +f_redrawEEG_Wave_Viewer(1); +end + + + + +function zoomout_large(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl;%%Global variable +if isempty(observe_EEGDAT.EEG) + return; +end +EStudio_gui_erp_totl.eegProcess_messg.String = ''; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def; +EEG_plotset = estudioworkingmemory('EEG_plotset'); +try + Winlength = EEG_plotset{3}; +catch + Winlength = 5; + EEG_plotset{3} = 5; +end +[chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); +Frames = sampleNum*trialNum; +if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier = size(observe_EEGDAT.EEG.data,2); + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); +else + multiplier = observe_EEGDAT.EEG.srate; + multiplier_winleg = multiplier; +end + +if isempty(Winlength)|| Winlength<0 || (Winlength>floor(Frames/multiplier_winleg)) + Winlength = 5; + EEG_plotset{3} = 5; +end +estudioworkingmemory('EEG_plotset',EEG_plotset); +StartimesMax = max(0,ceil((Frames-1)/multiplier)-Winlength); +if ndims(observe_EEGDAT.EEG.data)==3 + StartimesMax = StartimesMax+1; +end +Startimes = StartimesMax; + + +estudioworkingmemory('Startimes',Startimes); + +EStudio_gui_erp_totl.eeg_zoom_edit.String =num2str(Startimes); +f_redrawEEG_Wave_Viewer(1); +end + + +%%-------------------------------Page Editor------------------------------- +function page_edit(Source,~) +global observe_EEGDAT; +if isempty(observe_EEGDAT.EEG) + return; +end + +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end + +Pagecurrent = str2num(Source.String); + +EEGset_selected = estudioworkingmemory('EEGArray'); +if isempty(EEGset_selected) + EEGset_selected=observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGset_selected); +end + +pageNum = numel(EEGset_selected); +if ~isempty(Pagecurrent) && numel(Pagecurrent)~=1 %%if two or more numbers are entered + Pagecurrent =Pagecurrent(1); +end + +if ~isempty(Pagecurrent) && Pagecurrent>0 && Pagecurrent<= pageNum%% + Source.String = num2str(Pagecurrent); + observe_EEGDAT.CURRENTSET = EEGset_selected(Pagecurrent); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('Startimes',0); + f_redrawEEG_Wave_Viewer(); + observe_EEGDAT.count_current_eeg=2; +end +end + + + + +%------------------Display the waveform for proir ERPset-------------------- +function page_minus(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl; +if isempty(observe_EEGDAT.EEG) + return; +end +%%first check if the changed parameters have been applied in any panels +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end +Pagecurrent = str2num(EStudio_gui_erp_totl.eegpageinfo_edit.String); +EEGset_selected = estudioworkingmemory('EEGArray'); +if isempty(EEGset_selected) + EEGset_selected=observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGset_selected); +end + +pageNum = numel(EEGset_selected); +if ~isempty(Pagecurrent) && numel(Pagecurrent)~=1 %%if two or more numbers are entered + Pagecurrent =Pagecurrent(1); +elseif isempty(Pagecurrent) + [xpos, ypos] = find(EEGset_selected==observe_EEGDAT.CURRENTSET); + if isempty(ypos) + Pagecurrent=1; + observe_EEGDAT.CURRENTSET = EEGset_selected(1); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + else + Pagecurrent = ypos; + end +end +Pagecurrent = Pagecurrent-1; +if Pagecurrent>0 && Pagecurrent<=pageNum + EStudio_gui_erp_totl.eegpageinfo_edit.String = num2str(Pagecurrent); + observe_EEGDAT.CURRENTSET = EEGset_selected(Pagecurrent); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('Startimes',0); + f_redrawEEG_Wave_Viewer(1); + observe_EEGDAT.count_current_eeg=2; +else + return; +end +end + + +%------------------Display the waveform for next ERPset-------------------- +function page_plus(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl; +if isempty(observe_EEGDAT.EEG) + return; +end +%%first check if the changed parameters have been applied in any panels +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end +Pagecurrent = str2num(EStudio_gui_erp_totl.eegpageinfo_edit.String); +EEGset_selected = estudioworkingmemory('EEGArray'); +if isempty(EEGset_selected) + EEGset_selected=observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGset_selected); +end + +pageNum = numel(EEGset_selected); +if ~isempty(Pagecurrent) && numel(Pagecurrent)~=1 %%if two or more numbers are entered + Pagecurrent =Pagecurrent(1); +elseif isempty(Pagecurrent) + [xpos, ypos] = find(EEGset_selected==observe_EEGDAT.CURRENTSET); + if isempty(ypos) + Pagecurrent=1; + observe_EEGDAT.CURRENTSET = EEGset_selected(1); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg =2; + f_redrawEEG_Wave_Viewer(); + return; + else + Pagecurrent = ypos; + end +end +Pagecurrent = Pagecurrent+1; +if Pagecurrent>0 && Pagecurrent<=pageNum + EStudio_gui_erp_totl.eegpageinfo_edit.String = num2str(Pagecurrent); + observe_EEGDAT.CURRENTSET = EEGset_selected(Pagecurrent); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('Startimes',0); + f_redrawEEG_Wave_Viewer(1); + observe_EEGDAT.count_current_eeg=2; +else + return; +end +end + + + + +function Show_command(~,~) +global observe_EEGDAT; +if isempty(observe_EEGDAT.EEG) + return; +end +%%first check if the changed parameters have been applied in any panels +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end +MessageViewer= char(strcat('Show Command')); +estudioworkingmemory('f_EEG_proces_messg',MessageViewer); +try + observe_EEGDAT.eeg_panel_message=1; + OutputViewereegpar = f_preparms_eegwaviewer(observe_EEGDAT.EEG,1,'command'); + observe_EEGDAT.eeg_panel_message=2; +catch + observe_EEGDAT.eeg_panel_message=3; +end +end + + + +%%-------------------------Save figure as---------------------------------- +function figure_saveas(~,~) +global observe_EEGDAT; +% addlistener(observe_EEGDAT,'Messg_EEG_change',@Messg_EEG_change); +if isempty(observe_EEGDAT.EEG) + return; +end + +%%first check if the changed parameters have been applied in any panels +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end +MessageViewer= char(strcat('Save Figure As')); +estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + +pathstr = pwd; +[~, namedef, ~] = fileparts(observe_EEGDAT.EEG.setname); +[figurename, erppathname, indxs] = uiputfile({'*.pdf';'*.svg';'*.jpg';'*.png';'*.tif';'*.bmp';'*.eps'},... + 'Save as',[fullfile(pathstr,namedef)]); + +if isequal(figurename,0) + % observe_EEGDAT.eeg_panel_message=3; + return +end + +History = 'off'; +[pathstr, figurename1, ext] = fileparts(figurename) ; + +if isempty(ext) + figurename = fullfile(erppathname,char(strcat(figurename,'.pdf'))); +else + figurename = fullfile(erppathname,figurename); +end + +observe_EEGDAT.eeg_panel_message=1; +OutputViewereegpar = f_preparms_eegwaviewer(observe_EEGDAT.EEG,1,History,figurename); +observe_EEGDAT.eeg_panel_message=2; + +end + + +%%------------------------Reset parameters--------------------------------- +function eeg_paras_reset(~,~) +global observe_EEGDAT; +global observe_ERPDAT; +global EStudio_gui_erp_totl; + +estudioworkingmemory('EEGUpdate',0); +observe_EEGDAT.count_current_eeg =1; + +estudioworkingmemory('ViewerFlag', 0); +observe_ERPDAT.Count_currentERP=1; + +%%first check if the changed parameters have been applied in any panels +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end + +estudioworkingmemory('f_EEG_proces_messg','Reset parameters for EEG panels'); +app = feval('estudio_reset_paras',[1 0 0 0]); +waitfor(app,'Finishbutton',1); +reset_paras = [0 0 0 0]; +try + reset_paras = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave +catch + return; +end +if isempty(reset_paras) + return; +end +EStudio_gui_erp_totl.ERP_autoplot=1; +EStudio_gui_erp_totl.EEG_autoplot = 1; + +observe_EEGDAT.eeg_panel_message=1; +if reset_paras(2)==1 + EStudio_gui_erp_totl.clear_alleeg = 1; +else + EStudio_gui_erp_totl.clear_alleeg = 0; +end + +if reset_paras(1)==1 + observe_EEGDAT.Reset_eeg_paras_panel=1; + if EStudio_gui_erp_totl.clear_alleeg == 0 + f_redrawEEG_Wave_Viewer(); + else + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + estudioworkingmemory('EEGArray',1); + observe_EEGDAT.count_current_eeg =1; + end +else + if EStudio_gui_erp_totl.clear_alleeg == 1 + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + estudioworkingmemory('EEGArray',1); + observe_EEGDAT.count_current_eeg =1; + end +end +observe_EEGDAT.eeg_panel_message=2; +%%---------------- -------------erp tab------------------------------------ +if reset_paras(4)==1 + EStudio_gui_erp_totl.clear_allerp = 1; +else + EStudio_gui_erp_totl.clear_allerp = 0; +end + +if reset_paras(3)==1 + observe_ERPDAT.Reset_erp_paras_panel = 1; + if EStudio_gui_erp_totl.clear_allerp == 0 + f_redrawERP(); + else + observe_ERPDAT.ALLERP = []; + observe_ERPDAT.ERP = []; + observe_ERPDAT.CURRENTERP = 1; + estudioworkingmemory('selectederpstudio',1); + observe_ERPDAT.Count_currentERP = 1; + end +else + if EStudio_gui_erp_totl.clear_allerp == 1 + + observe_ERPDAT.ALLERP = []; + observe_ERPDAT.ERP = []; + observe_ERPDAT.CURRENTERP = 1; + estudioworkingmemory('selectederpstudio',1); + observe_ERPDAT.Count_currentERP = 1; + end +end + +end + + + +%%-----------------Pop figure--------------------------------------------- +function figure_out(~,~) +global observe_EEGDAT; + +if isempty(observe_EEGDAT.EEG) + return; +end + +%%first check if the changed parameters have been applied in any panels +[messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); +if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; +end + + +MessageViewer= char(strcat('Create Static/Exportable Plot')); +estudioworkingmemory('f_EEG_proces_messg',MessageViewer); +try + figurename = observe_EEGDAT.EEG.setname; +catch + figurename = ''; +end +History = 'off'; +observe_EEGDAT.eeg_panel_message=1; +OutputViewereegpar = f_preparms_eegwaviewer(observe_EEGDAT.EEG,1,History,figurename); +observe_EEGDAT.eeg_panel_message=2; +end + + +% %%------------------------Message panel------------------------------------ +function eeg_panel_change_message(~,~) +global observe_EEGDAT; +global EStudio_gui_erp_totl; +% addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); + +if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.ALLEEG) + return; +end +FonsizeDefault = f_get_default_fontsize(); +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) || numel(ColorB_def)~=3 || min(ColorB_def(:))<0 || max(ColorB_def(:))>1 + ColorB_def = [0.7020 0.77 0.85]; +end +Processed_Method=estudioworkingmemory('f_EEG_proces_messg'); +EEGMessagepre = estudioworkingmemory('f_EEG_proces_messg_pre'); +if isempty(EEGMessagepre) + EEGMessagepre = {'',0}; +end +try + if strcmpi(EEGMessagepre{1},Processed_Method) && observe_EEGDAT.eeg_panel_message == EEGMessagepre{2} + return; + end +catch +end +estudioworkingmemory('f_EEG_proces_messg_pre',{Processed_Method,observe_EEGDAT.eeg_panel_message}); + + +EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = [0.95 0.95 0.95]; +EStudio_gui_erp_totl.eegProcess_messg.FontSize = FonsizeDefault; + +if observe_EEGDAT.eeg_panel_message==1 + EStudio_gui_erp_totl.eegProcess_messg.String = strcat('1- ',Processed_Method,': Running....'); + EStudio_gui_erp_totl.eegProcess_messg.ForegroundColor = [0 0 0]; + pause(0.1); +elseif observe_EEGDAT.eeg_panel_message==2 + EStudio_gui_erp_totl.eegProcess_messg.String = strcat('2- ',Processed_Method,': Complete'); + EStudio_gui_erp_totl.eegProcess_messg.ForegroundColor = [0 0.5 0]; + pause(0.1); +elseif observe_EEGDAT.eeg_panel_message==3 + if ~strcmp(EStudio_gui_erp_totl.eegProcess_messg.String,strcat('3- ',Processed_Method,': Error (see Command Window)')) + fprintf([Processed_Method,32,32,32,datestr(datetime('now')),'\n.']); + end + EStudio_gui_erp_totl.eegProcess_messg.String = strcat('3- ',Processed_Method,': Error (see Command Window)'); + EStudio_gui_erp_totl.eegProcess_messg.ForegroundColor = [1 0 0]; +else + if ~strcmpi(EStudio_gui_erp_totl.eegProcess_messg.String,strcat('Warning:',32,Processed_Method,32,'(see Command Window).')) + fprintf([Processed_Method,32,32,32,datestr(datetime('now')),'\n.']); + end + EStudio_gui_erp_totl.eegProcess_messg.String = strcat('Warning:',32,Processed_Method,32,'(see Command Window).'); + + pause(0.1); + EStudio_gui_erp_totl.eegProcess_messg.ForegroundColor = [1 0.65 0]; +end +if observe_EEGDAT.eeg_panel_message==2 || observe_EEGDAT.eeg_panel_message==3 + pause(0.01); + EStudio_gui_erp_totl.eegProcess_messg.String = ''; + EStudio_gui_erp_totl.eegProcess_messg.BackgroundColor = ColorB_def;%[0.95 0.95 0.95]; +end +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%-------------------------------Plot eeg waves--------------------------%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [EStudio_gui_erp_totl,errmeg] = f_plotviewereegwave(EEG,ChanArray,ICArray,EEGdispFlag,ICdispFlag,Winlength,... + AmpScale,ChanLabel,Submean,EventOnset,StackFlag,NormFlag,Startimes,AmpIC,bufftobo,EStudio_gui_erp_totl,Axesreset) + +if nargin<17 + Axesreset=0; +end + +if isempty(Axesreset) || numel(Axesreset)~=1 || (Axesreset~=0 && Axesreset~=1) + Axesreset=0; +end + +if Axesreset ==1%%Speed up the execute time + cla(EStudio_gui_erp_totl.myeegviewer,'reset'); + set(EStudio_gui_erp_totl.myeegviewer,'Box','on'); +else + EStudio_gui_erp_totl.myeegviewer = axes('Parent', EStudio_gui_erp_totl.eegViewAxes,'Color','none','Box','on','FontWeight','normal'); + Pos = EStudio_gui_erp_totl.myeegviewer.Position; + EStudio_gui_erp_totl.myeegviewer.Position = [Pos(1)*0.5,Pos(2)*0.5,Pos(3)*1.15,Pos(4)*1.05];%%x,y,width,height + estudioworkingmemory('egfigsize',[EStudio_gui_erp_totl.myeegviewer.Position(3),EStudio_gui_erp_totl.myeegviewer.Position(4)]); +end + +hold(EStudio_gui_erp_totl.myeegviewer,'on'); + +myeegviewer = EStudio_gui_erp_totl.myeegviewer; + + +errmeg = []; +if nargin<1 + help f_plotviewereegwave; + return +end + +if isempty(EEG) + errmeg = 'EEG is empty'; + return; +end + + +%%selected channels +nbchan = EEG.nbchan; +if nargin<2 + ChanArray = 1:nbchan; +end +if isempty(ChanArray) || min(ChanArray(:)) >nbchan || max(ChanArray(:))> nbchan|| min(ChanArray(:))<=0 + ChanArray = 1:nbchan; +end + +%%selected ICs +if nargin<3 + ICArray = []; +end +if isempty(EEG.icachansind) + ICArray = []; +else + nIC = numel(EEG.icachansind); + if isempty(ICArray) || min(ICArray(:))>nIC || max(ICArray(:)) > nIC || min(ICArray(:))<=0 + ICArray = 1:nIC; + end +end + +%%display EEG? +if nargin<4 + EEGdispFlag=1; +end +if isempty(EEGdispFlag) || (EEGdispFlag~=0 && EEGdispFlag~=1) + EEGdispFlag = 1; +end + +%%Dispaly ICs? +if nargin<5 + ICdispFlag=0; +end +if isempty(ICdispFlag) || (ICdispFlag~=0 && ICdispFlag~=1) + ICdispFlag = 0; +end +if ICdispFlag==0 + ICArray = []; +end + +%%Time range that is to display (1s or 5s)? +if nargin<6 + Winlength=5; +end +if isempty(Winlength) || numel(Winlength)~=1 || min(Winlength(:))<=0 + Winlength=5; +end + +%%Vertical scale? +if nargin<7 + AmpScale = 50; +end +if isempty(AmpScale) || numel(AmpScale)~=1 || AmpScale<=0 + AmpScale = 50; +end +OldAmpScale = AmpScale; + +%%channe labels (name or number) +if nargin<8 + ChanLabel = 1; +end +if isempty(ChanLabel) || numel(ChanLabel)~=1 || (ChanLabel~=0 && ChanLabel~=1) + ChanLabel = 1; +end + +%%remove DC? +if nargin<9 + Submean = 0; +end +if isempty(Submean) || numel(Submean)~=1 || (Submean~=0 && Submean~=1) + Submean = 1; +end + + +%%Display events? +if nargin<10 + EventOnset = 1; +end +if isempty(EventOnset) || numel(EventOnset)~=1 || (EventOnset~=0 && EventOnset~=1) + EventOnset = 1; +end + + +%%Stack? +if nargin<11 + StackFlag = 0; +end +if isempty(StackFlag) || numel(StackFlag)~=1 || (StackFlag~=0&&StackFlag~=1) + StackFlag = 0; +end + +%%Norm? +if nargin<12 + NormFlag = 0; +end +if isempty(NormFlag) ||numel(NormFlag)~=1 || (NormFlag~=0 && NormFlag~=1) + NormFlag = 0; +end + +% Startimes =20; +%%start time for the displayed data +if nargin < 13 + if ndims(EEG.data) ==3 + Startimes=1; + else + Startimes=0; + end +end + +%%VERTICAL SCALE for ICs +if nargin<14 + AmpIC = 20; +end + +if isempty(AmpIC) || numel(AmpIC)~=1 || AmpIC<=0 + AmpIC = 20; +end +OldAmpIC = AmpIC; + +%%buffer at top and bottom +if nargin<15 + bufftobo = 100; +end +if isempty(bufftobo) || numel(bufftobo)~=1 || any(bufftobo(:)<=0) + bufftobo = 100; +end + + +[ChanNum,Allsamples,tmpnb] = size(EEG.data); +Allsamples = Allsamples*tmpnb; +if ndims(EEG.data) > 2 + multiplier = size(EEG.data,2); +else + multiplier = EEG.srate; +end + +if isempty(Startimes) || Startimes<0 || Startimes>(ceil((Allsamples-1)/multiplier)-Winlength) + if ndims(EEG.data) ==3 + Startimes=1; + else + Startimes=0; + end +end + +%%determine the time range that will be dispalyed +lowlim = round(Startimes*multiplier+1); +highlim = round(min((Startimes+Winlength)*multiplier+1,Allsamples)); + + +%%--------------------prepare event array if any -------------------------- +Events = EEG.event; +if ~isempty(Events) + if ~isfield(Events, 'type') || ~isfield(Events, 'latency'), Events = []; end +end +if ~isempty(Events) + if ischar(Events(1).type) + [Eventtypes tmpind indexcolor] = unique_bc({Events.type}); % indexcolor countinas the event type + else [Eventtypes tmpind indexcolor] = unique_bc([ Events.type ]); + end + Eventcolors = { 'r', [0 0.8 0], 'm', 'c', 'k', 'b', [0 0.8 0] }; + Eventstyle = { '-' '-' '-' '-' '-' '-' '-' '--' '--' '--' '--' '--' '--' '--'}; + Eventwidths = [ 2.5 1 ]; + Eventtypecolors = Eventcolors(mod([1:length(Eventtypes)]-1 ,length(Eventcolors))+1); + Eventcolors = Eventcolors(mod(indexcolor-1 ,length(Eventcolors))+1); + Eventtypestyle = Eventstyle (mod([1:length(Eventtypes)]-1 ,length(Eventstyle))+1); + Eventstyle = Eventstyle (mod(indexcolor-1 ,length(Eventstyle))+1); + + % for width, only boundary events have width 2 (for the line) + % ----------------------------------------------------------- + indexwidth = ones(1,length(Eventtypes))*2; + if iscell(Eventtypes) + for index = 1:length(Eventtypes) + if strcmpi(Eventtypes{index}, 'boundary'), indexwidth(index) = 1; end + end + else + end + Eventtypewidths = Eventwidths (mod(indexwidth([1:length(Eventtypes)])-1 ,length(Eventwidths))+1); + Eventwidths = Eventwidths (mod(indexwidth(indexcolor)-1 ,length(Eventwidths))+1); + + % latency and duration of events + % ------------------------------ + Eventlatencies = [ Events.latency ]+1; + if isfield(Events, 'duration') + durations = { Events.duration }; + durations(cellfun(@isempty, durations)) = { NaN }; + Eventlatencyend = Eventlatencies + [durations{:}]+1; + else Eventlatencyend = []; + end + % EventOnset = 1; +end + +if isempty(Events) + EventOnset = 0; +end + +chanNum = numel(ChanArray); + + +%%-------------------------------IC and original data---------------------- +dataica = [];chaNum=0; +if ~isempty(EEG.icaweights) && ~isempty(ICArray)%%pop_eegplot from eeglab + tmpdata = eeg_getdatact(EEG, 'component', [1:size(EEG.icaweights,1)]); + try + dataica = tmpdata(ICArray,:); + catch + dataica = tmpdata(:,:); + ICArray = [1:size(tmpdata,1)]; + end +end + +if EEGdispFlag==1 + dataeeg = EEG.data(ChanArray,:); + chaNum = numel(ChanArray); +else + dataeeg =[]; + chaNum = 0; +end + +%%---------------------------Normalize------------------------------------- +if NormFlag==1 + %%Norm for origanal + % data2 = []; + if ~isempty(dataeeg) + datastd = std(dataeeg(:,1:min(1000,Allsamples)),[],2);% + for i = 1:size(dataeeg,1) + dataeeg(i,:,:) = dataeeg(i,:,:)/datastd(i); + % if ~isempty(data2) + % data2(i,:,:) = data2(i,:,:)*datastd(i); + % end + end + end + + %%norm for IC data + if ~isempty(dataica) + dataicstd = std(dataica(:,1:min(1000,Allsamples)),[],2); + for i = 1:size(dataica,1) + dataica(i,:,:) = dataica(i,:,:)/dataicstd(i); + % if ~isempty(data2) + % data2(i,:,:) = data2(i,:,:)*dataicstd(i); + % end + end + end +end + +% Removing DC for IC data? +% ------------------------- +meandataica =[];ICNum=0; +if ICdispFlag==1 + if ~isempty(EEG.icaweights) && ~isempty(ICArray) && ~isempty(dataica)%%pop_eegplot from eeglab + switch Submean % subtract the mean ? + case 1 + meandataica = mean(dataica(:,lowlim:highlim)'); + if any(isnan(meandataica)) + meandataica = nan_mean(dataica(:,lowlim:highlim)'); + end + otherwise, meandataica = zeros(1,numel(ICArray)); + end + end + ICNum = numel(ICArray); +else + ICNum = 0; +end + +% Removing DC for original data? +% ------------------------- +meandata = []; +if EEGdispFlag==1 && ~isempty(dataeeg) + switch Submean % subtract the mean ? + case 1 + meandata = mean(dataeeg(:,lowlim:highlim)'); + if any(isnan(meandata)) + meandata = nan_mean(dataeeg(:,lowlim:highlim)'); + end + otherwise, meandata = zeros(1,numel(ChanArray)); + end +end + + +PlotNum = chaNum+ICNum; +if chaNum==0 && ICNum==0 + Ampscold = 0*[1:PlotNum]'; + if StackFlag==1 + Ampsc = 0*[1:PlotNum]'; + else + Ampsc = Ampscold; + end + AmpScaleold = 0; + ylims = [0 (PlotNum+1)*AmpScale]; + data = [dataeeg;dataica]; + meandata = [meandata,meandataica]; +elseif ICNum==0 && chaNum~=0 + Ampscold = AmpScale*[1:PlotNum]'; + if StackFlag==1 + Ampsc = ((Ampscold(end)+AmpScale)/2)*ones(1,PlotNum)'; + else + Ampsc = Ampscold; + end + AmpScaleold = AmpScale; + ylims = [AmpScale*(100-bufftobo)/100 PlotNum*AmpScale+AmpScale*bufftobo/100]; + data = [dataeeg;dataica]; + meandata = [meandata,meandataica]; +elseif ICNum~=0 && chaNum==0 + Ampscold = AmpIC*[1:PlotNum]'; + if StackFlag==1 + Ampsc = ((Ampscold(end)+AmpIC)/2)*ones(1,PlotNum)'; + else + Ampsc = Ampscold; + end + ylims = [AmpIC*(100-bufftobo)/100 PlotNum*AmpIC+AmpIC*bufftobo/100]; + AmpScaleold = AmpIC; + data = [dataeeg;dataica]; + meandata = [meandata,meandataica]; + AmpICNew = AmpIC; +elseif ICNum~=0 && chaNum~=0 + AmpICNew = (AmpScale*chaNum+AmpScale/2)/ICNum; + Ampscold1 = AmpICNew*[1:ICNum]'; + Ampscold2 = Ampscold1(end)+AmpScale/2+AmpScale*[1:chaNum]'; + Ampscold = [Ampscold1;Ampscold2]; + if StackFlag==1 + Ampsc = [(Ampscold1(end)/2)*ones(ICNum,1);((Ampscold2(end)+AmpScale+Ampscold2(1)+AmpIC)/2)*ones(chaNum,1)]; + else + Ampsc = Ampscold; + end + AmpScaleold = AmpScale; + ylims = [AmpICNew*(100-bufftobo)/100 Ampscold(end)+AmpScale*bufftobo/100]; + data = [dataeeg;(AmpICNew/AmpIC)*dataica]; + meandata = [meandata,(AmpICNew/AmpIC)*meandataica]; +end + + +Colorgbwave = []; +%%set the wave color for each channel +if ~isempty(data) + ColorNamergb = roundn([255 0 7;186 85 255;255 192 0;0 238 237;0 78 255;0 197 0]/255,-3); + Colorgb_chan = []; + if ~isempty(dataeeg) + chanNum = numel(ChanArray); + if chanNum<=6 + Colorgb_chan = ColorNamergb(1:chanNum,:); + else + jj = floor(chanNum/6); + Colorgb_chan = []; + for ii = 1:jj + Colorgb_chan = [Colorgb_chan; ColorNamergb]; + end + if jj*6~=chanNum + Colorgb_chan = [Colorgb_chan; ColorNamergb(1:chanNum-jj*6,:)]; + end + end + end + + %%colors for ICs + % Coloricrgb = roundn([211,211,211;169,169,16;128,128,128]/255,-3); + Coloricrgb = roundn([180 0 0;127 68 127;228 88 44;15 175 175;0 0 0;9 158 74]/255,-3); + Colorgb_IC = []; + if ~isempty(ICArray) + ICNum = numel(ICArray); + if ICNum<7 + Colorgb_IC = Coloricrgb(1:ICNum,:); + else + jj = floor(ICNum/6); + for ii = 1:jj + Colorgb_IC = [Colorgb_IC; Coloricrgb]; + end + + if jj*6~=ICNum + Colorgb_IC = [Colorgb_IC; Coloricrgb(1:ICNum-jj*6,:)]; + end + + end + end + Colorgbwave = [Colorgb_chan;Colorgb_IC]; +end + + +PlotNum =0; +if ICdispFlag==1 && EEGdispFlag==1 + if ~isempty(EEG.icaweights) && ~isempty(ICArray) + PlotNum = chanNum +numel(ICArray); + else + PlotNum = chanNum; + end +elseif ICdispFlag==0 && EEGdispFlag==1 + PlotNum = chanNum; +elseif ICdispFlag==1 && EEGdispFlag==0 + if ~isempty(EEG.icaweights) && ~isempty(ICArray) + PlotNum = numel(ICArray); + end +end +%% +EventOnsetdur =1; +Trialstag = size(EEG.data,2); +GapSize = ceil(numel([lowlim:highlim])/40); +if GapSize<=2 + GapSize=5; +end +% ------------------------------------------------------------------------- +% -------------------------draw events if any------------------------------ +% ------------------------------------------------------------------------- +% ylims = [0 (PlotNum+1)*AmpScale]; + +FonsizeDefault = f_get_default_fontsize(); +if isempty(FonsizeDefault) || numel(FonsizeDefault)~=1|| any(FonsizeDefault(:)<=0) + FonsizeDefault=10; +end + +if EventOnset==1 && ~isempty(data) && PlotNum~=0 + MAXEVENTSTRING = 75; + if MAXEVENTSTRING<0 + MAXEVENTSTRING = 0; + elseif MAXEVENTSTRING>75 + MAXEVENTSTRING=75; + end + % AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100]; + % + + % find event to plot + % ------------------ + event2plot = find ( Eventlatencies >=lowlim & Eventlatencies <= highlim ); + if ~isempty(Eventlatencyend) + event2plot2 = find ( Eventlatencyend >= lowlim & Eventlatencyend <= highlim ); + event2plot3 = find ( Eventlatencies < lowlim & Eventlatencyend > highlim ); + event2plot = setdiff(union(event2plot, event2plot2), event2plot3); + end + for index = 1:length(event2plot) + %Just repeat for the first one + if index == 1 + EVENTFONT = [' \fontsize{',num2str(FonsizeDefault),'} ']; + end + + % draw latency line + % ----------------- + if ndims(EEG.data)==2 + tmplat = Eventlatencies(event2plot(index))-lowlim-1; + else + % ----------------- + tmptaglat = [lowlim:highlim]; + tmpind = find(mod(tmptaglat-1,Trialstag) == 0); + tmpind = setdiff(tmpind,[1,numel(tmptaglat)]); + alltaglat = setdiff(tmptaglat(tmpind),[1,tmptaglat(end)]); + %%add gap between epochs if any + if ~isempty(tmpind) && ~isempty(alltaglat) %%two or multiple epochs were displayed + if length(alltaglat)==1 + if Eventlatencies(event2plot(index)) >= alltaglat + Singlat = Eventlatencies(event2plot(index))+GapSize; + else + Singlat = Eventlatencies(event2plot(index)); + end + else + if Eventlatencies(event2plot(index)) < alltaglat(1)%%check the first epoch + Singlat = Eventlatencies(event2plot(index)); + else%%the other epochs + for ii = 2:length(alltaglat) + if Eventlatencies(event2plot(index)) >= alltaglat(ii-1) && Eventlatencies(event2plot(index)) < alltaglat(ii) + Singlat = Eventlatencies(event2plot(index))+GapSize*(ii-1); + break; + elseif Eventlatencies(event2plot(index)) >= alltaglat(end) %%check the last epoch + Singlat = Eventlatencies(event2plot(index))+GapSize*length(alltaglat); + break; + end + end + end + end + tmplat = Singlat-lowlim;%%adjust the latency if any + else%%within one epoch + tmplat = Eventlatencies(event2plot(index))-lowlim;%-1; + end + end + tmph = plot(myeegviewer, [ tmplat tmplat ], ylims, 'color', Eventcolors{ event2plot(index) }, ... + 'linestyle', Eventstyle { event2plot(index) }, ... + 'linewidth', Eventwidths( event2plot(index) ) ); + + % schtefan: add Event types text above event latency line + % ------------------------------------------------------- + evntxt = strrep(num2str(Events(event2plot(index)).type),'_','-'); + if length(evntxt)>MAXEVENTSTRING, evntxt = [ evntxt(1:MAXEVENTSTRING-1) '...' ]; end % truncate + try, + if tmplat>=0 + tmph2 = text(myeegviewer, [tmplat], ylims(2)-0.005, [EVENTFONT evntxt], ... + 'color', Eventcolors{ event2plot(index) }, ... + 'horizontalalignment', 'left',... + 'rotation',90,'FontSize',FonsizeDefault); + end + catch, end + + % draw duration is not 0 + % ---------------------- + % if EventOnsetdur && ~isempty(Eventlatencyend) ... + % && Eventwidths( event2plot(index) ) ~= 2.5 % do not plot length of boundary events + % tmplatend = Eventlatencyend(event2plot(index))-lowlim-1; + % if tmplatend ~= 0 + % tmplim = ylims; + % tmpcol = Eventcolors{ event2plot(index) }; + % h = patch(myeegviewer, [ tmplat tmplatend tmplatend tmplat ], ... + % [ tmplim(1) tmplim(1) tmplim(2) tmplim(2) ], ... + % tmpcol ); % this argument is color + % set(h, 'EdgeColor', 'none') + % end + % end + end +else % JavierLC + MAXEVENTSTRING = 10; % default + % AXES_POSITION = [0.0964286 0.15 0.842 0.75-(MAXEVENTSTRING-5)/100]; +end + + +DEFAULT_GRID_SPACING =Winlength/5; + +% if StackFlag==1 +% AmpScale=0; +% end + +% Ampsc = AmpScale*[1:PlotNum]'; +% ------------------------------------------------------------------------- +% -----------------draw EEG wave if any------------------------------------ +% ------------------------------------------------------------------------- +leftintv = []; +%%Plot continuous EEG +tmpcolor = [ 0 0 0.4 ]; +if ndims(EEG.data)==2 + if ~isempty(data) && PlotNum~=0 + + for ii = size(data,1):-1:1 + try + plot(myeegviewer, (data(ii,lowlim:highlim)+ Ampsc(size(data,1)-ii+1)-meandata(ii))' , ... + 'color', Colorgbwave(ii,:), 'clipping','on','LineWidth',0.75);%% + catch + plot(myeegviewer, (data(ii,lowlim:highlim)+ Ampsc(size(data,1)-ii+1)-meandata(ii))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',0.75);%% + end + end + set(myeegviewer,'TickDir', 'in','LineWidth',1); + %%xtick + set(myeegviewer, 'Xlim',[1 Winlength*multiplier+1],... + 'XTick',[1:multiplier*DEFAULT_GRID_SPACING:Winlength*multiplier+1]); + set(myeegviewer, 'XTickLabel', num2str((Startimes:DEFAULT_GRID_SPACING:Startimes+Winlength)')); + + %% + %%-----------------plot scale------------------ + leftintv = Winlength*multiplier+1; + else + set(myeegviewer, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); + end +end + +%%------------------------------plot single-trial EEG---------------------- +%%Thanks for the eeglab developers so that we can borrow their codes +isfreq = 0; +Limits = [EEG.times(1),EEG.times(end)]; +Srate = EEG.srate; +Freqlimits = []; +if EEG.trials>1 + if ~isempty(data) && PlotNum~=0 + % plot trial limits + % ----------------- + tmptag = [lowlim:highlim]; + tmpind = find(mod(tmptag-1,Trialstag) == 0); + % for index = tmpind + % plot(ax0, [tmptag(index)-lowlim tmptag(index)-lowlim], [0 1], 'b--'); + % end + alltag = tmptag(tmpind); + if isempty(tmpind) + epochNum = 0; + else + epochNum = numel(setdiff(tmpind,[0 1 numel(tmptag)])); + end + % compute epoch number + % -------------- + alltag1 = alltag; + if ~isempty(tmpind) + tagnum = (alltag1-1)/Trialstag+1; + for ii = 1:numel(tmpind) + alltag1(ii) = alltag1(ii)+(ii-1)*GapSize; + end + for ii = 1:numel(tagnum) + text(myeegviewer, [alltag1(ii)-lowlim+Trialstag/2],ylims(2)+1.1, [32,num2str(tagnum(ii))], ... + 'color', 'k','FontSize',FonsizeDefault, ... + 'horizontalalignment', 'left','rotation',90); %% + set(myeegviewer,'Xlim',[1 (Winlength*multiplier+epochNum*GapSize)]); + end + end + + %%add the gap between epochs if any + Epochintv = []; + + if ~isempty(tmpind) + if (numel(tmpind)==1 && tmpind(end) == numel(tmptag)) || (numel(tmpind)==1 && tmpind(1) == 1) + dataplot = data(:,lowlim:highlim); + Epochintv(1,1) =1; + Epochintv(1,2) =numel(lowlim:highlim); + else + tmpind = unique(setdiff([0,tmpind, numel(tmptag)],1)); + dataplotold = data(:,lowlim:highlim); + dataplot_new = []; + for ii = 2:numel(tmpind) + GapLeft = tmpind(ii-1)+1; + GapRight = tmpind(ii); + if GapLeft<1 + GapLeft =1; + end + if GapRight > numel(tmptag) + GapRight = numel(tmptag); + end + dataplot_new = [dataplot_new,dataplotold(:,GapLeft:GapRight),nan(size(dataplotold,1),GapSize)]; + Epochintv(ii-1,1) = GapLeft+(ii-2)*GapSize; + Epochintv(ii-1,2) = GapRight+(ii-2)*GapSize; + end + if ~isempty(dataplot_new) + dataplot = dataplot_new; + else + dataplot = dataplotold; + end + end + end + + %%-----------plot background color for trias with artifact--------- + %%highlight waves with labels + Value_adjust = floor(Startimes+1); + if Value_adjust<1 + Value_adjust=1; + end + tagnum = unique([Value_adjust,tagnum]); + + try trialsMakrs = EEG.reject.rejmanual(tagnum);catch trialsMakrs = zeros(1,numel(tagnum)) ; end + try trialsMakrschan = EEG.reject.rejmanualE(:,tagnum);catch trialsMakrschan = zeros(EEG.nbchan,numel(tagnum)) ; end + tmpcolsbgc = [1 1 0.783]; + if ~isempty(Epochintv) + for jj = 1:size(Epochintv,1) + [xpos,~]=find(trialsMakrschan(:,jj)==1); + if jj<= numel(trialsMakrs) && ~isempty(xpos) + if trialsMakrs(jj)==1 + patch(myeegviewer,[Epochintv(jj,1),Epochintv(jj,2),Epochintv(jj,2),Epochintv(jj,1)],... + [ylims(1),ylims(1),ylims(end),ylims(end)],tmpcolsbgc,'EdgeColor','none','FaceAlpha',.5); + %%highlight the wave if the channels exist + if chaNum~=0 + ChanArray = reshape(ChanArray,1,numel(ChanArray)); + [~,ypos1]=find(ChanArray==xpos); + if ~isempty(ypos1) + for kk = 1:numel(ypos1) + dataChan = nan(1,size(dataplot,2)); + dataChan (1,Epochintv(jj,1):Epochintv(jj,2)) = dataplot(ypos1(kk),Epochintv(jj,1):Epochintv(jj,2)); + dataChan1= nan(1,size(dataplot,2)); + dataChan1 (1,Epochintv(jj,1):Epochintv(jj,1)) = dataplot(ypos1(kk),Epochintv(jj,1):Epochintv(jj,1)); + try + plot(myeegviewer, (dataChan+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))' , ... + 'color', Colorgbwave(ypos1(kk),:), 'clipping','on','LineWidth',1.5);%% + + plot(myeegviewer, (dataChan1+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))' , ... + 'color', Colorgbwave(ypos1(kk),:), 'clipping','on','LineWidth',1.5,'Marker' ,'s','MarkerSize',8,... + 'MarkerEdgeColor',Colorgbwave(ypos1(kk),:),'MarkerFaceColor',Colorgbwave(ypos1(kk),:));%% + catch + plot(myeegviewer, (dataChan+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',1.5);%% + plot(myeegviewer, (dataChan1+ Ampsc(size(dataplot,1)-ypos1(kk)+1)-meandata(ypos1(kk)))', ... + 'color', tmpcolor, 'clipping','on','LineWidth',1.5,'Marker' ,'s','MarkerSize',8,... + 'MarkerEdgeColor',Colorgbwave(ypos1(kk),:),'MarkerFaceColor',Colorgbwave(ypos1(kk),:));%% + end + end + end + end + end + end + end + end + + %% + for ii = size(dataplot,1):-1:1 + try + plot(myeegviewer, (dataplot(ii,:)+ Ampsc(size(dataplot,1)-ii+1)-meandata(ii))' + (PlotNum+1)*(OldAmpScale-AmpScale)/2, ... + 'color', Colorgbwave(ii,:), 'clipping','on','LineWidth',0.75);%% + catch + plot(myeegviewer, (dataplot(ii,:)+ Ampsc(size(dataplot,1)-ii+1)-meandata(ii))' + (PlotNum+1)*(OldAmpScale-AmpScale)/2, ... + 'color', tmpcolor, 'clipping','on','LineWidth',0.75);%% + end + end + + %------------------------Xticks------------------------------------ + tagpos = []; + tagtext = []; + if ~isempty(alltag) + alltag = [alltag(1)-Trialstag alltag alltag(end)+Trialstag]; % add border trial limits + else + alltag = [ floor(lowlim/Trialstag)*Trialstag ceil(highlim/Trialstag)*Trialstag ]+1; + end + + nbdiv = 20/Winlength; % approximative number of divisions + divpossible = [ 100000./[1 2 4 5] 10000./[1 2 4 5] 1000./[1 2 4 5] 100./[1 2 4 5 10 20]]; % possible increments + [tmp indexdiv] = min(abs(nbdiv*divpossible-(Limits(2)-Limits(1)))); % closest possible increment + incrementpoint = divpossible(indexdiv)/1000*Srate; + + % tag zero below is an offset used to be sure that 0 is included + % in the absicia of the data epochs + if Limits(2) < 0, tagzerooffset = (Limits(2)-Limits(1))/1000*Srate+1; + else tagzerooffset = -Limits(1)/1000*Srate; + end + if tagzerooffset < 0, tagzerooffset = 0; end + + for i=1:length(alltag)-1 + if ~isempty(tagpos) && tagpos(end)-alltag(i)<2*incrementpoint/3 + tagpos = tagpos(1:end-1); + end + if ~isempty(Freqlimits) + tagpos = [ tagpos linspace(alltag(i),alltag(i+1)-1, nbdiv) ]; + else + if tagzerooffset ~= 0 + tmptagpos = [alltag(i)+tagzerooffset:-incrementpoint:alltag(i)]; + else + tmptagpos = []; + end + tagpos = [ tagpos [tmptagpos(end:-1:2) alltag(i)+tagzerooffset:incrementpoint:(alltag(i+1)-1)]]; + end + end + + % find corresponding epochs + % ------------------------- + if ~isfreq + tmplimit = Limits; + tpmorder = 1E-3; + else + tmplimit =Freqlimits; + tpmorder = 1; + end + tagtext = eeg_point2lat(tagpos, floor((tagpos)/Trialstag)+1, Srate, tmplimit,tpmorder); + + %%adjust xticks + EpochFlag = floor((tagpos)/Trialstag)+1;%% + + EpochFlag = reshape(EpochFlag,1,numel(EpochFlag)); + xtickstr = tagpos-lowlim+1; + [xpos,ypos] = find(xtickstr>0); + if ~isempty(ypos) + EpochFlag =EpochFlag(ypos); + xtickstr = xtickstr(ypos); + tagtext = tagtext(ypos); + end + + EpochFlagunique =unique(setdiff(EpochFlag,0)); + if numel(EpochFlagunique)~=1 + for ii = 2:numel(EpochFlagunique) + [xpos,ypos]= find(EpochFlag==EpochFlagunique(ii)); + if ~isempty(ypos) + xtickstr(ypos) = xtickstr(ypos)+(EpochFlagunique(ii)-EpochFlagunique(1))*GapSize;%*(1000/Srate); + end + end + end + set(myeegviewer, 'Xlim',[1 (Winlength*multiplier+epochNum*GapSize)],... + 'XTick',xtickstr,... + 'XTickLabel', tagtext,... + 'FontWeight','normal',... + 'xaxislocation', 'bottom','FontSize',FonsizeDefault); + XTickLabel = cellstr(myeegviewer.XTickLabel); + for Numofxtick = 1:length(XTickLabel) + if strcmpi(XTickLabel{Numofxtick,:},'-0') + XTickLabel{Numofxtick} = '0'; + end + end + set(myeegviewer,'XTickLabel',XTickLabel); + %% + %%-----------------plot scale------------------ + leftintv = (Winlength*multiplier+epochNum*GapSize); + else + set(myeegviewer, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); + end +end + + +%% +%%----------------------------plot y scale--------------------------------- +if ~isempty(data) && PlotNum~=0 && ~isempty(leftintv) + ytick_bottom = myeegviewer.TickLength(1)*diff(myeegviewer.XLim); + % xtick_bottom = myeegviewer.TickLength(1)*diff(myeegviewer.YLim); + leftintv = leftintv+ytick_bottom*2.5; + rightintv = leftintv; + if ICdispFlag~=0 + line(myeegviewer,[leftintv,rightintv],[ylims(1) AmpICNew+ylims(1)],'color','k','LineWidth',1, 'clipping','off'); + line(myeegviewer,[leftintv-ytick_bottom,rightintv+ytick_bottom],[ylims(1) ylims(1)],'color','k','LineWidth',1, 'clipping','off'); + line(myeegviewer,[leftintv-ytick_bottom,rightintv+ytick_bottom],[AmpICNew+ylims(1) AmpICNew+ylims(1)],'color','k','LineWidth',1, 'clipping','off'); + text(myeegviewer,leftintv,((ylims(2)-ylims(1))/43+AmpICNew+ylims(1)), [num2str(AmpIC),32,'\muV'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + text(myeegviewer,leftintv,((ylims(2)-ylims(1))/20+AmpICNew+ylims(1)), ['ICs'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + end + if EEGdispFlag~=0 + line(myeegviewer,[leftintv,rightintv],[ylims(end)-AmpScale ylims(end)],'color','k','LineWidth',1, 'clipping','off'); + line(myeegviewer,[leftintv-ytick_bottom,rightintv+ytick_bottom],[ylims(end)-AmpScale ylims(end)-AmpScale],'color','k','LineWidth',1, 'clipping','off'); + line(myeegviewer,[leftintv-ytick_bottom,rightintv+ytick_bottom],[ylims(end) ylims(end)],'color','k','LineWidth',1, 'clipping','off'); + text(myeegviewer,leftintv,(ylims(2)-ylims(1))/43+ylims(end), [num2str(AmpScale),32,'\muV'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + text(myeegviewer,leftintv,(ylims(2)-ylims(1))/20+ylims(end), ['Chans'],'HorizontalAlignment', 'center','FontSize',FonsizeDefault); + end +end + +%%---------------------------ytick ticklabels------------------------------ +if ~isempty(data) && PlotNum~=0 + if chaNum==0 + ChanArray = []; + end + set(myeegviewer, 'ylim',[ylims(1) ylims(end)],'YTick',[ylims(1) Ampscold']); + [YLabels,chaName,ICName] = f_eeg_read_chan_IC_names(EEG.chanlocs,ChanArray,ICArray,ChanLabel); + YLabels = flipud(char(YLabels,'')); + set(myeegviewer,'YTickLabel',cellstr(YLabels),... + 'TickLength',[.005 .005],... + 'Color','none',... + 'XColor','k',... + 'YColor','k',... + 'FontWeight','normal',... + 'TickDir', 'in',... + 'LineWidth',0.5,'FontSize',FonsizeDefault);%%,'HorizontalAlignment','center' + count=0; + for ii = length(myeegviewer.YTickLabel):-1:2 + count = count+1; + Cellsing = strrep(myeegviewer.YTickLabel{ii},'_','\_'); + myeegviewer.YTickLabel{ii} = strcat('\color[rgb]{',num2str(Colorgbwave(count,:)),'}', Cellsing); + end +end +end + diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_duplicateeg.m b/studio_functions/Functions/EStudio/EEG Tab/pop_duplicateeg.m new file mode 100644 index 00000000..ba0b1454 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_duplicateeg.m @@ -0,0 +1,193 @@ +% PURPOSE: pop_duplicateeg.m +% duplicate ERPset +% + +% FORMAT: +% [EEG, erpcom] = pop_duplicateeg( EEG, 'ChanArray',ChanArray,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%EEG -EEG structure +%ChanArray -index(es) of channels + + + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2024 + + + + +function [EEG, erpcom] = pop_duplicateeg(EEG, varargin) +erpcom = ''; + +if nargin < 1 + help pop_duplicateeg + return +end +if isempty(EEG) + msgboxText = 'Cannot duplicate an empty EEGset'; + title = 'ERPLAB: pop_duplicateeg() error'; + errorfound(msgboxText, title); + return +end +if isempty(EEG(1).data) + msgboxText = 'Cannot duplicate an empty EEGset'; + title = 'ERPLAB: pop_duplicateeg() error'; + errorfound(msgboxText, title); + return +end + + + +if length(EEG)>1 + msgboxText = 'Cannot duplicate multiple EEGsets!'; + title = 'ERPLAB: pop_duplicateeg() error'; + errorfound(msgboxText, title); + return +end +if nargin==1 + def = erpworkingmemory('pop_duplicateeg'); + if isempty(def) + def = {[]}; + end + ChanArray =def{1}; + + def = f_ERP_duplicate(EEG,ChanArray); + if isempty(def) + return; + end + ChanArray = def{1}; + erpworkingmemory('pop_duplicateeg',def); + % + % Somersault + % + [EEG, erpcom] = pop_duplicateeg( EEG, 'ChanArray',ChanArray,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('EEG'); +% option(s) +p.addParamValue('ChanArray', [],@isnumeric); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(EEG, varargin{:}); + +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>EEG.nbchan) || any(ChanArray(:)<=0) + ChanArray = [[1:EEG.nbchan]]; +end + + +if ~isempty(ChanArray) + EEG.saved = 'no'; + EEG.filepath = ''; + chanDelete = setdiff([1:EEG.nbchan],ChanArray); + if ~isempty(chanDelete) + count = 0; + for ii = chanDelete + count = count+1; + ChanArrayStr{count} = EEG.chanlocs(ii).labels; + end + EEG = pop_select( EEG, 'rmchannel', ChanArrayStr); + % EEG = eeg_checkset(EEG); + end +end + + + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + +EEG.saved = 'no'; + +% +% History +% + +skipfields = {'EEG', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_duplicateeg( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + else + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ERPset from GUI +% +if issaveas + [EEG, ~] = pop_saveset( EEG, 'filename',EEG.filename,'filepath',EEG.filepath); +end + + + +% get history from script. EEG +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + EEG = eegh(erpcom, EEG); + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_editdatachanlocs.m b/studio_functions/Functions/EStudio/EEG Tab/pop_editdatachanlocs.m new file mode 100644 index 00000000..5a763221 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_editdatachanlocs.m @@ -0,0 +1,267 @@ +% PURPOSE: pop_editdatachanlocs.m is to edit the channel locations +% +% + +% FORMAT : +% +% pop_editdatachanlocs(ALLEEG, CURRENTSET, parameters); +% + +% ALLEEG - structure array of ALLEEG/ERP structures +% CURRENTSET - Index for current EEGset/ERPset + + + +% The available parameters are as follows: +% +%ChanArray -index(es) for the selected channels +%Chanlocs - channel locations for the selected channels + + + +%%Output +%%EEG -EEG/ERP structure with the changed chan locations of the selected channels + + +%%Example: +%EEG = pop_editdatachanlocs( ALLEEG, 2, 'ChanArray', [1 2 3], 'Chanlocs', chanlocs, 'History', 'implicit' ); + + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + + +function [EEG,eegcom] = pop_editdatachanlocs(ALLEEG,CURRENTSET,varargin) + +eegcom = ''; +if nargin < 1 + help pop_editdatachanlocs + return; +end + +if isempty(ALLEEG)%% + beep; + disp('ALLEEG is empty'); + return; +end + +if nargin< 3 + %%Do we need to create a GUI that the user can use it to define the + %%desired parameters? + + if nargin< 2 || isempty(CURRENTSET) || numel(CURRENTSET)~=1 || CURRENTSET>length(ALLEEG) || CURRENTSET<=0 + CURRENTSET = length(ALLEEG); + end + EEG = ALLEEG(CURRENTSET); + if ~isfield(EEG,'chanlocs') + beep; + disp('The current dataset donot have chanlocs field'); + return; + end + chanlocs = EEG.chanlocs; + if ~isfield(chanlocs,'labels') + beep; + disp('There is no labels for chanlocs for the current dataset'); + return; + end + + ChanArray = [1:length(EEG.chanlocs)]; + + + titleName= ['Dataset',32,num2str(CURRENTSET),': Add/Edit Channel locations']; + EEGIN = EEG; + EEGIN.chanlocs = EEG.chanlocs(ChanArray); + app = feval('f_editchan_gui',EEGIN,titleName); + waitfor(app,'Finishbutton',1); + try + EEGINOUT = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.5); %wait for app to leave + catch + disp('User selected Cancel') + return + end + if isempty(EEGINOUT) + disp('User selected Cancel') + return + end + + Chanlocs = EEGINOUT.chanlocs; + %%add suffix + try + ALLEEG(CURRENTSET).setname = [ALLEEG(CURRENTSET).setname,'_editchan']; + catch + ALLEEG(CURRENTSET).erpname = [ALLEEG(CURRENTSET).erpname,'_editchan']; + end + [EEG, eegcom] = pop_editdatachanlocs(ALLEEG,CURRENTSET,'ChanArray',ChanArray,'Chanlocs',Chanlocs,'History', 'gui'); + pause(0.1); + return; +end + + +% +% Parsing inputs +% +% colordef = getcolorcellerps; %{'k' 'r' 'b' 'g' 'c' 'm' 'y' 'w'};% default colors +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLEEG'); +p.addRequired('CURRENTSET'); + +%Option(s) +p.addParamValue('ChanArray',[],@isnumeric); +p.addParamValue('Chanlocs','', @isstruct); + +p.addParamValue('History', '', @ischar); % history from scripting + +p.parse(ALLEEG,CURRENTSET,varargin{:}); + +p_Results = p.Results; + +if strcmpi(p_Results.History,'command') + shist = 4;%%Show Maltab command only and donot plot the wave +elseif strcmpi(p_Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p_Results.History,'script') + shist = 2; % script +elseif strcmpi(p_Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + +if isempty(ALLEEG)%% + beep; + disp('ALLEEG is empty'); + return; +end + + +if isempty(CURRENTSET) || numel(CURRENTSET)~=1 || CURRENTSET>length(ALLEEG) || CURRENTSET<=0 + CURRENTSET = length(ALLEEG); +end + +EEG = ALLEEG(CURRENTSET); +if ~isfield(EEG,'chanlocs') + beep; + disp('The current dataset donot have chanlocs field'); + return; +end +chanlocs = EEG.chanlocs; +if ~isfield(chanlocs,'labels') + beep; + disp('There is no labels for chanlocs for the current dataset'); + return; +end + + +%%channel array +qchanArray = p_Results.ChanArray; +nbchan = length(EEG.chanlocs); +if isempty(qchanArray) || min(qchanArray(:))>nbchan || max(qchanArray(:))>nbchan || min(qchanArray(:))<=0 + qchanArray = [1:nbchan]; +end + + + +%%IC array (the default is empty, that is, donot display ICs) +qChanlocsnew = p_Results.Chanlocs; +if isempty(qChanlocsnew) + disp('Chanlocs is empty'); + return; +end + +% +%%adjust the number of channels and channel names +for Numofchan = 1:numel(qchanArray) + try + qChanlocsnew(Numofchan) = qChanlocsnew(Numofchan); + catch + qChanlocsnew(Numofchan) = EEG.chanlocs(qchanArray(Numofchan)); + fprintf(2,['\n Warning: Location for channel ',32,num2str(qchanArray(Numofchan)),32,'was not defined, we threfore used its original one.\n']); + end +end + + +%%--------------change the channel names----------------------------------- +for Numofchan = 1:numel(qchanArray) + fprintf(['Chan',32,num2str(qchanArray(Numofchan)),': Location was edited.\n']); + EEG.chanlocs(qchanArray(Numofchan)) = qChanlocsnew(Numofchan); +end + + + +%%history +fn = fieldnames(p.Results); +skipfields = {'ALLEEG','CURRENTSET'}; +if isfield(EEG,'datatype') && strcmpi(EEG.datatype,'ERP') + eegcom = sprintf( 'ERP = pop_editdatachanlocs( %s %s', 'ALLERP,',num2str(CURRENTSET)); +else +eegcom = sprintf( 'EEG = pop_editdatachanlocs( %s %s', 'ALLEEG,',num2str(CURRENTSET)); +end +for q=1:length(fn) + fn2com = fn{q}; % inputname + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); % input value + if ~isempty(fn2res) + if isstruct(fn2res) + eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, fn2com); + elseif iscell(fn2res) + nn = length(fn2res); + eegcom = sprintf( '%s, ''%s'', {''%s'' ', eegcom, fn2com, fn2res{1}); + for ff=2:nn + eegcom = sprintf( '%s, ''%s'' ', eegcom, fn2res{ff}); + end + eegcom = sprintf( '%s}', eegcom); + elseif isnumeric(fn2res) + + if size(fn2res,1)==1 + fn2res_trans = char(num2str(fn2res)); + else + fn2res_trans = vect2colon(fn2res); + end + fn2res = fn2res_trans; + eegcom = sprintf( '%s, ''%s'', [%s', eegcom,fn2com,fn2res); + eegcom = sprintf( '%s]', eegcom); + else + % if ~ismember_bc2(fn2com,{'xscale','yscale'}) + % eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, vect2colon(fn2res,'Repeat','on')); + % else + % xyscalestr = sprintf('[ %.1f %.1f %s ]', fn2res(1), fn2res(2), vect2colon(fn2res(3:end),'Delimiter','off')); + % eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, xyscalestr); + % end + end + end + end +end + +eegcom = sprintf( '%s );', eegcom); +% get history from script. ERP +% shist = 1; +switch shist + case 1 % from GUI + displayEquiComERP(eegcom); + case 2 % from script + for i=1:length(ALLEEG) + ALLEEG(i) = erphistory(ALLEEG(i), [], eegcom, 1); + end + case 3 + % implicit + case 4 + displayEquiComERP(eegcom); + + otherwise %off or none + eegcom = ''; + return +end + +return; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_ar_summary.m b/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_ar_summary.m new file mode 100644 index 00000000..7e705d42 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_ar_summary.m @@ -0,0 +1,48 @@ +%%This function is to display the summary of trial information +% +% FORMAT : +% +% pop_eeg_ar_summary(ALLEEG,EEGArray); +% +% ALLEEG - structure array of EEG structures +% EEGArray -index of eegsets + + + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Apr. 2024 + + + +function eegcom = pop_eeg_ar_summary(ALLEEG,EEGArray) + +eegcom = ''; +if nargin < 1 || nargin >2 + help pop_eeg_ar_summary + return +end +if nargin < 2 + EEGArray = [1:length(ALLEEG)]; +end +if isempty(EEGArray) || any(EEGArray(:)>length(ALLEEG)) || any(EEGArray(:)<1) + EEGArray = [1:length(ALLEEG)]; +end +if isempty(ALLEEG) + msgboxText = ['ALLEEG is empty.']; + title = 'ERPLAB Studio: pop_eeg_ar_summary() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + +if ~isempty(EEGArray) + app = feval('EEG_trial_rejection_sumr',ALLEEG(EEGArray),1); + waitfor(app,'Finishbutton',1); +end +EEGArraystr= vect2colon(EEGArray); +eegcom = sprintf('eegcom = pop_eeg_ar_summary(ALLEEG,%s);',EEGArraystr); +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_eventlist_view.m b/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_eventlist_view.m new file mode 100644 index 00000000..973c23ff --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_eventlist_view.m @@ -0,0 +1,144 @@ +% PURPOSE: pop_eeg_eventlist_view.m +% display eventlist + +% FORMAT: +% [ALLEEG, erpcom] = pop_eeg_eventlist_view( ALLEEG, 'EEGArray',EEGArray,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ALLEEG -ALLEEG structure +%EEGArray -index(es) of eegsets + + + +% *** This function is part of ALLEEGLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% May 2024 + + + + +function [ALLEEG, erpcom] = pop_eeg_eventlist_view(ALLEEG, varargin) +erpcom = ''; + +if nargin < 1 + help pop_eeg_eventlist_view + return +end +if isempty(ALLEEG) + msgboxText = 'Cannot handle an empty EEGset'; + title = 'ERPLAB: pop_eeg_eventlist_view() error'; + errorfound(msgboxText, title); + return +end +if isempty(ALLEEG(1)) + msgboxText = 'Cannot handle an empty EEGset'; + title = 'ERPLAB: pop_eeg_eventlist_view() error'; + errorfound(msgboxText, title); + return +end + + + +if nargin==1 + EEGArray = [1:length(ALLEEG)]; + [ALLEEG, erpcom] = pop_eeg_eventlist_view( ALLEEG, 'EEGArray',EEGArray,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLEEG'); +% option(s) +p.addParamValue('EEGArray', [],@isnumeric); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLEEG, varargin{:}); + + +EEGArray = p.Results.EEGArray; + +if isempty(EEGArray) || any(EEGArray(:)>length(ALLEEG)) || any(EEGArray(:)<1) + EEGArray = [1:length(ALLEEG)]; +end + +feval("EEG_evenlist_gui",ALLEEG(EEGArray)); + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + + +% +% History +% + +skipfields = {'ALLEEG', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_eeg_eventlist_view( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') && ~strcmpi(fn2res,'no') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + erpcom = sprintf( '%s, ''%s'', %s', erpcom, fn2com, vect2colon(fn2res,'Repeat','on')); + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ALLEEGset from GUI +% +if issaveas + for ii = 1:length(ALLEEG) + [ALLEEG(ii), ~] = pop_saveset( ALLEEG(ii), 'filename',ALLEEG(ii).filename,'filepath',[ALLEEG(ii).filepath,filesep]); + end +end + + +% get history from script. ALLEEG +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for ii = 1:length(EEGArray) + ALLEEG(EEGArray(ii)) = eegh(erpcom, ALLEEG(EEGArray(ii))); + end + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_save_trial_information.m b/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_save_trial_information.m new file mode 100644 index 00000000..83975938 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_eeg_save_trial_information.m @@ -0,0 +1,287 @@ +%write trial information to .text or .xls file + + + +function eegcom = pop_eeg_save_trial_information(ALLEEG, varargin) + +eegcom = ''; +if nargin<1 + help pop_eeg_save_trial_information + return +end + +if nargin==1 + if isempty(ALLEEG) + msgboxText = ['pop_eeg_save_trial_information: ALLEEG is empty!']; + titlNamerro = 'Error for pop_eeg_save_trial_information'; + estudio_warning(msgboxText,titlNamerro); + return; + end + EEGArray = [1:length(ALLEEG)]; + binArray = [1:ALLEEG(1).EVENTLIST.nbin]; + + eegcom = pop_eeg_save_trial_information(ALLEEG, 'EEGArray',EEGArray,'binArray',binArray,'History', 'gui'); + pause(0.01); + return +end + +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLEEG'); + +p.addParamValue('EEGArray', [], @isnumeric); % +p.addParamValue('binArray', [], @isnumeric); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLEEG, varargin{:}); +p_Results = p.Results; + +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + +BackERPLABcolor = [1 0.9 0.3]; % ERPLAB main window background +question = 'In order to see your summary, What would you like to do?'; +title = 'Artifact detection summary'; +oldcolor = get(0,'DefaultUicontrolBackgroundColor'); +set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) +button = questdlg(question, title,'Save in a .txt file','Save in a .xls file', 'Cancel','Cancel'); +set(0,'DefaultUicontrolBackgroundColor',oldcolor); + +if strcmpi(button,'Save in a .txt file') + write_spreadsheet=1; + formatname = {'*.txt'}; +elseif strcmpi(button,'Save in a .xls file') + write_spreadsheet=2; + formatname = {'*.xls';'*.xlsx'}; +else + return; +end + +ERPtooltype = erpgettoolversion('tooltype'); +if strcmpi(ERPtooltype,'EStudio') + pathstr= estudioworkingmemory('EEG_save_folder'); + if isempty(pathstr) + pathstr = pwd; + end +else + pathstr = pwd; +end + +namedef ='EEG_Trial_information'; +[erpfilename, erppathname, indxs] = uiputfile(formatname, ... + ['Export trial informationb for epoched EEG'],... + fullfile(pathstr,namedef)); +if isequal(erpfilename,0) + return +end +if isequal(erpfilename,0) + return +end + +[pathstr, erpfilename, ext] = fileparts(erpfilename) ; +if write_spreadsheet==1 + ext = '.txt'; +else + if indxs==1 + ext = '.xls'; + elseif indxs==2 + ext = '.xlsx'; + else + ext = '.xls'; + end +end + +erpFilename = char(strcat(erppathname,erpfilename,ext)); + +delete(erpFilename);%%delete the exist file + +qEEGArray = p_Results.EEGArray; +EEGArray = qEEGArray; +if isempty(qEEGArray) || any(qEEGArray(:)>length(ALLEEG)) || any(qEEGArray(:)<1) + qEEGArray = 1:length(ALLEEG); +end + +qbinArray = p_Results.binArray; +binArray = qbinArray; + +for Numoferp = 1:numel(qEEGArray) + + EEG = ALLEEG(qEEGArray(Numoferp)); + [EEG, tprej, acce, rej, histoflags, com] = pop_summary_AR_eeg_detection(EEG, 'none'); + ERP = pop_averager(EEG, 'Criterion', 'good', 'DSindex', 1, 'SEM', 'off'); + + if isempty(qbinArray) || any(qbinArray(:)>ERP.nbin) || any(qbinArray(:)<1) + qbinArray = [1:ERP.nbin]; + end + %%txt file + if write_spreadsheet==1 + if Numoferp==1 + fileID = fopen(erpFilename,'w+'); + end + fprintf(fileID,'%s\n','*'); + fprintf(fileID,'%s\n','**'); + columName1{1,1} = ['Name:',32,EEG.setname]; + fprintf(fileID,'%s\n\n\n',columName1{1,:}); + + %%Table title + formatSpec2 =['%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\n']; + columName2 = {'Bin', 'Total trials','Included trials', 'Rejected trials', 'Invalid trials','F2','F3','F4','F5','F6','F7','F8'}; + fprintf(fileID,formatSpec2,columName2{1,:}); + for ii = 1:length(qbinArray) + try + data{1,1} = [num2str(qbinArray(ii)),'.',ERP.bindescr{qbinArray(ii)}]; + data{1,2} = [num2str(ERP.ntrials.accepted(qbinArray(ii))+ERP.ntrials.rejected(qbinArray(ii))+ERP.ntrials.invalid(qbinArray(ii)))]; + data{1,3} = [num2str(ERP.ntrials.accepted(qbinArray(ii)))]; + data{1,4} = [num2str(ERP.ntrials.rejected(qbinArray(ii)))]; + data{1,5} = [num2str(ERP.ntrials.invalid(qbinArray(ii)))]; + data{1,6} = [num2str(histoflags(ii,2))];%%F2 + data{1,7} = [num2str(histoflags(ii,3))];%%F3 + data{1,8} = [num2str(histoflags(ii,4))]; + data{1,9} = [num2str(histoflags(ii,5))]; + data{1,10} = [num2str(histoflags(ii,6))]; + data{1,11} = [num2str(histoflags(ii,7))]; + data{1,12} = [num2str(histoflags(ii,8))]; + catch + data{1,1} = ''; + data{1,3} = ''; + data{1,4} = ''; + data{1,5} = ''; + data{1,6} = '';%%F2 + data{1,7} = '';%%F3 + data{1,8} = ''; + data{1,9} = ''; + data{1,10} = ''; + data{1,11} = ''; + data{1,12} = ''; + end + fprintf(fileID,formatSpec2,data{1,:}); + end + + if Numoferp~=length(ALLEEG) + data1{1,1} = ''; + data1{1,2} = ''; + data1{1,3} = ''; + data1{1,4} = ''; + data1{1,5} = ''; + data1{1,6} = '';%%F2 + data1{1,7} = '';%%F3 + data1{1,8} = ''; + data1{1,9} = ''; + data1{1,10} = ''; + data1{1,11} = ''; + data1{1,12} = ''; + formatSpec3 =['%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t','%s\n\n\n\n\n\n']; + fprintf(fileID,formatSpec3,data1{1,:}); + end + end + + %%xls file + if write_spreadsheet==2 + data = []; + binname = ''; + columName2 = {ERP.erpname,'Total trials','Included trials', 'Rejected trials', 'Invalid trials','F2','F3','F4','F5','F6','F7','F8'}; + for ii = 1:length(qbinArray) + try + data(ii,1) = [ERP.ntrials.accepted(qbinArray(ii))+ERP.ntrials.rejected(qbinArray(ii))+ERP.ntrials.invalid(qbinArray(ii))]; + data(ii,2) = [ERP.ntrials.accepted(qbinArray(ii))]; + data(ii,3) = [ERP.ntrials.rejected(qbinArray(ii))]; + data(ii,4) = [ERP.ntrials.invalid(qbinArray(ii))]; + data(ii,5) = histoflags(ii,2);%%F2 + data(ii,6) = histoflags(ii,3);%%F3 + data(ii,7) = histoflags(ii,4); + data(ii,8) = histoflags(ii,5); + data(ii,9) = histoflags(ii,6); + data(ii,10) = histoflags(ii,7); + data(ii,11) = histoflags(ii,8); + catch + data(ii,1) = []; + data(ii,2) = []; + data(ii,3) = []; + data(ii,4) = []; + data(ii,5) = [];%%F2 + data(ii,6) = [];%%F3 + data(ii,7) = []; + data(ii,8) = []; + data(ii,9) = []; + data(ii,10) = []; + data(ii,11) = []; + end + try + binname{ii,1} = ERP.bindescr{qbinArray(ii)}; + catch + binname{ii,1} = 'none'; + end + end + if Numoferp==1 + end + sheet_label_T = table(columName2); + sheetname = char(EEG.setname); + if length(sheetname)>31 + sheetname = sheetname(1:31); + end + writetable(sheet_label_T,erpFilename,'Sheet',Numoferp,'Range','A1','WriteVariableNames',false,'Sheet',sheetname,"AutoFitWidth",false); + xls_d = table(binname,data); + writetable(xls_d,erpFilename,'Sheet',Numoferp,'Range','A2','WriteVariableNames',false,'Sheet',sheetname,"AutoFitWidth",false); % write data + end +end + +if write_spreadsheet==1 + fclose(fileID); +end +disp(['A new file for trial information was created at ' erpFilename '']) + + +skipfields = {'ALLEEG', 'History'}; + +if isempty(EEGArray) + skipfields = [skipfields,{'EEGArray'}]; +end + +if isempty(binArray) + skipfields = [skipfields,{'binArray'}]; +end + +fn = fieldnames(p.Results); +eegcom = sprintf( 'eegcom = pop_eeg_save_trial_information( %s', 'ALLEEG'); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') && ~strcmpi(fn2res,'no') + eegcom = sprintf( '%s, ''%s'', ''%s''', eegcom, fn2com, fn2res); + end + else + eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, vect2colon(fn2res,'Repeat','on')); + end + end + end +end +eegcom = sprintf( '%s );', eegcom); + +% get history from script. ERP +switch shist + case 1 % from GUI + displayEquiComERP(eegcom); + case 2 % from script + for i=1:length(ALLEEG) + ALLEEG(i)= eegh(eegcom, ALLEEG(i)); + end + case 3 + + otherwise %off or none + eegcom = ''; + return +end + +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_ploteegset.m b/studio_functions/Functions/EStudio/EEG Tab/pop_ploteegset.m new file mode 100644 index 00000000..ad9e04d5 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_ploteegset.m @@ -0,0 +1,405 @@ +% PURPOSE: pop_ploteegset.m +% plot continuous/epoched EEG waves +% + + +%%FORMAT: +% [EEG, eegcom] = pop_ploteegset(EEG,'ChanArray',ChanArray,'ICArray',ICArray,'Winlength',Winlength,... +% 'Ampchan',Ampchan,'ChanLabel',ChanLabel,'Submean',Submean,'EventOnset',EventOnset,... +% 'StackFlag',StackFlag,'NormFlag',NormFlag,'Startimes',Startimes,'figureName',figureName,'figSize',figSize,'History', 'gui'); + + +% Inputs: +% +%EEG -EEGSET +%ChanArray -index(es) of channel(s) to plot ( 5 10 11 ...) +%ICArray -index(es) of IC(s) to plot (1 2 5 3...). Please set +% empty if you donot want to display ICs +%Winlength -the length of time-wondow to display the wave e.g., +% 5s for continuous EEG; For epoched EEG, it is the +% number of epochs, e.g., 5 epochs +%Ampchan -Verticl amplitude scales for chans e.g., 50 +%ChanLabel -display channel names or numbers. 1 is name and 0 is +% number +%Submean -remove DC? 1 (yes) or 0 (no) +%EventOnset -display events? 1(yes) or 0 (no) +%StackFlag -stack the waves for different channels or ics. 1 or 0 +%NormFlag -normalize the data? 1 or 0 +%Startimes -the start time for the dispalyed data e.g.,from 2nd s +%figureName - figure name +%figSize -width and height for the figure e.g., [1800 900] + + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% August 2023 + + + + +function [EEG,eegcom] = pop_ploteegset(EEG,varargin) + +eegcom = ''; +if nargin < 1 + help pop_ploteegset + return; +end + +if isempty(EEG)%% + beep; + disp('EEG is empty'); + return; +end + +if nargin==1 + %%Do we need to create a GUI that the user can use it to define the + %%desired parameters? + + %%channels that will be plotted + nbchan = EEG.nbchan; + ChanArray = 1:nbchan; + + %%display ICs + ICArray = []; + + %%window length for displayed EEG + Winlength=5; + + %%vertical voltage + Ampchan = 50; + Ampic = 20;%%vertical voltage for ICs + bufftobo = 100;%%buffer at top and bottom + %%channel name (1) or number (0) + ChanLabel = 1; + + %%remove DC for the displayed EEG? + Submean = 0; + + %%Display events if any? + EventOnset = 1; + + %%Stack on/off? + StackFlag = 0; + + %%Norm on/off? + NormFlag = 0; + + %%start time for displayed EEG data + if ndims(EEG.data) ==3 + Startimes=1; + else + Startimes=0; + end + + [ChanNum,Allsamples,tmpnb] = size(EEG.data); + Allsamples = Allsamples*tmpnb; + if ndims(EEG.data) > 2 + multiplier = size(EEG.data,2); + else + multiplier = EEG.srate; + end + + if isempty(Startimes) || Startimes<0 || Startimes>(ceil((Allsamples-1)/multiplier)-Winlength) + if ndims(EEG.data) ==3 + Startimes=1; + else + Startimes=0; + end + end + + %%figure name if any + figureName = EEG.setname; + %%Figure position + figSize = []; + + [EEG, eegcom] = pop_ploteegset(EEG,'ChanArray',ChanArray,'ICArray',ICArray,'Winlength',Winlength,'bufftobo',bufftobo,... + 'Ampchan',Ampchan,'Ampic',Ampic,'ChanLabel',ChanLabel,'Submean',Submean,'EventOnset',EventOnset,... + 'StackFlag',StackFlag,'NormFlag',NormFlag,'Startimes',Startimes,'figureName',figureName,'figSize',figSize,'History', 'gui'); + pause(0.1); + return; +end + +% +% Parsing inputs +% +% colordef = getcolorcellerps; %{'k' 'r' 'b' 'g' 'c' 'm' 'y' 'w'};% default colors +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('EEG'); + +%Option(s) +p.addParamValue('ChanArray',[],@isnumeric); +p.addParamValue('ICArray',[], @isnumeric); +p.addParamValue('Winlength',[], @isnumeric); +p.addParamValue('Ampchan',[], @isnumeric); +p.addParamValue('Ampic',[], @isnumeric); +p.addParamValue('bufftobo',[], @isnumeric); +p.addParamValue('ChanLabel',[], @isnumeric); +p.addParamValue('Submean',[], @isnumeric); +p.addParamValue('EventOnset',[], @isnumeric); +p.addParamValue('StackFlag',[], @isnumeric); +p.addParamValue('NormFlag',[], @isnumeric); +p.addParamValue('Startimes',[], @isnumeric); +p.addParamValue('figureName','', @ischar); +p.addParamValue('figSize',[], @isnumeric); + +p.addParamValue('ErrorMsg', '', @ischar); +p.addParamValue('History', '', @ischar); % history from scripting + + +p.parse(EEG,varargin{:}); + +p_Results = p.Results; + +if strcmpi(p_Results.History,'command') + shist = 4;%%Show Maltab command only and donot plot the wave +elseif strcmpi(p_Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p_Results.History,'script') + shist = 2; % script +elseif strcmpi(p_Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + +if strcmpi(p_Results.ErrorMsg,'popup') + errormsgtype = 1; % open popup window +else + errormsgtype = 0; % error in red at command window +end + +if isempty(EEG)%% + beep; + disp('EEG is empty'); + return; +end + + +%%channel array +qchanArray = p_Results.ChanArray; +nbchan = EEG.nbchan; +if ~isempty(qchanArray) + if min(qchanArray(:))>nbchan || max(qchanArray(:))>nbchan || min(qchanArray(:))<=0 + qchanArray = [1:nbchan]; + end +end + +%%IC array (the default is empty, that is, donot display ICs) +qICArray = p_Results.ICArray; +if isempty(EEG.icachansind) + qICArray = []; +else + if ~isempty(qICArray) && (min(qICArray(:))> numel(EEG.icachansind) || max(qICArray(:))> numel(EEG.icachansind) || min(qICArray(:))<=0) + qICArray = []; + end +end + + +%%the window length +qWinlength = p_Results.Winlength; +if ~isempty(qWinlength) && numel(qWinlength)~=1 + qWinlength = qWinlength(1); +end +if isempty(qWinlength) || numel(qWinlength)~=1 || min(qWinlength(:))<=0 + qWinlength=5; +end + +%%vertical amplitude scale for chans +qAmpchan = p_Results.Ampchan; +if ~isempty(qAmpchan) && numel(qAmpchan)~=1 + qAmpchan = qAmpchan(1); +end +if isempty(qAmpchan)|| qAmpchan<=0 + qAmpchan = 50; +end + + +%%vertical amplitude scale for ics +qAmpic = p_Results.Ampic; +if ~isempty(qAmpic) && numel(qAmpic)~=1 + qAmpic = qAmpic(1); +end +if isempty(qAmpic)|| qAmpic<=0 + qAmpic = 10; +end + +%%buffer at top and bottom +qbufftobo = p_Results.bufftobo; +if isempty(qbufftobo) || numel(qbufftobo)~=1 || any(qbufftobo(:)<=0) + qbufftobo = 100; +end + + + +%%channel with names (1) or numbers(0) +qChanLabel = p_Results.ChanLabel; +if ~isempty(qChanLabel) && numel(qChanLabel)~=1 + qChanLabel = qChanLabel(1); +end +if isempty(qChanLabel) || (qChanLabel~=0 && qChanLabel~=1) + qChanLabel =1; +end + + +%%remove DCs from the displayed EEG data? +qSubmean = p_Results.Submean; +if ~isempty(qSubmean) && numel(qSubmean)~=1 + qSubmean = qSubmean(1); +end +if isempty(qSubmean) || (qSubmean~=0 && qSubmean~=1) + qSubmean=0; +end + + +%%event onset or offset if any? +qEventOnset = p_Results.EventOnset; +if ~isempty(qEventOnset) && numel(qEventOnset)~=1 + qEventOnset = qEventOnset(1); +end +if isempty(qEventOnset) || (qEventOnset~=0 && qEventOnset~=1) + qEventOnset =1; +end + +%%stack on/off? +qStackFlag = p_Results.StackFlag; +if ~isempty(qStackFlag) && numel(qStackFlag)~=1 + qStackFlag = qStackFlag(1); +end +if isempty(qStackFlag) || (qStackFlag~=0 && qStackFlag~=1) + qStackFlag =1; +end + +%%normalization? +qNormFlag = p_Results.NormFlag; +if ~isempty(qNormFlag) && numel(qNormFlag)~=1 + qNormFlag = qNormFlag(1); +end +if isempty(qNormFlag) || (qNormFlag~=0 && qNormFlag~=1) + qNormFlag =1; +end + + +%%start time of the displayed EEG +qStartimes = p_Results.Startimes; +if ~isempty(qStartimes) && numel(qStartimes)~=1 + qStartimes = qStartimes(1); +end +[ChanNum,Allsamples,tmpnb] = size(EEG.data); +Allsamples = Allsamples*tmpnb; +if ndims(EEG.data) > 2 + multiplier = size(EEG.data,2); +else + multiplier = EEG.srate; +end + +if isempty(qStartimes) || qStartimes<0 || qStartimes>(ceil((Allsamples-1)/multiplier)-qWinlength) + if ndims(EEG.data) ==3 + qStartimes=1; + else + qStartimes=0; + end +end + + +%%figure name +qfigureName = p_Results.figureName; +if isempty(qfigureName) + qfigureName =EEG.setname; +end + +%%figure position +qfigSize = p_Results.figSize; +if ~isempty(qfigSize) && numel(qfigSize)~=2 + qfigSize = []; +end + +%%%%%%%%%%%%%%% +% insert the function that is to plot the EEG +if ~isempty(qfigureName) && shist~=4 + f_ploteegwave(EEG,qchanArray,qICArray,qWinlength,... + qAmpchan,qChanLabel,qSubmean,qEventOnset,qStackFlag,qNormFlag,qStartimes,... + qAmpic,qbufftobo,qfigSize,qfigureName) ; + +end + +%%history +fn = fieldnames(p.Results); +skipfields = {'EEG'}; +eegcom = sprintf( 'EEG = pop_ploteegset( %s', 'EEG'); + +for q=1:length(fn) + fn2com = fn{q}; % inputname + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); % input value + if ~isempty(fn2res) + if ischar(fn2res) + if strcmpi(fn2com,'History') && strcmpi(fn2res,'command') + fn2res = 'gui'; + end + if ~strcmpi(fn2res,'off') + eegcom = sprintf( '%s, ''%s'', ''%s''', eegcom, fn2com, fn2res); + end + elseif iscell(fn2res) + nn = length(fn2res); + eegcom = sprintf( '%s, ''%s'', {''%s'' ', eegcom, fn2com, fn2res{1}); + for ff=2:nn + eegcom = sprintf( '%s, ''%s'' ', eegcom, fn2res{ff}); + end + eegcom = sprintf( '%s}', eegcom); + elseif isnumeric(fn2res) + if ~ismember_bc2(fn2com,{'LineColor','GridSpace','GridposArray'}) + eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, vect2colon(fn2res,'Repeat','on')); + else + if size(fn2res,1)==1 + fn2res_trans = char(num2str(fn2res)); + else + fn2res_trans = char(num2str(fn2res(1,:))); + for ii = 2:size(fn2res,1) + fn2res_trans = char(strcat(fn2res_trans,';',num2str(fn2res(ii,:)))); + end + end + fn2res = fn2res_trans; + eegcom = sprintf( '%s, ''%s'', [%s', eegcom,fn2com,fn2res); + eegcom = sprintf( '%s]', eegcom); + end + + else + % if ~ismember_bc2(fn2com,{'xscale','yscale'}) + % eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, vect2colon(fn2res,'Repeat','on')); + % else + % xyscalestr = sprintf('[ %.1f %.1f %s ]', fn2res(1), fn2res(2), vect2colon(fn2res(3:end),'Delimiter','off')); + % eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, xyscalestr); + % end + end + end + end +end + + +eegcom = sprintf( '%s );', eegcom); +% get history from script. ERP +% shist = 1; +switch shist + case 1 % from GUI + displayEquiComERP(eegcom); + case 2 % from script + EEG = eegh(eegcom, EEG); + case 3 + % implicit + case 4 + displayEquiComERP(eegcom); + otherwise %off or none + eegcom = ''; + return +end + + + +return; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_rename2chan.m b/studio_functions/Functions/EStudio/EEG Tab/pop_rename2chan.m new file mode 100644 index 00000000..ade149fc --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_rename2chan.m @@ -0,0 +1,272 @@ +% PURPOSE: pop_rename2chan.m is to change the channel names +% +% + +% FORMAT : +% +% pop_rename2chan(ALLEEG, CURRENTSET, parameters); +% + +% ALLEEG - structure array of EEG structures +% CURRENTSET - Index for current EEGset + + + +% The available parameters are as follows: +% +%ChanArray -index(es) for the selected channels +%Chanlabels - new names for the selected channels + + + +%%Output +%%EEG -EEG structure with the changed names of the selected channels + + +%%Example: +%EEG = pop_rename2chan( ALLEEG, 2, 'ChanArray', [1 2 3], 'Chanlabels', {'FP1-1' , 'F3-2' , 'F7-3' }, 'History', 'implicit' ); + + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + + +function [EEG,eegcom] = pop_rename2chan(ALLEEG,CURRENTSET,varargin) + +eegcom = ''; +if nargin < 1 + help pop_rename2chan + return; +end + +if isempty(ALLEEG)%% + beep; + disp('ALLEEG is empty'); + return; +end + +if nargin< 3 + %%Do we need to create a GUI that the user can use it to define the + %%desired parameters? + + if nargin< 2 || isempty(CURRENTSET) || numel(CURRENTSET)~=1 || CURRENTSET>length(ALLEEG) || CURRENTSET<=0 + CURRENTSET = length(ALLEEG); + end + EEG = ALLEEG(CURRENTSET); + if ~isfield(EEG,'chanlocs') + beep; + disp('The current dataset donot have chanlocs field'); + return; + end + chanlocs = EEG.chanlocs; + if ~isfield(chanlocs,'labels') + beep; + disp('There is no labels for chanlocs for the current dataset'); + return; + end + + ChanArray = [1:length(EEG.chanlocs)]; + [eloc, Chanlabelsold, theta, radius, indices] = readlocs( chanlocs); + + + def = erpworkingmemory('pop_rename2chan'); + if isempty(def) + def = Chanlabelsold; + end + erplab_studio_default_values; + version = erplabstudiover; + titleName= ['Dataset',32,num2str(CURRENTSET),': ERPLAB',32,num2str(version), 32,'Change Channel Name']; + Chanlabelsnew= f_change_chan_name_GUI(Chanlabelsold,def,titleName); + + if isempty(Chanlabelsnew) + return + end + erpworkingmemory('pop_rename2chan',Chanlabelsnew); + %%add suffix + try + ALLEEG(CURRENTSET).setname = [ALLEEG(CURRENTSET).setname,'_rnchan']; + catch + ALLEEG(CURRENTSET).erpname = [ALLEEG(CURRENTSET).erpname,'_rnchan']; + end + [EEG, eegcom] = pop_rename2chan(ALLEEG,CURRENTSET,'ChanArray',ChanArray,'Chanlabels',Chanlabelsnew,'History', 'gui'); + pause(0.1); + return; +end + + +% +% Parsing inputs +% +% colordef = getcolorcellerps; %{'k' 'r' 'b' 'g' 'c' 'm' 'y' 'w'};% default colors +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLEEG'); +p.addRequired('CURRENTSET'); + +%Option(s) +p.addParamValue('ChanArray',[],@isnumeric); +p.addParamValue('Chanlabels','', @iscell); + +p.addParamValue('History', '', @ischar); % history from scripting + +p.parse(ALLEEG,CURRENTSET,varargin{:}); + +p_Results = p.Results; + +if strcmpi(p_Results.History,'command') + shist = 4;%%Show Maltab command only and donot plot the wave +elseif strcmpi(p_Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p_Results.History,'script') + shist = 2; % script +elseif strcmpi(p_Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + +if isempty(ALLEEG)%% + beep; + disp('ALLEEG is empty'); + return; +end + + +if isempty(CURRENTSET) || numel(CURRENTSET)~=1 || CURRENTSET>length(ALLEEG) || CURRENTSET<=0 + CURRENTSET = length(ALLEEG); +end + +EEG = ALLEEG(CURRENTSET); +if ~isfield(EEG,'chanlocs') + beep; + disp('The current dataset donot have chanlocs field'); + return; +end +chanlocs = EEG.chanlocs; +if ~isfield(chanlocs,'labels') + beep; + disp('There is no labels for chanlocs for the current dataset'); + return; +end + + +%%channel array +qchanArray = p_Results.ChanArray; +nbchan = length(EEG.chanlocs); +if isempty(qchanArray) || min(qchanArray(:))>nbchan || max(qchanArray(:))>nbchan || min(qchanArray(:))<=0 + qchanArray = [1:nbchan]; +end + + + +%%IC array (the default is empty, that is, donot display ICs) +qChanlabelsnew = p_Results.Chanlabels; +if isempty(qChanlabelsnew) + disp('Chanlabels is empty'); + return; +end + +% +%%adjust the number of channels and channel names +for Numofchan = 1:numel(qchanArray) + try + if isempty(char(qChanlabelsnew{Numofchan})) + qChanlabelsnew{Numofchan,1} = EEG.chanlocs(qchanArray(Numofchan)).labels; + fprintf(2,['\n Warning: name for channel ',32,num2str(qchanArray(Numofchan)),32,' was empty, we threfore used its original name',32,qChanlabelsnew{Numofchan,1},'.\n']); + else + qChanlabelsnew{Numofchan,1} = char(qChanlabelsnew{Numofchan}); + end + catch + qChanlabelsnew{Numofchan,1} = EEG.chanlocs(qchanArray(Numofchan)).labels; + fprintf(2,['\n Warning: name for channel ',32,num2str(qchanArray(Numofchan)),32,'was not defined, we threfore used its original name',32,qChanlabelsnew{Numofchan,1},'.\n']); + end +end + + +%%--------------change the channel names----------------------------------- +for Numofchan = 1:numel(qchanArray) + fprintf(['Chan',32,num2str(qchanArray(Numofchan)),':',32,EEG.chanlocs(qchanArray(Numofchan)).labels,32,'was changed to',32,qChanlabelsnew{Numofchan,1},'.\n']); + EEG.chanlocs(qchanArray(Numofchan)).labels = char(qChanlabelsnew{Numofchan,1}); +end + + + +%%history +fn = fieldnames(p.Results); +skipfields = {'ALLEEG','CURRENTSET'}; +if isfield(EEG,'datatype') && strcmpi(EEG.datatype,'ERP') + eegcom = sprintf( 'ERP = pop_rename2chan( %s %s', 'ALLERP,',num2str(CURRENTSET)); +else +eegcom = sprintf( 'EEG = pop_rename2chan( %s %s', 'ALLEEG,',num2str(CURRENTSET)); +end +for q=1:length(fn) + fn2com = fn{q}; % inputname + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); % input value + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + eegcom = sprintf( '%s, ''%s'', ''%s''', eegcom, fn2com, fn2res); + end + elseif iscell(fn2res) + nn = length(fn2res); + eegcom = sprintf( '%s, ''%s'', {''%s'' ', eegcom, fn2com, fn2res{1}); + for ff=2:nn + eegcom = sprintf( '%s, ''%s'' ', eegcom, fn2res{ff}); + end + eegcom = sprintf( '%s}', eegcom); + elseif isnumeric(fn2res) + + if size(fn2res,1)==1 + fn2res_trans = char(num2str(fn2res)); + else + fn2res_trans = char(num2str(fn2res(1,:))); + for ii = 2:size(fn2res,1) + fn2res_trans = char(strcat(fn2res_trans,';',num2str(fn2res(ii,:)))); + end + end + fn2res = fn2res_trans; + eegcom = sprintf( '%s, ''%s'', [%s', eegcom,fn2com,fn2res); + eegcom = sprintf( '%s]', eegcom); + else + % if ~ismember_bc2(fn2com,{'xscale','yscale'}) + % eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, vect2colon(fn2res,'Repeat','on')); + % else + % xyscalestr = sprintf('[ %.1f %.1f %s ]', fn2res(1), fn2res(2), vect2colon(fn2res(3:end),'Delimiter','off')); + % eegcom = sprintf( '%s, ''%s'', %s', eegcom, fn2com, xyscalestr); + % end + end + end + end +end + +eegcom = sprintf( '%s );', eegcom); +% get history from script. ERP +% shist = 1; +switch shist + case 1 % from GUI + displayEquiComERP(eegcom); + case 2 % from script + for i=1:length(ALLEEG) + ALLEEG(i) = erphistory(ALLEEG(i), [], eegcom, 1); + end + case 3 + % implicit + case 4 + displayEquiComERP(eegcom); + + otherwise %off or none + eegcom = ''; + return +end + +return; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_renameeg.m b/studio_functions/Functions/EStudio/EEG Tab/pop_renameeg.m new file mode 100644 index 00000000..b011f3ce --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_renameeg.m @@ -0,0 +1,180 @@ +% PURPOSE: pop_renameeg.m +% rename ALLEEGset +% + +% FORMAT: +% [ALLEEG, erpcom] = pop_renameeg( ALLEEG, 'eegnames',eegnames,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ALLEEG -ALLEEG structure +%eegnames -strings for erpsets + + + +% *** This function is part of ALLEEGLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2024 + + + + +function [ALLEEG, erpcom] = pop_renameeg(ALLEEG, varargin) +erpcom = ''; + +if nargin < 1 + help pop_renameeg + return +end +if isempty(ALLEEG) + msgboxText = 'Cannot rename an empty EEGset'; + title = 'ERPLAB: pop_renameeg() error'; + errorfound(msgboxText, title); + return +end +if isempty(ALLEEG(1).data) + msgboxText = 'Cannot rename an empty EEGset'; + title = 'ERPLAB: pop_renameeg() error'; + errorfound(msgboxText, title); + return +end + + + +if nargin==1 + + app = feval('EEG_Tab_rename_gui',ALLEEG,1:length(ALLEEG)); + waitfor(app,'Finishbutton',1); + try + eegnames = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + if isempty(eegnames) + return; + end + % + % Somersault + % + [ALLEEG, erpcom] = pop_renameeg( ALLEEG, 'eegnames',eegnames,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLEEG'); +% option(s) +p.addParamValue('eegnames', '',@iscell); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLEEG, varargin{:}); + + +eegnames = p.Results.eegnames; +if ischar(eegnames) && numel(ALLEEG)==1 + ALLEEG.erpname = eegnames; + ALLEEG.saved = 'no'; +elseif iscell(eegnames) + for Numoferp = 1:numel(ALLEEG) + newName = eegnames{Numoferp}; + [~, newName, ~] = fileparts(newName) ; + if ~isempty(newName) + ALLEEG(Numoferp).setname = newName; + ALLEEG(Numoferp).saved = 'no'; + else + ALLEEG(Numoferp).saved = 'no'; + end + end +end + + + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + + +% +% History +% + +skipfields = {'ALLEEG', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_renameeg( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', {''%s'' ', erpcom, fn2com, fn2res{1}); + end + else + if iscell(fn2res) + nn = length(fn2res); + erpcom = sprintf( '%s, ''%s'', {''%s'' ', erpcom, fn2com, fn2res{1}); + for ff=2:nn + erpcom = sprintf( '%s, ''%s'' ', erpcom, fn2res{ff}); + end + erpcom = sprintf( '%s}', erpcom); + end + + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ALLEEGset from GUI +% +if issaveas + for ii = 1:length(ALLEEG) + [ALLEEG(ii), ~] = pop_saveset( ALLEEG(ii), 'filename',ALLEEG(ii).filename,'filepath',[ALLEEG(ii).filepath,filesep]); + end +end + + + +% get history from script. ALLEEG +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for ii = 1:length(ALLEEG) + ALLEEG(ii) = eegh(erpcom, ALLEEG(ii)); + end + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_resampleeg.m b/studio_functions/Functions/EStudio/EEG Tab/pop_resampleeg.m new file mode 100644 index 00000000..2774884a --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_resampleeg.m @@ -0,0 +1,306 @@ +% PURPOSE: pop_resampleeg.m +% resample ERPsets +% + +% FORMAT: +% [EEG, LASTCOM] = pop_resamplerp( EEG, 'Freq2resamp',Freq2resamp, 'TimeRange',TimeRange,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%EEG -EEG structure +%Freq2resamp -new sampling rate e.g., 200 Hz +%TimeRange -new time range e.g., [-300 900]ms + + +%%We used some functions from EEGlab in this routine + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Mar. 2024 + +function [EEG, LASTCOM] = pop_resampleeg(EEG, varargin) +LASTCOM = ''; + +if nargin < 1 + help pop_resampleeg + return +end +if isempty(EEG) + msgboxText = 'Cannot resample an empty eegset'; + title = 'ERPLAB: pop_resampleeg() error'; + errorfound(msgboxText, title); + return +end +if isempty(EEG(1).data) + msgboxText = 'Cannot resample an empty EEGset'; + title = 'ERPLAB: pop_resampleeg() error'; + errorfound(msgboxText, title); + return +end + +if EEG(1).trials==1 + msgboxText = 'Cannot resample continous EEGset'; + title = 'ERPLAB: pop_resampleeg() error'; + errorfound(msgboxText, title); + return +end + +if nargin==1 + + Freq2resamp = EEG.srate; + TimeRange = [EEG.times(1),EEG.times(end)]; + % + % Somersault + % + [EEG, LASTCOM] = pop_resampleeg( EEG, 'Freq2resamp',Freq2resamp, 'TimeRange',TimeRange,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('EEG'); +% option(s) +p.addParamValue('Freq2resamp', [],@isnumeric); +p.addParamValue('TimeRange', [], @isnumeric); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(EEG, varargin{:}); + +Freq2resamp = p.Results.Freq2resamp; +if isempty(Freq2resamp) || numel(Freq2resamp)~=1 || any(Freq2resamp<=0) + Freq2resamp = EEG.srate; +end + +TimeRange= p.Results.TimeRange; +TimeRange = unique(TimeRange); +if isempty(TimeRange) || numel(TimeRange)~=2 || TimeRange(1)>=EEG.times(end) || TimeRange(2)<=EEG.times(1) + TimeRange = [EEG.times(1),EEG.times(end)]; +end +if TimeRange(1)>=0 + msgboxText = ['The left number of the new time range should be smaller than 0']; + title = 'ERPLAB: pop_resampleeg() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + +if TimeRange(2)<=0 + msgboxText = ['The right number of the new time range should be larger than 0']; + title = 'ERPLAB: pop_resampleeg() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + + +latency0_old = 1-(EEG.xmin*EEG.srate); % time 0 point +alllatencies_old = linspace( latency0_old, EEG.pnts*(EEG.trials-1)+latency0_old, EEG.trials); + + +%%-------------------------adjust the left edge---------------------------- +if roundn(TimeRange(1),-2)>= roundn(EEG.times(1),-2) + [xxx, latsamp, latdiffms] = closest(EEG.times, TimeRange(1)); + EEG.times = EEG.times(latsamp:end); + EEG.xmin = EEG.times(1)/1000; + EEG.data = EEG.data(:,latsamp:end,:); +else + TimesNew = EEG.times; + timeint = 1000/EEG.srate; + count=0; + for ii=1:10000 + timeStart = TimesNew(1)-timeint; + if timeStart>=TimeRange(1) + count = count+1; + TimesNew = [timeStart,TimesNew]; + else + break; + end + end + if count~=0 + EEG.times = TimesNew; + EEG.xmin = EEG.times(1)/1000; + datadd= zeros(size(EEG.data,1),count); + for ii = 1:size(EEG.data,3) + newdata(:,:,ii) = [datadd,squeeze(EEG.data(:,:,ii))]; + end + EEG.data = newdata; + end +end +%%-------------------------adjust the right edge--------------------------- +if roundn(TimeRange(2),-2)<= roundn(EEG.times(end),-2) + [xxx, latsamp, latdiffms] = closest(EEG.times, TimeRange(2)); + EEG.times = EEG.times(1:latsamp); + EEG.xmax = EEG.times(end)/1000; + EEG.data = EEG.data(:,1:latsamp,:); +else + TimesNew = EEG.times; + timeint = 1000/EEG.srate; + count=0; + for ii=1:10000 + timend = TimesNew(end)+timeint; + if timend<=TimeRange(2) + count = count+1; + TimesNew = [TimesNew,timend]; + else + break; + end + end + if count~=0 + newdata = []; + EEG.times = TimesNew; + EEG.xmax = EEG.times(end)/1000; + datadd= zeros(size(EEG.data,1),count); + for ii = 1:size(EEG.data,3) + newdata(:,:,ii) = [squeeze(EEG.data(:,:,ii)),datadd]; + end + EEG.data = newdata; + end +end + +count = 0; +check_left = []; +for ii = 1:numel(EEG.times) + if roundn(EEG.times(ii),-2)< roundn(TimeRange(1),-2) || roundn(EEG.times(ii),-2)> roundn(TimeRange(2),-2) + count = count+1; + check_left(count) = ii; + end +end +EEG.data(:,check_left,:) =[]; +EEG.times(check_left) = []; +EEG.pnts = size(EEG.data,2); +EEG.xmax = EEG.times(end)/1000; +EEG.xmin = EEG.times(1)/1000; + + +%%Adjust events +latency0_new = 1-(EEG.xmin*EEG.srate); % time 0 point +alllatencies_new = linspace( latency0_new, EEG.pnts*(EEG.trials-1)+latency0_new, EEG.trials); +Latency_all = []; +for Numofevent = 1:length( EEG.event) + epochindex(Numofevent,1) = EEG.event(Numofevent).epoch; + Latency_all(Numofevent,1) = EEG.event(Numofevent).latency; +end +%%adjust event latency +count = 0; +eventrm = []; +for Numoftrial = 1:EEG.trials + [xpos,ypos]= find(epochindex==Numoftrial); + count1= 0; + eventrm_epoch = []; + Latency_single= Latency_all(xpos); + Latency_single = Latency_single-alllatencies_old(Numoftrial); + for ii = 1:numel(xpos) + EEG.event(xpos(ii)).latency = Latency_single(ii)+alllatencies_new(Numoftrial);%%update latency for each epoch + if (EEG.event(xpos(ii)).latency-alllatencies_new(Numoftrial))<(1-latency0_new) || (EEG.event(xpos(ii)).latency-alllatencies_new(Numoftrial))>(numel(EEG.times)-latency0_new) + count = count+1; + eventrm(count) = xpos(ii);%%remove event exceeds the epoch + end + end +end +EEG.event(eventrm) = []; +EEG.urevent = []; +EEG = eeg_checkset(EEG, 'eventconsistency'); +% EEG = eeg_checkset(EEG,'epochconsist'); +%%resampling data based on eeglab routine +if EEG.srate~=Freq2resamp + setnameold = EEG.setname; + EEG = pop_resample( EEG, Freq2resamp); + EEG.setname = setnameold; +end +EEG = eeg_checkset(EEG); + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end +EEG.saved = 'no'; +EEG = eeg_checkset(EEG); +% +% History +% +% +% Completion statement +% +% msg2end + +% +% History +% + +skipfields = {'EEG', 'Saveas','History'}; +fn = fieldnames(p.Results); +LASTCOM = sprintf( '%s = pop_resampleeg( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + LASTCOM = sprintf( '%s, ''%s'', ''%s''', LASTCOM, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + LASTCOM = sprintf( ['%s, ''%s'', ' fnformat], LASTCOM, fn2com, fn2resstr); + end + else + LASTCOM = sprintf( ['%s, ''%s'', ' fnformat], LASTCOM, fn2com, fn2resstr); + end + end + end + end +end +LASTCOM = sprintf( '%s );', LASTCOM); + +% Save ERPset from GUI +% +if issaveas + [EEG, LASTCOM1] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM1, EEG); +end + +% get history from script. ERP +switch shist + case 1 % from GUI + displayEquiComERP(LASTCOM); + case 2 % from script + EEG = eegh(LASTCOM, EEG); + case 3 + % implicit + otherwise %off or none + LASTCOM = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/EEG Tab/pop_suffixeeg.m b/studio_functions/Functions/EStudio/EEG Tab/pop_suffixeeg.m new file mode 100644 index 00000000..27efe298 --- /dev/null +++ b/studio_functions/Functions/EStudio/EEG Tab/pop_suffixeeg.m @@ -0,0 +1,165 @@ +% PURPOSE: pop_suffixeeg.m +% add suffix to ALLEEG names +% + +% FORMAT: +% [ALLEEG, erpcom] = pop_suffixeeg( ALLEEG, 'suffixstr',suffixstr,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ALLEEG -ALLEEG structure +%suffixstr -strings for erpsets + + + +% *** This function is part of ALLEEGLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2024 + + + + +function [ALLEEG, erpcom] = pop_suffixeeg(ALLEEG, varargin) +erpcom = ''; + +if nargin < 1 + help pop_suffixeeg + return +end +if isempty(ALLEEG) + msgboxText = 'Cannot rename an empty EEGset'; + title = 'ERPLAB: pop_suffixeeg() error'; + errorfound(msgboxText, title); + return +end +if isempty(ALLEEG(1).data) + msgboxText = 'Cannot rename an empty EEGset'; + title = 'ERPLAB: pop_suffixeeg() error'; + errorfound(msgboxText, title); + return +end + + +if nargin==1 + + suffixstr = f_EEG_suffix_gui('Suffix'); + + if isempty(suffixstr) + return; + end + % + % Somersault + % + [ALLEEG, erpcom] = pop_suffixeeg( ALLEEG, 'suffixstr',suffixstr,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLEEG'); +% option(s) +p.addParamValue('suffixstr', '',@ischar); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLEEG, varargin{:}); + + + +suffixstr = p.Results.suffixstr; + +for Numoferp = 1:numel(ALLEEG) + ALLEEG(Numoferp).setname = [ALLEEG(Numoferp).setname,'_',suffixstr]; + ALLEEG(Numoferp).saved = 'no'; + +end + + + + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + + +% +% History +% + +skipfields = {'ALLEEG', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_suffixeeg( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s'' ', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + nn = length(fn2res); + erpcom = sprintf( '%s, ''%s'', {''%s'' ', erpcom, fn2com, fn2res{1}); + for ff=2:nn + erpcom = sprintf( '%s, ''%s'' ', erpcom, fn2res{ff}); + end + erpcom = sprintf( '%s}', erpcom); + end + + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ALLEEGset from GUI +% +if issaveas + for ii = 1:length(ALLEEG) + [ALLEEG(ii), ~] = pop_saveset( ALLEEG(ii), 'filename',ALLEEG(ii).filename,'filepath',[ALLEEG(ii).filepath,filesep]); + end +end + + + +% get history from script. ALLEEG +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for ii = 1:length(ALLEEG) + ALLEEG(ii) = eegh(erpcom, ALLEEG(ii)); + end + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERPLAB_ERP_Viewer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERPLAB_ERP_Viewer.m index 2404bd3a..0024cd83 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERPLAB_ERP_Viewer.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERPLAB_ERP_Viewer.m @@ -1,7 +1,6 @@ - -% New ERP viewer GUI Layout - Simple ERP viewer 0.014 +% New ERP viewer GUI Layout % -% Author: Guanghui Zhang & Steve J. Luck & Andrew Stewart +% Author: Guanghui Zhang & Steve J. Luck % Center for Mind and Brain % University of California, Davis, % Davis, CA @@ -36,14 +35,20 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Parameterfile) tic;% -disp(' ERP Waveform Viewer is launching...'); +disp('ERP Waveform Viewer is launching. Please be patient...'); +EStudioversion = geterplabeversion; global viewer_ERPDAT; global gui_erp_waviewer; ERPtooltype = erpgettoolversion('tooltype'); -% global observe_ERPDAT; -% if ~strcmpi(ERPtooltype,'EStudio') + +%%try to close existing Viewer +try + close(gui_erp_waviewer.Window);%%close previous GUI if exists +catch +end + viewer_ERPDAT = v_ERPDAT; % end % addlistener(observe_ERPDAT,'erpschange',@allErpChanged); @@ -58,21 +63,6 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete observe_ERPDAT.Count_currentERP = 0; observe_ERPDAT.Process_messg = 0; end -try - close(EStudio_gui_erp_totl.Window); -catch -end - -if exist('memoryerpstudiopanels.erpm','file')==2 - iserpmem = 1; % file for memory exists -else - iserpmem = 0; % does not exist file for memory -end -if iserpmem==0 - p1 = which('o_ERPDAT'); - p1 = p1(1:findstr(p1,'o_ERPDAT.m')-1); - save(fullfile(p1,'memoryerpstudiopanels.erpm'),'ERPtooltype') -end @@ -81,10 +71,15 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete else iserpmem = 0; % does not exist file for memory end + + if iserpmem==0 - p1 = which('o_ERPDAT'); - p1 = p1(1:findstr(p1,'o_ERPDAT.m')-1); - save(fullfile(p1,'memoryerpstudio.erpm'),'ERPtooltype') + mshock = 0; + if iserpmem==0 + p1 = which('o_ERPDAT'); + p1 = p1(1:findstr(p1,'o_ERPDAT.m')-1); + save(fullfile(p1,'memoryerpstudio.erpm'),'EStudioversion') + end end @@ -167,23 +162,13 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete return; end -erpworkingmemory('ERPLAB_ERPWaviewer',0);%%Update the Viewer based on the changes in ERPLAB -% if ~strcmpi(ERPtooltype,'EStudio') -% addlistener(viewer_ERPDAT,'count_loadproper_change',@count_loadproper_change); -% addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); -% addlistener(viewer_ERPDAT,'v_messg_change',@V_messg_change); -% addlistener(viewer_ERPDAT,'count_legend_change',@count_legend_change); -% addlistener(viewer_ERPDAT,'page_xyaxis_change',@page_xyaxis_change); -% % end - +estudioworkingmemory('ERPLAB_ERPWaviewer',0);%%Update the Viewer based on the changes in ERPLAB viewer_ERPDAT.Count_currentERP = 0; % viewer_ERPDAT.Process_messg = 0;%0 is the default means there is no message for processing procedure; %1 means the processign procedure is running %2 means the processign procedure is done %3 means there are some errors for processing procedure -viewer_ERPDAT.count_legend=0;%% this is to capture the changes of legend name -viewer_ERPDAT.page_xyaxis=0;%%get the changes of x/y axis based on the changed pages or selected ERPsets viewer_ERPDAT.loadproper_count = 0; viewer_ERPDAT.Process_messg = 0; viewer_ERPDAT.count_twopanels = 0;%% Automaticlly saving the changes on the other panel if the current panel is changed @@ -199,8 +184,7 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete try test = uix.HBoxFlex(); catch - beep; - disp('The GUI Layout Toolbox might not be installed. Quitting') + disp('The GUI Layout Toolbox might not be included. Please download it from:https://www.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox') return end @@ -214,38 +198,43 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete estudioworkingmemory('MyViewer_linelegend',0); estudioworkingmemory('MyViewer_other',0); -ERPwaviewer.ALLERP =ALLERP; -ERPwaviewer.ERP = ALLERP(selectedERP_index(end)); -ERPwaviewer.CURRENTERP =selectedERP_index(end); -ERPwaviewer.SelectERPIdx =selectedERP_index; -ERPwaviewer.bin = binArray; -ERPwaviewer.chan = chanArray; -ERPwaviewer.binchan_op = 1;%% 1. Auto; 2.Custom - -ERPwaviewer.plot_org.Grid = 1; %1.Channels; 2.Bins; 3. ERPsets; 4. None -ERPwaviewer.plot_org.Overlay = 2; %1.Channels; 2.Bins; 3. ERPsets; 4. None -ERPwaviewer.plot_org.Pages = 3; %1.Channels; 2.Bins; 3. ERPsets; 4. None -ERPwaviewer.plot_org.gridlayout.op = 1; %1.Auto; 2. Custom -ERPwaviewer.plot_org.gridlayout.data = []; -ERPwaviewer.Lines = []; -ERPwaviewer.Legend = []; -ERPwaviewer.xaxis = []; -ERPwaviewer.yaxis = []; -ERPwaviewer.polarity = []; -ERPwaviewer.SEM = []; -ERPwaviewer.PageIndex = 1; -ERPwaviewer.baselinecorr = 'none'; -ERPwaviewer.chanbinsetlabel = []; -ERPwaviewer.figbackgdcolor = [1 1 1]; -ERPwaviewer.figname = 'My Viewer'; -ERPwaviewer.FigOutpos=[]; -assignin('base','ALLERPwaviewer',ERPwaviewer); - -% estudioworkingmemory('zoomSpace',0);%%sett for zoom in and zoom out +gui_erp_waviewer.ERPwaviewer.ALLERP =ALLERP; +gui_erp_waviewer.ERPwaviewer.ERP = ALLERP(selectedERP_index(end)); try - close(gui_erp_waviewer.Window);%%close previous GUI if exists + CURRENTERP = evalin('base','CURRENTERP'); catch + CURRENTERP = numel(selectedERP_index); +end +gui_erp_waviewer.ERPwaviewer.CURRENTERP =CURRENTERP; +[xpos,ypos] = find(selectedERP_index==CURRENTERP); +if ~isempty(ypos) + gui_erp_waviewer.ERPwaviewer.PageIndex =ypos; +else + gui_erp_waviewer.ERPwaviewer.PageIndex=numel(selectedERP_index); end +gui_erp_waviewer.ERPwaviewer.SelectERPIdx =selectedERP_index; +gui_erp_waviewer.ERPwaviewer.bin = binArray; +gui_erp_waviewer.ERPwaviewer.chan = chanArray; +gui_erp_waviewer.ERPwaviewer.binchan_op = 1;%% 1. Auto; 2.Custom + +gui_erp_waviewer.ERPwaviewer.plot_org.Grid = 1; %1.Channels; 2.Bins; 3. ERPsets; 4. None +gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = 2; %1.Channels; 2.Bins; 3. ERPsets; 4. None +gui_erp_waviewer.ERPwaviewer.plot_org.Pages = 3; %1.Channels; 2.Bins; 3. ERPsets; 4. None +gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op = 1; %1.Auto; 2. Custom +gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data = []; +gui_erp_waviewer.ERPwaviewer.Lines = []; +gui_erp_waviewer.ERPwaviewer.Legend = []; +gui_erp_waviewer.ERPwaviewer.xaxis = []; +gui_erp_waviewer.ERPwaviewer.yaxis = []; +gui_erp_waviewer.ERPwaviewer.polarity = []; +gui_erp_waviewer.ERPwaviewer.SEM = []; +gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; +gui_erp_waviewer.ERPwaviewer.chanbinsetlabel = []; +gui_erp_waviewer.ERPwaviewer.figbackgdcolor = [1 1 1]; +gui_erp_waviewer.ERPwaviewer.figname = 'My Viewer'; +gui_erp_waviewer.ERPwaviewer.FigOutpos=[]; +% +% estudioworkingmemory('zoomSpace',0);%%sett for zoom in and zoom out createInterface_ERPWave_viewer(ERPtooltype); @@ -263,23 +252,19 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete set(0,'DefaultUicontrolBackgroundColor',oldcolor); if strcmpi(button,'Yes') - ERPwaviewerdef = evalin('base','ALLERPwaviewer'); - Parameterfile.ALLERP= ERPwaviewerdef.ALLERP; - Parameterfile.ERP = ERPwaviewerdef.ERP; + Parameterfile.ALLERP= gui_erp_waviewer.ERPwaviewer.ALLERP; + Parameterfile.ERP = gui_erp_waviewer.ERPwaviewer.ERP; else if strcmpi(button,'No') - beep; viewer_ERPDAT.Process_messg =3; fprintf(2,'\n\n My viewer > ERPLAB_ERP_Viewer: \n Cannot use the file because no ALLERP can be used.\n\n'); else - beep viewer_ERPDAT.Process_messg =3; fprintf(2,'\n\n My viewer > ERPLAB_ERP_Viewer: \n User selected cancel.\n\n'); end return; end end - assignin('base','ALLERPwaviewer',Parameterfile); viewer_ERPDAT.loadproper_count = 1; f_redrawERP_viewer_test(); end @@ -287,58 +272,56 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete fprintf([32,'It took',32,num2str(timeElapsed),'s to launch ERP Waveform Viewer.\n\n']); function createInterface_ERPWave_viewer(ERPtooltype); + try + erplabstudiover = num2str(geterplabeversion); + catch + erplabstudiover = '??'; + end + if strcmpi(ERPtooltype,'EStudio') - try - [version reldate] = geterplabstudioversion; - erplabstudiover = version; - catch - erplabstudiover = '??'; - end - currvers = ['ERPLAB Studio ' erplabstudiover,'- My Viewer']; else - try - [version reldate] = geterplabversion; - erplabstudiover = version; - catch - erplabstudiover = '??'; - end - currvers = ['ERPLAB ' erplabstudiover,'- My Viewer']; end estudioworkingmemory('viewername','My Viewer'); try [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; catch - ColorBviewer_def = [0.7765,0.7294,0.8627]; + ColorBviewer_def = [0.8 0.8 0.9]; end - % gui_erp_waviewer = struct(); - % First, let's start the window + gui_erp_waviewer.Window = figure( 'Name', currvers, ... 'NumberTitle', 'off', ... 'MenuBar', 'none', ... 'Toolbar', 'none', ... - 'HandleVisibility', 'off', 'tag', 'rollover'); + 'HandleVisibility', 'on',... + 'tag', 'rollover',... + 'DockControls','off');%%donot allow to dock ScreenPos = []; - - new_pos= erpworkingmemory('ERPWaveScreenPos'); - if isempty(new_pos) - new_pos = [0.01,0.01,75,75]; - erpworkingmemory('ERPWaveScreenPos',new_pos); + new_pos= estudioworkingmemory('ERPWaviewerScreenPos'); + if isempty(new_pos) || numel(new_pos)~=2 + new_pos = [75,75]; + estudioworkingmemory('ERPWaviewerScreenPos',new_pos); end try ScreenPos = get( groot, 'Screensize' ); catch ScreenPos = get( 0, 'Screensize' ); end - gui_erp_waviewer.screen_pos = new_pos; - new_pos =[ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100,ScreenPos(3)*new_pos(3)/100,ScreenPos(4)*new_pos(4)/100]; + gui_erp_waviewer.monitor_size = ScreenPos;%%save monitor size + gui_erp_waviewer.screen_pos = new_pos;%%GUI size + if ~isempty(new_pos(2)) && new_pos(2) >100 + POS4 = (100-new_pos(2))/100; + new_pos =[0,ScreenPos(4)*POS4,ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100]; + else + new_pos =[0,0,ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100]; + end set(gui_erp_waviewer.Window, 'Position', new_pos); % + View menu gui_erp_waviewer.exit = uimenu( gui_erp_waviewer.Window, 'Label','Exit', 'Callback', @onExit); - gui_erp_waviewer.help = uimenu( gui_erp_waviewer.Window, 'Label', 'Help', 'Callback', @onhelp); +% gui_erp_waviewer.help = uimenu( gui_erp_waviewer.Window, 'Label', 'Help', 'Callback', @onhelp); %%-----------Setting------------------------------------------------ %% Create tabs @@ -357,37 +340,26 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete set(gui_erp_waviewer.panelscroll,'BackgroundColor',ColorBviewer_def); % + Adjust the main layout set( gui_erp_waviewer.tabERP, 'Widths', [-4, 270]); % Viewpanel and settings panel - - gui_erp_waviewer.panel_fonts = f_get_default_fontsize(); %% get the default fontsize based on the different plat form, e.g., Mac - gui_erp_waviewer.settingLayout = uiextras.VBox('Parent', gui_erp_waviewer.panelscroll,'BackgroundColor',ColorBviewer_def); % + Create the settings window panels for ERP panel gui_erp_waviewer.panel{1} = f_ERPsets_waviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); - gui_erp_waviewer.panelSizes(1) = 255; - + gui_erp_waviewer.panelSizes(1) = 360; gui_erp_waviewer.panel{2} = f_ERP_Binchan_waviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); gui_erp_waviewer.panelSizes(2) = 280; - gui_erp_waviewer.panel{3} = f_ERP_timeampscal_waveviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); gui_erp_waviewer.panelSizes(3) = 490; - gui_erp_waviewer.panel{4} = f_ERP_plotorg_waveviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); gui_erp_waviewer.panelSizes(4) = 385; - gui_erp_waviewer.panel{5} = f_ERP_labelset_waveviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); gui_erp_waviewer.panelSizes(5) = 200; - gui_erp_waviewer.panel{6} = f_ERP_lineset_waveviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); gui_erp_waviewer.panelSizes(6) = 375; - gui_erp_waviewer.panel{7} = f_ERP_otherset_waveviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); gui_erp_waviewer.panelSizes(7) = 225; - gui_erp_waviewer.panel{8} = f_ERP_property_waveviewer_GUI(gui_erp_waviewer.settingLayout,gui_erp_waviewer.panel_fonts); - gui_erp_waviewer.panelSizes(8) = 130; - + gui_erp_waviewer.panelSizes(8) = 140; set(gui_erp_waviewer.settingLayout, 'Heights', gui_erp_waviewer.panelSizes); gui_erp_waviewer.panelscroll.Heights = sum(gui_erp_waviewer.panelSizes); @@ -417,16 +389,11 @@ function ERPLAB_ERP_Viewer(ALLERP,selectedERP_index,binArray,chanArray,Paramete %% + Create the view p = gui_erp_waviewer.ViewContainer; gui_erp_waviewer.ViewAxes = uiextras.HBox( 'Parent', p,'BackgroundColor',ColorBviewer_def); - gui_erp_waviewer.Resize=1; + gui_erp_waviewer.Resize=0; end % createInterface_ERPWave_viewer function nMinimize( eventSource, eventData, whichpanel) %#ok - try - [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; - catch - ColorBviewer_def = [0.7020 0.77 0.85]; - end minned = gui_erp_waviewer.panel{whichpanel}.IsMinimized; szs = get( gui_erp_waviewer.settingLayout, 'Sizes' ); if minned @@ -436,9 +403,8 @@ function nMinimize( eventSource, eventData, whichpanel) %#ok set( gui_erp_waviewer.panel{whichpanel}, 'IsMinimized', true); szs(whichpanel) = 25; end - set( gui_erp_waviewer.settingLayout, 'Sizes', szs ,'BackgroundColor',ColorBviewer_def); + set( gui_erp_waviewer.settingLayout, 'Sizes', szs); gui_erp_waviewer.panelscroll.Heights = sum(szs); - set(gui_erp_waviewer.panelscroll,'BackgroundColor',ColorBviewer_def); end % nMinimize @@ -454,7 +420,6 @@ function onExit(~,~) if strcmpi(button1,'Yes') try close(gui_erp_waviewer.Window); - clear ALLERPwaviewer; catch return; end @@ -468,17 +433,13 @@ function onhelp(~,~) end -%%Resize the GUI automatically as the user changes the size of the window at run-time. -% function WAviewerResize(~,~) -% if gui_erp_waviewer.Resize ~= 0 -% new_pos = gui_erp_waviewer.Window.Position; -% erpworkingmemory('ERPWaveScreenPos',new_pos); -% gui_erp_waviewer.screen_pos = new_pos; -% % set(gui_erp_waviewer.Window, 'Position', new_pos); -% f_redrawERP_viewer_test(); -% end -% end +%%%%%%%%%%%%%%%%%%%%%%% +end % end of the function -%%%%%%%%%%%%%%%%%%%%%%% -end % end of the function \ No newline at end of file +%%---------------------ERPLAB VERSION-------------------------------------- +function erplabver1 = geterplabeversion +erplab_default_values; +erplabver1 = str2num(erplabver); +estudioworkingmemory('erplabver', erplabver); +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.fig b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.fig old mode 100644 new mode 100755 index d5671987..bb4964d2 Binary files a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.fig and b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.fig differ diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.m old mode 100644 new mode 100755 index 01dafaad..451d0805 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/ERP_layoutstringGUI.m @@ -53,31 +53,10 @@ function ERP_layoutstringGUI_OpeningFcn(hObject, eventdata, handles, varargin) end handles.AllabelArray = AllabelArray; -% usedIndex = zeros(length(AllabelArray),1); -% for jj = 1:length(AllabelArray) -% for ii = 1:length(plotArrayFormt) -% if strcmp(AllabelArray{jj},plotArrayFormt{ii}) -% usedIndex(jj) = 1; -% end -% end -% end -% handles.usedIndex = usedIndex; % f = waitbar(0.2,'Loading Custtom Grid Layout GUI...'); Numrows = plotBox(1); Numcolumns = plotBox(2); -% GridinforDatadef = cell(Numrows,Numcolumns); -% count = 0; -% for Numofrows = 1:Numrows -% for Numofcolumns = 1:Numcolumns -% count = count +1; -% if count> numel(plotArray) -% GridinforDatadef{Numofrows,Numofcolumns} = ''; -% else -% GridinforDatadef{Numofrows,Numofcolumns} = char(plotArray{count}); -% end -% end -% end try GridinforData = varargin{2}; @@ -87,37 +66,7 @@ function ERP_layoutstringGUI_OpeningFcn(hObject, eventdata, handles, varargin) end handles.GridinforData = GridinforData; handles.GridinforData_def = GridinforData; -% if isempty(GridinforData) -% GridinforData = GridinforDatadef; -% end -% if size(GridinforData,1)~= Numrows || size(GridinforData,2)~= Numcolumns -% GridinforData = GridinforDatadef; -% end - -% FonsizeDefault = f_get_default_fontsize(); -% % tablePosition = handles.uitable1_layout.Position; -% for Numofcolumns = 1:Numcolumns -% columFormat{Numofcolumns} = 'char'; -% ColumnEditable(Numofcolumns) =1; -% ColumnName{1,Numofcolumns} = char(['C',num2str(Numofcolumns)]); -% end -% -% for Numofrows = 1:Numrows -% RowName{1,Numofrows} = char(['R',num2str(Numofrows)]); -% end -% set(handles.uitable1_layout,'Data',GridinforData); -% handles.uitable1_layout.ColumnEditable = logical(ColumnEditable); -% handles.uitable1_layout.ColumnName = ColumnName; -% handles.uitable1_layout.RowName = RowName; -% handles.uitable1_layout.ColumnFormat = columFormat; -% handles.uitable1_layout.FontSize = FonsizeDefault; -% handles.uitable1_layout.CellEditCallback = {@MakerLabels,handles}; - -% f = waitbar(0.7,'Loading Custtom Grid Layout GUI...'); - -% [plotArrayFormt] = f_MarkLabels_gridlocations_ERP_Waveiwer(GridinforData,usedIndex,AllabelArray); -% handles.listbox_Labels.String = ''; -% handles.listbox_Labels.String = plotArrayFormt; + % % % Color GUI % @@ -127,25 +76,11 @@ function ERP_layoutstringGUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.textrow5.BackgroundColor = ColorBviewer_def; handles.text6_columns.BackgroundColor = ColorBviewer_def; handles.text7_message.BackgroundColor = ColorBviewer_def; -% handles.listbox_Labels.Min = 0; -% handles.listbox_Labels.Max =1; -% handles.listbox_Labels.Enable = 'off'; -% handles.listbox_Labels.Value = 1; handles.text_rownum.String = num2str(Numrows); handles.edit1_columnsNum.String = num2str(Numcolumns); handles.text7_message.String = sprintf([' In the right panel:\n Blue labels: unused.\n Red labels: used more than once.\n Black labels: used once.\n *: Selected in main GUI.']); -% Data = handles.uitable1_layout.Data; -% -% Data = f_checktable_gridlocations_waviewer(Data,AllabelArray); -% try -% SingleCell = AllabelArray{handles.listbox_Labels.Value}; -% catch -% SingleCell = AllabelArray{1}; -% end -% Data = f_add_bgcolor_cell(Data,SingleCell); -% handles.uitable1_layout.Data=Data; %% handles = Datacreate(plotBox,GridinforData,plotArrayFormt,AllabelArray,handles); @@ -471,47 +406,6 @@ function text_rownum_Callback(hObject, eventdata, handles) -%%Mark the labels with different colors(blue: unused; black:used; red:Repeated;* means items were selected in the main GUI) -% function [LabelStrout] = f_MarkLabels_gridlocations_ERP_Waveiwer(Gridata,LabelStr,AllabelArray) -% usedIndex = zeros(length(AllabelArray),1); -% for jj = 1:length(AllabelArray) -% for ii = 1:length(LabelStr) -% if strcmp(AllabelArray{jj},LabelStr{ii}) -% usedIndex(jj) = 1; -% end -% end -% end -% -% LabelsFlag = [0 0 0]; -% for ii = 1:length(AllabelArray) -% code1 = 0; -% for jj = 1:size(Gridata,1) -% for kk = 1:size(Gridata,2) -% if strcmp(AllabelArray{ii},Gridata{jj,kk}) -% code1 = code1+1; -% end -% end -% end -% -% if usedIndex(ii)==1%% the item will be marked with * if the labels was selected -% % AllabelArray{ii} = strcat(AllabelArray{ii},'*'); -% Numstr = strcat('*',num2str(ii)); -% else -% Numstr = strcat(num2str(ii)); -% end -% -% if code1 ==0 -% LabelStrout{ii} = ['',Numstr,'.',32,AllabelArray{ii},'']; -% LabelsFlag(1) = 1; -% elseif code1 >1 -% LabelStrout{ii} = ['',Numstr,'.',32,AllabelArray{ii},'']; -% LabelsFlag(3) = 1; -% else -% LabelStrout{ii} = ['',Numstr,'.',32,AllabelArray{ii},'']; -% LabelsFlag(2) = 1; -% end -% end - function Data = f_add_bgcolor_cell(Data,SingleCell) colergen = @(color,text) ['
',text,'
']; @@ -525,49 +419,6 @@ function text_rownum_Callback(hObject, eventdata, handles) end -% function [Data, EPStr]= f_checktable_gridlocations_waviewer(Data,LabelStr) -% countEp = 0; -% EPStr = ''; -% for ii = 1:size(Data,1) -% for jj = 1:size(Data,2) -% count = 0; -% for kk = 1:length(LabelStr) -% Data1= strrep(Data{ii,jj},'
',''); -% Data1 = strrep(Data1,'
',''); -% Data{ii,jj} = char(Data1); -% if strcmp(strtrim(char(LabelStr{kk})),strtrim(char(Data{ii,jj}))) -% Data{ii,jj} = char(LabelStr{kk}); -% count = count +1; -% end -% end -% if count==0 -% countEp = countEp+1; -% if countEp==1 -% if ischar(Data{ii,jj}) -% if ~isempty(Data{ii,jj}) -% EPStr = char(Data{ii,jj}); -% end -% elseif isnumeric(Data{ii,jj}) -% if ~isempty(Data{ii,jj}) -% EPStr = num2str(Data{ii,jj}); -% end -% end -% else -% if ischar(Data{ii,jj}) -% if ~isempty(Data{ii,jj}) -% EPStr = strcat(EPStr,',',char(Data{ii,jj})); -% end -% elseif isnumeric(Data{ii,jj}) -% if ~isempty(Data{ii,jj}) -% EPStr = strcat(EPStr,',',num2str(Data{ii,jj})); -% end -% end -% end -% Data{ii,jj} = ''; -% end -% end -% end - function Labels_used = unique_str(Data) @@ -587,30 +438,31 @@ function text_rownum_Callback(hObject, eventdata, handles) % --- Executes on button press in pushbutton6_import. function pushbutton6_import_Callback(hObject, eventdata, handles) -[filename, filepath] = uigetfile('*.txt', ... - 'Load Gird Locations', ... - 'MultiSelect', 'off'); +[filename, filepath] = uigetfile({'*.tsv;*.txt'}, ... + 'Load Gird Locations'); if isequal(filename,0) - disp('User selected Cancel'); return; end try - % DataInput = importdata([filepath,filename]);%%There are some errors - % when using importdata - DataInput = readcell([filepath,filename]); + DataInput = readtable([filepath,filename], "FileType","text",'PreserveVariableNames',true); CellNum=2; catch - - DataInput = readcell([filepath,filename]); handles.text7_message.String = sprintf(['Cannot import:',filepath,filename]); return; - CellNum=2; end if isempty(DataInput) handles.text7_message.String = sprintf(['The file is empty.']); return; end +DataInput = table2cell(DataInput); +[rows,columns] = size(DataInput); +if columns==1 + handles.text7_message.String = sprintf(['Import is invalid']); + return; +end +DataInput = DataInput(:,2:end); + DataOutput = f_gridlocation_transcell(DataInput,CellNum); AllabelArray = handles.AllabelArray; @@ -744,8 +596,8 @@ function pushbutton6_import_Callback(hObject, eventdata, handles) function pushbutton8_Export_Callback(hObject, eventdata, handles) pathstr = pwd; -namedef ='GridLocations'; -[erpfilename, erppathname, indxs] = uiputfile({'*.txt'}, ... +namedef ='GridLocations_viewer'; +[erpfilename, erppathname, indxs] = uiputfile({'*.tsv'}, ... ['Save Grid Locations as'],... fullfile(pathstr,namedef)); if isequal(erpfilename,0) @@ -754,7 +606,7 @@ function pushbutton8_Export_Callback(hObject, eventdata, handles) end [pathstr, erpfilename, ext] = fileparts(erpfilename) ; -ext = '.txt'; +ext = '.tsv'; erpFilename = char(strcat(erppathname,erpfilename,ext)); AllabelArray = handles.AllabelArray; @@ -764,15 +616,30 @@ function pushbutton8_Export_Callback(hObject, eventdata, handles) [nrows,ncols] = size(Data); Data = f_gridlocation_respace_addnan(Data); formatSpec =''; -for jj = 1:ncols - formatSpec = strcat(formatSpec,'%s\t',32); +for jj = 1:ncols+1 + if jj==ncols+1 + formatSpec = strcat(formatSpec,'%s'); + else + formatSpec = strcat(formatSpec,'%s\t',32); + end + if jj==1 + columName{1,jj} = ''; + else + columName{1,jj} = ['Column',32,num2str(jj-1)]; + end end formatSpec = strcat(formatSpec,'\n'); - +fprintf(fileID,formatSpec,columName{1,:}); for row = 1:nrows - fprintf(fileID,formatSpec,Data{row,:}); + rowdata = cell(1,ncols+1); + rowdata{1,1} = char(['Row',num2str(row)]); + for jj = 1:ncols + rowdata{1,jj+1} = Data{row,jj}; + end + fprintf(fileID,formatSpec,rowdata{1,:}); end fclose(fileID); + disp(['The file for ERP Viewer Grid layout was created at ' erpFilename '']) function data = f_gridlocation_respace_addnan(data) @@ -784,7 +651,7 @@ function pushbutton8_Export_Callback(hObject, eventdata, handles) if ~isempty(labx) labx = regexprep(labx,'\\|\/|\*|\#|\$|\@','_'); else - labx = 'NaN'; + labx = ' '; end data{ii,jj} = labx; end @@ -844,6 +711,3 @@ function pushbutton8_Export_Callback(hObject, eventdata, handles) handles.listbox_Labels.Min = 0; handles.listbox_Labels.Max =1; handles.listbox_Labels.Value = 1; -% - - diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/default_amp_ticks_viewer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/default_amp_ticks_viewer.m index f01c70e9..03bb292b 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/default_amp_ticks_viewer.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/default_amp_ticks_viewer.m @@ -42,7 +42,7 @@ if yrange(1)>= yrange(2) beep; - disp('Please the left edge of y scale should be smaller than the righ edge.'); + disp('The left edge of y scale should be smaller than the righ edge.'); return; end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_Binchan_waviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_Binchan_waviewer_GUI.m index f6861d3c..61a7ece9 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_Binchan_waviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_Binchan_waviewer_GUI.m @@ -13,30 +13,21 @@ % Initial setup % function varargout = f_ERP_Binchan_waviewer_GUI(varargin) -% global viewer_ERPDAT -global observe_ERPDAT; - +global gui_erp_waviewer; addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); addlistener(viewer_ERPDAT,'count_twopanels_change',@count_twopanels_change); addlistener(viewer_ERPDAT,'Reset_Waviewer_panel_change',@Reset_Waviewer_panel_change); -addlistener(viewer_ERPDAT,'ERPset_Chan_bin_label_change',@ERPset_Chan_bin_label_change); -addlistener(observe_ERPDAT,'ERP_chan_change',@ERP_chan_changed); -addlistener(observe_ERPDAT,'ERP_bin_change',@ERP_bin_changed); -addlistener(observe_ERPDAT,'Two_GUI_change',@Two_GUI_change); - ERPwaveview_binchan = struct(); -%---------Setting the parameter which will be used in the other panels----------- try [version reldate,ColorBviewer_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; catch - ColorBviewer_def = [0.7765 0.7294 0.8627]; + ColorBviewer_def = [0.8 0.8 0.9]; end -ERPdatasets = []; % Local data structure % global Chanbin_waveviewer_box; if nargin == 0 fig = figure(); % Parent figure @@ -51,7 +42,6 @@ elseif nargin == 4 Chanbin_waveviewer_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Channels and Bins', 'Padding', 5, ... 'FontSize', varargin{2},'BackgroundColor',ColorBviewer_def,'TitleColor',[0.5 0.5 0.9],'ForegroundColor','w'); - end try @@ -73,57 +63,16 @@ function drawui_erpsetbinchan_viewer(FonsizeDefault) try [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; catch - ColorBviewer_def = [0.7765 0.7294 0.8627]; - end - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - SelectedIndex = ERPwaviewer.SelectERPIdx; - ALLERP = ERPwaviewer.ALLERP; - if max(SelectedIndex(:))> length(ALLERP) - SelectedIndex =length(ALLERP); - end - catch - beep; - disp('f_ERP_Binchan_waviewer_GUI error: Restart ERPwave Viewer'); - return; + ColorBviewer_def = [0.8 0.8 0.9]; end + ERPwaveview_binchan.vBox = uiextras.VBox('Parent', Chanbin_waveviewer_box, 'Spacing', 5,'BackgroundColor',ColorBviewer_def); % VBox for everything ERPtooltype = erpgettoolversion('tooltype'); + MERPWaveViewer_chanbin{1}=0; - if ~strcmpi(ERPtooltype,'EStudio') %&& ~strcmpi(ERPtooltype,'ERPLAB') - ERPwaviewer.erp_binchan_op = 0; - MERPWaveViewer_chanbin{1}=0; - end - try - Enable_auto = MERPWaveViewer_chanbin{1}; - catch - Enable_auto = 1; - MERPWaveViewer_chanbin{1}=1; - end - if numel(Enable_auto)~=1 || (Enable_auto~=0 && Enable_auto~=1) - Enable_auto = 1; - MERPWaveViewer_chanbin{1}=1; - end - if Enable_auto ==1 - Enable_label = 'off'; - elseif Enable_auto ==0 - Enable_label = 'on'; - end - %%---------------------Options for selecting channel and bins----------------------------------------------------- - ERPwaveview_binchan.opts_title = uiextras.HBox('Parent', ERPwaveview_binchan.vBox, 'Spacing', 5,'BackgroundColor',ColorBviewer_def); - ERPwaveview_binchan.auto = uicontrol('Style', 'radiobutton','Parent', ERPwaveview_binchan.opts_title,... - 'String','Same as EStudio','callback',@Chanbin_auto,'Value',Enable_auto,'Enable','on','FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); - ERPwaveview_binchan.auto.KeyPressFcn = @setbinchan_presskey; - - ERPwaveview_binchan.custom = uicontrol('Style', 'radiobutton','Parent', ERPwaveview_binchan.opts_title,... - 'String','Custom','callback',@Chanbin_custom,'Value',~Enable_auto,'Enable','on','FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); - ERPwaveview_binchan.custom.KeyPressFcn = @setbinchan_presskey; - - % %%---------------------Display channel and bin labels----------------------------------------------------- - ERPwaveview_binchan.DataSelGrid = uiextras.HBox('Parent', ERPwaveview_binchan.vBox,'BackgroundColor',ColorBviewer_def); - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,SelectedIndex); + [chanStr,binStr,diff_mark] = f_geterpschanbin(gui_erp_waviewer.ERPwaviewer.ALLERP,gui_erp_waviewer.ERPwaviewer.SelectERPIdx); Chanlist_name = cell(length(chanStr)+1,1); Chanlist_name(1) = {'All'}; @@ -132,28 +81,29 @@ function drawui_erpsetbinchan_viewer(FonsizeDefault) end % Channel information Chanlist = chanStr; - Chan_seldef = ERPwaviewer.chan; + Chan_seldef = gui_erp_waviewer.ERPwaviewer.chan; if ~isempty(Chan_seldef) - if max(Chan_seldef)> numel(Chanlist) + if any(Chan_seldef> numel(Chanlist)) Chan_seldef= 1:length(Chanlist); end else Chan_seldef= 1:length(Chanlist); end - try - Chan_sel = MERPWaveViewer_chanbin{2}; - catch - MERPWaveViewer_chanbin{2} = Chan_seldef; + if strcmpi(ERPtooltype,'EStudio') Chan_sel = Chan_seldef; + MERPWaveViewer_chanbin{2} = Chan_seldef; + else + Chan_sel = 1:length(Chanlist); + MERPWaveViewer_chanbin{2} = Chan_sel; end Chan_sel = unique(Chan_sel); - if isempty(Chan_sel) || max(Chan_sel(:))> length(Chanlist) || min(Chan_sel(:))> length(Chanlist) || min(Chan_sel(:))<=0 + if isempty(Chan_sel) || any(Chan_sel(:)> length(Chanlist)) || any(Chan_sel(:)<=0) MERPWaveViewer_chanbin{2} = Chan_seldef; Chan_sel = Chan_seldef; end - ERPwaviewer.chan = Chan_sel; + gui_erp_waviewer.ERPwaviewer.chan = Chan_sel; ERPwaveview_binchan.ElecRange = uicontrol('Parent', ERPwaveview_binchan.DataSelGrid,'Style','listbox','min',1,'max',length(Chanlist_name),... - 'String', Chanlist_name,'Callback',@ViewerElecRange,'FontSize',FonsizeDefault,'Enable',Enable_label); % 2B + 'String', Chanlist_name,'Callback',@ViewerElecRange,'FontSize',FonsizeDefault,'Enable','on','BackgroundColor',[1 1 1]); % 2B ERPwaveview_binchan.ElecRange.KeyPressFcn = @setbinchan_presskey; if numel(Chan_sel) == numel(Chanlist) @@ -164,31 +114,32 @@ function drawui_erpsetbinchan_viewer(FonsizeDefault) %%Bin information brange = cell(length(binStr)+1,1); BinNum = length(binStr); - Bin_seldef = ERPwaviewer.bin; + Bin_seldef = gui_erp_waviewer.ERPwaviewer.bin; if ~isempty(Bin_seldef) - if max(Bin_seldef)> BinNum + if any(Bin_seldef> BinNum) Bin_seldef= 1:BinNum; end else Bin_seldef= 1:BinNum; end - try - Bin_sel = MERPWaveViewer_chanbin{3}; - catch + if strcmpi(ERPtooltype,'EStudio') MERPWaveViewer_chanbin{3} = Bin_seldef; Bin_sel = Bin_seldef; + else + Bin_sel = 1:BinNum; + MERPWaveViewer_chanbin{3} = Bin_sel; end - if isempty(Bin_sel) || max(Bin_sel(:))> length(binStr) || min(Bin_sel(:))> length(binStr) || min(Bin_sel(:))<=0 - MERPWaveViewer_chanbin{3} = Bin_seldef; - Bin_sel = Bin_seldef; + if isempty(Bin_sel) || any(Bin_sel(:)> length(binStr)) || any(Bin_sel(:)<=0) + Bin_sel = 1:BinNum; + MERPWaveViewer_chanbin{3} = Bin_sel; end - ERPwaviewer.bin=Bin_sel; + gui_erp_waviewer.ERPwaviewer.bin=Bin_sel; brange(1) = {'All'}; for Numofbin11 = 1:length(binStr) brange(Numofbin11+1) = {char(strcat(num2str(Numofbin11),'.',32,char(binStr(Numofbin11))))}; end ERPwaveview_binchan.BinRange = uicontrol('Parent', ERPwaveview_binchan.DataSelGrid,'Style','listbox','Min',1,'Max',BinNum+1,... - 'String', brange,'callback',@ViewerBinRange,'FontSize',FonsizeDefault,'Enable',Enable_label); % 2C + 'String', brange,'callback',@ViewerBinRange,'FontSize',FonsizeDefault,'Enable','on','BackgroundColor',[1 1 1]); % 2C ERPwaveview_binchan.BinRange.KeyPressFcn = @setbinchan_presskey; if BinNum== numel(Bin_sel) ERPwaveview_binchan.BinRange.Value =1; @@ -197,34 +148,25 @@ function drawui_erpsetbinchan_viewer(FonsizeDefault) end set(ERPwaveview_binchan.DataSelGrid, 'Sizes',[ -1.2 -2]); - if strcmpi(ERPtooltype,'EStudio') - ERPwaveview_binchan.auto.String = 'Same as EStudio'; - else - ERPwaveview_binchan.auto.String = ''; - ERPwaveview_binchan.auto.Enable = 'off'; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.custom.String = ''; - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Enable = 'off'; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - end - - %%Help and apply ERPwaveview_binchan.help_apply_title = uiextras.HBox('Parent', ERPwaveview_binchan.vBox,'BackgroundColor',ColorBviewer_def); uiextras.Empty('Parent',ERPwaveview_binchan.help_apply_title ); - uicontrol('Style','pushbutton','Parent', ERPwaveview_binchan.help_apply_title ,'String','Cancel',... - 'callback',@setbinchan_help,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold','HorizontalAlignment','left' + ERPwaveview_binchan.cancel = uicontrol('Style','pushbutton','Parent', ERPwaveview_binchan.help_apply_title ,'String','Cancel',... + 'callback',@setbinchan_cancel,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold','HorizontalAlignment','left' uiextras.Empty('Parent',ERPwaveview_binchan.help_apply_title ); ERPwaveview_binchan.apply = uicontrol('Style','pushbutton','Parent',ERPwaveview_binchan.help_apply_title ,'String','Apply',... 'callback',@setbinchan_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'HorizontalAlignment','left' -% ERPwaveview_binchan.custom.KeyPressFcn = @setbinchan_presskey; + % ERPwaveview_binchan.custom.KeyPressFcn = @setbinchan_presskey; uiextras.Empty('Parent',ERPwaveview_binchan.help_apply_title ); set(ERPwaveview_binchan.help_apply_title ,'Sizes',[40 70 20 70 20]); - set(ERPwaveview_binchan.vBox, 'Sizes', [20 190 25]); - assignin('base','ALLERPwaviewer',ERPwaviewer); - estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); + set(ERPwaveview_binchan.vBox, 'Sizes', [210 25]); + + estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); %%save chan array and bin array + estudioworkingmemory('MyViewer_chanbin',0); + + gui_erp_waviewer.ERPwaviewer.bin = Bin_sel; + gui_erp_waviewer.ERPwaviewer.chan = Chan_sel; + end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -250,6 +192,8 @@ function ViewerElecRange(Source,~) ERPwaveview_binchan.apply.BackgroundColor = [0.4940 0.1840 0.5560]; ERPwaveview_binchan.apply.ForegroundColor = [1 1 1]; Chanbin_waveviewer_box.TitleColor= [0.4940 0.1840 0.5560]; + ERPwaveview_binchan.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + ERPwaveview_binchan.cancel.ForegroundColor = [1 1 1]; end @@ -269,193 +213,40 @@ function ViewerBinRange(BinSource,~) BinSource.Value = 1; end end - estudioworkingmemory('MyViewer_chanbin',1); ERPwaveview_binchan.apply.BackgroundColor = [0.4940 0.1840 0.5560]; ERPwaveview_binchan.apply.ForegroundColor = [1 1 1]; Chanbin_waveviewer_box.TitleColor= [0.4940 0.1840 0.5560]; + ERPwaveview_binchan.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + ERPwaveview_binchan.cancel.ForegroundColor = [1 1 1]; end -%%---------------Setting for auto option----------------------------------- - function Chanbin_auto(source,~) - [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); - if ~isempty(messgStr) && viewerpanelIndex~=2 - viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; - end - estudioworkingmemory('MyViewer_chanbin',1); - ERPwaveview_binchan.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - ERPwaveview_binchan.apply.ForegroundColor = [1 1 1]; - Chanbin_waveviewer_box.TitleColor= [0.4940 0.1840 0.5560]; - ERPtooltype = erpgettoolversion('tooltype'); - if strcmpi(ERPtooltype,'EStudio') - ERPwaveview_binchan.auto.Value = 1; - ERPwaveview_binchan.custom.Value =0; - ERPwaveview_binchan.ElecRange.Enable = 'off'; - ERPwaveview_binchan.BinRange.Enable = 'off'; - Selected_erpset= estudioworkingmemory('selectederpstudio'); - Geterpbinchan = estudioworkingmemory('geterpbinchan'); - CurrentERPIndex = Geterpbinchan.Select_index; - try - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); - ALLERPIN = ERPwaviewerIN.ALLERP; - if max(Selected_erpset(:))> length(ALLERPIN) - Selected_erpset =1; - CurrentERPIndex =1; - end - catch - beep; - disp('f_ERP_Binchan_waviewer_GUI error: Restart ERPwave Viewer'); - return; - end - - BinArray = Geterpbinchan.bins{Geterpbinchan.Select_index}; - chanArray = Geterpbinchan.elecs_shown{Geterpbinchan.Select_index}; - chan_bin = Geterpbinchan.bins_chans(CurrentERPIndex); - if chan_bin ==1 - ERPwaviewerIN.plot_org.Grid =2; - ERPwaviewerIN.plot_org.Overlay=1; - ERPwaviewerIN.plot_org.Pages=3; - elseif chan_bin==0 - ERPwaviewerIN.plot_org.Grid =1; - ERPwaviewerIN.plot_org.Overlay=2; - ERPwaviewerIN.plot_org.Pages=3; - end - - % Channel information - chanStr = [1:(numel(ERPwaveview_binchan.ElecRange.String)-1)]; - Chanlist = chanStr; - Chan_sel = chanArray; - if ~isempty(Chan_sel) - if max(Chan_sel)> numel(Chanlist) - Chan_sel= 1:length(Chanlist); - end - else - Chan_sel= 1:length(Chanlist); - end - try - if length(Chan_sel) == numel(chanStr) - ERPwaveview_binchan.ElecRange.Value =1; - else - ERPwaveview_binchan.ElecRange.Value =Chan_sel+1; - end - catch - ERPwaveview_binchan.ElecRange.Value =1; - end - - %%Bin information - binStr = ERPwaveview_binchan.BinRange.String; - BinNum = length(binStr)-1; - Bin_sel = BinArray; - if ~isempty(Bin_sel) - if max(Bin_sel)> BinNum - Bin_sel= 1:BinNum; - end - else - Bin_sel= 1:BinNum; - end - - if BinNum== numel(Bin_sel) - ERPwaveview_binchan.BinRange.Value =1; - else - ERPwaveview_binchan.BinRange.Value = Bin_sel+1; - end - - elseif strcmpi(ERPtooltype,'ERPLAB') - ERPwaveview_binchan.auto.Value = 1; - ERPwaveview_binchan.custom.Value =0; - ERPwaveview_binchan.ElecRange.Enable = 'off'; - ERPwaveview_binchan.BinRange.Enable = 'off'; - Selected_erpset = evalin('base','CURRENTERP'); - ALLERP = evalin('base','ALLERP'); - if ~isempty(Selected_erpset) && ~isempty(ALLERP) && (Selected_erpset<= length(ALLERP)) && min(Selected_erpset)>0 - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,SelectedIndex); - Chanlist_name = cell(length(chanStr)+1,1); - Chanlist_name(1) = {'All'}; - for Numofchan11 = 1:length(chanStr) - Chanlist_name(Numofchan11+1) = {char(strcat(num2str(Numofchan11),'.',32,char(chanStr(Numofchan11))))}; - end - ERPwaveview_binchan.ElecRange.String = Chanlist_name; - ERPwaveview_binchan.ElecRange.Value =1; - - brange = cell(length(binStr)+1,1); - brange(1) = {'All'}; - for Numofbin11 = 1:length(binStr) - brange(Numofbin11+1) = {char(strcat(num2str(Numofbin11),'.',32,char(binStr(Numofbin11))))}; - end - ERPwaveview_binchan.BinRange.String = brange; - ERPwaveview_binchan.BinRange.Value = 1; - end - else - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - end - end -%%---------------Setting for custom option--------------------------------- - function Chanbin_custom(source,~) - [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); - if ~isempty(messgStr) && viewerpanelIndex~=2 - viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; - end - - estudioworkingmemory('MyViewer_chanbin',1); - ERPwaveview_binchan.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - ERPwaveview_binchan.apply.ForegroundColor = [1 1 1]; - Chanbin_waveviewer_box.TitleColor= [0.4940 0.1840 0.5560]; - - ERPtooltype = erpgettoolversion('tooltype'); - if ~strcmpi(ERPtooltype,'EStudio') && ~strcmpi(ERPtooltype,'ERPLAB') - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - ERPwaveview_binchan.auto.Enable = 'off'; - else - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - end - end - - %%-------------------------------Help-------------------------------------- - function setbinchan_help(~,~) + function setbinchan_cancel(~,~) [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=2 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - changeFlag = estudioworkingmemory('MyViewer_chanbin'); if changeFlag~=1 return; end MessageViewer= char(strcat('Channels and Bins > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nChannels and Bins > Cancel-f_ERP_Binchan_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - if ERPwaviewer_apply.binchan_op==1 - ERPwaveview_binchan.auto.Value = 1; - ERPwaveview_binchan.custom.Value =0; - ERPwaveview_binchan.ElecRange.Enable = 'off'; - ERPwaveview_binchan.BinRange.Enable = 'off'; - else - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; + + binArray = gui_erp_waviewer.ERPwaviewer.bin; + if isempty(binArray) || any(binArray<=0) || any(binArray>length(ERPwaveview_binchan.BinRange.String)-1) + binArray = [1:length(ERPwaveview_binchan.BinRange.String)-1]; + gui_erp_waviewer.ERPwaviewer.bin=binArray; end - binArray = ERPwaviewer_apply.bin; - chanArray = ERPwaviewer_apply.chan; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + if isempty(chanArray) || any(chanArray<=0) || any(chanArray> length(ERPwaveview_binchan.ElecRange.String)-1) + chanArray = [1:length(ERPwaveview_binchan.BinRange.String)-1]; + gui_erp_waviewer.ERPwaviewer.chan= chanArray; + end if numel(binArray) == length(ERPwaveview_binchan.BinRange.String)-1 ERPwaveview_binchan.BinRange.Value =1; else @@ -467,18 +258,17 @@ function setbinchan_help(~,~) ERPwaveview_binchan.ElecRange.Value =chanArray+1; end - ERPtooltype = erpgettoolversion('tooltype'); - if ~strcmpi(ERPtooltype,'EStudio') %&& ~strcmpi(ERPtooltype,'ERPLAB') - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - end + ERPwaveview_binchan.ElecRange.Enable = 'on'; + ERPwaveview_binchan.BinRange.Enable = 'on'; estudioworkingmemory('MyViewer_chanbin',0); ERPwaveview_binchan.apply.BackgroundColor = [1 1 1]; Chanbin_waveviewer_box.TitleColor= [0.5 0.5 0.9]; ERPwaveview_binchan.apply.ForegroundColor = [0 0 0]; - MessageViewer= char(strcat('Channels and Bins > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + ERPwaveview_binchan.cancel.BackgroundColor = [1 1 1]; + ERPwaveview_binchan.cancel.ForegroundColor = [0 0 0]; + MessageViewer= char(strcat('Channels and Bins > Cancel')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -490,74 +280,79 @@ function setbinchan_apply(~,~) end MessageViewer= char(strcat('Channels and Bins > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nChannels and Bins > Apply-f_ERP_Binchan_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - ERPwaviewer_apply.binchan_op = ERPwaveview_binchan.auto.Value; + gui_erp_waviewer.ERPwaviewer.binchan_op = 0; ChanArrayValue = ERPwaveview_binchan.ElecRange.Value; - if numel(ChanArrayValue)== 1&& ChanArrayValue ==1 + if numel(ChanArrayValue)== 1 && ChanArrayValue ==1 ChanArray = [1:length(ERPwaveview_binchan.ElecRange.String)-1]; else ChanArray = ChanArrayValue-1; end - ERPwaviewer_apply.chan = ChanArray; + chandef = gui_erp_waviewer.ERPwaviewer.chan; + if numel(ChanArray)> numel(chandef) + chandiff = setdiff(ChanArray,chandef); + else + chandiff = setdiff(chandef,ChanArray); + end + if ~isempty(chandiff) + gui_erp_waviewer.ERPwaviewer.chan = ChanArray; + end BinArrayValue = ERPwaveview_binchan.BinRange.Value; if BinArrayValue ==1 BinArray = [1:length(ERPwaveview_binchan.BinRange.String)-1]; else BinArray = BinArrayValue-1; end - ERPwaviewer_apply.bin = BinArray; - - %%recover the label for bin and channel panel, and reset - %%backgroundcolor of "Apply" + bindef = gui_erp_waviewer.ERPwaviewer.bin; + if numel(BinArray)>numel(bindef) + bindiff = setdiff(BinArray,bindef); + else + bindiff = setdiff(bindef,BinArray); + end + if ~isempty(bindiff) + gui_erp_waviewer.ERPwaviewer.bin = BinArray; + end estudioworkingmemory('MyViewer_chanbin',0); ERPwaveview_binchan.apply.BackgroundColor = [1 1 1]; Chanbin_waveviewer_box.TitleColor= [0.5 0.5 0.9]; ERPwaveview_binchan.apply.ForegroundColor = [0 0 0]; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); + ERPwaveview_binchan.cancel.BackgroundColor = [1 1 1]; + ERPwaveview_binchan.cancel.ForegroundColor = [0 0 0]; - %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ERPwaviewer_apply.binchan_op; - MERPWaveViewer_chanbin{2} =ERPwaviewer_apply.chan; - MERPWaveViewer_chanbin{3} =ERPwaviewer_apply.bin; + MERPWaveViewer_chanbin{1} = 0; + MERPWaveViewer_chanbin{2} =gui_erp_waviewer.ERPwaviewer.chan; + MERPWaveViewer_chanbin{3} =gui_erp_waviewer.ERPwaviewer.bin; estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); %%change the other panels based on the changed bins and channels - viewer_ERPDAT.Count_currentERP = viewer_ERPDAT.Count_currentERP+1; - %%plot waves - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP = 1; viewer_ERPDAT.Process_messg =2; end %%---------change channels and bins based on the selected ERPsets---------- function v_currentERP_change(~,~) - try - ERPwaviewer_S = evalin('base','ALLERPwaviewer'); - catch + if viewer_ERPDAT.Count_currentERP~=2 return; end - ALLERP_S = ERPwaviewer_S.ALLERP; - Selected_ERPsetlabel = ERPwaviewer_S.SelectERPIdx; - if max(Selected_ERPsetlabel(:))> length(ALLERP_S) - Selected_ERPsetlabel =length(ALLERP_S); + ALLERP_S = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + + if any(ERPsetArray(:)> length(ALLERP_S)) + ERPsetArray =length(ALLERP_S); + gui_erp_waviewer.ERPwaviewer.SelectERPIdx =ERPsetArray; end try - ERPwaviewer_S.ERP = ALLERP_S(Selected_ERPsetlabel(1)); - ERPwaviewer_S.CURRENTERP =Selected_ERPsetlabel(1); + gui_erp_waviewer.ERPwaviewer.ERP = ALLERP_S(ERPsetArray(1)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPsetArray(1); catch - ERPwaviewer_S.ERP = ALLERP_S(Selected_ERPsetlabel(1)); - ERPwaviewer_S.CURRENTERP =Selected_ERPsetlabel(1); + gui_erp_waviewer.ERPwaviewer.ERP = ALLERP_S(ERPsetArray(1)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPsetArray(1); + gui_erp_waviewer.ERPwaviewer.PageIndex=1; end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP_S,Selected_ERPsetlabel); + [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP_S,ERPsetArray); % Channel information Chanlist_name = cell(length(chanStr)+1,1); Chanlist_name(1) = {'All'}; @@ -566,19 +361,14 @@ function v_currentERP_change(~,~) end % Channel information Chanlist = chanStr; - Chan_selindex = ERPwaveview_binchan.ElecRange.Value; - if numel(Chan_selindex) ==1 && Chan_selindex==1 - Chan_sel = [1:numel(ERPwaveview_binchan.ElecRange.String)-1]; - else - Chan_sel =Chan_selindex-1; - end - if ~isempty(Chan_sel) - if max(Chan_sel)> numel(Chanlist) - Chan_sel= 1:length(Chanlist); - end - else - Chan_sel= 1:length(Chanlist); + Chan_selindex = gui_erp_waviewer.ERPwaviewer.chan; + if isempty(Chan_selindex) || any(Chan_selindex>length(Chanlist)) || any(Chan_selindex(:)<=0) + Chan_selindex =[1:length(Chanlist)]; + gui_erp_waviewer.ERPwaviewer.chan= Chan_selindex; end + + Chan_sel =Chan_selindex; + ERPwaveview_binchan.ElecRange.String = Chanlist_name; try if length(Chan_sel) == numel(chanStr) @@ -592,22 +382,15 @@ function v_currentERP_change(~,~) ERPwaveview_binchan.ElecRange.Min = 1; ERPwaveview_binchan.ElecRange.Max = length(ERPwaveview_binchan.ElecRange.String)+1; - %%Bin information + %%----------------------Bin information---------------------------- brange = cell(length(binStr)+1,1); BinNum = length(binStr); - Bin_selIndex = ERPwaveview_binchan.BinRange.Value; - if numel(Bin_selIndex) ==1 && Bin_selIndex==1 - Bin_sel = [1:numel(ERPwaveview_binchan.BinRange.String)-1]; - else - Bin_sel = Bin_selIndex-1; - end - if ~isempty(Bin_sel) - if max(Bin_sel)> BinNum - Bin_sel= 1:BinNum; - end - else - Bin_sel= 1:BinNum; + Bin_selIndex = gui_erp_waviewer.ERPwaviewer.bin; + if isempty(Bin_selIndex) || any(Bin_selIndex>BinNum) || any(Bin_selIndex<=0) + Bin_selIndex = [1:BinNum]; + gui_erp_waviewer.ERPwaviewer.bin=Bin_selIndex; end + Bin_sel = Bin_selIndex; brange(1) = {'All'}; for Numofbin11 = 1:length(binStr) brange(Numofbin11+1) = {char(strcat(num2str(Numofbin11),'.',32,char(binStr(Numofbin11))))}; @@ -625,7 +408,7 @@ function v_currentERP_change(~,~) else ChanArray = ChanArrayValue-1; end - ERPwaviewer_S.chan = ChanArray; + gui_erp_waviewer.ERPwaviewer.chan = ChanArray; BinArrayValue =ERPwaveview_binchan.BinRange.Value ; if BinArrayValue ==1 @@ -633,44 +416,38 @@ function v_currentERP_change(~,~) else BinArray = BinArrayValue-1; end - ERPwaviewer_S.bin = BinArray; - assignin('base','ALLERPwaviewer',ERPwaviewer_S); + gui_erp_waviewer.ERPwaviewer.bin = BinArray; + ERPwaveview_binchan.ElecRange.Enable = 'on'; + ERPwaveview_binchan.BinRange.Enable = 'on'; %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ERPwaviewer_S.binchan_op; - MERPWaveViewer_chanbin{2} =ERPwaviewer_S.chan; - MERPWaveViewer_chanbin{3} =ERPwaviewer_S.bin; + MERPWaveViewer_chanbin{1} = 0; + MERPWaveViewer_chanbin{2} =gui_erp_waviewer.ERPwaviewer.chan; + MERPWaveViewer_chanbin{3} =gui_erp_waviewer.ERPwaviewer.bin; estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); + viewer_ERPDAT.Count_currentERP=3; end - - %%------------update this panel based on the imported parameters----------- function loadproper_change(~,~) if viewer_ERPDAT.loadproper_count ~=2 return; end - try - ERPwaviewer_S = evalin('base','ALLERPwaviewer'); - catch - return; - end - ALLERP_S = ERPwaviewer_S.ALLERP; - Selected_ERPsetlabel = ERPwaviewer_S.SelectERPIdx; - - if max(Selected_ERPsetlabel(:))> length(ALLERP_S) - Selected_ERPsetlabel =length(ALLERP_S); + ALLERP_S = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + if max(ERPsetArray(:))> length(ALLERP_S) + ERPsetArray =length(ALLERP_S); end try - ERPwaviewer_S.ERP = ALLERP_S(Selected_ERPsetlabel(1)); - ERPwaviewer_S.CURRENTERP =Selected_ERPsetlabel(1); + gui_erp_waviewer.ERPwaviewer.ERP = ALLERP_S(ERPsetArray(1)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPsetArray(1); catch - ERPwaviewer_S.ERP = ALLERP_S(Selected_ERPsetlabel(1)); - ERPwaviewer_S.CURRENTERP =Selected_ERPsetlabel(1); + gui_erp_waviewer.ERPwaviewer.ERP = ALLERP_S(ERPsetArray(1)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPsetArray(1); end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP_S,Selected_ERPsetlabel); + [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP_S,ERPsetArray); % Channel information Chanlist_name = cell(length(chanStr)+1,1); Chanlist_name(1) = {'All'}; @@ -679,7 +456,7 @@ function loadproper_change(~,~) end % Channel information Chanlist = chanStr; - Chan_sel =ERPwaviewer_S.chan; + Chan_sel =gui_erp_waviewer.ERPwaviewer.chan; if ~isempty(Chan_sel) if max(Chan_sel)> numel(Chanlist) Chan_sel= 1:length(Chanlist); @@ -687,7 +464,7 @@ function loadproper_change(~,~) else Chan_sel= 1:length(Chanlist); end - ERPwaviewer_S.chan = Chan_sel; + gui_erp_waviewer.ERPwaviewer.chan = Chan_sel; ERPwaveview_binchan.ElecRange.String = Chanlist_name; try if length(Chan_sel) == numel(chanStr) @@ -704,7 +481,7 @@ function loadproper_change(~,~) %%Bin information brange = cell(length(binStr)+1,1); BinNum = length(binStr); - Bin_sel = ERPwaviewer_S.bin; + Bin_sel = gui_erp_waviewer.ERPwaviewer.bin; if ~isempty(Bin_sel) if max(Bin_sel)> BinNum Bin_sel= 1:BinNum; @@ -722,270 +499,32 @@ function loadproper_change(~,~) else ERPwaveview_binchan.BinRange.Value = Bin_sel+1; end - ERPwaviewer_S.bin = Bin_sel; + gui_erp_waviewer.ERPwaviewer.bin = Bin_sel; ERPtooltype = erpgettoolversion('tooltype'); if ~strcmpi(ERPtooltype,'EStudio') && ~strcmpi(ERPtooltype,'ERPLAB') - ERPwaviewer_S.erp_binchan_op = 0; + gui_erp_waviewer.ERPwaviewer.erp_binchan_op = 0; end %%Auto or Custom - binchanOp = ERPwaviewer_S.binchan_op; - if binchanOp ==1 - ERPwaveview_binchan.auto.Value = 1; - ERPwaveview_binchan.custom.Value =0; - ERPwaveview_binchan.ElecRange.Enable = 'off'; - ERPwaveview_binchan.BinRange.Enable = 'off'; - else - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - end + ERPwaveview_binchan.ElecRange.Enable = 'on'; + ERPwaveview_binchan.BinRange.Enable = 'on'; + %%settings dependent on runing EStudio or ERPLAB or other way (e.g.,script). - if strcmpi(ERPtooltype,'EStudio') - ERPwaveview_binchan.auto.String = 'Same as EStudio'; - elseif strcmpi(ERPtooltype,'ERPLAB') - ERPwaveview_binchan.auto.String = ''; - ERPwaveview_binchan.BinRange.Enable = 'on'; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.auto.Enable = 'off'; - ERPwaveview_binchan.custom.Enable = 'off'; - else - ERPwaveview_binchan.auto.String = ''; - ERPwaveview_binchan.auto.Enable = 'off'; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.custom.String = ''; - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Enable = 'off'; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - end + ERPwaveview_binchan.ElecRange.Enable = 'on'; + ERPwaveview_binchan.BinRange.Enable = 'on'; - assignin('base','ALLERPwaviewer',ERPwaviewer_S); %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ERPwaviewer_S.binchan_op; - MERPWaveViewer_chanbin{2} =ERPwaviewer_S.chan; - MERPWaveViewer_chanbin{3} =ERPwaviewer_S.bin; + gui_erp_waviewer.ERPwaviewer.binchan_op=0; + MERPWaveViewer_chanbin{1} = 0; + MERPWaveViewer_chanbin{2} =gui_erp_waviewer.ERPwaviewer.chan; + MERPWaveViewer_chanbin{3} =gui_erp_waviewer.ERPwaviewer.bin; estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); viewer_ERPDAT.loadproper_count=3; end -%%modify the channels based on the changes of main EStudio - function ERP_chan_changed(~,~) - ALLERPStudio = observe_ERPDAT.ALLERP; - if isempty(ALLERPStudio) || (length(ALLERPStudio)==1&& strcmpi(ALLERPStudio(1).erpname,'No ERPset loaded')) || strcmpi(ALLERPStudio(length(ALLERPStudio)).erpname,'No ERPset loaded') - return; - end - try - ChanBinAutoValue = ERPwaveview_binchan.auto.Value; - catch - return; - end - - ChanArrayStudio = observe_ERPDAT.ERP_chan; - chanNumdef = length(ERPwaveview_binchan.ElecRange.String)-1; - - if ~isempty(ChanArrayStudio) && ChanBinAutoValue==1 - if min(ChanArrayStudio(:))<=0 || max(ChanArrayStudio(:))>chanNumdef - return; - end - - MessageViewer= char(strcat('Channels and Bins > Channel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - % viewer_ERPDAT.Process_messg =1; - - try - ALLERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nChannels and Bins -f_ERP_Binchan_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - try - if numel(ChanArrayStudio)==chanNumdef - ERPwaveview_binchan.ElecRange.Value =1; - else - ERPwaveview_binchan.ElecRange.Value =ChanArrayStudio+1; - end - catch - ERPwaveview_binchan.ElecRange.Value =1; - end - ALLERPwaviewer_apply.chan = ChanArrayStudio; - assignin('base','ALLERPwaviewer',ALLERPwaviewer_apply); - %%change the other panels based on the changed bins and channels - viewer_ERPDAT.Count_currentERP = viewer_ERPDAT.Count_currentERP+1; - - %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ALLERPwaviewer_apply.binchan_op; - MERPWaveViewer_chanbin{2} =ALLERPwaviewer_apply.chan; - MERPWaveViewer_chanbin{3} =ALLERPwaviewer_apply.bin; - estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); - %%plot waves - f_redrawERP_viewer_test(); - end - end - -%%modify the bins based on the changes of main EStudio - function ERP_bin_changed(~,~) - ALLERPStudio = observe_ERPDAT.ALLERP; - if isempty(ALLERPStudio) || (length(ALLERPStudio)==1&& strcmpi(ALLERPStudio(1).erpname,'No ERPset loaded')) || strcmpi(ALLERPStudio(length(ALLERPStudio)).erpname,'No ERPset loaded') - return; - end - - try - ChanBinAutoValue = ERPwaveview_binchan.auto.Value; - catch - return; - end - BinArrayStudio = observe_ERPDAT.ERP_bin; - binNumdef = length(ERPwaveview_binchan.BinRange.String)-1; - if ~isempty(BinArrayStudio) && ChanBinAutoValue==1 - if min(BinArrayStudio(:))<=0 || max(BinArrayStudio(:))> binNumdef - return; - end - MessageViewer= char(strcat('Channels and Bins > Bin')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - % viewer_ERPDAT.Process_messg =1; - - try - ALLERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nChannels and Bins -f_ERP_Binchan_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - try - if numel(BinArrayStudio)==binNumdef - ERPwaveview_binchan.BinRange.Value =1; - else - ERPwaveview_binchan.BinRange.Value =BinArrayStudio+1; - end - catch - ERPwaveview_binchan.BinRange.Value =1; - end - ALLERPwaviewer_apply.bin = BinArrayStudio; - assignin('base','ALLERPwaviewer',ALLERPwaviewer_apply); - - %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ALLERPwaviewer_apply.binchan_op; - MERPWaveViewer_chanbin{2} =ALLERPwaviewer_apply.chan; - MERPWaveViewer_chanbin{3} =ALLERPwaviewer_apply.bin; - estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); - - %%change the other panels based on the changed bins and channels - viewer_ERPDAT.Count_currentERP = viewer_ERPDAT.Count_currentERP+1; - %%plot waves - f_redrawERP_viewer_test(); - end - end -%%change channels and bins based on the main EStudio - function Two_GUI_change(~,~) - if observe_ERPDAT.Two_GUI~=2 - return; - end - - ERPtooltype = erpgettoolversion('tooltype'); - if isempty(observe_ERPDAT.ALLERP) - try - % % cprintf('red',['\n ERP Wave viewer will be closed because ALLERP is empty.\n\n']); - close(gui_erp_waviewer.Window); - catch - end - assignin('base','ALLERPwaviewer',[]); - return; - end - - - ALLERPStudio = observe_ERPDAT.ALLERP; - if strcmpi(ERPtooltype,'EStudio') - if (length(ALLERPStudio)==1&& strcmpi(ALLERPStudio(1).erpname,'No ERPset loaded')) || strcmpi(ALLERPStudio(length(ALLERPStudio)).erpname,'No ERPset loaded') - try - % cprintf('red',['\n ERP Wave viewer will be closed because ALLERP is empty.\n\n']); - close(gui_erp_waviewer.Window); - catch - end - assignin('base','ALLERPwaviewer',[]); - return; - end - end - - try - ALLERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nChannels and Bins -f_ERP_Binchan_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - - try - ChanBinAutoValue = ERPwaveview_binchan.auto.Value; - catch - return; - end - MessageViewer= char(strcat('Channels and Bins')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - - if strcmpi(ERPtooltype,'EStudio') && ChanBinAutoValue==1 - ALLERPwaviewer_apply.bin=observe_ERPDAT.ERP_bin; - ALLERPwaviewer_apply.chan=observe_ERPDAT.ERP_chan; - end - - BinArrayStudio = ALLERPwaviewer_apply.bin; - binNumdef = length(ERPwaveview_binchan.BinRange.String)-1; - if ~isempty(BinArrayStudio) && ChanBinAutoValue==1 - if min(BinArrayStudio(:))<=0 || max(BinArrayStudio(:))> binNumdef - return; - end - try - if numel(BinArrayStudio)==binNumdef - ERPwaveview_binchan.BinRange.Value =1; - else - ERPwaveview_binchan.BinRange.Value =BinArrayStudio+1; - end - catch - ERPwaveview_binchan.BinRange.Value =1; - end - ALLERPwaviewer_apply.bin = BinArrayStudio; - end - - ChanArrayStudio = ALLERPwaviewer_apply.chan; - chanNumdef = length(ERPwaveview_binchan.ElecRange.String)-1; - if ~isempty(ChanArrayStudio) && ChanBinAutoValue==1 - if min(ChanArrayStudio(:))<=0 || max(ChanArrayStudio(:))>chanNumdef - return; - end - try - if numel(ChanArrayStudio)==chanNumdef - ERPwaveview_binchan.ElecRange.Value =1; - else - ERPwaveview_binchan.ElecRange.Value =ChanArrayStudio+1; - end - ERPwaveview_binchan.ElecRange.Max = length( ERPwaveview_binchan.ElecRange.String)+2; - catch - ERPwaveview_binchan.ElecRange.Value =1; - end - ALLERPwaviewer_apply.chan = ChanArrayStudio; - end - ERPwaveview_binchan.ElecRange.Max = length(ERPwaveview_binchan.ElecRange.String)+2; - assignin('base','ALLERPwaviewer',ALLERPwaviewer_apply); - - %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ALLERPwaviewer_apply.binchan_op; - MERPWaveViewer_chanbin{2} =ALLERPwaviewer_apply.chan; - MERPWaveViewer_chanbin{3} =ALLERPwaviewer_apply.bin; - estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); - - - %%change the other panels based on the changed bins and channels - viewer_ERPDAT.Count_currentERP = viewer_ERPDAT.Count_currentERP+1; - %%plot waves - f_redrawERP_viewer_test(); - observe_ERPDAT.Two_GUI = 0; - end - %%------------------------------------------------------------------------- %%Automatically saving the changed parameters for the current panel if the %%user change parameters for the other panels. @@ -1003,171 +542,47 @@ function count_twopanels_change(~,~) %%Reset this panel with the default parameters function Reset_Waviewer_panel_change(~,~) - if viewer_ERPDAT.Reset_Waviewer_panel==2 - ERPtooltype = erpgettoolversion('tooltype'); - try - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); - ALLERPIN = ERPwaviewerIN.ALLERP; - catch - beep; - disp('f_ERP_Binchan_waviewer_GUI error: Restart ERPwave Viewer'); - return; - end + if viewer_ERPDAT.Reset_Waviewer_panel~=2 + return; + end + ERPwaveview_binchan.ElecRange.Enable = 'on'; + ERPwaveview_binchan.BinRange.Enable = 'on'; + Selected_erpset = evalin('base','CURRENTERP'); + ALLERP = evalin('base','ALLERP'); + if ~isempty(Selected_erpset) && ~isempty(ALLERP) && (Selected_erpset<= length(ALLERP)) && min(Selected_erpset)>0 + [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,Selected_erpset); + Chanlist_name = cell(length(chanStr)+1,1); + Chanlist_name(1) = {'All'}; + for Numofchan11 = 1:length(chanStr) + Chanlist_name(Numofchan11+1) = {char(strcat(num2str(Numofchan11),'.',32,char(chanStr(Numofchan11))))}; + end + ERPwaveview_binchan.ElecRange.String = Chanlist_name; + ERPwaveview_binchan.ElecRange.Value =1; - if strcmpi(ERPtooltype,'EStudio') - ERPwaveview_binchan.auto.Value = 1; - ERPwaveview_binchan.custom.Value =0; - ERPwaveview_binchan.ElecRange.Enable = 'off'; - ERPwaveview_binchan.BinRange.Enable = 'off'; - Selected_erpset= estudioworkingmemory('selectederpstudio'); - Geterpbinchan = estudioworkingmemory('geterpbinchan'); - CurrentERPIndex = Geterpbinchan.Select_index; - - if max(Selected_erpset(:))> length(ALLERPIN) - Selected_erpset =1; - CurrentERPIndex =1; - end - BinArray = Geterpbinchan.bins{Geterpbinchan.Select_index}; - chanArray = Geterpbinchan.elecs_shown{Geterpbinchan.Select_index}; - chan_bin = Geterpbinchan.bins_chans(CurrentERPIndex); - if chan_bin ==1 - ERPwaviewerIN.plot_org.Grid =2; - ERPwaviewerIN.plot_org.Overlay=1; - ERPwaviewerIN.plot_org.Pages=3; - elseif chan_bin==0 - ERPwaviewerIN.plot_org.Grid =1; - ERPwaviewerIN.plot_org.Overlay=2; - ERPwaviewerIN.plot_org.Pages=3; - end - - % Channel information - chanStr = [1:(numel(ERPwaveview_binchan.ElecRange.String)-1)]; - Chanlist = chanStr; - Chan_sel = chanArray; - if ~isempty(Chan_sel) - if max(Chan_sel)> numel(Chanlist) - Chan_sel= 1:length(Chanlist); - end - else - Chan_sel= 1:length(Chanlist); - end - try - if length(Chan_sel) == numel(chanStr) - ERPwaveview_binchan.ElecRange.Value =1; - else - ERPwaveview_binchan.ElecRange.Value =Chan_sel+1; - end - catch - ERPwaveview_binchan.ElecRange.Value =1; - end - - %%Bin information - binStr = ERPwaveview_binchan.BinRange.String; - BinNum = length(binStr)-1; - Bin_sel = BinArray; - if ~isempty(Bin_sel) - if max(Bin_sel)> BinNum - Bin_sel= 1:BinNum; - end - else - Bin_sel= 1:BinNum; - end - - if BinNum== numel(Bin_sel) - ERPwaveview_binchan.BinRange.Value =1; - else - ERPwaveview_binchan.BinRange.Value = Bin_sel+1; - end - - ERPwaviewerIN.bin = Bin_sel; - ERPwaviewerIN.chan = Chan_sel; - ERPwaviewerIN.binchan_op = 1; - elseif strcmpi(ERPtooltype,'ERPLAB') - ERPwaveview_binchan.auto.Value = 0; - ERPwaveview_binchan.custom.Value =1; - ERPwaveview_binchan.auto.Enable = 'off'; - ERPwaveview_binchan.custom.Enable = 'off'; - ERPwaveview_binchan.ElecRange.Enable = 'on'; - ERPwaveview_binchan.BinRange.Enable = 'on'; - Selected_erpset = evalin('base','CURRENTERP'); - ALLERP = evalin('base','ALLERP'); - if ~isempty(Selected_erpset) && ~isempty(ALLERP) && (Selected_erpset<= length(ALLERP)) && min(Selected_erpset)>0 - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,Selected_erpset); - Chanlist_name = cell(length(chanStr)+1,1); - Chanlist_name(1) = {'All'}; - for Numofchan11 = 1:length(chanStr) - Chanlist_name(Numofchan11+1) = {char(strcat(num2str(Numofchan11),'.',32,char(chanStr(Numofchan11))))}; - end - ERPwaveview_binchan.ElecRange.String = Chanlist_name; - ERPwaveview_binchan.ElecRange.Value =1; - - brange = cell(length(binStr)+1,1); - brange(1) = {'All'}; - for Numofbin11 = 1:length(binStr) - brange(Numofbin11+1) = {char(strcat(num2str(Numofbin11),'.',32,char(binStr(Numofbin11))))}; - end - ERPwaveview_binchan.BinRange.String = brange; - ERPwaveview_binchan.BinRange.Value = 1; - end - ERPwaviewerIN.bin = [1:length(ERPwaveview_binchan.BinRange.String)-1]; - ERPwaviewerIN.chan = [1:length(ERPwaveview_binchan.ElecRange.String)-1]; - ERPwaviewerIN.binchan_op = 0; + brange = cell(length(binStr)+1,1); + brange(1) = {'All'}; + for Numofbin11 = 1:length(binStr) + brange(Numofbin11+1) = {char(strcat(num2str(Numofbin11),'.',32,char(binStr(Numofbin11))))}; end - assignin('base','ALLERPwaviewer',ERPwaviewerIN); - - %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ERPwaviewerIN.binchan_op; - MERPWaveViewer_chanbin{2} =ERPwaviewerIN.chan; - MERPWaveViewer_chanbin{3} =ERPwaviewerIN.bin; - estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); - - ERPwaveview_binchan.apply.BackgroundColor = [1 1 1]; - Chanbin_waveviewer_box.TitleColor= [0.5 0.5 0.9]; - ERPwaveview_binchan.apply.ForegroundColor = [0 0 0]; - viewer_ERPDAT.Reset_Waviewer_panel=3; + ERPwaveview_binchan.BinRange.String = brange; + ERPwaveview_binchan.BinRange.Value = 1; end + gui_erp_waviewer.ERPwaviewer.bin = [1:length(ERPwaveview_binchan.BinRange.String)-1]; + gui_erp_waviewer.ERPwaviewer.chan = [1:length(ERPwaveview_binchan.ElecRange.String)-1]; + gui_erp_waviewer.ERPwaviewer.binchan_op = 0; + + %%save the parameters to memory file + MERPWaveViewer_chanbin{1} = 0; + MERPWaveViewer_chanbin{2} =gui_erp_waviewer.ERPwaviewer.chan; + MERPWaveViewer_chanbin{3} =gui_erp_waviewer.ERPwaviewer.bin; + estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); + + ERPwaveview_binchan.apply.BackgroundColor = [1 1 1]; + Chanbin_waveviewer_box.TitleColor= [0.5 0.5 0.9]; + ERPwaveview_binchan.apply.ForegroundColor = [0 0 0]; + viewer_ERPDAT.Reset_Waviewer_panel=3; end%%reset end -%%Update the change of label indeces - function ERPset_Chan_bin_label_change(~,~) - if viewer_ERPDAT.ERPset_Chan_bin_label~=1 - return; - end - try - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_Binchan_waviewer_GUI error: Restart ERPwave Viewer'); - return; - end - - if ERPwaveview_binchan.auto.Value ==0 - BinArray = ERPwaviewerIN.bin; - ChanArray = ERPwaviewerIN.chan; - ChaNum= length(ERPwaveview_binchan.ElecRange.String)-1; - if max(ChanArray(:)) <=ChaNum - if ChaNum== numel(ChanArray) - ERPwaveview_binchan.ElecRange.Value=1; - else - ERPwaveview_binchan.ElecRange.Value= ChanArray+1; - end - end - BiNum = length(ERPwaveview_binchan.BinRange.String)-1; - if max(BinArray(:)) <=BiNum - if numel(BinArray)==BiNum - ERPwaveview_binchan.BinRange.Value=1; - else - ERPwaveview_binchan.BinRange.Value=BinArray+1; - end - end - - %%save the parameters to memory file - MERPWaveViewer_chanbin{1} = ERPwaviewerIN.binchan_op; - MERPWaveViewer_chanbin{2} =ERPwaviewerIN.chan; - MERPWaveViewer_chanbin{3} =ERPwaviewerIN.bin; - estudioworkingmemory('MERPWaveViewer_chanbin',MERPWaveViewer_chanbin); - end - end %%Execute the panel when press "Return" or "Enter" diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_labelset_waveviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_labelset_waveviewer_GUI.m index 580d9db3..a6b564ad 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_labelset_waveviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_labelset_waveviewer_GUI.m @@ -11,10 +11,11 @@ function varargout = f_ERP_labelset_waveviewer_GUI(varargin) global viewer_ERPDAT; +global gui_erp_waviewer; addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); -% addlistener(viewer_ERPDAT,'Process_messg_change',@Process_messg_change); addlistener(viewer_ERPDAT,'count_twopanels_change',@count_twopanels_change); addlistener(viewer_ERPDAT,'Reset_Waviewer_panel_change',@Reset_Waviewer_panel_change); +addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); gui_labelset_waveviewer = struct(); @@ -49,13 +50,6 @@ function drawui_plot_property(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_labelset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end %%--------------------channel and bin setting---------------------- gui_labelset_waveviewer.DataSelBox = uiextras.VBox('Parent', box_erplabelset_viewer_property,'BackgroundColor',ColorBviewer_def); @@ -112,9 +106,9 @@ function drawui_plot_property(FonsizeDefault) gui_labelset_waveviewer.nolabel.Value = ~gui_labelset_waveviewer.customlabel.Value; customdefEnable = 'on'; end - ERPwaviewer.chanbinsetlabel.location.auto = gui_labelset_waveviewer.labelauto.Value; - ERPwaviewer.chanbinsetlabel.location.no = gui_labelset_waveviewer.nolabel.Value; - ERPwaviewer.chanbinsetlabel.location.custom =gui_labelset_waveviewer.customlabel.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto = gui_labelset_waveviewer.labelauto.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no = gui_labelset_waveviewer.nolabel.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom =gui_labelset_waveviewer.customlabel.Value; if locationAuto ==1 xperDef = 50; yperDef = 100; @@ -150,9 +144,9 @@ function drawui_plot_property(FonsizeDefault) 'callback',@label_center,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'Enable',customdefEnable,'Value',CenDef); % gui_labelset_waveviewer.center.KeyPressFcn = @labels_presskey; set(gui_labelset_waveviewer.labelloc_title,'Sizes',[30 45 30 45 80]); - ERPwaviewer.chanbinsetlabel.location.xperc = str2num(char(gui_labelset_waveviewer.xperc_edit.String)); - ERPwaviewer.chanbinsetlabel.location.yperc = str2num(char(gui_labelset_waveviewer.yperc_edit.String)); - ERPwaviewer.chanbinsetlabel.location.center = gui_labelset_waveviewer.center.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc = str2num(char(gui_labelset_waveviewer.xperc_edit.String)); + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc = str2num(char(gui_labelset_waveviewer.yperc_edit.String)); + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center = gui_labelset_waveviewer.center.Value; % %%--------------------font and font size--------------------------- @@ -192,8 +186,8 @@ function drawui_plot_property(FonsizeDefault) 'callback',@label_fontsize,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',LabelfontsizeValue,'Enable',customdefEnable); % gui_labelset_waveviewer.font_custom_size.KeyPressFcn = @labels_presskey; set(gui_labelset_waveviewer.font_custom_title,'Sizes',[30 110 30 70]); - ERPwaviewer.chanbinsetlabel.font = gui_labelset_waveviewer.font_custom_type.Value; - ERPwaviewer.chanbinsetlabel.fontsize = labelfontsizeinum(gui_labelset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font = gui_labelset_waveviewer.font_custom_type.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize = labelfontsizeinum(gui_labelset_waveviewer.font_custom_size.Value); %%--------------Label text color----------- try @@ -212,21 +206,22 @@ function drawui_plot_property(FonsizeDefault) uiextras.Empty('Parent',gui_labelset_waveviewer.labelcolor_title); uiextras.Empty('Parent',gui_labelset_waveviewer.labelcolor_title); set(gui_labelset_waveviewer.labelcolor_title,'Sizes',[40 100 30 70]); - ERPwaviewer.chanbinsetlabel.textcolor = gui_labelset_waveviewer.labelcolor.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor = gui_labelset_waveviewer.labelcolor.Value; %%-----------------------help and apply---------------------------- gui_labelset_waveviewer.help_apply_title = uiextras.HBox('Parent', gui_labelset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); uiextras.Empty('Parent',gui_labelset_waveviewer.help_apply_title ); - uicontrol('Style','pushbutton','Parent', gui_labelset_waveviewer.help_apply_title ,'String','Cancel',... - 'callback',@label_help,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold','HorizontalAlignment','left' + gui_labelset_waveviewer.cancel = uicontrol('Style','pushbutton','Parent', gui_labelset_waveviewer.help_apply_title ,'String','Cancel',... + 'callback',@label_cancel,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold','HorizontalAlignment','left' uiextras.Empty('Parent',gui_labelset_waveviewer.help_apply_title ); gui_labelset_waveviewer.Apply= uicontrol('Style','pushbutton','Parent',gui_labelset_waveviewer.help_apply_title ,'String','Apply',... 'callback',@label_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'HorizontalAlignment','left' uiextras.Empty('Parent',gui_labelset_waveviewer.help_apply_title ); set(gui_labelset_waveviewer.help_apply_title ,'Sizes',[40 70 20 70 20]); set(gui_labelset_waveviewer.DataSelBox ,'Sizes',[20 25 25 20 25 25 25]); - assignin('base','ALLERPwaviewer',ERPwaviewer); estudioworkingmemory('MERPWaveViewer_label',MERPWaveViewer_label); + + estudioworkingmemory('MyViewer_labels',0); end %%***********************************************************************%% @@ -242,6 +237,8 @@ function labelauto(~,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_labelset_waveviewer.labelauto.Value = 1; gui_labelset_waveviewer.nolabel.Value = 0; @@ -259,20 +256,12 @@ function labelauto(~,~) gui_labelset_waveviewer.labelcolor.Enable = Enable; gui_labelset_waveviewer.label_customtable.Enable = Enable; gui_labelset_waveviewer.labelcolor.Value = 1; - %%----------------Update the label----------------- - try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer = ALLERPwaviewer; - catch - beep; - disp('f_ERP_labelset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - binArray = ERPwaviewer.bin; - chanArray = ERPwaviewer.chan; - ERPsetArray = ERPwaviewer.SelectERPIdx; - ALLERPIN = ERPwaviewer.ALLERP; + %%----------------Update the label----------------- + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end @@ -281,17 +270,17 @@ function labelauto(~,~) LabelName{ii,1} = ''; LabelNamenum(ii,1) =ii; end - if ERPwaviewer.plot_org.Grid ==1 %% if the selected Channel is "Grid" + if gui_erp_waviewer.ERPwaviewer.plot_org.Grid ==1 %% if the selected Channel is "Grid" plotArray = chanArray; for Numofplot = 1:numel(plotArray) LabelName{Numofplot,1} = chanStr{plotArray(Numofplot)}; end - elseif ERPwaviewer.plot_org.Grid == 2 %% if the selected Bin is "Grid" + elseif gui_erp_waviewer.ERPwaviewer.plot_org.Grid == 2 %% if the selected Bin is "Grid" plotArray = binArray; for Numofplot = 1:numel(plotArray) LabelName{Numofplot,1} = chanStr{plotArray(Numofplot)}; end - elseif ERPwaviewer.plot_org.Grid == 3%% if the selected ERPset is "Grid" + elseif gui_erp_waviewer.ERPwaviewer.plot_org.Grid == 3%% if the selected ERPset is "Grid" plotArray = ERPsetArray; for Numoferpset = 1:numel(plotArray) LabelName{Numoferpset,1} = {char(ALLERPIN(plotArray(Numoferpset)).erpname)}; @@ -302,7 +291,6 @@ function labelauto(~,~) LabelName{Numofplot,1} = chanStr{plotArray(Numofplot)}; end end - labels_str = table(LabelNamenum,LabelName); labels_str = table2cell(labels_str); gui_labelset_waveviewer.label_customtable.Data = labels_str; @@ -318,18 +306,18 @@ function nolabel(~,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_labelset_waveviewer.labelauto.Value = 0; gui_labelset_waveviewer.nolabel.Value = 1; gui_labelset_waveviewer.customlabel.Value = 0; - Enable = 'off'; - gui_labelset_waveviewer.xperc_edit.Enable =Enable ; - gui_labelset_waveviewer.yperc_edit.Enable = Enable; - gui_labelset_waveviewer.center.Enable = Enable; - gui_labelset_waveviewer.font_custom_type.Enable = Enable; - gui_labelset_waveviewer.font_custom_size.Enable = Enable; - gui_labelset_waveviewer.labelcolor.Enable = Enable; - gui_labelset_waveviewer.label_customtable.Enable = Enable; + gui_labelset_waveviewer.xperc_edit.Enable ='off'; + gui_labelset_waveviewer.yperc_edit.Enable = 'off'; + gui_labelset_waveviewer.center.Enable = 'off'; + gui_labelset_waveviewer.font_custom_type.Enable = 'off'; + gui_labelset_waveviewer.font_custom_size.Enable = 'off'; + gui_labelset_waveviewer.labelcolor.Enable = 'off'; + gui_labelset_waveviewer.label_customtable.Enable = 'off'; end %%-------------------------Setting for Save as----------------------------- @@ -342,18 +330,19 @@ function customlabel(~,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_labelset_waveviewer.labelauto.Value = 0; gui_labelset_waveviewer.nolabel.Value =0; gui_labelset_waveviewer.customlabel.Value = 1; - Enable = 'on'; - gui_labelset_waveviewer.xperc_edit.Enable =Enable ; - gui_labelset_waveviewer.yperc_edit.Enable = Enable; - gui_labelset_waveviewer.center.Enable = Enable; - gui_labelset_waveviewer.font_custom_type.Enable = Enable; - gui_labelset_waveviewer.font_custom_size.Enable = Enable; - gui_labelset_waveviewer.labelcolor.Enable = Enable; - gui_labelset_waveviewer.label_customtable.Enable = Enable; + + gui_labelset_waveviewer.xperc_edit.Enable ='on'; + gui_labelset_waveviewer.yperc_edit.Enable = 'on'; + gui_labelset_waveviewer.center.Enable = 'on'; + gui_labelset_waveviewer.font_custom_type.Enable = 'on'; + gui_labelset_waveviewer.font_custom_size.Enable = 'on'; + gui_labelset_waveviewer.labelcolor.Enable = 'on'; + gui_labelset_waveviewer.label_customtable.Enable = 'on'; end %%-------------------X percentage------------------------------------------ @@ -366,10 +355,12 @@ function label_xperc(Source,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; if isempty(str2num(Source.String)) || numel(str2num(Source.String))~=1 viewer_ERPDAT.Process_messg =4; messgStr = strcat('Chan/Bin/ERPset Label Properties > X% should a number and we therefore used 50'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); gui_labelset_waveviewer.xperc_edit.String ='50' ; end end @@ -384,10 +375,12 @@ function label_yperc(Source,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; if isempty(str2num(Source.String)) || numel(str2num(Source.String))~=1 viewer_ERPDAT.Process_messg =4; messgStr = strcat('Chan/Bin/ERPset Label Properties > Y% should a number and we therefore used 100'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); gui_labelset_waveviewer.yperc_edit.String = '100'; end end @@ -402,6 +395,8 @@ function label_center(Source,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%--------------------------Font of label text----------------------------- @@ -414,6 +409,8 @@ function label_font(Source,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%------------------------Fontsize of label text--------------------------- @@ -426,6 +423,8 @@ function label_fontsize(Source,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%-----------------------color of label text------------------------------- @@ -438,57 +437,51 @@ function label_color(Source,~) gui_labelset_waveviewer.Apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_labelset_waveviewer.Apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_labelset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%--------------------------Help------------------------------------------- - function label_help(~,~) + function label_cancel(~,~) [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=5 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end MessageViewer= char(strcat('Chan/Bin/ERPset Labels > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; changeFlag = estudioworkingmemory('MyViewer_labels'); if changeFlag~=1 MessageViewer= char(strcat('Chan/Bin/ERPset Labels > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; return; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Chan/Bin/ERPset Labels > Apply-f_ERP_labelset_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - - if ERPwaviewer_apply.chanbinsetlabel.location.auto==1 + if gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto==1 Enable = 'off'; gui_labelset_waveviewer.labelauto.Value = 1; gui_labelset_waveviewer.nolabel.Value = 0; gui_labelset_waveviewer.customlabel.Value = 0; - elseif ERPwaviewer_apply.chanbinsetlabel.location.no==1 + elseif gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no==1 Enable = 'off'; gui_labelset_waveviewer.labelauto.Value = 0; gui_labelset_waveviewer.nolabel.Value = 1; gui_labelset_waveviewer.customlabel.Value = 0; - elseif ERPwaviewer_apply.chanbinsetlabel.location.custom==1 + elseif gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom==1 Enable = 'on'; gui_labelset_waveviewer.labelauto.Value = 0; gui_labelset_waveviewer.nolabel.Value = 0; gui_labelset_waveviewer.customlabel.Value = 1; end gui_labelset_waveviewer.xperc_edit.Enable = Enable; - gui_labelset_waveviewer.xperc_edit.String = num2str( ERPwaviewer_apply.chanbinsetlabel.location.xperc); + gui_labelset_waveviewer.xperc_edit.String = num2str( gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc); gui_labelset_waveviewer.yperc_edit.Enable = Enable; - gui_labelset_waveviewer.yperc_edit.String = num2str( ERPwaviewer_apply.chanbinsetlabel.location.yperc); + gui_labelset_waveviewer.yperc_edit.String = num2str( gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc); gui_labelset_waveviewer.font_custom_type.Enable = Enable; - gui_labelset_waveviewer.font_custom_type.Value = ERPwaviewer_apply.chanbinsetlabel.font; + gui_labelset_waveviewer.font_custom_type.Value = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; gui_labelset_waveviewer.font_custom_size.Enable = Enable; - FontSize = ERPwaviewer_apply.chanbinsetlabel.fontsize; + FontSize = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize; fontsizeStr = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; labelfontsizeinum = str2num(char(fontsizeStr)); @@ -498,16 +491,18 @@ function label_help(~,~) end gui_labelset_waveviewer.font_custom_size.Value = X_label; gui_labelset_waveviewer.labelcolor.Enable = Enable; - gui_labelset_waveviewer.labelcolor.Value = ERPwaviewer_apply.chanbinsetlabel.textcolor; + gui_labelset_waveviewer.labelcolor.Value = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; gui_labelset_waveviewer.center.Enable = Enable; - gui_labelset_waveviewer.center.Value = ERPwaviewer_apply.chanbinsetlabel.location.center; + gui_labelset_waveviewer.center.Value = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; estudioworkingmemory('MyViewer_labels',0); gui_labelset_waveviewer.Apply.BackgroundColor = [1 1 1]; gui_labelset_waveviewer.Apply.ForegroundColor = [0 0 0]; box_erplabelset_viewer_property.TitleColor= [0.5 0.5 0.9]; + gui_labelset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_labelset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Chan/Bin/ERPset Labels > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -522,53 +517,46 @@ function label_apply(~,~) gui_labelset_waveviewer.Apply.BackgroundColor = [1 1 1]; gui_labelset_waveviewer.Apply.ForegroundColor = [0 0 0]; box_erplabelset_viewer_property.TitleColor= [0.5 0.5 0.9]; - + gui_labelset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_labelset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Chan/Bin/ERPset Labels > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Chan/Bin/ERPset Labels > Apply-f_ERP_labelset_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - ERPwaviewer_apply.chanbinsetlabel.location.auto = gui_labelset_waveviewer.labelauto.Value; - ERPwaviewer_apply.chanbinsetlabel.location.no = gui_labelset_waveviewer.nolabel.Value; - ERPwaviewer_apply.chanbinsetlabel.location.custom =gui_labelset_waveviewer.customlabel.Value; - ERPwaviewer_apply.chanbinsetlabel.location.xperc = str2num(char(gui_labelset_waveviewer.xperc_edit.String)); - ERPwaviewer_apply.chanbinsetlabel.location.yperc = str2num(char(gui_labelset_waveviewer.yperc_edit.String)); - MERPWaveViewer_label{1} = ERPwaviewer_apply.chanbinsetlabel.location.auto; - MERPWaveViewer_label{2} = ERPwaviewer_apply.chanbinsetlabel.location.no; - MERPWaveViewer_label{3} =ERPwaviewer_apply.chanbinsetlabel.location.custom; - MERPWaveViewer_label{4} =ERPwaviewer_apply.chanbinsetlabel.location.xperc; - MERPWaveViewer_label{5} =ERPwaviewer_apply.chanbinsetlabel.location.yperc; - if ( ERPwaviewer_apply.chanbinsetlabel.location.no==1 || ERPwaviewer_apply.chanbinsetlabel.location.custom ==1) && (isempty(ERPwaviewer_apply.chanbinsetlabel.location.xperc) || isempty(ERPwaviewer_apply.chanbinsetlabel.location.yperc)) - ERPwaviewer_apply.chanbinsetlabel.location.auto = 1; - ERPwaviewer_apply.chanbinsetlabel.location.no = 0; - ERPwaviewer_apply.chanbinsetlabel.location.custom =0; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto = gui_labelset_waveviewer.labelauto.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no = gui_labelset_waveviewer.nolabel.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom =gui_labelset_waveviewer.customlabel.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc = str2num(char(gui_labelset_waveviewer.xperc_edit.String)); + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc = str2num(char(gui_labelset_waveviewer.yperc_edit.String)); + MERPWaveViewer_label{1} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto; + MERPWaveViewer_label{2} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no; + MERPWaveViewer_label{3} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom; + MERPWaveViewer_label{4} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + MERPWaveViewer_label{5} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + + if ( gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no==1 || gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom ==1) && (isempty(gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc) || isempty(gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc)) + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto = 1; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no = 0; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom =0; end - ERPwaviewer_apply.chanbinsetlabel.location.center = gui_labelset_waveviewer.center.Value; - MERPWaveViewer_label{6} = ERPwaviewer_apply.chanbinsetlabel.location.center; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center = gui_labelset_waveviewer.center.Value; + MERPWaveViewer_label{6} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; labelfontsizeinum = str2num(char(fontsize)); - ERPwaviewer_apply.chanbinsetlabel.font = gui_labelset_waveviewer.font_custom_type.Value; - MERPWaveViewer_label{7} = ERPwaviewer_apply.chanbinsetlabel.font; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font = gui_labelset_waveviewer.font_custom_type.Value; + MERPWaveViewer_label{7} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; try - ERPwaviewer_apply.chanbinsetlabel.fontsize = labelfontsizeinum(gui_labelset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize = labelfontsizeinum(gui_labelset_waveviewer.font_custom_size.Value); catch - ERPwaviewer_apply.chanbinsetlabel.fontsize = 10; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize = 10; end - ERPwaviewer_apply.chanbinsetlabel.textcolor = gui_labelset_waveviewer.labelcolor.Value; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor = gui_labelset_waveviewer.labelcolor.Value; MERPWaveViewer_label{8} = gui_labelset_waveviewer.font_custom_size.Value; - MERPWaveViewer_label{9} = ERPwaviewer_apply.chanbinsetlabel.textcolor; + MERPWaveViewer_label{9} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; - ALLERPwaviewer=ERPwaviewer_apply; - assignin('base','ALLERPwaviewer',ALLERPwaviewer); - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP = 1; viewer_ERPDAT.Process_messg =2; estudioworkingmemory('MERPWaveViewer_label',MERPWaveViewer_label); end @@ -579,16 +567,10 @@ function loadproper_change(~,~) if viewer_ERPDAT.loadproper_count ~=5 return; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_labelset_waveviewer_GUI() > Apply error: Please run the ERP wave viewer again.'); - return; - end - AutoValue = ERPwaviewer_apply.chanbinsetlabel.location.auto; - NoValue = ERPwaviewer_apply.chanbinsetlabel.location.no; - CustomValue = ERPwaviewer_apply.chanbinsetlabel.location.custom; + + AutoValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto; + NoValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no; + CustomValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom; if AutoValue ==1 && NoValue==0 && CustomValue==0 gui_labelset_waveviewer.labelauto.Value = 1; gui_labelset_waveviewer.nolabel.Value = 0; @@ -630,39 +612,39 @@ function loadproper_change(~,~) gui_labelset_waveviewer.labelcolor.Enable = Enable; gui_labelset_waveviewer.label_customtable.Enable = Enable; end - Xperc = ERPwaviewer_apply.chanbinsetlabel.location.xperc; - Yperc = ERPwaviewer_apply.chanbinsetlabel.location.yperc; - Center = ERPwaviewer_apply.chanbinsetlabel.location.center; + Xperc = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + Yperc = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + Centerflag = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; gui_labelset_waveviewer.xperc_edit.String = num2str(Xperc); gui_labelset_waveviewer.yperc_edit.String = num2str(Yperc); - if Center ==1 + if Centerflag ==1 gui_labelset_waveviewer.center.Value = 1; else gui_labelset_waveviewer.center.Value = 0; end - Labelfont = ERPwaviewer_apply.chanbinsetlabel.font; + Labelfont = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; gui_labelset_waveviewer.font_custom_type.Value = Labelfont; - Labelfontsize = ERPwaviewer_apply.chanbinsetlabel.fontsize; + Labelfontsize = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; fontsize = str2num(char(fontsize)); [xsize,y] = find(fontsize ==Labelfontsize); gui_labelset_waveviewer.font_custom_size.Value = xsize; - textColor = ERPwaviewer_apply.chanbinsetlabel.textcolor; + textColor = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; gui_labelset_waveviewer.labelcolor.Value = textColor; - viewer_ERPDAT.loadproper_count =6; %%save the parameters to memory file - MERPWaveViewer_label{1} = ERPwaviewer_apply.chanbinsetlabel.location.auto; - MERPWaveViewer_label{2} = ERPwaviewer_apply.chanbinsetlabel.location.no; - MERPWaveViewer_label{3} =ERPwaviewer_apply.chanbinsetlabel.location.custom; - MERPWaveViewer_label{4} =ERPwaviewer_apply.chanbinsetlabel.location.xperc; - MERPWaveViewer_label{5} =ERPwaviewer_apply.chanbinsetlabel.location.yperc; - MERPWaveViewer_label{6} = ERPwaviewer_apply.chanbinsetlabel.location.center; - MERPWaveViewer_label{7} = ERPwaviewer_apply.chanbinsetlabel.font; + MERPWaveViewer_label{1} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto; + MERPWaveViewer_label{2} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no; + MERPWaveViewer_label{3} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom; + MERPWaveViewer_label{4} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + MERPWaveViewer_label{5} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + MERPWaveViewer_label{6} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; + MERPWaveViewer_label{7} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; MERPWaveViewer_label{8} = gui_labelset_waveviewer.font_custom_size.Value; - MERPWaveViewer_label{9} = ERPwaviewer_apply.chanbinsetlabel.textcolor; + MERPWaveViewer_label{9} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; estudioworkingmemory('MERPWaveViewer_label',MERPWaveViewer_label); + viewer_ERPDAT.loadproper_count =6; end @@ -685,64 +667,142 @@ function count_twopanels_change(~,~) %%-----------------Reset this panel with the default parameters------------ %%------------------------------------------------------------------------- function Reset_Waviewer_panel_change(~,~) - if viewer_ERPDAT.Reset_Waviewer_panel==5 - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_labelset_waveviewer_GUI error: Restart ERPwave Viewer'); - return; - end - gui_labelset_waveviewer.labelauto.Value=1; % - gui_labelset_waveviewer.nolabel.Value=0; % - gui_labelset_waveviewer.customlabel.Value=0; % - ERPwaviewerin.chanbinsetlabel.location.auto =1; - ERPwaviewerin.chanbinsetlabel.location.no =0; - ERPwaviewerin.chanbinsetlabel.location.custom=0; - %%label position - gui_labelset_waveviewer.xperc_edit.String = '50'; - gui_labelset_waveviewer.xperc_edit.Enable ='off'; % - gui_labelset_waveviewer.yperc_edit.String ='100'; - gui_labelset_waveviewer.yperc_edit.Enable='off'; % - gui_labelset_waveviewer.center.Value =1; - gui_labelset_waveviewer.center.Enable='off'; % - ERPwaviewerin.chanbinsetlabel.location.xperc =50; - ERPwaviewerin.chanbinsetlabel.location.yperc = 100; - ERPwaviewerin.chanbinsetlabel.location.center =1; - %%label font, fontsize and color - ERPwaviewerin.chanbinsetlabel.font =3; - ERPwaviewerin.chanbinsetlabel.fontsize =10; - ERPwaviewerin.chanbinsetlabel.textcolor=1; - fonttype = {'Courier','Geneva','Helvetica','Monaco','Times'}; - gui_labelset_waveviewer.font_custom_type.Value=3; - gui_labelset_waveviewer.font_custom_type.String = fonttype; - gui_labelset_waveviewer.font_custom_type.Enable='off'; % - gui_labelset_waveviewer.font_custom_size.Value=4; - gui_labelset_waveviewer.font_custom_size.Enable='off'; % - gui_labelset_waveviewer.labelcolor.Value=1; - gui_labelset_waveviewer.labelcolor.Enable='off'; % - assignin('base','ALLERPwaviewer',ERPwaviewerin); - gui_labelset_waveviewer.Apply.BackgroundColor = [1 1 1]; - gui_labelset_waveviewer.Apply.ForegroundColor = [0 0 0]; - box_erplabelset_viewer_property.TitleColor= [0.5 0.5 0.9]; - - %%save the default parameters to memory file - MERPWaveViewer_label{1} = ERPwaviewerin.chanbinsetlabel.location.auto; - MERPWaveViewer_label{2} = ERPwaviewerin.chanbinsetlabel.location.no; - MERPWaveViewer_label{3} =ERPwaviewerin.chanbinsetlabel.location.custom; - MERPWaveViewer_label{4} =ERPwaviewerin.chanbinsetlabel.location.xperc; - MERPWaveViewer_label{5} =ERPwaviewerin.chanbinsetlabel.location.yperc; - MERPWaveViewer_label{6} = ERPwaviewerin.chanbinsetlabel.location.center; - MERPWaveViewer_label{7} = ERPwaviewerin.chanbinsetlabel.font; - MERPWaveViewer_label{8} = gui_labelset_waveviewer.font_custom_size.Value; - MERPWaveViewer_label{9} = ERPwaviewerin.chanbinsetlabel.textcolor; - estudioworkingmemory('MERPWaveViewer_label',MERPWaveViewer_label); - - viewer_ERPDAT.Reset_Waviewer_panel=6; + if viewer_ERPDAT.Reset_Waviewer_panel~=5 + return; end + gui_labelset_waveviewer.labelauto.Value=1; % + gui_labelset_waveviewer.nolabel.Value=0; % + gui_labelset_waveviewer.customlabel.Value=0; % + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto =1; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no =0; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom=0; + %%label position + gui_labelset_waveviewer.xperc_edit.String = '50'; + gui_labelset_waveviewer.xperc_edit.Enable ='off'; % + gui_labelset_waveviewer.yperc_edit.String ='100'; + gui_labelset_waveviewer.yperc_edit.Enable='off'; % + gui_labelset_waveviewer.center.Value =1; + gui_labelset_waveviewer.center.Enable='off'; % + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc =50; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc = 100; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center =1; + %%label font, fontsize and color + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font =3; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize =10; + gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor=1; + fonttype = {'Courier','Geneva','Helvetica','Monaco','Times'}; + gui_labelset_waveviewer.font_custom_type.Value=3; + gui_labelset_waveviewer.font_custom_type.String = fonttype; + gui_labelset_waveviewer.font_custom_type.Enable='off'; % + gui_labelset_waveviewer.font_custom_size.Value=4; + gui_labelset_waveviewer.font_custom_size.Enable='off'; % + gui_labelset_waveviewer.labelcolor.Value=1; + gui_labelset_waveviewer.labelcolor.Enable='off'; % + gui_labelset_waveviewer.Apply.BackgroundColor = [1 1 1]; + gui_labelset_waveviewer.Apply.ForegroundColor = [0 0 0]; + box_erplabelset_viewer_property.TitleColor= [0.5 0.5 0.9]; + + %%save the default parameters to memory file + MERPWaveViewer_label{1} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto; + MERPWaveViewer_label{2} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no; + MERPWaveViewer_label{3} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom; + MERPWaveViewer_label{4} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + MERPWaveViewer_label{5} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + MERPWaveViewer_label{6} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; + MERPWaveViewer_label{7} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; + MERPWaveViewer_label{8} = gui_labelset_waveviewer.font_custom_size.Value; + MERPWaveViewer_label{9} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; + estudioworkingmemory('MERPWaveViewer_label',MERPWaveViewer_label); + viewer_ERPDAT.Reset_Waviewer_panel=6; end -%%using "Return" key to execute this panel + +%%------------------------change this panel-------------------------------- + function v_currentERP_change(~,~) + if viewer_ERPDAT.Count_currentERP~=5 + return; + end + AutoValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto; + NoValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no; + CustomValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom; + if AutoValue ==1 && NoValue==0 && CustomValue==0 + gui_labelset_waveviewer.labelauto.Value = 1; + gui_labelset_waveviewer.nolabel.Value = 0; + gui_labelset_waveviewer.customlabel.Value = 0; + Enable = 'off'; + gui_labelset_waveviewer.xperc_edit.Enable =Enable ; + gui_labelset_waveviewer.yperc_edit.Enable = Enable; + gui_labelset_waveviewer.center.Enable = Enable; + gui_labelset_waveviewer.font_custom_type.Enable = Enable; + gui_labelset_waveviewer.font_custom_size.Enable = Enable; + gui_labelset_waveviewer.font_custom_type.Value = 2; + gui_labelset_waveviewer.font_custom_size.Value = 4; + gui_labelset_waveviewer.xperc_edit.String ='50' ; + gui_labelset_waveviewer.yperc_edit.String = '100'; + gui_labelset_waveviewer.labelcolor.Enable = Enable; + gui_labelset_waveviewer.label_customtable.Enable = Enable; + elseif AutoValue ==0 && NoValue==1 && CustomValue==0 + gui_labelset_waveviewer.labelauto.Value = 0; + gui_labelset_waveviewer.nolabel.Value = 1; + gui_labelset_waveviewer.customlabel.Value = 0; + Enable = 'off'; + gui_labelset_waveviewer.xperc_edit.Enable =Enable ; + gui_labelset_waveviewer.yperc_edit.Enable = Enable; + gui_labelset_waveviewer.center.Enable = Enable; + gui_labelset_waveviewer.font_custom_type.Enable = Enable; + gui_labelset_waveviewer.font_custom_size.Enable = Enable; + gui_labelset_waveviewer.labelcolor.Enable = Enable; + gui_labelset_waveviewer.label_customtable.Enable = Enable; + elseif AutoValue ==0 && NoValue==0 && CustomValue==1 + gui_labelset_waveviewer.labelauto.Value = 0; + gui_labelset_waveviewer.nolabel.Value =0; + gui_labelset_waveviewer.customlabel.Value = 1; + Enable = 'on'; + gui_labelset_waveviewer.xperc_edit.Enable =Enable ; + gui_labelset_waveviewer.yperc_edit.Enable = Enable; + gui_labelset_waveviewer.center.Enable = Enable; + gui_labelset_waveviewer.font_custom_type.Enable = Enable; + gui_labelset_waveviewer.font_custom_size.Enable = Enable; + gui_labelset_waveviewer.labelcolor.Enable = Enable; + gui_labelset_waveviewer.label_customtable.Enable = Enable; + end + Xperc = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + Yperc = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + Center = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; + gui_labelset_waveviewer.xperc_edit.String = num2str(Xperc); + gui_labelset_waveviewer.yperc_edit.String = num2str(Yperc); + if Center ==1 + gui_labelset_waveviewer.center.Value = 1; + else + gui_labelset_waveviewer.center.Value = 0; + end + Labelfont = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; + gui_labelset_waveviewer.font_custom_type.Value = Labelfont; + Labelfontsize = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize; + fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... + '40','50','60','70','80','90','100'}; + fontsize = str2num(char(fontsize)); + [xsize,y] = find(fontsize ==Labelfontsize); + gui_labelset_waveviewer.font_custom_size.Value = xsize; + textColor = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; + gui_labelset_waveviewer.labelcolor.Value = textColor; + + %%save the parameters to memory file + MERPWaveViewer_label{1} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.auto; + MERPWaveViewer_label{2} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no; + MERPWaveViewer_label{3} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom; + MERPWaveViewer_label{4} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + MERPWaveViewer_label{5} =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + MERPWaveViewer_label{6} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; + MERPWaveViewer_label{7} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; + MERPWaveViewer_label{8} = gui_labelset_waveviewer.font_custom_size.Value; + MERPWaveViewer_label{9} = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; + estudioworkingmemory('MERPWaveViewer_label',MERPWaveViewer_label); + viewer_ERPDAT.Count_currentERP=6; + end + + +%%----------------using "Return" key to execute this panel----------------- function labels_presskey(hObject, eventdata) keypress = eventdata.Key; if strcmp (keypress, 'return') || strcmp (keypress , 'enter') diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_lineset_waveviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_lineset_waveviewer_GUI.m index 85a35e47..57e1e448 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_lineset_waveviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_lineset_waveviewer_GUI.m @@ -5,14 +5,13 @@ % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2022 +% 2022 && Nov. 2023 function varargout = f_ERP_lineset_waveviewer_GUI(varargin) global viewer_ERPDAT; -addlistener(viewer_ERPDAT,'legend_change',@legend_change); -addlistener(viewer_ERPDAT,'page_xyaxis_change',@page_xyaxis_change); +global gui_erp_waviewer; addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); addlistener(viewer_ERPDAT,'count_twopanels_change',@count_twopanels_change); @@ -50,13 +49,6 @@ function drawui_lineset_property(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end %%--------------------channel and bin setting---------------------- gui_erplinset_waveviewer.DataSelBox = uiextras.VBox('Parent', box_erplineset_viewer_property,'BackgroundColor',ColorBviewer_def); @@ -92,15 +84,15 @@ function drawui_lineset_property(FonsizeDefault) %%-----------Setting for line table----------------------------- gui_erplinset_waveviewer.line_customtable_title = uiextras.HBox('Parent', gui_erplinset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); try - plot_org = ERPwaviewer.plot_org; + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; if plot_org.Grid ==1 - GridNum = numel(ERPwaviewer.chan); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.chan); elseif plot_org.Grid ==2 - GridNum = numel(ERPwaviewer.bin); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.bin); elseif plot_org.Grid ==3 - GridNum = numel(ERPwaviewer.SelectERPIdx); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.SelectERPIdx); else - GridNum = numel(ERPwaviewer.chan); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.chan); end catch GridNum = []; @@ -133,15 +125,14 @@ function drawui_lineset_property(FonsizeDefault) gui_erplinset_waveviewer.line_customtable.ColumnWidth = {25 80 65 50}; gui_erplinset_waveviewer.line_customtable.CellEditCallback = @line_customtable; gui_erplinset_waveviewer.line_customtable.KeyPressFcn = @line_presskey; - %%setting for uitable: https://undocumentedmatlab.com/artiALLERPwaviewercles/multi-line-uitable-column-headers + %%setting for uitable: https://undocumentedmatlab.com/articles/multi-line-uitable-column-headers if gui_erplinset_waveviewer.linesauto.Value ==1 gui_erplinset_waveviewer.line_customtable.Enable = 'off'; else gui_erplinset_waveviewer.line_customtable.Enable = 'on'; end - ERPwaviewer.Lines.auto =gui_erplinset_waveviewer.linesauto.Value; - ERPwaviewer.Lines.data =gui_erplinset_waveviewer.line_customtable.Data; - + gui_erp_waviewer.ERPwaviewer.Lines.auto =gui_erplinset_waveviewer.linesauto.Value; + gui_erp_waviewer.ERPwaviewer.Lines.data =gui_erplinset_waveviewer.line_customtable.Data; %%-----------Setting for legend table ----------------------------- % gui_erplinset_waveviewer.legend_customtable_title = uiextras.HBox('Parent', gui_erplinset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -149,17 +140,17 @@ function drawui_lineset_property(FonsizeDefault) LegendName{ii,1} = ''; LegendNamenum(ii,1) =ii; end - ALLERPIN = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; if max(ERPsetArray(:))> length(ALLERPIN) ERPsetArray =length(ALLERPIN); end [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); try - plot_org = ERPwaviewer.plot_org; - ERPIN = ERPwaviewer.ERP; + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; + ERPIN = gui_erp_waviewer.ERPwaviewer.ERP; if plot_org.Overlay ==1 - ChanArray = ERPwaviewer.chan; + ChanArray = gui_erp_waviewer.ERPwaviewer.chan; for Numofchan = 1:numel(ChanArray) LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); end @@ -167,7 +158,7 @@ function drawui_lineset_property(FonsizeDefault) legendset_str = table2cell(legendset_str); LegendArray = ChanArray; elseif plot_org.Overlay ==2 - binArray = ERPwaviewer.bin; + binArray = gui_erp_waviewer.ERPwaviewer.bin; for Numofbin = 1:numel(binArray) LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); end @@ -175,8 +166,8 @@ function drawui_lineset_property(FonsizeDefault) legendset_str = table2cell(legendset_str); LegendArray = binArray; elseif plot_org.Overlay ==3 - ALLERP = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; for Numoferpset = 1:numel(ERPsetArray) LegendName{Numoferpset,1} = char(ALLERP(Numoferpset).erpname); end @@ -184,7 +175,7 @@ function drawui_lineset_property(FonsizeDefault) legendset_str = table2cell(legendset_str); LegendArray = ERPsetArray; else - binArray = ERPwaviewer.bin; + binArray = gui_erp_waviewer.ERPwaviewer.bin; for Numofbin = 1:numel(binArray) LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); end @@ -196,7 +187,7 @@ function drawui_lineset_property(FonsizeDefault) legendset_str = table(LegendNamenum,LegendName); legendset_str = table2cell(legendset_str); end - ERPwaviewer.Legend.data = legendset_str; + gui_erp_waviewer.ERPwaviewer.Legend.data = legendset_str; % %%--------------------legend font and font size--------------------------- @@ -220,13 +211,12 @@ function drawui_lineset_property(FonsizeDefault) 'callback',@font_color_custom,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'Value',~fontcolorAuto); % gui_erplinset_waveviewer.font_colorcustom.KeyPressFcn = @line_presskey; set(gui_erplinset_waveviewer.fontcolor_title,'Sizes',[60 70 70]); - ERPwaviewer.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; if gui_erplinset_waveviewer.font_colorauto.Value==1 fontEnable = 'off'; else fontEnable = 'on'; end - gui_erplinset_waveviewer.labelfont_title = uiextras.HBox('Parent', gui_erplinset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); try @@ -265,9 +255,8 @@ function drawui_lineset_property(FonsizeDefault) 'callback',@legendfontsize,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',LabelfontsizeValue,'Enable',fontEnable); % gui_erplinset_waveviewer.font_custom_size.KeyPressFcn = @line_presskey; set(gui_erplinset_waveviewer.labelfont_title,'Sizes',[30 110 30 70]); - ERPwaviewer.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; - ERPwaviewer.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); - + gui_erp_waviewer.ERPwaviewer.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; + gui_erp_waviewer.ERPwaviewer.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); %%----------------------------Legend textcolor--------------------- try @@ -294,10 +283,10 @@ function drawui_lineset_property(FonsizeDefault) 'callback',@legendtextcustom,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'Value',~legendtextcolorAuto,'Enable',fontEnable,'HorizontalAlignment','left'); % gui_erplinset_waveviewer.legendtextcustom.KeyPressFcn = @line_presskey; set(gui_erplinset_waveviewer.legend_textitle,'Sizes',[70 60 150]); - ERPwaviewer.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; %%------------------------Legend columns--------------------------- - legendcolumnsdef = round(sqrt( length(LegendArray))); + legendcolumnsdef = ceil(sqrt( length(LegendArray))); try legendcolumns= MERPWaveViewer_linelegend{7}; catch @@ -323,13 +312,13 @@ function drawui_lineset_property(FonsizeDefault) gui_erplinset_waveviewer.legendcolumns.KeyPressFcn = @line_presskey; uiextras.Empty('Parent', gui_erplinset_waveviewer.legend_columnstitle ); set(gui_erplinset_waveviewer.legend_columnstitle,'Sizes',[60 100 70]); - ERPwaviewer.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; + gui_erp_waviewer.ERPwaviewer.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; %%-------------------------help and apply-------------------------- gui_erplinset_waveviewer.help_apply_title = uiextras.HBox('Parent', gui_erplinset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); uiextras.Empty('Parent',gui_erplinset_waveviewer.help_apply_title ); - uicontrol('Style','pushbutton','Parent', gui_erplinset_waveviewer.help_apply_title ,'String','Cancel',... + gui_erplinset_waveviewer.cancel = uicontrol('Style','pushbutton','Parent', gui_erplinset_waveviewer.help_apply_title ,'String','Cancel',... 'callback',@linelegend_help,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold','HorizontalAlignment','left' uiextras.Empty('Parent',gui_erplinset_waveviewer.help_apply_title ); gui_erplinset_waveviewer.apply = uicontrol('Style','pushbutton','Parent',gui_erplinset_waveviewer.help_apply_title ,'String','Apply',... @@ -338,8 +327,21 @@ function drawui_lineset_property(FonsizeDefault) set(gui_erplinset_waveviewer.help_apply_title ,'Sizes',[40 70 20 70 20]); set(gui_erplinset_waveviewer.DataSelBox ,'Sizes',[20 200 20 25 25 25 25]); - assignin('base','ALLERPwaviewer',ERPwaviewer); + estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend); + + gui_erp_waviewer.ERPwaviewer.Lines.auto = gui_erplinset_waveviewer.linesauto.Value; + gui_erp_waviewer.ERPwaviewer.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; + fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... + '40','50','60','70','80','90','100'}; + labelfontsizeinum = str2num(char(fontsize)); + gui_erp_waviewer.ERPwaviewer.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; + gui_erp_waviewer.ERPwaviewer.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; + gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; + + estudioworkingmemory('MyViewer_linelegend',0); end %%**************************************************************************%% @@ -356,29 +358,23 @@ function lines_auto(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_erplinset_waveviewer.linesauto.Value =1; gui_erplinset_waveviewer.linescustom.Value = 0; gui_erplinset_waveviewer.line_customtable.Enable = 'off'; + try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer = ALLERPwaviewer; - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - try - plot_org = ERPwaviewer.plot_org; + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; if plot_org.Grid ==1 - GridNum = numel(ERPwaviewer.chan); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.chan); elseif plot_org.Grid ==2 - GridNum = numel(ERPwaviewer.bin); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.bin); elseif plot_org.Grid ==3 - GridNum = numel(ERPwaviewer.SelectERPIdx); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.SelectERPIdx); else - GridNum = numel(ERPwaviewer.chan); + GridNum = numel(gui_erp_waviewer.ERPwaviewer.chan); end catch GridNum = []; @@ -402,7 +398,8 @@ function lines_custom(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_erplinset_waveviewer.linesauto.Value =0; gui_erplinset_waveviewer.linescustom.Value = 1; gui_erplinset_waveviewer.line_customtable.Enable = 'on'; @@ -427,11 +424,12 @@ function line_customtable(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; end - -%%Auto for font, fontsize, color, columns for legend +%%------------Auto for font, fontsize, color, columns for legend---------- function font_color_auto(Source,~) [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges();%%check if the changes were applied for the other panels if ~isempty(messgStr) && viewerpanelIndex~=6 @@ -441,32 +439,26 @@ function font_color_auto(Source,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp(' Line & Legends> Legend Auto error: Please run the ERP wave viewer again.'); - return; - end - ALLERPIN = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; if max(ERPsetArray(:))> length(ALLERPIN) ERPsetArray =length(ALLERPIN); end [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); - plot_org = ERPwaviewer.plot_org; + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; if plot_org.Overlay ==1 - LegendArray = ERPwaviewer.chan; + LegendArray = gui_erp_waviewer.ERPwaviewer.chan; elseif plot_org.Overlay ==2 - LegendArray = ERPwaviewer.bin; + LegendArray = gui_erp_waviewer.ERPwaviewer.bin; elseif plot_org.Overlay ==3 - LegendArray = ERPwaviewer.SelectERPIdx; + LegendArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; else - LegendArray = ERPwaviewer.bin; + LegendArray = gui_erp_waviewer.ERPwaviewer.bin; end - gui_erplinset_waveviewer.font_colorauto.Value=1; % gui_erplinset_waveviewer.font_colorcustom.Value = 0; gui_erplinset_waveviewer.font_custom_type.Enable = 'off'; % @@ -479,7 +471,6 @@ function font_color_auto(Source,~) gui_erplinset_waveviewer.legendcolumns.Enable = 'off'; gui_erplinset_waveviewer.font_custom_size.Value = 4; gui_erplinset_waveviewer.font_custom_type.Value =3; - end %%Custom for font, fontsize, color, columns for legend @@ -492,7 +483,8 @@ function font_color_custom(Source,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_erplinset_waveviewer.font_colorauto.Value=0; % gui_erplinset_waveviewer.font_colorcustom.Value = 1; gui_erplinset_waveviewer.font_custom_type.Enable = 'on'; % @@ -512,6 +504,8 @@ function legendfont(Source,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%----------------------fontsize of legend text---------------------------- @@ -524,6 +518,8 @@ function legendfontsize(Source,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; end @@ -537,7 +533,8 @@ function legendtextauto(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_erplinset_waveviewer.legendtextauto.Value =1; % gui_erplinset_waveviewer.legendtextcustom.Value =0; end @@ -553,7 +550,8 @@ function legendtextcustom(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_erplinset_waveviewer.legendtextauto.Value =0; % gui_erplinset_waveviewer.legendtextcustom.Value =1; end @@ -568,6 +566,8 @@ function legendcolumns(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; %%mark the changes gui_erplinset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplineset_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [1 1 1]; end @@ -578,50 +578,41 @@ function linelegend_help(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end MessageViewer= char(strcat('Lines & Legends > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; changeFlag = estudioworkingmemory('MyViewer_linelegend'); if changeFlag~=1 MessageViewer= char(strcat('Lines & Legends > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; return; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nLines & Legends > Cancel-f_ERP_lineset_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - - gui_erplinset_waveviewer.linesauto.Value= ERPwaviewer_apply.Lines.auto; - gui_erplinset_waveviewer.linescustom.Value= ~ERPwaviewer_apply.Lines.auto; - gui_erplinset_waveviewer.line_customtable.Data=ERPwaviewer_apply.Lines.data; + gui_erplinset_waveviewer.linesauto.Value= gui_erp_waviewer.ERPwaviewer.Lines.auto; + gui_erplinset_waveviewer.linescustom.Value= ~gui_erp_waviewer.ERPwaviewer.Lines.auto; + gui_erplinset_waveviewer.line_customtable.Data=gui_erp_waviewer.ERPwaviewer.Lines.data; if gui_erplinset_waveviewer.linesauto.Value==1 gui_erplinset_waveviewer.line_customtable.Enable = 'off'; else gui_erplinset_waveviewer.line_customtable.Enable = 'on'; end - fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; labelfontsizeinum = str2num(char(fontsize)); - gui_erplinset_waveviewer.font_custom_type.Value= ERPwaviewer_apply.Legend.font; - fontsizeValue = ERPwaviewer_apply.Legend.fontsize ; + gui_erplinset_waveviewer.font_custom_type.Value= gui_erp_waviewer.ERPwaviewer.Legend.font; + fontsizeValue = gui_erp_waviewer.ERPwaviewer.Legend.fontsize ; [x_label,y_label] = find(labelfontsizeinum==fontsizeValue); if isempty(x_label) x_label = 4; end gui_erplinset_waveviewer.font_custom_size.Value= x_label; - gui_erplinset_waveviewer.legendtextauto.Value= ERPwaviewer_apply.Legend.textcolor; - gui_erplinset_waveviewer.legendtextcustom.Value= ~ERPwaviewer_apply.Legend.textcolor; - gui_erplinset_waveviewer.legendcolumns.Value=ERPwaviewer_apply.Legend.columns; + gui_erplinset_waveviewer.legendtextauto.Value= gui_erp_waviewer.ERPwaviewer.Legend.textcolor; + gui_erplinset_waveviewer.legendtextcustom.Value= ~gui_erp_waviewer.ERPwaviewer.Legend.textcolor; + gui_erplinset_waveviewer.legendcolumns.Value=gui_erp_waviewer.ERPwaviewer.Legend.columns; try - FontColorAuto= ERPwaviewer_apply.Legend.FontColorAuto; + FontColorAuto= gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto; catch FontColorAuto=1; end @@ -639,13 +630,14 @@ function linelegend_help(~,~) gui_erplinset_waveviewer.legendtextcustom.Enable = LegendEnable; gui_erplinset_waveviewer.legendcolumns.Enable = LegendEnable; - estudioworkingmemory('MyViewer_linelegend',0); gui_erplinset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_erplinset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erplineset_viewer_property.TitleColor= [0.5 0.5 0.9]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Lines & Legends > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -661,30 +653,22 @@ function LineLegend_apply(~,~) gui_erplinset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_erplinset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erplineset_viewer_property.TitleColor= [0.5 0.5 0.9]; - + gui_erplinset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Lines & Legends > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer_apply = ALLERPwaviewer; - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Lines & Legends > Apply-f_ERP_lineset_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - ERPwaviewer_apply.Lines.auto = gui_erplinset_waveviewer.linesauto.Value; - ERPwaviewer_apply.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; + + gui_erp_waviewer.ERPwaviewer.Lines.auto = gui_erplinset_waveviewer.linesauto.Value; + gui_erp_waviewer.ERPwaviewer.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; labelfontsizeinum = str2num(char(fontsize)); - ERPwaviewer_apply.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; - ERPwaviewer_apply.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); - ERPwaviewer_apply.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; - ERPwaviewer_apply.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; - ERPwaviewer_apply.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); - + gui_erp_waviewer.ERPwaviewer.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; + gui_erp_waviewer.ERPwaviewer.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; + gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; %%Save the parameters for this panel to memory file MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; @@ -696,203 +680,40 @@ function LineLegend_apply(~,~) MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file - f_redrawERP_viewer_test(); - viewer_ERPDAT.Process_messg =2; - end - - -%%--------------change the legend name------------------------------------- - function legend_change(~,~) - if viewer_ERPDAT.count_legend==0 - return; - end - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - for ii = 1:100 - LegendName{ii,1} = ''; - LegendNamenum(ii,1) =ii; - end - ALLERPIN = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; - if max(ERPsetArray(:))> length(ALLERPIN) - ERPsetArray =length(ALLERPIN); - end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); - LegendArray = [1:4]; - try - plot_org = ERPwaviewer.plot_org; - ERPIN = ERPwaviewer.ERP; - if plot_org.Overlay ==1 - ChanArray = ERPwaviewer.chan; - for Numofchan = 1:numel(ChanArray) - LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = ChanArray; - elseif plot_org.Overlay ==2 - binArray = ERPwaviewer.bin; - for Numofbin = 1:numel(binArray) - LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = binArray; - elseif plot_org.Overlay ==3 - ALLERP = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; - for Numoferpset = 1:numel(ERPsetArray) - LegendName{Numoferpset,1} = char(ALLERP(ERPsetArray(Numoferpset)).erpname); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = ERPsetArray; - else - binArray = ERPwaviewer.bin; - for Numofbin = 1:numel(binArray) - LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = binArray; - end - catch - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - end - ERPwaviewer.Legend.data = legendset_str; - if gui_erplinset_waveviewer.font_colorauto.Value==1 - gui_erplinset_waveviewer.legendcolumns.Value =round(sqrt(length(LegendArray))); - ERPwaviewer.Legend.columns = round(sqrt(length(LegendArray))); - end - assignin('base','ALLERPwaviewer',ERPwaviewer); + gui_erp_waviewer.ERPwaviewer.Lines.auto = gui_erplinset_waveviewer.linesauto.Value; + gui_erp_waviewer.ERPwaviewer.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; + gui_erp_waviewer.ERPwaviewer.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; + gui_erp_waviewer.ERPwaviewer.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; + gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; - %%Save parameters for this panel to memory file - MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; - MERPWaveViewer_linelegend{2}= gui_erplinset_waveviewer.line_customtable.Data; - MERPWaveViewer_linelegend{3}=gui_erplinset_waveviewer.font_colorauto.Value; - MERPWaveViewer_linelegend{4}=gui_erplinset_waveviewer.font_custom_type.Value; - MERPWaveViewer_linelegend{5}=gui_erplinset_waveviewer.font_custom_size.Value; - MERPWaveViewer_linelegend{6}= gui_erplinset_waveviewer.legendtextauto.Value; - MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; - estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file - end - -%%--------changed the legend names based on the current page--------------- - function page_xyaxis_change(~,~) - if viewer_ERPDAT.page_xyaxis==0 - return; - end - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - for ii = 1:100 - LegendName{ii,1} = ''; - LegendNamenum(ii,1) =ii; - end - ALLERPIN = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; - if max(ERPsetArray(:))> length(ALLERPIN) - ERPsetArray =length(ALLERPIN); - end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); - LegendArray = [1:4]; - try - plot_org = ERPwaviewer.plot_org; - ERPIN = ERPwaviewer.ERP; - if plot_org.Overlay ==1 - ChanArray = ERPwaviewer.chan; - for Numofchan = 1:numel(ChanArray) - LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = ChanArray; - elseif plot_org.Overlay ==2 - binArray = ERPwaviewer.bin; - for Numofbin = 1:numel(binArray) - LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = binArray; - elseif plot_org.Overlay ==3 - ALLERP = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; - for Numoferpset = 1:numel(ERPsetArray) - LegendName{Numoferpset,1} = char(ALLERP(ERPsetArray(Numoferpset)).erpname); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = ERPsetArray; - else - binArray = ERPwaviewer.bin; - for Numofbin = 1:numel(binArray) - LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray = binArray; - end - catch - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - end - - ERPwaviewer.Legend.data = legendset_str; - if gui_erplinset_waveviewer.font_colorauto.Value==1 - gui_erplinset_waveviewer.legendcolumns.Value =round(sqrt(length(LegendArray))); - ERPwaviewer.Legend.columns = round(sqrt(length(LegendArray))); - end - assignin('base','ALLERPwaviewer',ERPwaviewer); - - MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; - MERPWaveViewer_linelegend{2}= gui_erplinset_waveviewer.line_customtable.Data; - MERPWaveViewer_linelegend{3}=gui_erplinset_waveviewer.font_colorauto.Value; - MERPWaveViewer_linelegend{4}=gui_erplinset_waveviewer.font_custom_type.Value; - MERPWaveViewer_linelegend{5}=gui_erplinset_waveviewer.font_custom_size.Value; - MERPWaveViewer_linelegend{6}= gui_erplinset_waveviewer.legendtextauto.Value; - MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; - estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file + viewer_ERPDAT.Count_currentERP = 1; + viewer_ERPDAT.Process_messg =2; end %%-----change legend if ERPsets is changed from the first two panels------- function v_currentERP_change(~,~) - if viewer_ERPDAT.Count_currentERP == 0 - return; - end - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); + if viewer_ERPDAT.Count_currentERP ~=6 return; end + for ii = 1:100 LegendName{ii,1} = ''; LegendNamenum(ii,1) =ii; end - ALLERP = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; if max(ERPsetArray(:))> length(ALLERP) ERPsetArray =length(ALLERP); end [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,ERPsetArray); LegendArray = [1:4]; try - plot_org = ERPwaviewer.plot_org; + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; if plot_org.Overlay ==1 - ChanArray = ERPwaviewer.chan; + ChanArray = gui_erp_waviewer.ERPwaviewer.chan; for Numofchan = 1:numel(ChanArray) LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); end @@ -900,7 +721,7 @@ function v_currentERP_change(~,~) legendset_str = table2cell(legendset_str); LegendArray =ChanArray ; elseif plot_org.Overlay ==2 - binArray = ERPwaviewer.bin; + binArray = gui_erp_waviewer.ERPwaviewer.bin; for Numofbin = 1:numel(binArray) LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); end @@ -915,7 +736,7 @@ function v_currentERP_change(~,~) legendset_str = table2cell(legendset_str); LegendArray =ERPsetArray ; else - binArray = ERPwaviewer.bin; + binArray = gui_erp_waviewer.ERPwaviewer.bin; for Numofbin = 1:numel(binArray) LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); end @@ -927,13 +748,12 @@ function v_currentERP_change(~,~) legendset_str = table(LegendNamenum,LegendName); legendset_str = table2cell(legendset_str); end - ERPwaviewer.Legend.data = legendset_str; - if gui_erplinset_waveviewer.font_colorauto.Value==1 - gui_erplinset_waveviewer.legendcolumns.Value =round(sqrt(length(LegendArray))); - ERPwaviewer.Legend.columns = round(sqrt(length(LegendArray))); + gui_erp_waviewer.ERPwaviewer.Legend.data = legendset_str; + if gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto ==1 + gui_erplinset_waveviewer.legendcolumns.Value =ceil(sqrt(length(LegendArray))); + gui_erp_waviewer.ERPwaviewer.Legend.columns = ceil(sqrt(length(LegendArray))); end - assignin('base','ALLERPwaviewer',ERPwaviewer); - + MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; MERPWaveViewer_linelegend{2}= gui_erplinset_waveviewer.line_customtable.Data; MERPWaveViewer_linelegend{3}=gui_erplinset_waveviewer.font_colorauto.Value; @@ -942,7 +762,18 @@ function v_currentERP_change(~,~) MERPWaveViewer_linelegend{6}= gui_erplinset_waveviewer.legendtextauto.Value; MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file - + gui_erp_waviewer.ERPwaviewer.Lines.auto = gui_erplinset_waveviewer.linesauto.Value; + gui_erp_waviewer.ERPwaviewer.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; + fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... + '40','50','60','70','80','90','100'}; + labelfontsizeinum = str2num(char(fontsize)); + gui_erp_waviewer.ERPwaviewer.Lines.auto = gui_erplinset_waveviewer.linesauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.font = gui_erplinset_waveviewer.font_custom_type.Value; + gui_erp_waviewer.ERPwaviewer.Legend.fontsize = labelfontsizeinum(gui_erplinset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.Legend.textcolor = gui_erplinset_waveviewer.legendtextauto.Value; + gui_erp_waviewer.ERPwaviewer.Legend.columns = gui_erplinset_waveviewer.legendcolumns.Value; + gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; + viewer_ERPDAT.Count_currentERP =7; end @@ -952,18 +783,12 @@ function loadproper_change(~,~) if viewer_ERPDAT.loadproper_count ~=6 return; end - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + %%-----------------------Line settings----------------------------- - LineValue = ERPwaviewer.Lines.auto; + LineValue = gui_erp_waviewer.ERPwaviewer.Lines.auto; if numel(LineValue)~=1 || (LineValue~=1 && LineValue~=0) LineValue = 1; - ERPwaviewer.Lines.auto = 1; + gui_erp_waviewer.ERPwaviewer.Lines.auto = 1; end if LineValue==1 gui_erplinset_waveviewer.linesauto.Value =1; @@ -975,7 +800,6 @@ function loadproper_change(~,~) gui_erplinset_waveviewer.line_customtable.Enable = 'on'; end - [lineNameStr,linecolors,linetypes,linewidths,linecolors_str,linetypes_str,linewidths_str,linecolorsrgb] = f_get_lineset_ERPviewer(); lineset_str =table(lineNameStr,linecolors,linetypes,linewidths); lineset_str = table2cell(lineset_str); @@ -983,10 +807,10 @@ function loadproper_change(~,~) {'solid','dash','dot','dashdot','plus','circle','asterisk'},... {'0.25','0.5','1','1.5','2','2.5','3','3.5','4','4.5','5','5.5','6','6.5','7','7.5','8','8.5','9','9.5','10','10.5'}}; - LineData = ERPwaviewer.Lines.data; + LineData = gui_erp_waviewer.ERPwaviewer.Lines.data; if LineValue==1 LineData= lineset_str; - ERPwaviewer.Lines.data = LineData; + gui_erp_waviewer.ERPwaviewer.Lines.data = LineData; end gui_erplinset_waveviewer.line_customtable.Data = LineData; @@ -996,17 +820,17 @@ function loadproper_change(~,~) LegendName{ii,1} = ''; LegendNamenum(ii,1) =ii; end - ALLERP = ERPwaviewer.ALLERP; - ERPsetArray = ERPwaviewer.SelectERPIdx; + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; if max(ERPsetArray(:))> length(ALLERP) ERPsetArray =length(ALLERP); end [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,ERPsetArray); LegendArray = [1:4]; try - plot_org = ERPwaviewer.plot_org; + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; if plot_org.Overlay ==1 - ChanArray = ERPwaviewer.chan; + ChanArray = gui_erp_waviewer.ERPwaviewer.chan; for Numofchan = 1:numel(ChanArray) LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); end @@ -1014,7 +838,7 @@ function loadproper_change(~,~) legendset_str = table2cell(legendset_str); LegendArray = ChanArray; elseif plot_org.Overlay ==2 - binArray = ERPwaviewer.bin; + binArray = gui_erp_waviewer.ERPwaviewer.bin; for Numofbin = 1:numel(binArray) LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); end @@ -1029,7 +853,7 @@ function loadproper_change(~,~) legendset_str = table2cell(legendset_str); LegendArray = ERPsetArray; else - binArray = ERPwaviewer.bin; + binArray = gui_erp_waviewer.ERPwaviewer.bin; for Numofbin = 1:numel(binArray) LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); end @@ -1041,7 +865,7 @@ function loadproper_change(~,~) legendset_str = table(LegendNamenum,LegendName); legendset_str = table2cell(legendset_str); end - ERPwaviewer.Legend.data=legendset_str; + gui_erp_waviewer.ERPwaviewer.Legend.data=legendset_str; LegendfontColorAuto = gui_erplinset_waveviewer.font_colorauto.Value; if LegendfontColorAuto==1 @@ -1051,7 +875,6 @@ function loadproper_change(~,~) gui_erplinset_waveviewer.legendtextcustom.Enable = 'off'; gui_erplinset_waveviewer.legendtextauto.Value = 1; gui_erplinset_waveviewer.legendtextcustom.Value = 0; - % gui_erplinset_waveviewer.legendcolumns.Value =1; gui_erplinset_waveviewer.legendcolumns.Value =round(sqrt(length(LegendArray))); gui_erplinset_waveviewer.legendcolumns.Enable = 'off'; gui_erplinset_waveviewer.font_colorauto.Value=1; @@ -1067,9 +890,9 @@ function loadproper_change(~,~) end - legendfont =ERPwaviewer.Legend.font; + legendfont =gui_erp_waviewer.ERPwaviewer.Legend.font; gui_erplinset_waveviewer.font_custom_type.Value = legendfont; - legendfontsize = ERPwaviewer.Legend.fontsize; + legendfontsize = gui_erp_waviewer.ERPwaviewer.Legend.fontsize; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; gui_erplinset_waveviewer.font_custom_size.String = fontsize; @@ -1077,7 +900,7 @@ function loadproper_change(~,~) [xsize,y] = find(fontsize ==legendfontsize); gui_erplinset_waveviewer.font_custom_size.Value = xsize; - Legendtextcolor = ERPwaviewer.Legend.textcolor; + Legendtextcolor = gui_erp_waviewer.ERPwaviewer.Legend.textcolor; if Legendtextcolor==1 gui_erplinset_waveviewer.legendtextauto.Value =1; % gui_erplinset_waveviewer.legendtextcustom.Value =0; @@ -1085,13 +908,12 @@ function loadproper_change(~,~) gui_erplinset_waveviewer.legendtextauto.Value =0; % gui_erplinset_waveviewer.legendtextcustom.Value =1; end - legendColumns = ERPwaviewer.Legend.columns; + legendColumns = gui_erp_waviewer.ERPwaviewer.Legend.columns; gui_erplinset_waveviewer.legendcolumns.Value = legendColumns; for Numoflegend = 1:100 columnStr{Numoflegend} = num2str(Numoflegend); end gui_erplinset_waveviewer.legendcolumns.String = columnStr; - assignin('base','ALLERPwaviewer',ERPwaviewer); %%save the parameters to memory file MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; @@ -1102,7 +924,6 @@ function loadproper_change(~,~) MERPWaveViewer_linelegend{6}= gui_erplinset_waveviewer.legendtextauto.Value; MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file - viewer_ERPDAT.loadproper_count =7; end @@ -1125,117 +946,111 @@ function count_twopanels_change(~,~) %%-----------------Reset this panel with the default parameters------------ %%------------------------------------------------------------------------- function Reset_Waviewer_panel_change(~,~) - if viewer_ERPDAT.Reset_Waviewer_panel==6 - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI error: Restart ERPwave Viewer'); - return; - end - %%-------------------------Lines------------------------------- - gui_erplinset_waveviewer.linesauto.Value =1; - gui_erplinset_waveviewer.linescustom.Value = 0; - gui_erplinset_waveviewer.line_customtable.Enable = 'off'; - [lineNameStr,linecolors,linetypes,linewidths,linecolors_str,linetypes_str,linewidths_str,linecolorsrgb] = f_get_lineset_ERPviewer(); - lineset_str =table(lineNameStr,linecolors,linetypes,linewidths); - lineset_str = table2cell(lineset_str); - gui_erplinset_waveviewer.line_customtable.ColumnFormat = {'char', 'char',... - {'solid','dash','dot','dashdot','plus','circle','asterisk'},... - {'0.25','0.5','1','1.5','2','2.5','3','3.5','4','4.5','5','5.5','6','6.5','7','7.5','8','8.5','9','9.5','10','10.5'}}; - gui_erplinset_waveviewer.line_customtable.Data = lineset_str; - ERPwaviewerin.Lines.auto =1; - ERPwaviewerin.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; - - %%-----------------------Legends------------------------------- - gui_erplinset_waveviewer.font_colorauto.Value =1; - gui_erplinset_waveviewer.font_colorcustom.Value =0; - - gui_erplinset_waveviewer.font_custom_type.Enable = 'off'; % - gui_erplinset_waveviewer.font_custom_size.Enable = 'off'; - gui_erplinset_waveviewer.legendtextauto.Enable = 'off'; - gui_erplinset_waveviewer.legendtextcustom.Enable = 'off'; - gui_erplinset_waveviewer.legendtextauto.Value = 1; - gui_erplinset_waveviewer.legendtextcustom.Value = 0; - % gui_erplinset_waveviewer.legendcolumns.Value =1; - gui_erplinset_waveviewer.legendcolumns.Enable = 'off'; - % - for ii = 1:100 - LegendName{ii,1} = ''; - LegendNamenum(ii,1) =ii; - end - ALLERP = ERPwaviewerin.ALLERP; - ERPsetArray = ERPwaviewerin.SelectERPIdx; - if max(ERPsetArray(:))> length(ALLERP) - ERPsetArray =length(ALLERP); - end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,ERPsetArray); - LegendArray = [1:4]; - try - plot_org = ERPwaviewerin.plot_org; - if plot_org.Overlay ==1 - ChanArray = ERPwaviewerin.chan; - for Numofchan = 1:numel(ChanArray) - LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray =ChanArray; - elseif plot_org.Overlay ==2 - binArray = ERPwaviewerin.bin; - for Numofbin = 1:numel(binArray) - LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray =binArray; - elseif plot_org.Overlay ==3 - for Numoferpset = 1:numel(ERPsetArray) - LegendName{Numoferpset,1} = char(ALLERP(ERPsetArray(Numoferpset)).erpname); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray =ERPsetArray; - else - binArray = ERPwaviewerin.bin; - for Numofbin = 1:numel(binArray) - LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); - end - legendset_str = table(LegendNamenum,LegendName); - legendset_str = table2cell(legendset_str); - LegendArray =binArray; + if viewer_ERPDAT.Reset_Waviewer_panel~=6 + return; + end + + %%-------------------------Lines------------------------------- + gui_erplinset_waveviewer.linesauto.Value =1; + gui_erplinset_waveviewer.linescustom.Value = 0; + gui_erplinset_waveviewer.line_customtable.Enable = 'off'; + [lineNameStr,linecolors,linetypes,linewidths,linecolors_str,linetypes_str,linewidths_str,linecolorsrgb] = f_get_lineset_ERPviewer(); + lineset_str =table(lineNameStr,linecolors,linetypes,linewidths); + lineset_str = table2cell(lineset_str); + gui_erplinset_waveviewer.line_customtable.ColumnFormat = {'char', 'char',... + {'solid','dash','dot','dashdot','plus','circle','asterisk'},... + {'0.25','0.5','1','1.5','2','2.5','3','3.5','4','4.5','5','5.5','6','6.5','7','7.5','8','8.5','9','9.5','10','10.5'}}; + gui_erplinset_waveviewer.line_customtable.Data = lineset_str; + gui_erp_waviewer.ERPwaviewer.Lines.auto =1; + gui_erp_waviewer.ERPwaviewer.Lines.data = gui_erplinset_waveviewer.line_customtable.Data; + + %%-----------------------Legends------------------------------- + gui_erplinset_waveviewer.font_colorauto.Value =1; + gui_erplinset_waveviewer.font_colorcustom.Value =0; + + gui_erplinset_waveviewer.font_custom_type.Enable = 'off'; % + gui_erplinset_waveviewer.font_custom_size.Enable = 'off'; + gui_erplinset_waveviewer.legendtextauto.Enable = 'off'; + gui_erplinset_waveviewer.legendtextcustom.Enable = 'off'; + gui_erplinset_waveviewer.legendtextauto.Value = 1; + gui_erplinset_waveviewer.legendtextcustom.Value = 0; + gui_erplinset_waveviewer.legendcolumns.Enable = 'off'; + for ii = 1:100 + LegendName{ii,1} = ''; + LegendNamenum(ii,1) =ii; + end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + if max(ERPsetArray(:))> length(ALLERP) + ERPsetArray =length(ALLERP); + end + [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,ERPsetArray); + LegendArray = [1:4]; + try + plot_org = gui_erp_waviewer.ERPwaviewer.plot_org; + if plot_org.Overlay ==1 + ChanArray = gui_erp_waviewer.ERPwaviewer.chan; + for Numofchan = 1:numel(ChanArray) + LegendName{Numofchan,1} = char(chanStr(ChanArray(Numofchan))); end - catch legendset_str = table(LegendNamenum,LegendName); legendset_str = table2cell(legendset_str); + LegendArray =ChanArray; + elseif plot_org.Overlay ==2 + binArray = gui_erp_waviewer.ERPwaviewer.bin; + for Numofbin = 1:numel(binArray) + LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); + end + legendset_str = table(LegendNamenum,LegendName); + legendset_str = table2cell(legendset_str); + LegendArray =binArray; + elseif plot_org.Overlay ==3 + for Numoferpset = 1:numel(ERPsetArray) + LegendName{Numoferpset,1} = char(ALLERP(ERPsetArray(Numoferpset)).erpname); + end + legendset_str = table(LegendNamenum,LegendName); + legendset_str = table2cell(legendset_str); + LegendArray =ERPsetArray; + else + binArray = gui_erp_waviewer.ERPwaviewer.bin; + for Numofbin = 1:numel(binArray) + LegendName{Numofbin,1} = char(binStr(binArray(Numofbin))); + end + legendset_str = table(LegendNamenum,LegendName); + legendset_str = table2cell(legendset_str); + LegendArray =binArray; end - - gui_erplinset_waveviewer.legendcolumns.Value =round(sqrt(length(LegendArray))); - gui_erplinset_waveviewer.font_custom_size.Value = 4; - gui_erplinset_waveviewer.font_custom_type.Value =3; - ERPwaviewerin.Legend.data =legendset_str; - ERPwaviewerin.Legend.font=3; - ERPwaviewerin.Legend.fontsize=10; - ERPwaviewerin.Legend.textcolor=1; - ERPwaviewerin.Legend.columns=1; - ERPwaviewerin.Legend.FontColorAuto=1; - - assignin('base','ALLERPwaviewer',ERPwaviewerin); - gui_erplinset_waveviewer.apply.BackgroundColor = [1 1 1]; - gui_erplinset_waveviewer.apply.ForegroundColor = [0 0 0]; - box_erplineset_viewer_property.TitleColor= [0.5 0.5 0.9]; - - MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; - MERPWaveViewer_linelegend{2}= gui_erplinset_waveviewer.line_customtable.Data; - MERPWaveViewer_linelegend{3}=gui_erplinset_waveviewer.font_colorauto.Value; - MERPWaveViewer_linelegend{4}=gui_erplinset_waveviewer.font_custom_type.Value; - MERPWaveViewer_linelegend{5}=gui_erplinset_waveviewer.font_custom_size.Value; - MERPWaveViewer_linelegend{6}= gui_erplinset_waveviewer.legendtextauto.Value; - MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; - estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file - - viewer_ERPDAT.Reset_Waviewer_panel=7; + catch + legendset_str = table(LegendNamenum,LegendName); + legendset_str = table2cell(legendset_str); end + + gui_erplinset_waveviewer.legendcolumns.Value =round(sqrt(length(LegendArray))); + gui_erplinset_waveviewer.font_custom_size.Value = 4; + gui_erplinset_waveviewer.font_custom_type.Value =3; + gui_erp_waviewer.ERPwaviewer.Legend.data =legendset_str; + gui_erp_waviewer.ERPwaviewer.Legend.font=3; + gui_erp_waviewer.ERPwaviewer.Legend.fontsize=10; + gui_erp_waviewer.ERPwaviewer.Legend.textcolor=1; + gui_erp_waviewer.ERPwaviewer.Legend.columns=1; + gui_erp_waviewer.ERPwaviewer.Legend.FontColorAuto=1; + + gui_erplinset_waveviewer.apply.BackgroundColor = [1 1 1]; + gui_erplinset_waveviewer.apply.ForegroundColor = [0 0 0]; + box_erplineset_viewer_property.TitleColor= [0.5 0.5 0.9]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [0 0 0]; + + MERPWaveViewer_linelegend{1}=gui_erplinset_waveviewer.linesauto.Value; + MERPWaveViewer_linelegend{2}= gui_erplinset_waveviewer.line_customtable.Data; + MERPWaveViewer_linelegend{3}=gui_erplinset_waveviewer.font_colorauto.Value; + MERPWaveViewer_linelegend{4}=gui_erplinset_waveviewer.font_custom_type.Value; + MERPWaveViewer_linelegend{5}=gui_erplinset_waveviewer.font_custom_size.Value; + MERPWaveViewer_linelegend{6}= gui_erplinset_waveviewer.legendtextauto.Value; + MERPWaveViewer_linelegend{7}=gui_erplinset_waveviewer.legendcolumns.Value; + estudioworkingmemory('MERPWaveViewer_linelegend',MERPWaveViewer_linelegend);%%save the parameters for this panel to memory file + + viewer_ERPDAT.Reset_Waviewer_panel=7; end function line_presskey(hObject, eventdata) @@ -1246,6 +1061,8 @@ function line_presskey(hObject, eventdata) gui_erplinset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_erplinset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erplineset_viewer_property.TitleColor= [0.5 0.5 0.9]; + gui_erplinset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_erplinset_waveviewer.cancel.ForegroundColor = [0 0 0]; else return; end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_otherset_waveviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_otherset_waveviewer_GUI.m index 9bd5503b..76a00bb6 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_otherset_waveviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_otherset_waveviewer_GUI.m @@ -11,12 +11,11 @@ function varargout = f_ERP_otherset_waveviewer_GUI(varargin) global viewer_ERPDAT; +global gui_erp_waviewer; addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); -% addlistener(viewer_ERPDAT,'Process_messg_change',@Process_messg_change); addlistener(viewer_ERPDAT,'count_twopanels_change',@count_twopanels_change); addlistener(viewer_ERPDAT,'Reset_Waviewer_panel_change',@Reset_Waviewer_panel_change); - - +addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); gui_otherset_waveviewer = struct(); %-----------------------------Name the title---------------------------------------------- @@ -48,14 +47,6 @@ function drawui_otherset_waviewer(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_lineset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - gui_otherset_waveviewer.DataSelBox = uiextras.VBox('Parent', box_erplabelset_viewer_otherset,'BackgroundColor',ColorBviewer_def); %%----------Polarity Setting--------------------------------------- MERPWaveViewer_others= estudioworkingmemory('MERPWaveViewer_others');%%call the parameters for this panel @@ -80,7 +71,7 @@ function drawui_otherset_waviewer(FonsizeDefault) 'callback',@polardown, 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'Value',~Polaritylabel); %,'FontWeight','bold' gui_otherset_waveviewer.polarity_down.KeyPressFcn = @otherset_presskey; set(gui_otherset_waveviewer.polarity_title,'Sizes',[50 90 90]); - ERPwaviewer.polarity=gui_otherset_waveviewer.polarity_up.Value; + gui_erp_waviewer.ERPwaviewer.polarity=gui_otherset_waveviewer.polarity_up.Value; %%----------------SEM of wave-------------------------------------- try @@ -104,8 +95,8 @@ function drawui_otherset_waviewer(FonsizeDefault) 'callback',@SEMerror,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',SEMCustomValue+1); % gui_otherset_waveviewer.SEM_custom.KeyPressFcn = @otherset_presskey; set(gui_otherset_waveviewer.SEM_title,'Sizes',[160 80]); - ERPwaviewer.SEM.active =gui_otherset_waveviewer.show_SEM.Value; - ERPwaviewer.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; + gui_erp_waviewer.ERPwaviewer.SEM.active =gui_otherset_waveviewer.show_SEM.Value; + gui_erp_waviewer.ERPwaviewer.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; try SEMtransValue= MERPWaveViewer_others{4}; catch @@ -127,7 +118,7 @@ function drawui_otherset_waviewer(FonsizeDefault) gui_otherset_waveviewer.SEM_custom.Enable = 'off'; gui_otherset_waveviewer.SEMtrans_custom.Enable = 'off'; end - ERPwaviewer.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; + gui_erp_waviewer.ERPwaviewer.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; %%----------------baseline correction------------------------------ try @@ -207,17 +198,17 @@ function drawui_otherset_waviewer(FonsizeDefault) set( gui_otherset_waveviewer.bsl_title_3,'Sizes',[80 155]); if gui_otherset_waveviewer.bsl_none.Value ==1 - ERPwaviewer.baselinecorr = 'none'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; elseif gui_otherset_waveviewer.bsl_pre.Value ==1 - ERPwaviewer.baselinecorr = 'pre'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'pre'; elseif gui_otherset_waveviewer.bsl_post.Value ==1 - ERPwaviewer.baselinecorr = 'post'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'post'; elseif gui_otherset_waveviewer.bsl_whole.Value ==1 - ERPwaviewer.baselinecorr = 'whole'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'whole'; elseif gui_otherset_waveviewer.bsl_custom.Value ==1 - ERPwaviewer.baselinecorr = str2num(char(gui_otherset_waveviewer.bsl_customedit.String)); + gui_erp_waviewer.ERPwaviewer.baselinecorr = str2num(char(gui_otherset_waveviewer.bsl_customedit.String)); else - ERPwaviewer.baselinecorr = 'none'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; end %%Figure background color: the default is white @@ -238,13 +229,13 @@ function drawui_otherset_waviewer(FonsizeDefault) 'callback',@figbackcolor,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'HorizontalAlignment','left' gui_otherset_waveviewer.figurebakcolor.KeyPressFcn = @otherset_presskey; set(gui_otherset_waveviewer.figurebakcolor_title,'Sizes',[150 85]); - ERPwaviewer.figbackgdcolor = str2num(gui_otherset_waveviewer.figurebakcolor.String); + gui_erp_waviewer.ERPwaviewer.figbackgdcolor = str2num(gui_otherset_waveviewer.figurebakcolor.String); %%Apply and save the changed parameters gui_otherset_waveviewer.help_run_title = uiextras.HBox('Parent', gui_otherset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); uiextras.Empty('Parent', gui_otherset_waveviewer.help_run_title ); - uicontrol('Style','pushbutton','Parent', gui_otherset_waveviewer.help_run_title,'String','Cancel',... + gui_otherset_waveviewer.cancel = uicontrol('Style','pushbutton','Parent', gui_otherset_waveviewer.help_run_title,'String','Cancel',... 'callback',@other_help,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold'%,'HorizontalAlignment','left' uiextras.Empty('Parent', gui_otherset_waveviewer.help_run_title ); gui_otherset_waveviewer.apply = uicontrol('Style','pushbutton','Parent', gui_otherset_waveviewer.help_run_title ,'String','Apply',... @@ -253,8 +244,9 @@ function drawui_otherset_waviewer(FonsizeDefault) set(gui_otherset_waveviewer.help_run_title,'Sizes',[40 70 20 70 20]); set(gui_otherset_waveviewer.DataSelBox,'Sizes',[25 25 25 20 20 25 25 25]); - assignin('base','ALLERPwaviewer',ERPwaviewer); estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); + + estudioworkingmemory('MyViewer_other',0); end %%**************************************************************************%% @@ -274,6 +266,8 @@ function polarup(~,~) box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.polarity_up.Value = 1; gui_otherset_waveviewer.polarity_down.Value = 0; + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%-------------------------Setting for Polarity down----------------------- @@ -282,12 +276,12 @@ function polardown(~,~) if ~isempty(messgStr) && viewerpanelIndex~=7 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - estudioworkingmemory('MyViewer_other',1); gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_otherset_waveviewer.polarity_up.Value = 0; gui_otherset_waveviewer.polarity_down.Value = 1; end @@ -303,7 +297,8 @@ function showSEM(Str,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; Value = Str.Value; if Value ==1 gui_otherset_waveviewer.SEM_custom.Enable = 'on'; @@ -311,8 +306,8 @@ function showSEM(Str,~) else gui_otherset_waveviewer.SEM_custom.Enable = 'off'; gui_otherset_waveviewer.SEMtrans_custom.Enable = 'off'; - gui_otherset_waveviewer.SEM_custom.Value = 1; - gui_otherset_waveviewer.SEMtrans_custom.Value = 1; + % gui_otherset_waveviewer.SEM_custom.Value = 1; + % gui_otherset_waveviewer.SEMtrans_custom.Value = 1; end end @@ -327,6 +322,8 @@ function SEMerror(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%---------------------------SEM trans.------------------------------------ function SEMtrans(~,~) @@ -338,6 +335,8 @@ function SEMtrans(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; end @@ -347,12 +346,12 @@ function bsl_none(~,~) if ~isempty(messgStr) && viewerpanelIndex~=7 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - estudioworkingmemory('MyViewer_other',1); gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_otherset_waveviewer.bsl_none.Value =1; gui_otherset_waveviewer.bsl_pre.Value =0; gui_otherset_waveviewer.bsl_post.Value =0; @@ -372,7 +371,8 @@ function bsl_pre(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_otherset_waveviewer.bsl_none.Value =0; gui_otherset_waveviewer.bsl_pre.Value =1; gui_otherset_waveviewer.bsl_post.Value =0; @@ -384,7 +384,6 @@ function bsl_pre(~,~) %%--------------------Baseline correction:post----------------------------- function bsl_post(~,~) - [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=7 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; @@ -393,7 +392,8 @@ function bsl_post(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_otherset_waveviewer.bsl_none.Value =0; gui_otherset_waveviewer.bsl_pre.Value =0; gui_otherset_waveviewer.bsl_post.Value =1; @@ -413,7 +413,8 @@ function bsl_whole(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_otherset_waveviewer.bsl_none.Value =0; gui_otherset_waveviewer.bsl_pre.Value =0; gui_otherset_waveviewer.bsl_post.Value =0; @@ -432,7 +433,8 @@ function bsl_custom(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_otherset_waveviewer.bsl_none.Value =0; gui_otherset_waveviewer.bsl_pre.Value =0; gui_otherset_waveviewer.bsl_post.Value =0; @@ -450,45 +452,40 @@ function bsl_customedit(Str,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; MessageViewer= char(strcat('Other > Baseline Correction > Custom')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer = ALLERPwaviewer; - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Other > Baseline Correction > Custom() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + bacselinePeriod = str2num(char(Str.String)); if isempty(bacselinePeriod) || numel(bacselinePeriod)==1 - viewer_ERPDAT.Process_messg =3; Str.String = ''; - fprintf(2,'\n Other > Baseline Correction > Custom() error: \n Inputs must be two numbers.\n\n'); + msgboxText = strcat('Other > Baseline Correction > Custom() error: Inputs must be two numbers'); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); + viewer_ERPDAT.Process_messg =4; return; end - TimeRange = ERPwaviewer.ERP.times; + TimeRange = gui_erp_waviewer.ERPwaviewer.ERP.times; if bacselinePeriod(1) Baseline Correction > Custom(): Left edge of baseline period should be larger than',32,num2str(TimeRange(1)),'ms'); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); Str.String = ''; - fprintf(2,['\n Other > Baseline Correction > Custom() error: \n',32,msgboxText,'.\n\n']); + viewer_ERPDAT.Process_messg =4; return; end if bacselinePeriod(2)>TimeRange(end) - msgboxText = strcat('Right edge of baseline period should be smaller than',32,num2str(TimeRange(end)),'ms'); - viewer_ERPDAT.Process_messg =3; + msgboxText = strcat('Other > Baseline Correction > Custom(): Right edge of baseline period should be smaller than',32,num2str(TimeRange(end)),'ms'); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); + viewer_ERPDAT.Process_messg =4; Str.String = ''; - fprintf(2,['\n Other > Baseline Correction > Custom() error: \n',32,msgboxText,'.\n\n']); return; end if bacselinePeriod(1)>=bacselinePeriod(end) - msgboxText = strcat('Right edge of baseline period should be larger than left edge'); - viewer_ERPDAT.Process_messg =3; + msgboxText = strcat('Other > Baseline Correction > Custom(): Right edge of baseline period should be larger than left edge'); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); + viewer_ERPDAT.Process_messg =4; Str.String = ''; - fprintf(2,['\n Other > Baseline Correction > Custom() error: \n',32,msgboxText,'.\n\n']); return; end end @@ -496,7 +493,6 @@ function bsl_customedit(Str,~) %%-------------------figure background color------------------------------- function figbackcolor(Str,~) - [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=7 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; @@ -505,21 +501,22 @@ function figbackcolor(Str,~) gui_otherset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_otherset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erplabelset_viewer_otherset.TitleColor= [0.4940 0.1840 0.5560]; - + gui_otherset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_otherset_waveviewer.cancel.ForegroundColor = [1 1 1]; bgColor = str2num(Str.String); if isempty(bgColor) - viewer_ERPDAT.Process_messg =4; msgboxText = strcat('Other > Figure Background Color: Inputs are invalid and it should be,e.g., [1 1 1]'); - erpworkingmemory('ERPViewer_proces_messg',msgboxText); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); Str.String = num2str([1 1 1]); + viewer_ERPDAT.Process_messg =4; return; end if max(bgColor)>1 || min(bgColor) <0 || numel(bgColor)~=3 - viewer_ERPDAT.Process_messg =4; msgboxText = strcat('Other > Figure Background Color: Inputs are invalid and it should be,e.g., [1 1 1]'); - erpworkingmemory('ERPViewer_proces_messg',msgboxText); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); Str.String = num2str([1 1 1]); + viewer_ERPDAT.Process_messg =4; return; end end @@ -531,33 +528,25 @@ function other_help(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end MessageViewer= char(strcat('Other > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; changeFlag = estudioworkingmemory('MyViewer_other'); if changeFlag~=1 MessageViewer= char(strcat('Other > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; return; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\nOther > Cancel-f_ERP_otherset_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - - gui_otherset_waveviewer.polarity_up.Value=ERPwaviewer_apply.polarity;%% the polarity of wave - gui_otherset_waveviewer.polarity_down.Value = ~ERPwaviewer_apply.polarity; + gui_otherset_waveviewer.polarity_up.Value=gui_erp_waviewer.ERPwaviewer.polarity;%% the polarity of wave + gui_otherset_waveviewer.polarity_down.Value = ~gui_erp_waviewer.ERPwaviewer.polarity; %%SME - SMEActiveFlag = ERPwaviewer_apply.SEM.active; + SMEActiveFlag = gui_erp_waviewer.ERPwaviewer.SEM.active; gui_otherset_waveviewer.show_SEM.Value=SMEActiveFlag; - gui_otherset_waveviewer.SEM_custom.Value=ERPwaviewer_apply.SEM.error +1; + gui_otherset_waveviewer.SEM_custom.Value=gui_erp_waviewer.ERPwaviewer.SEM.error +1; %%trans - gui_otherset_waveviewer.SEMtrans_custom.Value = 10* ERPwaviewer_apply.SEM.trans +1; + gui_otherset_waveviewer.SEMtrans_custom.Value = 10* gui_erp_waviewer.ERPwaviewer.SEM.trans +1; if SMEActiveFlag==1 Enable = 'on'; else @@ -565,9 +554,9 @@ function other_help(~,~) end gui_otherset_waveviewer.SEM_custom.Enable = Enable; gui_otherset_waveviewer.SEMtrans_custom.Enable = Enable; - gui_otherset_waveviewer.figurebakcolor.String=num2str(ERPwaviewer_apply.figbackgdcolor); + gui_otherset_waveviewer.figurebakcolor.String=num2str(gui_erp_waviewer.ERPwaviewer.figbackgdcolor); %%baseline correction method - BslMethod = ERPwaviewer_apply.baselinecorr; + BslMethod = gui_erp_waviewer.ERPwaviewer.baselinecorr; gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; gui_otherset_waveviewer.bsl_customedit.String = ''; if ischar(BslMethod) @@ -595,7 +584,6 @@ function other_help(~,~) gui_otherset_waveviewer.bsl_pre.Value=0; gui_otherset_waveviewer.bsl_post.Value=0; gui_otherset_waveviewer.bsl_whole.Value=1; - end elseif isnumeric(BslMethod) gui_otherset_waveviewer.bsl_custom.Value =1; @@ -610,8 +598,10 @@ function other_help(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_otherset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erplabelset_viewer_otherset.TitleColor= [0.5 0.5 0.9]; + gui_otherset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_otherset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Other > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -627,60 +617,53 @@ function other_apply(~,~) gui_otherset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_otherset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erplabelset_viewer_otherset.TitleColor= [0.5 0.5 0.9]; + gui_otherset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_otherset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Other > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Other > Apply-f_ERP_otherset_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - ERPwaviewer_apply.polarity = gui_otherset_waveviewer.polarity_up.Value;%% the polarity of wave - MERPWaveViewer_others{1} = ERPwaviewer_apply.polarity; + + gui_erp_waviewer.ERPwaviewer.polarity = gui_otherset_waveviewer.polarity_up.Value;%% the polarity of wave + MERPWaveViewer_others{1} = gui_erp_waviewer.ERPwaviewer.polarity; %%SME - ERPwaviewer_apply.SEM.active = gui_otherset_waveviewer.show_SEM.Value; - ERPwaviewer_apply.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; - MERPWaveViewer_others{2} = ERPwaviewer_apply.SEM.active; - MERPWaveViewer_others{3} = ERPwaviewer_apply.SEM.error; + gui_erp_waviewer.ERPwaviewer.SEM.active = gui_otherset_waveviewer.show_SEM.Value; + gui_erp_waviewer.ERPwaviewer.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; + + MERPWaveViewer_others{2} = gui_erp_waviewer.ERPwaviewer.SEM.active; + MERPWaveViewer_others{3} = gui_erp_waviewer.ERPwaviewer.SEM.error; %%trans - ERPwaviewer_apply.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; - MERPWaveViewer_others{4} = ERPwaviewer_apply.SEM.trans; + gui_erp_waviewer.ERPwaviewer.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; + MERPWaveViewer_others{4} = gui_erp_waviewer.ERPwaviewer.SEM.trans; %%baseline correction - ERPwaviewer_apply.figbackgdcolor = str2num(gui_otherset_waveviewer.figurebakcolor.String); - MERPWaveViewer_others{6} = ERPwaviewer_apply.figbackgdcolor; + gui_erp_waviewer.ERPwaviewer.figbackgdcolor = str2num(gui_otherset_waveviewer.figurebakcolor.String); + MERPWaveViewer_others{6} = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; %%baseline correction method if gui_otherset_waveviewer.bsl_none.Value ==1 - ERPwaviewer_apply.baselinecorr = 'none'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; elseif gui_otherset_waveviewer.bsl_pre.Value ==1 - ERPwaviewer_apply.baselinecorr = 'pre'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'pre'; elseif gui_otherset_waveviewer.bsl_post.Value ==1 - ERPwaviewer_apply.baselinecorr = 'post'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'post'; elseif gui_otherset_waveviewer.bsl_whole.Value ==1 - ERPwaviewer_apply.baselinecorr = 'whole'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'whole'; elseif gui_otherset_waveviewer.bsl_custom.Value ==1 - ERPwaviewer_apply.baselinecorr = str2num(char(gui_otherset_waveviewer.bsl_customedit.String)); + gui_erp_waviewer.ERPwaviewer.baselinecorr = str2num(char(gui_otherset_waveviewer.bsl_customedit.String)); %checking the defined time-window for baselne correction - if isempty(ERPwaviewer_apply.baselinecorr)|| numel(ERPwaviewer_apply.baselinecorr)==1 - msgboxText = strcat(' Inputs must be two numbers! If you donot change it, "none" will be used for baseline correction!'); - title = 'EStudio>ERP Wave Viewer: Baseline period for "Baseline Correction" on "Other"'; - errorfound(msgboxText, title); - ERPwaviewer_apply.baselinecorr = 'none'; + if isempty(gui_erp_waviewer.ERPwaviewer.baselinecorr)|| numel(gui_erp_waviewer.ERPwaviewer.baselinecorr)==1 + msgboxText = strcat('Other > Baseline Period: Inputs must be two numbers! If you donot change it, "none" will be used for baseline correction!'); + estudioworkingmemory('ERPViewer_proces_messg',msgboxText); + viewer_ERPDAT.Process_messg =4; return; end - %%may check the left and right edges for the defined - %%time=window else - ERPwaviewer_apply.baselinecorr = 'none'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; end - MERPWaveViewer_others{5} = ERPwaviewer_apply.baselinecorr; + MERPWaveViewer_others{5} = gui_erp_waviewer.ERPwaviewer.baselinecorr; + estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP=1; viewer_ERPDAT.Process_messg =2; - estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); end %%---------change this panel based on the loaded paras.-------------------- @@ -688,15 +671,8 @@ function loadproper_change(~,~) if viewer_ERPDAT.loadproper_count ~=7 return; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_otherset_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - PolirityValue = ERPwaviewer_apply.polarity; + PolirityValue = gui_erp_waviewer.ERPwaviewer.polarity; if PolirityValue ==1 gui_otherset_waveviewer.polarity_up.Value = 1; gui_otherset_waveviewer.polarity_down.Value = 0; @@ -707,25 +683,25 @@ function loadproper_change(~,~) % %%SEM settings - SEMValue = ERPwaviewer_apply.SEM.active; + SEMValue = gui_erp_waviewer.ERPwaviewer.SEM.active; if isempty(SEMValue) || numel(SEMValue)~=1 || (SEMValue~=0 && SEMValue~=1) SEMValue=0; - ERPwaviewer_apply.SEM.active=0; + gui_erp_waviewer.ERPwaviewer.SEM.active=0; end if SEMValue==1 gui_otherset_waveviewer.show_SEM.Value =1; gui_otherset_waveviewer.SEM_custom.Enable = 'on'; gui_otherset_waveviewer.SEMtrans_custom.Enable = 'on'; - ERRORValue = ERPwaviewer_apply.SEM.error; + ERRORValue = gui_erp_waviewer.ERPwaviewer.SEM.error; if isempty(ERRORValue) || ERRORValue<=0 || ERRORValue>10 ERRORValue = 1; - ERPwaviewer_apply.SEM.error = 1; + gui_erp_waviewer.ERPwaviewer.SEM.error = 1; end gui_otherset_waveviewer.SEM_custom.Value =ERRORValue+1; - SEMTrans = ERPwaviewer_apply.SEM.trans; + SEMTrans = gui_erp_waviewer.ERPwaviewer.SEM.trans; if isempty(SEMTrans) || SEMTrans<=0 || SEMTrans>1 SEMTrans = 2; - ERPwaviewer_apply.SEM.trans = 0.2; + gui_erp_waviewer.ERPwaviewer.SEM.trans = 0.2; end gui_otherset_waveviewer.SEMtrans_custom.Value = SEMTrans*10 +1; else @@ -734,13 +710,13 @@ function loadproper_change(~,~) gui_otherset_waveviewer.SEMtrans_custom.Enable = 'off'; gui_otherset_waveviewer.SEM_custom.Value =1; gui_otherset_waveviewer.SEMtrans_custom.Value =1; - ERPwaviewer_apply.SEM.error = 0; - ERPwaviewer_apply.SEM.trans = 0; + gui_erp_waviewer.ERPwaviewer.SEM.error = 0; + gui_erp_waviewer.ERPwaviewer.SEM.trans = 0; end % %%Baseline settings - BalineCorrection = ERPwaviewer_apply.baselinecorr; + BalineCorrection = gui_erp_waviewer.ERPwaviewer.baselinecorr; if numel(BalineCorrection) ==2 if ~isnumeric(BalineCorrection) gui_otherset_waveviewer.bsl_none.Value =1; @@ -749,7 +725,7 @@ function loadproper_change(~,~) gui_otherset_waveviewer.bsl_whole.Value =0; gui_otherset_waveviewer.bsl_custom.Value = 0; gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; - ERPwaviewer_apply.baselinecorr = 'none'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; else gui_otherset_waveviewer.bsl_none.Value =0; gui_otherset_waveviewer.bsl_pre.Value =0; @@ -760,7 +736,6 @@ function loadproper_change(~,~) gui_otherset_waveviewer.bsl_customedit.String = num2str(BalineCorrection); end else - if strcmpi(BalineCorrection,'pre') gui_otherset_waveviewer.bsl_none.Value =0; gui_otherset_waveviewer.bsl_pre.Value =1; @@ -795,7 +770,7 @@ function loadproper_change(~,~) % %%Background color try - BackgroundColor = ERPwaviewer_apply.figbackgdcolor; + BackgroundColor = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; catch BackgroundColor = [1 1 1]; end @@ -804,18 +779,16 @@ function loadproper_change(~,~) end gui_otherset_waveviewer.figurebakcolor.String = num2str(BackgroundColor); - ERPwaviewer_apply.figbackgdcolor = BackgroundColor; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); + gui_erp_waviewer.ERPwaviewer.figbackgdcolor = BackgroundColor; viewer_ERPDAT.loadproper_count =0; %%save the reset parameters for this panel - MERPWaveViewer_others{1} = ERPwaviewer_apply.polarity; - MERPWaveViewer_others{2} = ERPwaviewer_apply.SEM.active; - MERPWaveViewer_others{3} = ERPwaviewer_apply.SEM.error; - MERPWaveViewer_others{4} = ERPwaviewer_apply.SEM.trans; - MERPWaveViewer_others{6} = ERPwaviewer_apply.figbackgdcolor; - MERPWaveViewer_others{5} = ERPwaviewer_apply.baselinecorr; + MERPWaveViewer_others{1} = gui_erp_waviewer.ERPwaviewer.polarity; + MERPWaveViewer_others{2} = gui_erp_waviewer.ERPwaviewer.SEM.active; + MERPWaveViewer_others{3} = gui_erp_waviewer.ERPwaviewer.SEM.error; + MERPWaveViewer_others{4} = gui_erp_waviewer.ERPwaviewer.SEM.trans; + MERPWaveViewer_others{6} = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; + MERPWaveViewer_others{5} = gui_erp_waviewer.ERPwaviewer.baselinecorr; estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); - end @@ -839,56 +812,174 @@ function count_twopanels_change(~,~) %%-----------------Reset this panel with the default parameters------------ %%------------------------------------------------------------------------- function Reset_Waviewer_panel_change(~,~) - if viewer_ERPDAT.Reset_Waviewer_panel==7 - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_otherset_waveviewer_GUI error: Restart ERPwave Viewer'); - return; + if viewer_ERPDAT.Reset_Waviewer_panel~=7 + return; + end + gui_otherset_waveviewer.polarity_up.Value =1; + gui_otherset_waveviewer.polarity_down.Value =0; + gui_erp_waviewer.ERPwaviewer.polarity = gui_otherset_waveviewer.polarity_up.Value;%% the polarity of wave + + %%SME + gui_otherset_waveviewer.show_SEM.Value =0; + gui_erp_waviewer.ERPwaviewer.SEM.active = gui_otherset_waveviewer.show_SEM.Value; + gui_otherset_waveviewer.SEM_custom.Value =2; + gui_otherset_waveviewer.SEM_custom.Enable = 'off'; + gui_erp_waviewer.ERPwaviewer.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; + %%trans + gui_otherset_waveviewer.SEMtrans_custom.Value =3; + gui_erp_waviewer.ERPwaviewer.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; + gui_otherset_waveviewer.SEMtrans_custom.Enable = 'off'; + gui_otherset_waveviewer.bsl_none.Value =1; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; + gui_otherset_waveviewer.bsl_pre.Value =0; + gui_otherset_waveviewer.bsl_post.Value =0; + gui_otherset_waveviewer.bsl_whole.Value =0; + gui_otherset_waveviewer.bsl_custom.Value =0; + gui_otherset_waveviewer.bsl_customedit.String = ''; + gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; + gui_otherset_waveviewer.figurebakcolor.String ='1,1,1'; + gui_erp_waviewer.ERPwaviewer.figbackgdcolor =[1 1 1]; + gui_otherset_waveviewer.apply.BackgroundColor = [1 1 1]; + gui_otherset_waveviewer.apply.ForegroundColor = [0 0 0]; + box_erplabelset_viewer_otherset.TitleColor= [0.5 0.5 0.9]; + gui_otherset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_otherset_waveviewer.cancel.ForegroundColor = [0 0 0]; + %%save the reset parameters for this panel + MERPWaveViewer_others{1} = gui_erp_waviewer.ERPwaviewer.polarity; + MERPWaveViewer_others{2} = gui_erp_waviewer.ERPwaviewer.SEM.active; + MERPWaveViewer_others{3} = gui_erp_waviewer.ERPwaviewer.SEM.error; + MERPWaveViewer_others{4} = gui_erp_waviewer.ERPwaviewer.SEM.trans; + MERPWaveViewer_others{6} = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; + MERPWaveViewer_others{5} = gui_erp_waviewer.ERPwaviewer.baselinecorr; + estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); + + viewer_ERPDAT.Reset_Waviewer_panel=8; + end + +%%------------------------change this panel-------------------------------- + function v_currentERP_change(~,~) + if viewer_ERPDAT.Count_currentERP~=7 + return; + end + PolirityValue = gui_erp_waviewer.ERPwaviewer.polarity; + if PolirityValue ==1 + gui_otherset_waveviewer.polarity_up.Value = 1; + gui_otherset_waveviewer.polarity_down.Value = 0; + else + gui_otherset_waveviewer.polarity_up.Value = 0; + gui_otherset_waveviewer.polarity_down.Value = 1; + end + + % + %%SEM settings + SEMValue = gui_erp_waviewer.ERPwaviewer.SEM.active; + if isempty(SEMValue) || numel(SEMValue)~=1 || (SEMValue~=0 && SEMValue~=1) + SEMValue=0; + gui_erp_waviewer.ERPwaviewer.SEM.active=0; + end + if SEMValue==1 + gui_otherset_waveviewer.show_SEM.Value =1; + gui_otherset_waveviewer.SEM_custom.Enable = 'on'; + gui_otherset_waveviewer.SEMtrans_custom.Enable = 'on'; + ERRORValue = gui_erp_waviewer.ERPwaviewer.SEM.error; + if isempty(ERRORValue) || ERRORValue<=0 || ERRORValue>10 + ERRORValue = 1; + gui_erp_waviewer.ERPwaviewer.SEM.error = 1; end - - gui_otherset_waveviewer.polarity_up.Value =1; - gui_otherset_waveviewer.polarity_down.Value =0; - ERPwaviewerin.polarity = gui_otherset_waveviewer.polarity_up.Value;%% the polarity of wave - - %%SME + gui_otherset_waveviewer.SEM_custom.Value =ERRORValue+1; + SEMTrans = gui_erp_waviewer.ERPwaviewer.SEM.trans; + if isempty(SEMTrans) || SEMTrans<=0 || SEMTrans>1 + SEMTrans = 2; + gui_erp_waviewer.ERPwaviewer.SEM.trans = 0.2; + end + gui_otherset_waveviewer.SEMtrans_custom.Value = SEMTrans*10 +1; + else gui_otherset_waveviewer.show_SEM.Value =0; - ERPwaviewerin.SEM.active = gui_otherset_waveviewer.show_SEM.Value; - gui_otherset_waveviewer.SEM_custom.Value =2; gui_otherset_waveviewer.SEM_custom.Enable = 'off'; - ERPwaviewerin.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; - %%trans - gui_otherset_waveviewer.SEMtrans_custom.Value =3; - ERPwaviewerin.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; gui_otherset_waveviewer.SEMtrans_custom.Enable = 'off'; - gui_otherset_waveviewer.bsl_none.Value =1; - ERPwaviewerin.baselinecorr = 'none'; - gui_otherset_waveviewer.bsl_pre.Value =0; - gui_otherset_waveviewer.bsl_post.Value =0; - gui_otherset_waveviewer.bsl_whole.Value =0; - gui_otherset_waveviewer.bsl_custom.Value =0; - gui_otherset_waveviewer.bsl_customedit.String = ''; - gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; - gui_otherset_waveviewer.figurebakcolor.String ='1,1,1'; - ERPwaviewerin.figbackgdcolor =[1 1 1]; - assignin('base','ALLERPwaviewer',ERPwaviewerin); - gui_otherset_waveviewer.apply.BackgroundColor = [1 1 1]; - gui_otherset_waveviewer.apply.ForegroundColor = [0 0 0]; - box_erplabelset_viewer_otherset.TitleColor= [0.5 0.5 0.9]; - - %%save the reset parameters for this panel - MERPWaveViewer_others{1} = ERPwaviewerin.polarity; - MERPWaveViewer_others{2} = ERPwaviewerin.SEM.active; - MERPWaveViewer_others{3} = ERPwaviewerin.SEM.error; - MERPWaveViewer_others{4} = ERPwaviewerin.SEM.trans; - MERPWaveViewer_others{6} = ERPwaviewerin.figbackgdcolor; - MERPWaveViewer_others{5} = ERPwaviewerin.baselinecorr; - estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); end + gui_erp_waviewer.ERPwaviewer.SEM.error = gui_otherset_waveviewer.SEM_custom.Value-1; + gui_erp_waviewer.ERPwaviewer.SEM.trans = (gui_otherset_waveviewer.SEMtrans_custom.Value-1)/10; + % + %%Baseline settings + BalineCorrection = gui_erp_waviewer.ERPwaviewer.baselinecorr; + if numel(BalineCorrection) ==2 + if ~isnumeric(BalineCorrection) + gui_otherset_waveviewer.bsl_none.Value =1; + gui_otherset_waveviewer.bsl_pre.Value =0; + gui_otherset_waveviewer.bsl_post.Value =0; + gui_otherset_waveviewer.bsl_whole.Value =0; + gui_otherset_waveviewer.bsl_custom.Value = 0; + gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; + gui_erp_waviewer.ERPwaviewer.baselinecorr = 'none'; + else + gui_otherset_waveviewer.bsl_none.Value =0; + gui_otherset_waveviewer.bsl_pre.Value =0; + gui_otherset_waveviewer.bsl_post.Value =0; + gui_otherset_waveviewer.bsl_whole.Value =0; + gui_otherset_waveviewer.bsl_custom.Value = 1; + gui_otherset_waveviewer.bsl_customedit.Enable = 'on'; + gui_otherset_waveviewer.bsl_customedit.String = num2str(BalineCorrection); + end + else + if strcmpi(BalineCorrection,'pre') + gui_otherset_waveviewer.bsl_none.Value =0; + gui_otherset_waveviewer.bsl_pre.Value =1; + gui_otherset_waveviewer.bsl_post.Value =0; + gui_otherset_waveviewer.bsl_whole.Value =0; + gui_otherset_waveviewer.bsl_custom.Value = 0; + gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; + elseif strcmpi(BalineCorrection,'post') + gui_otherset_waveviewer.bsl_none.Value =0; + gui_otherset_waveviewer.bsl_pre.Value =0; + gui_otherset_waveviewer.bsl_post.Value =1; + gui_otherset_waveviewer.bsl_whole.Value =0; + gui_otherset_waveviewer.bsl_custom.Value = 0; + gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; + elseif strcmpi(BalineCorrection,'all') || strcmpi(BalineCorrection,'whole') + gui_otherset_waveviewer.bsl_none.Value =0; + gui_otherset_waveviewer.bsl_pre.Value =0; + gui_otherset_waveviewer.bsl_post.Value =0; + gui_otherset_waveviewer.bsl_whole.Value =1; + gui_otherset_waveviewer.bsl_custom.Value = 0; + gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; + else + gui_otherset_waveviewer.bsl_none.Value =1; + gui_otherset_waveviewer.bsl_pre.Value =0; + gui_otherset_waveviewer.bsl_post.Value =0; + gui_otherset_waveviewer.bsl_whole.Value =0; + gui_otherset_waveviewer.bsl_custom.Value = 0; + gui_otherset_waveviewer.bsl_customedit.Enable = 'off'; + end + end + + % + %%Background color + try + BackgroundColor = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; + catch + BackgroundColor = [1 1 1]; + end + if isempty(BackgroundColor) || numel(BackgroundColor)~=3 || max(BackgroundColor)>1 ||min (BackgroundColor)<0 + BackgroundColor = [1 1 1]; + end + gui_otherset_waveviewer.figurebakcolor.String = num2str(BackgroundColor); + + gui_erp_waviewer.ERPwaviewer.figbackgdcolor = BackgroundColor; + viewer_ERPDAT.loadproper_count =0; + %%save the reset parameters for this panel + MERPWaveViewer_others{1} = gui_erp_waviewer.ERPwaviewer.polarity; + MERPWaveViewer_others{2} = gui_erp_waviewer.ERPwaviewer.SEM.active; + MERPWaveViewer_others{3} = gui_erp_waviewer.ERPwaviewer.SEM.error; + MERPWaveViewer_others{4} = gui_erp_waviewer.ERPwaviewer.SEM.trans; + MERPWaveViewer_others{6} = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; + MERPWaveViewer_others{5} = gui_erp_waviewer.ERPwaviewer.baselinecorr; + estudioworkingmemory('MERPWaveViewer_others',MERPWaveViewer_others); + viewer_ERPDAT.Count_currentERP=8; end +%%----------------------execute "apply"------------------------------------ function otherset_presskey(hObject, eventdata) keypress = eventdata.Key; if strcmp (keypress, 'return') || strcmp (keypress , 'enter') @@ -897,6 +988,8 @@ function otherset_presskey(hObject, eventdata) gui_otherset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_otherset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erplabelset_viewer_otherset.TitleColor= [0.5 0.5 0.9]; + gui_otherset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_otherset_waveviewer.cancel.ForegroundColor = [0 0 0]; else return; end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_plotorg_waveviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_plotorg_waveviewer_GUI.m index 9abe70a5..76d75ca5 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_plotorg_waveviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_plotorg_waveviewer_GUI.m @@ -5,13 +5,13 @@ % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2022 +% 2022 && Nov. 2023 function varargout = f_ERP_plotorg_waveviewer_GUI(varargin) global viewer_ERPDAT - +global gui_erp_waviewer; addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); addlistener(viewer_ERPDAT,'count_twopanels_change',@count_twopanels_change); @@ -51,15 +51,10 @@ function drawui_plot_org(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; @@ -76,10 +71,24 @@ function drawui_plot_org(FonsizeDefault) plotorg_Index=1; MERPWaveViewer_plotorg{1}=1; end + ERPtooltype = erpgettoolversion('tooltype'); + if strcmpi(ERPtooltype,'EStudio') + ERPTab_plotset_pars= estudioworkingmemory('ERPTab_plotset_pars'); + try + overlay = ERPTab_plotset_pars{7}; + catch + overlay=0; + end + if overlay==0 + plotorg_Index=1; + else + plotorg_Index=3; + end + end if numel(unique(SrateNum_mp))~=1 && (plotorg_Index~=1 && plotorg_Index~=3) MessageViewer= char(strcat('Plot Organization - We will use "Channels,Bins, ERPsets" because Sampling rate varies across the selected ERPsets')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; plotorg_Index=1; MERPWaveViewer_plotorg{1}=1; @@ -181,9 +190,9 @@ function drawui_plot_org(FonsizeDefault) elseif gui_plotorg_waveviewer.plotorg_c6.Value ==1 GridValue=3; OverlayValue = 2; PageValue =1; end - ERPwaviewerin.plot_org.Grid = GridValue; - ERPwaviewerin.plot_org.Overlay = OverlayValue; - ERPwaviewerin.plot_org.Pages =PageValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Grid = GridValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = OverlayValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages =PageValue; gui_plotorg_waveviewer.LayoutFlag = plotorg_Value; %%----------------------Setting for grid layout------------------- @@ -209,13 +218,13 @@ function drawui_plot_org(FonsizeDefault) 'callback',@layout_custom,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'Value',~gridlayoutValue); % gui_plotorg_waveviewer.layout_custom.KeyPressFcn = @plotorg_presskey; set(gui_plotorg_waveviewer.layout_title, 'Sizes',[90 60 70]); - ERPwaviewerin.plot_org.gridlayout.op = gui_plotorg_waveviewer.layout_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op = gui_plotorg_waveviewer.layout_auto.Value; %%NUmber of rows and columns - binArray = ERPwaviewerin.bin; - chanArray = ERPwaviewerin.chan; - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end @@ -250,6 +259,10 @@ function drawui_plot_org(FonsizeDefault) plotBox = plotBoxdef; MERPWaveViewer_plotorg{3}=plotBox; end + if gui_plotorg_waveviewer.layout_auto.Value==1 + plotBox = plotBoxdef; + MERPWaveViewer_plotorg{3}=plotBox; + end if isempty(plotBox) || numel(plotBox)~=2 || min(plotBox(:))<1 || max(plotBox(:))>256 plotBox = plotBoxdef; MERPWaveViewer_plotorg{3}=plotBox; @@ -283,8 +296,8 @@ function drawui_plot_org(FonsizeDefault) 'callback',@plotorg_columnnum,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',Numcolumns,'Enable',rowcolumnEnable); % 1B gui_plotorg_waveviewer.columnnum.KeyPressFcn = @plotorg_presskey; set(gui_plotorg_waveviewer.row_column_title, 'Sizes',[20 35 65 55 65]); - ERPwaviewerin.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; - ERPwaviewerin.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; %%-------------------------Grid information------------------------ count = 0; @@ -298,10 +311,10 @@ function drawui_plot_org(FonsizeDefault) end end end - ERPwaviewerin.plot_org.gridlayout.data =GridinforData; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforData; columFormat = plotArrayFormt'; - ERPwaviewerin.plot_org.gridlayout.columFormat = columFormat; - % ERPwaviewerin.plot_org.gridlayout.columFormatOrig = columFormat; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = columFormat; + % gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormatOrig = columFormat; %%---------------------Gap between rows---------------------------- try @@ -357,8 +370,8 @@ function drawui_plot_org(FonsizeDefault) gui_plotorg_waveviewer.rowgapGTPcustom.String = '10'; end set(gui_plotorg_waveviewer.rowgap_title, 'Sizes',[60 90 85]); - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); try RowoverlayStr= MERPWaveViewer_plotorg{6}; @@ -382,8 +395,8 @@ function drawui_plot_org(FonsizeDefault) 'callback',@rowoverlapcustom,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',RowgapOVERLAPEnable); % gui_plotorg_waveviewer.rowgapoverlayedit.KeyPressFcn = @plotorg_presskey; set(gui_plotorg_waveviewer.rowgapcustom_title, 'Sizes',[60 90 85]); - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); %%---------------------Gap between columns------------------------ try @@ -433,8 +446,8 @@ function drawui_plot_org(FonsizeDefault) gui_plotorg_waveviewer.columngapgtpcustom.String = '10'; end set(gui_plotorg_waveviewer.columngap_title, 'Sizes',[60 90 85]); - ERPwaviewerin.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); try columnoverlayStr = MERPWaveViewer_plotorg{9}; catch @@ -464,8 +477,8 @@ function drawui_plot_org(FonsizeDefault) 'callback',@columnoverlaycustom,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',columngapOVERLAPEnable); % gui_plotorg_waveviewer.columngapoverlapedit.KeyPressFcn = @plotorg_presskey; set(gui_plotorg_waveviewer.columngapcustom_title, 'Sizes',[60 90 85]); - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); %%---------------help and apply the changed parameters------------- try @@ -491,7 +504,7 @@ function drawui_plot_org(FonsizeDefault) end set( gui_plotorg_waveviewer.editgridlayout_title,'Sizes',[150 60]); MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; - ERPwaviewerin.plot_org.gridlayout.GridLayoutAuto=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; gui_plotorg_waveviewer.help_run_title = uiextras.HBox('Parent', gui_plotorg_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -509,8 +522,8 @@ function drawui_plot_org(FonsizeDefault) set(gui_plotorg_waveviewer.DataSelBox,'Sizes',[150 25 25 25 25 25 25 25 25]); gui_plotorg_waveviewer.columFormatStr = ''; - assignin('base','ALLERPwaviewer',ERPwaviewerin); estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file + estudioworkingmemory('MyViewer_plotorg',0); end @@ -524,27 +537,21 @@ function plotorg_c1(source,~) if ~isempty(messgStr) && viewerpanelIndex~=4 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; end if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; return; end try - GridValueOld = ERPwaviewerin.plot_org.Grid; + GridValueOld = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; catch GridValueOld=1; end @@ -557,7 +564,7 @@ function plotorg_c1(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Sampling rate varies across ERPsets. Please select the first or third options')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -601,9 +608,7 @@ function plotorg_c1(source,~) end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -613,7 +618,7 @@ function plotorg_c1(source,~) gui_plotorg_waveviewer.plotorg_c6.Value = 0; gui_plotorg_waveviewer.LayoutFlag = [1,0,0,0,0,0]; try - chanArray = ERPwaviewerin.chan; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; plotArray = chanArray; plotBox = f_getrow_columnautowaveplot(plotArray);%% the first element is number of rows and the second element is the number of columns catch @@ -624,7 +629,6 @@ function plotorg_c1(source,~) gui_plotorg_waveviewer.layout_custom.Value = 0; gui_plotorg_waveviewer.rownum.Enable = 'off'; gui_plotorg_waveviewer.columnnum.Enable = 'off'; - gui_plotorg_waveviewer.rowgap_auto.Value = 1; gui_plotorg_waveviewer.rowgap_auto.Enable = 'off'; gui_plotorg_waveviewer.rowgapGTPcustom.String = '10'; @@ -659,27 +663,21 @@ function plotorg_c2(source,~) if ~isempty(messgStr) && viewerpanelIndex~=4 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; end if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) MessageViewer= char(strcat('Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; return; end try - GridValueOld = ERPwaviewerin.plot_org.Grid; + GridValueOld = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; catch GridValueOld=1; end @@ -693,7 +691,7 @@ function plotorg_c2(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Sampling rate varies across ERPsets. Please select the first or third options')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -739,10 +737,7 @@ function plotorg_c2(source,~) end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color(); gui_plotorg_waveviewer.plotorg_c1.Value = 0; gui_plotorg_waveviewer.plotorg_c2.Value = 1; gui_plotorg_waveviewer.plotorg_c3.Value = 0; @@ -750,7 +745,7 @@ function plotorg_c2(source,~) gui_plotorg_waveviewer.plotorg_c5.Value = 0; gui_plotorg_waveviewer.plotorg_c6.Value = 0; gui_plotorg_waveviewer.LayoutFlag = [0,1,0,0,0,0]; - chanArray = ERPwaviewerin.chan; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; try plotArray = chanArray; plotBox = f_getrow_columnautowaveplot(plotArray);%% the first element is number of rows and the second element is the number of columns @@ -787,7 +782,6 @@ function plotorg_c2(source,~) catch end end - estudioworkingmemory('OverlayIndex',1); end @@ -797,27 +791,21 @@ function plotorg_c3(source,~) if ~isempty(messgStr) && viewerpanelIndex~=4 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; end if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; return; end try - GridValueOld = ERPwaviewerin.plot_org.Grid; + GridValueOld = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; catch GridValueOld=1; end @@ -831,7 +819,7 @@ function plotorg_c3(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~=3 MessageViewer= char(strcat('Sampling rate varies across ERPsets. Please select the first or third options')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -845,7 +833,6 @@ function plotorg_c3(source,~) gui_plotorg_waveviewer.layout_custom.Value = 0; gui_plotorg_waveviewer.rownum.Enable = 'off'; gui_plotorg_waveviewer.columnnum.Enable = 'off'; - gui_plotorg_waveviewer.rowgap_auto.Value = 1; gui_plotorg_waveviewer.rowgap_auto.Enable = 'off'; gui_plotorg_waveviewer.rowgapGTPcustom.String = '10'; @@ -875,10 +862,7 @@ function plotorg_c3(source,~) end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color(); gui_plotorg_waveviewer.plotorg_c1.Value = 0; gui_plotorg_waveviewer.plotorg_c2.Value = 0; gui_plotorg_waveviewer.plotorg_c3.Value = 1; @@ -887,7 +871,7 @@ function plotorg_c3(source,~) gui_plotorg_waveviewer.plotorg_c6.Value = 0; gui_plotorg_waveviewer.LayoutFlag = [0,0,1,0,0,0]; try - plotArray = ERPwaviewerin.bin; + plotArray = gui_erp_waviewer.ERPwaviewer.bin; plotBox = f_getrow_columnautowaveplot(plotArray);%% the first element is number of rows and the second element is the number of columns catch plotBox = [1 1]; @@ -897,7 +881,6 @@ function plotorg_c3(source,~) gui_plotorg_waveviewer.layout_custom.Value = 0; gui_plotorg_waveviewer.rownum.Enable = 'off'; gui_plotorg_waveviewer.columnnum.Enable = 'off'; - gui_plotorg_waveviewer.rowgap_auto.Value = 1; gui_plotorg_waveviewer.rowgap_auto.Enable = 'off'; gui_plotorg_waveviewer.rowgapGTPcustom.String = '10'; @@ -922,7 +905,6 @@ function plotorg_c3(source,~) catch end end - estudioworkingmemory('OverlayIndex',1); end @@ -933,29 +915,21 @@ function plotorg_c4(source,~) if ~isempty(messgStr) && viewerpanelIndex~=4 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; end if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; return; end try - GridValueOld = ERPwaviewerin.plot_org.Grid; + GridValueOld = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; catch GridValueOld=1; end @@ -968,7 +942,7 @@ function plotorg_c4(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Sampling rate varies across ERPsets. Please select the first or third options')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -1013,10 +987,7 @@ function plotorg_c4(source,~) end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color(); gui_plotorg_waveviewer.plotorg_c1.Value = 0; gui_plotorg_waveviewer.plotorg_c2.Value = 0; gui_plotorg_waveviewer.plotorg_c3.Value = 0; @@ -1025,7 +996,7 @@ function plotorg_c4(source,~) gui_plotorg_waveviewer.plotorg_c6.Value = 0; gui_plotorg_waveviewer.LayoutFlag = [0,0,0,1,0,0]; try - plotArray = ERPwaviewerin.bin; + plotArray = gui_erp_waviewer.ERPwaviewer.bin; plotBox = f_getrow_columnautowaveplot(plotArray);%% the first element is number of rows and the second element is the number of columns catch plotBox = [1 1]; @@ -1062,8 +1033,6 @@ function plotorg_c4(source,~) end end estudioworkingmemory('OverlayIndex',1); - - end @@ -1074,27 +1043,21 @@ function plotorg_c5(source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; end if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; return; end try - GridValueOld = ERPwaviewerin.plot_org.Grid; + GridValueOld = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; catch GridValueOld=1; end @@ -1107,7 +1070,7 @@ function plotorg_c5(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Sampling rate varies across ERPsets. Please select the first or third options')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -1152,10 +1115,7 @@ function plotorg_c5(source,~) end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color(); gui_plotorg_waveviewer.plotorg_c1.Value = 0; gui_plotorg_waveviewer.plotorg_c2.Value = 0; gui_plotorg_waveviewer.plotorg_c3.Value = 0; @@ -1201,7 +1161,6 @@ function plotorg_c5(source,~) end end estudioworkingmemory('OverlayIndex',1); - end @@ -1211,28 +1170,20 @@ function plotorg_c6(source,~) if ~isempty(messgStr) && viewerpanelIndex~=4 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; end if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; return; end try - GridValueOld = ERPwaviewerin.plot_org.Grid; + GridValueOld = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; catch GridValueOld=1; end @@ -1245,7 +1196,7 @@ function plotorg_c6(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Sampling rate varies across ERPsets. Please select the first or third options')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -1291,12 +1242,8 @@ function plotorg_c6(source,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'on'; end - estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color(); gui_plotorg_waveviewer.plotorg_c1.Value = 0; gui_plotorg_waveviewer.plotorg_c2.Value = 0; gui_plotorg_waveviewer.plotorg_c3.Value = 0; @@ -1354,7 +1301,8 @@ function layout_auto(~,~) gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + gui_plotorg_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_plotorg_waveviewer.layout_auto.Value =1; gui_plotorg_waveviewer.layout_custom.Value = 0; gui_plotorg_waveviewer.rownum.Enable = 'off'; @@ -1375,6 +1323,61 @@ function layout_auto(~,~) gui_plotorg_waveviewer.columnoverlay.Enable = 'off'; gui_plotorg_waveviewer.columngapoverlapedit.Enable = 'off'; + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + if max(ERPsetArray) >length(ALLERPIN) + ERPsetArray =length(ALLERPIN); + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = ERPsetArray; + end + if gui_plotorg_waveviewer.plotorg_c1.Value ==1 + GridValue=1; OverlayValue = 2; PageValue =3; + elseif gui_plotorg_waveviewer.plotorg_c2.Value ==1 + GridValue=1; OverlayValue = 3; PageValue =2; + elseif gui_plotorg_waveviewer.plotorg_c3.Value ==1 + GridValue=2; OverlayValue = 1; PageValue =3; + elseif gui_plotorg_waveviewer.plotorg_c4.Value ==1 + GridValue=2; OverlayValue = 3; PageValue =1; + elseif gui_plotorg_waveviewer.plotorg_c5.Value ==1 + GridValue=3; OverlayValue = 1; PageValue =2; + elseif gui_plotorg_waveviewer.plotorg_c6.Value ==1 + GridValue=3; OverlayValue = 2; PageValue =1; + end + gui_erp_waviewer.ERPwaviewer.plot_org.Grid =GridValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = OverlayValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages = PageValue; + + [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); + if numel(binArray)> length(binStr) + binArray = [1:length(binStr)]; + gui_erp_waviewer.ERPwaviewer.bin = binArray; + end + if numel(chanArray)> length(chanStr) + chanArray = [1:length(chanStr)]; + gui_erp_waviewer.ERPwaviewer.chan = chanArray; + end + + if GridValue ==1 %% if the selected Channel is "Grid" + plotArray = chanArray; + elseif GridValue == 2 %% if the selected Bin is "Grid" + plotArray = binArray; + elseif GridValue == 3%% if the selected ERPset is "Grid" + plotArray = ERPsetArray; + else + plotArray = chanArray; + end + + plotBox = f_getrow_columnautowaveplot(plotArray);%% the first element is number of rows and the second element is the number of columns + if gui_plotorg_waveviewer.layout_auto.Value + try + gui_plotorg_waveviewer.rownum.Value = plotBox(1); + gui_plotorg_waveviewer.columnnum.Value = plotBox(2); + catch + gui_plotorg_waveviewer.rownum.Value=1; + gui_plotorg_waveviewer.columnnum.Value=1; + end + end end @@ -1386,9 +1389,7 @@ function layout_custom(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); gui_plotorg_waveviewer.layout_auto.Value =0; gui_plotorg_waveviewer.layout_custom.Value = 1; gui_plotorg_waveviewer.rownum.Enable = 'on'; @@ -1442,11 +1443,8 @@ function plotorg_rownum(Str,~) if ~isempty(messgStr) && viewerpanelIndex~=4 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); end @@ -1457,9 +1455,7 @@ function plotorg_columnnum(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); end @@ -1471,9 +1467,7 @@ function rowgapgtpauto(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); gui_plotorg_waveviewer.rowgap_auto.Value = 1; gui_plotorg_waveviewer.rowgapGTPcustom.Enable = 'on'; gui_plotorg_waveviewer.rowoverlap.Value =0; @@ -1487,13 +1481,11 @@ function rowgapgtpcustom(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); rowgap = str2num(Source.String); if isempty(rowgap) || numel(rowgap)~=1 || rowgap<=0 MessageViewer= char(strcat('Plot Organization > Row > Gap should be larger than 0')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; Source.String = '10'; return; @@ -1508,9 +1500,7 @@ function rowoverlap(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color(); gui_plotorg_waveviewer.rowgap_auto.Value = 0; gui_plotorg_waveviewer.rowgapGTPcustom.Enable = 'off'; gui_plotorg_waveviewer.rowoverlap.Value =1; @@ -1524,15 +1514,13 @@ function rowoverlapcustom(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" + rowoverlay = str2num(Source.String); if isempty(rowoverlay) || numel(rowoverlay)~=1 || rowoverlay<=0 || rowoverlay>=100 MessageViewer= char(strcat('Plot Organization > Column > Overlap should be larger than 0 and smaller than 100')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; - Source.String = '40'; return; end @@ -1549,6 +1537,8 @@ function columngapgtpop(~,~) gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + gui_plotorg_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_plotorg_waveviewer.columngapgtpop.Value =1; gui_plotorg_waveviewer.columngapgtpcustom.Enable = 'on'; @@ -1562,13 +1552,12 @@ function columngapGTPcustom(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" + columngap = str2num(Source.String); if isempty(columngap) || numel(columngap)~=1 || columngap<=0 MessageViewer= char(strcat('Plot Organization > Column > Gap should be larger than 0')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; Source.String = '10'; return; @@ -1583,9 +1572,7 @@ function columnoverlap(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" colnOverlay = str2num(char( gui_plotorg_waveviewer.columngapoverlapedit.String)); gui_plotorg_waveviewer.columngapgtpop.Value =0; @@ -1605,9 +1592,7 @@ function columnoverlaycustom(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" columnoverlay = str2num(Source.String); if isempty(columnoverlay) || numel(columnoverlay)~=1 || columnoverlay<=0 || columnoverlay>=100 @@ -1625,28 +1610,18 @@ function plotorg_edit_checkbox(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" if Source.Value==1 gui_plotorg_waveviewer.layout_custom_edit.Enable = 'on'; else gui_plotorg_waveviewer.layout_custom_edit.Enable = 'off'; end - if Source.Value==0 - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - binArray = ERPwaviewerin.bin; - chanArray = ERPwaviewerin.chan; - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end @@ -1695,10 +1670,9 @@ function plotorg_edit_checkbox(Source,~) end end end - ERPwaviewerin.plot_org.gridlayout.data = GridinforData; - ERPwaviewerin.plot_org.gridlayout.columFormat = plotArrayStr'; - ERPwaviewerin.plot_org.gridlayout.GridLayoutAuto = 0; - assignin('base','ALLERPwaviewer',ERPwaviewerin); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data = GridinforData; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = plotArrayStr'; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto = 0; end end @@ -1712,38 +1686,28 @@ function plotorg_edit(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_plotorg',1); - gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" MessageViewer= char(strcat('Plot Organization > Custom Grid Locations > Edit')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n f_ERP_plotorg_waveviewer_GUI()> plotorg_edit() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - columFormat = ERPwaviewerin.plot_org.gridlayout.columFormat; + columFormat = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat; - plotBox(1) = ERPwaviewerin.plot_org.gridlayout.rows; - plotBox(2) = ERPwaviewerin.plot_org.gridlayout.columns; + plotBox(1) = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows; + plotBox(2) = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns; try - GridinforData = ERPwaviewerin.plot_org.gridlayout.data; + GridinforData = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data; catch GridinforData = []; end - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end - GridValue= ERPwaviewerin.plot_org.Grid; + GridValue= gui_erp_waviewer.ERPwaviewer.plot_org.Grid; [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); if GridValue ==1 %% if the selected Channel is "Grid" AllabelArray = chanStr; @@ -1763,13 +1727,14 @@ function plotorg_edit(Source,~) gui_plotorg_waveviewer.apply.BackgroundColor = [1,1,1]; box_erpwave_viewer_plotorg.TitleColor= [0.5 0.5 0.9]; gui_plotorg_waveviewer.apply.ForegroundColor = [0 0 0]; - disp('User selected cancel'); + gui_plotorg_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [0 0 0]; return; end TableDataDf = def{1}; - ERPwaviewerin.plot_org.gridlayout.rows = size(TableDataDf,1); - ERPwaviewerin.plot_org.gridlayout.columns =size(TableDataDf,2); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = size(TableDataDf,1); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =size(TableDataDf,2); gui_plotorg_waveviewer.rownum.Value =size(TableDataDf,1); gui_plotorg_waveviewer.columnnum.Value =size(TableDataDf,2); try @@ -1778,31 +1743,31 @@ function plotorg_edit(Source,~) columFormatout = columFormat; end gui_plotorg_waveviewer.columFormatStr = columFormatout; - ERPwaviewerin.plot_org.gridlayout.columFormat = columFormatout; - ERPwaviewerin.plot_org.gridlayout.data =TableDataDf; - if ERPwaviewerin.plot_org.Grid==1 + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = columFormatout'; + + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =TableDataDf; + if gui_erp_waviewer.ERPwaviewer.plot_org.Grid==1 try - ERPwaviewerin.chan = def{3}; + gui_erp_waviewer.ERPwaviewer.chan = def{3}; catch end MERPWaveViewer_plotorg{1}=1; - elseif ERPwaviewerin.plot_org.Grid==2 + elseif gui_erp_waviewer.ERPwaviewer.plot_org.Grid==2 try - ERPwaviewerin.bin = def{3}; + gui_erp_waviewer.ERPwaviewer.bin = def{3}; catch end MERPWaveViewer_plotorg{1}=2; - elseif ERPwaviewerin.plot_org.Grid==3 + elseif gui_erp_waviewer.ERPwaviewer.plot_org.Grid==3 try - ERPwaviewerin.SelectERPIdx = def{3}; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = def{3}; catch end - if ERPwaviewerin.PageIndex> numel(ERPwaviewerin.SelectERPIdx) - ERPwaviewerin.PageIndex=1; + if gui_erp_waviewer.ERPwaviewer.PageIndex> numel(gui_erp_waviewer.ERPwaviewer.SelectERPIdx) + gui_erp_waviewer.ERPwaviewer.PageIndex=1; end MERPWaveViewer_plotorg{1}=3; end - assignin('base','ALLERPwaviewer',ERPwaviewerin); MERPWaveViewer_plotorg{2}=gui_plotorg_waveviewer.layout_auto.Value; plotBox(1) = gui_plotorg_waveviewer.rownum.Value; @@ -1818,20 +1783,20 @@ function plotorg_edit(Source,~) estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file viewer_ERPDAT.ERPset_Chan_bin_label=1; - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP=1; estudioworkingmemory('MyViewer_plotorg',0); gui_plotorg_waveviewer.apply.BackgroundColor = [1,1,1]; box_erpwave_viewer_plotorg.TitleColor= [0.5 0.5 0.9]; gui_plotorg_waveviewer.apply.ForegroundColor = [0 0 0]; + gui_plotorg_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [0 0 0]; end - - %%-------load the saved parameters for plotting organization--------------- function layout_custom_load(~,~) MessageViewer= char(strcat('Plot Organization > Load')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); @@ -1853,13 +1818,6 @@ function layout_custom_load(~,~) disp('Cannot load the file.'); return; end - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() > layout_custom_load() error: Please run the ERP wave viewer again.'); - return; - end %%check current version ERPtooltype = erpgettoolversion('tooltype'); @@ -1890,7 +1848,7 @@ function layout_custom_load(~,~) elseif strcmpi(ERPtooltype,'ERPLAB') MessageViewer= char(strcat('Plot Organization > Load - This settings file was created using an older version of ERPLAB')); end - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; end @@ -1903,10 +1861,10 @@ function layout_custom_load(~,~) end %%------------------default labels--------------------------------- - binArray = ERPwaviewerin.bin; - chanArray = ERPwaviewerin.chan; - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end @@ -1920,7 +1878,7 @@ function layout_custom_load(~,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if PageValue~= 3 MessageViewer= char(strcat('Plot Organization > Load - Sampling rate varies across ERPsets. We used the first option')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; GridValue = 1;OverlayValue = 2;PageValue=3; end @@ -1990,9 +1948,9 @@ function layout_custom_load(~,~) try gui_plotorg_waveviewer.layout_auto.Value=Plot_orgpar.gridlayout.op; gui_plotorg_waveviewer.layout_custom.Value = ~Plot_orgpar.gridlayout.op; - ERPwaviewerin.plot_org.Grid= GridValue; - ERPwaviewerin.plot_org.Overlay =OverlayValue; - ERPwaviewerin.plot_org.Pages=PageValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Grid= GridValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay =OverlayValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages=PageValue; catch beep; disp('The imported parameters were invalid.') @@ -2060,9 +2018,8 @@ function layout_custom_load(~,~) gui_plotorg_waveviewer.layoutinfor_table.Enable =LayOutauto; gui_plotorg_waveviewer.rownum.Enable=LayOutauto; gui_plotorg_waveviewer.columnnum.Enable=LayOutauto; - ERPwaviewerin.plot_org.gridlayout.rows = Plot_orgpar.gridlayout.rows; - ERPwaviewerin.plot_org.gridlayout.columns =Plot_orgpar.gridlayout.columns; - % ERPwaviewerin.plot_org.gridlayout.columFormat = plotArrayFormtimpChag; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = Plot_orgpar.gridlayout.rows; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =Plot_orgpar.gridlayout.columns; catch beep; disp('The imported parameters didnot match with those of "Plot Organization".') @@ -2123,16 +2080,14 @@ function layout_custom_load(~,~) if Plot_orgpar.gridlayout.GridLayoutAuto==0 gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value = 0; gui_plotorg_waveviewer.layout_custom_edit.Enable = 'off'; - ERPwaviewerin.plot_org.gridlayout.data= GridinforDatadef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data= GridinforDatadef; else EmptyItemStr = ''; gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value = 1; gui_plotorg_waveviewer.layout_custom_edit.Enable = 'on'; - ERPwaviewerin.plot_org.gridlayout.columFormat = plotArrayFormtdef; - plotArrayFormt= ERPwaviewerin.plot_org.gridlayout.columFormat'; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = plotArrayFormtdef; + plotArrayFormt= gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat'; GridinforDataOrg = Plot_orgpar.gridlayout.data; - % LabelUsedIndex = []; - % countlabel=0; for ii = 1:size(GridinforDataOrg,1) for jj = 1:size(GridinforDataOrg,2) code = 0; @@ -2155,32 +2110,28 @@ function layout_custom_load(~,~) end if ~isempty(EmptyItemStr) MessageViewer= char(strcat('Plot Organization > Load - Undefined items in grid locations:',EmptyItemStr,32,'. Because they donot match with the selected labels')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; end - - - ERPwaviewerin.plot_org.gridlayout.data =GridinforDataOrg; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforDataOrg; gui_plotorg_waveviewer.rownum.Value = size(GridinforDataOrg,1); gui_plotorg_waveviewer.columnnum.Value= size(GridinforDataOrg,2); - ERPwaviewerin.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; - ERPwaviewerin.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; - end - - - ERPwaviewerin.plot_org.gridlayout.op =gui_plotorg_waveviewer.layout_auto.Value; - ERPwaviewerin.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; - ERPwaviewerin.plot_org.gridlayout.columns = gui_plotorg_waveviewer.columnnum.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); - ERPwaviewerin.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); - ERPwaviewerin.plot_org.gridlayout.GridLayoutAuto = gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; - + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; + end + + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op =gui_plotorg_waveviewer.layout_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns = gui_plotorg_waveviewer.columnnum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto = gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; MERPWaveViewer_plotorg{2}=gui_plotorg_waveviewer.layout_auto.Value; plotBox(1) = gui_plotorg_waveviewer.rownum.Value; @@ -2195,14 +2146,10 @@ function layout_custom_load(~,~) MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file - assignin('base','ALLERPwaviewer',ERPwaviewerin); + viewer_ERPDAT.Count_currentERP=1; - viewer_ERPDAT.page_xyaxis = viewer_ERPDAT.page_xyaxis+1; - %%change the legend names based on the imported parameters - viewer_ERPDAT.count_legend = viewer_ERPDAT.count_legend+1; - f_redrawERP_viewer_test(); MessageViewer= char(strcat('Plot Organization > Load')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -2211,14 +2158,13 @@ function layout_custom_load(~,~) function layout_custom_save(~,~) [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex==4 - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; return; end MessageViewer= char(strcat('Plot Organization > Save as')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; ERPtooltype = erpgettoolversion('tooltype'); @@ -2238,15 +2184,6 @@ function layout_custom_save(~,~) end end - - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - if gui_plotorg_waveviewer.plotorg_c1.Value ==1 GridValue=1; OverlayValue = 2; PageValue =3; elseif gui_plotorg_waveviewer.plotorg_c2.Value ==1 @@ -2265,22 +2202,22 @@ function layout_custom_save(~,~) Plot_orgpar.Overlay = OverlayValue; Plot_orgpar.Pages = PageValue; Plot_orgpar.gridlayout.op =gui_plotorg_waveviewer.layout_auto.Value; - Plot_orgpar.gridlayout.data =ERPwaviewerin.plot_org.gridlayout.data; + Plot_orgpar.gridlayout.data =gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data; Plot_orgpar.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; Plot_orgpar.gridlayout.columns = gui_plotorg_waveviewer.columnnum.Value; - Plot_orgpar.gridlayout.columFormat = ERPwaviewerin.plot_org.gridlayout.columFormat; - Plot_orgpar.gridlayout.rowgap.GTPOP = ERPwaviewerin.plot_org.gridlayout.rowgap.GTPOP; - Plot_orgpar.gridlayout.rowgap.GTPValue = ERPwaviewerin.plot_org.gridlayout.rowgap.GTPValue; - Plot_orgpar.gridlayout.rowgap.OverlayOP = ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayOP; - Plot_orgpar.gridlayout.rowgap.OverlayValue = ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayValue; - - Plot_orgpar.gridlayout.columngap.GTPOP = ERPwaviewerin.plot_org.gridlayout.columngap.GTPOP; - Plot_orgpar.gridlayout.columngap.GTPValue = ERPwaviewerin.plot_org.gridlayout.columngap.GTPValue; - Plot_orgpar.gridlayout.columngap.OverlayOP = ERPwaviewerin.plot_org.gridlayout.columngap.OverlayOP; - Plot_orgpar.gridlayout.columngap.OverlayValue = ERPwaviewerin.plot_org.gridlayout.columngap.OverlayValue; - Plot_orgpar.gridlayout.GridLayoutAuto= ERPwaviewerin.plot_org.gridlayout.GridLayoutAuto; + Plot_orgpar.gridlayout.columFormat = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat; + Plot_orgpar.gridlayout.rowgap.GTPOP = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP; + Plot_orgpar.gridlayout.rowgap.GTPValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue; + Plot_orgpar.gridlayout.rowgap.OverlayOP = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP; + Plot_orgpar.gridlayout.rowgap.OverlayValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue; + + Plot_orgpar.gridlayout.columngap.GTPOP = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP; + Plot_orgpar.gridlayout.columngap.GTPValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue; + Plot_orgpar.gridlayout.columngap.OverlayOP = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP; + Plot_orgpar.gridlayout.columngap.OverlayValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue; + Plot_orgpar.gridlayout.GridLayoutAuto= gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto; pathstr = pwd; - namedef ='LayoutInfor'; + namedef ='LayoutInfor_viewer'; [erpfilename, erppathname, indxs] = uiputfile({'*.mat'}, ... ['Save "','Information of Plot Organization', '" as'],... fullfile(pathstr,namedef)); @@ -2288,7 +2225,7 @@ function layout_custom_save(~,~) disp('User selected Cancel') return end - % [pathx, filename, ext] = fileparts(erpfilename); + [pathstr, erpfilename, ext] = fileparts(erpfilename) ; ext = '.mat'; erpFilename = char(strcat(erpfilename,ext)); @@ -2296,14 +2233,13 @@ function layout_custom_save(~,~) save([erppathname,erpFilename],'Plot_orgpar','-v7.3'); catch MessageViewer = ['Plot Organization > Save as: Cannot save the parameters for "Plot Organization", please try again']; - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =3; + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; return; end MessageViewer= char(strcat('Plot Organization > Save as')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; - end @@ -2317,33 +2253,21 @@ function plotorg_cancel(~,~) if changeFlag~=1 return; end - MessageViewer= char(strcat('Plot Organization > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =1; + MessageViewer= char(strcat('Plot Organization > Cancel')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =1; try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Plot Organization > Cancel error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - try - GridValue=ERPwaviewer_apply.plot_org.Grid ; - OverlayValue=ERPwaviewer_apply.plot_org.Overlay; - PageValue=ERPwaviewer_apply.plot_org.Pages; + GridValue=gui_erp_waviewer.ERPwaviewer.plot_org.Grid ; + OverlayValue=gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + PageValue=gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch GridValue=1; OverlayValue = 2; PageValue =3; end - try - ALLERP = ERPwaviewer_apply.ALLERP; - indexerp = ERPwaviewer_apply.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp) = ALLERP(indexerp(Numofselectederp)).srate; end @@ -2411,8 +2335,8 @@ function plotorg_cancel(~,~) gui_plotorg_waveviewer.plotorg_c6.Value =1; gui_plotorg_waveviewer.LayoutFlag = [0,0,0,0,0,1]; end - gui_plotorg_waveviewer.layout_auto.Value = ERPwaviewer_apply.plot_org.gridlayout.op; - gui_plotorg_waveviewer.layout_custom.Value = ~ERPwaviewer_apply.plot_org.gridlayout.op; + gui_plotorg_waveviewer.layout_auto.Value = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op; + gui_plotorg_waveviewer.layout_custom.Value = ~gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op; gui_plotorg_waveviewer.layout_auto.Enable = 'on'; gui_plotorg_waveviewer.layout_custom.Enable = 'on'; if gui_plotorg_waveviewer.layout_auto.Value==1 @@ -2422,18 +2346,18 @@ function plotorg_cancel(~,~) EnableFlag = 'on'; gui_plotorg_waveviewer.layout_custom_edit.Enable = 'on'; end - gui_plotorg_waveviewer.rownum.Value= ERPwaviewer_apply.plot_org.gridlayout.rows; - gui_plotorg_waveviewer.columnnum.Value=ERPwaviewer_apply.plot_org.gridlayout.columns; - rowGapValue = ERPwaviewer_apply.plot_org.gridlayout.rowgap.GTPOP; + gui_plotorg_waveviewer.rownum.Value= gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows; + gui_plotorg_waveviewer.columnnum.Value=gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns; + rowGapValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP; gui_plotorg_waveviewer.rowgap_auto.Value=rowGapValue; gui_plotorg_waveviewer.rowoverlap.Value=~rowGapValue; - gui_plotorg_waveviewer.rowgapGTPcustom.String = num2str(ERPwaviewer_apply.plot_org.gridlayout.rowgap.GTPValue); - gui_plotorg_waveviewer.rowgapoverlayedit.String=num2str(ERPwaviewer_apply.plot_org.gridlayout.rowgap.OverlayValue); - columnGapValue =ERPwaviewer_apply.plot_org.gridlayout.columngap.GTPOP; + gui_plotorg_waveviewer.rowgapGTPcustom.String = num2str(gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue); + gui_plotorg_waveviewer.rowgapoverlayedit.String=num2str(gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue); + columnGapValue =gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP; gui_plotorg_waveviewer.columngapgtpop.Value= columnGapValue; gui_plotorg_waveviewer.columnoverlay.Value = ~columnGapValue; - gui_plotorg_waveviewer.columngapgtpcustom.String = num2str(ERPwaviewer_apply.plot_org.gridlayout.columngap.GTPValue); - gui_plotorg_waveviewer.columngapoverlapedit.String=num2str(ERPwaviewer_apply.plot_org.gridlayout.columngap.OverlayValue); + gui_plotorg_waveviewer.columngapgtpcustom.String = num2str(gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue); + gui_plotorg_waveviewer.columngapoverlapedit.String=num2str(gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue); gui_plotorg_waveviewer.rownum.Enable = EnableFlag; gui_plotorg_waveviewer.columnnum.Enable = EnableFlag; @@ -2465,22 +2389,22 @@ function plotorg_cancel(~,~) gui_plotorg_waveviewer.columngapoverlapedit.Enable = 'on'; end end - - if ERPwaviewer_apply.plot_org.gridlayout.GridLayoutAuto ==0 + if gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto ==0 gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value = 0; gui_plotorg_waveviewer.layout_custom_edit.Enable = 'off'; else gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value = 1; gui_plotorg_waveviewer.layout_custom_edit.Enable = 'on'; end - gui_plotorg_waveviewer.columFormatStr = ''; estudioworkingmemory('MyViewer_plotorg',0); gui_plotorg_waveviewer.apply.BackgroundColor = [1 1 1]; gui_plotorg_waveviewer.apply.ForegroundColor = [0 0 0]; box_erpwave_viewer_plotorg.TitleColor= [0.5 0.5 0.9]; - MessageViewer= char(strcat('Plot Organization > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + gui_plotorg_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [0 0 0]; + MessageViewer= char(strcat('Plot Organization > Cancel')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -2496,26 +2420,19 @@ function plotorg_apply(~,~) gui_plotorg_waveviewer.apply.BackgroundColor = [1 1 1]; gui_plotorg_waveviewer.apply.ForegroundColor = [0 0 0]; box_erpwave_viewer_plotorg.TitleColor= [0.5 0.5 0.9]; - + gui_plotorg_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Plot Organization > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - %%checking the numbers of rows and columns - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Plot Organization > Apply-f_ERP_plotorg_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - binArray = ERPwaviewerin.bin; - chanArray = ERPwaviewerin.chan; - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; + + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end - if gui_plotorg_waveviewer.plotorg_c1.Value ==1 GridValue=1; OverlayValue = 2; PageValue =3; MERPWaveViewer_plotorg{1}=1; @@ -2580,14 +2497,14 @@ function plotorg_apply(~,~) end if gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value ==0 - ERPwaviewerin.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; - ERPwaviewerin.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; - ERPwaviewerin.plot_org.gridlayout.columFormat = plotArrayFormt'; - ERPwaviewerin.plot_org.gridlayout.data =GridinforDatadef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = plotArrayFormt'; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforDatadef; else EmptyItemStr = ''; - ERPwaviewerin.plot_org.gridlayout.columFormat=plotArrayFormt'; - GridinforDataOrg = ERPwaviewerin.plot_org.gridlayout.data; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat=plotArrayFormt'; + GridinforDataOrg = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data; countEmp = 0; for ii = 1:size(GridinforDataOrg,1) for jj = 1:size(GridinforDataOrg,2) @@ -2613,7 +2530,7 @@ function plotorg_apply(~,~) end if ~isempty(EmptyItemStr) MessageViewer= char(strcat('Plot Organization > Apply-Undefined item(s) in grid locations:',EmptyItemStr,32,'because they donot match with the selected labels')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; end if countEmp == size(GridinforDataOrg,1)*size(GridinforDataOrg,2) || isempty(EmptyItemStr) @@ -2623,32 +2540,30 @@ function plotorg_apply(~,~) end if ~isempty(EmptyItemStr) MessageViewer= char(strcat('Plot Organization > Apply-Undefined item(s) in grid locations:',EmptyItemStr,32,'because they donot match with the selected labels')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; end end - - ERPwaviewerin.plot_org.gridlayout.data =GridinforDataOrg; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforDataOrg; gui_plotorg_waveviewer.rownum.Value = size(GridinforDataOrg,1); gui_plotorg_waveviewer.columnnum.Value= size(GridinforDataOrg,2); end - ERPwaviewerin.plot_org.Grid = GridValue; - ERPwaviewerin.plot_org.Overlay = OverlayValue; - ERPwaviewerin.plot_org.Pages = PageValue; - ERPwaviewerin.plot_org.gridlayout.op =gui_plotorg_waveviewer.layout_auto.Value; - ERPwaviewerin.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; - ERPwaviewerin.plot_org.gridlayout.columns = gui_plotorg_waveviewer.columnnum.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); - ERPwaviewerin.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); - ERPwaviewerin.plot_org.gridlayout.GridLayoutAuto = gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; - + gui_erp_waviewer.ERPwaviewer.plot_org.Grid = GridValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = OverlayValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages = PageValue; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op =gui_plotorg_waveviewer.layout_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns = gui_plotorg_waveviewer.columnnum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto = gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; MERPWaveViewer_plotorg{2}=gui_plotorg_waveviewer.layout_auto.Value; plotBox(1) = gui_plotorg_waveviewer.rownum.Value; @@ -2662,32 +2577,18 @@ function plotorg_apply(~,~) MERPWaveViewer_plotorg{9}=str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file - - assignin('base','ALLERPwaviewer',ERPwaviewerin); - overlayIndex = estudioworkingmemory('OverlayIndex'); - if ~isempty(overlayIndex) && overlayIndex==1 - viewer_ERPDAT.count_legend = viewer_ERPDAT.count_legend+1; - end - f_redrawERP_viewer_test();%%plot ERP waves + viewer_ERPDAT.Count_currentERP=1; viewer_ERPDAT.Process_messg =2; end %%----------------change ORG based on the selected ERPsets----------------- function v_currentERP_change(~,~) - if viewer_ERPDAT.Count_currentERP == 0 - return; - end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); + if viewer_ERPDAT.Count_currentERP ~=4 return; end - %%Force Grid, Overlay, and Pages to be 1,2,3, respectively if "Same as ERPLAB" - indexerp = ERPwaviewer_apply.SelectERPIdx; - ALLERP = ERPwaviewer_apply.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; for Numofselectederp = 1:numel(indexerp) SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; end @@ -2700,7 +2601,7 @@ function v_currentERP_change(~,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Sampling rate varies across ERPsets.\n We used the first option (i.e., Channels, Bins, ERPsets)')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -2716,15 +2617,14 @@ function v_currentERP_change(~,~) gui_plotorg_waveviewer.plotorg_c5.Enable = 'on'; gui_plotorg_waveviewer.plotorg_c6.Enable = 'on'; end - binArray = ERPwaviewer_apply.bin; - chanArray = ERPwaviewer_apply.chan; - ERPsetArray = ERPwaviewer_apply.SelectERPIdx; - ALLERPIN = ERPwaviewer_apply.ALLERP; + binArray = gui_erp_waviewer.ERPwaviewer.bin; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); - ERPwaviewer_apply.SelectERPIdx = ERPsetArray; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = ERPsetArray; end - if gui_plotorg_waveviewer.plotorg_c1.Value ==1 GridValue=1; OverlayValue = 2; PageValue =3; elseif gui_plotorg_waveviewer.plotorg_c2.Value ==1 @@ -2738,18 +2638,18 @@ function v_currentERP_change(~,~) elseif gui_plotorg_waveviewer.plotorg_c6.Value ==1 GridValue=3; OverlayValue = 2; PageValue =1; end - ERPwaviewer_apply.plot_org.Grid =GridValue; - ERPwaviewer_apply.plot_org.Overlay = OverlayValue; - ERPwaviewer_apply.plot_org.Pages = PageValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Grid =GridValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = OverlayValue; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages = PageValue; [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); if numel(binArray)> length(binStr) binArray = [1:length(binStr)]; - ERPwaviewer_apply.bin = binArray; + gui_erp_waviewer.ERPwaviewer.bin = binArray; end if numel(chanArray)> length(chanStr) chanArray = [1:length(chanStr)]; - ERPwaviewer_apply.chan = chanArray; + gui_erp_waviewer.ERPwaviewer.chan = chanArray; end if GridValue ==1 %% if the selected Channel is "Grid" @@ -2796,14 +2696,14 @@ function v_currentERP_change(~,~) end end if gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value==0 - ERPwaviewer_apply.plot_org.gridlayout.data =GridinforData; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforData; gui_plotorg_waveviewer.rownum.Value = size(GridinforData,1); gui_plotorg_waveviewer.columnnum.Value= size(GridinforData,2); - ERPwaviewer_apply.plot_org.gridlayout.columFormat = plotArrayFormt'; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = plotArrayFormt'; else EmptyItemStr = ''; - ERPwaviewer_apply.plot_org.gridlayout.columFormat=plotArrayFormt'; - GridinforDataOrg = ERPwaviewer_apply.plot_org.gridlayout.data; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat=plotArrayFormt'; + GridinforDataOrg = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data; for ii = 1:size(GridinforDataOrg,1) for jj = 1:size(GridinforDataOrg,2) code = 0; @@ -2827,17 +2727,16 @@ function v_currentERP_change(~,~) if ~isempty(EmptyItemStr) MessageViewer= char(strcat('Plot Organization > v_currentERP_change() - Undefined items in grid locations:',EmptyItemStr,32,'. Because they donot match with the selected labels')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; + return; end - - ERPwaviewer_apply.plot_org.gridlayout.data =GridinforDataOrg; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforDataOrg; gui_plotorg_waveviewer.rownum.Value = size(GridinforDataOrg,1); gui_plotorg_waveviewer.columnnum.Value= size(GridinforDataOrg,2); end - ERPwaviewer_apply.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; - ERPwaviewer_apply.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = gui_plotorg_waveviewer.rownum.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =gui_plotorg_waveviewer.columnnum.Value; %%save the parameters for this panel to memory file if gui_plotorg_waveviewer.plotorg_c1.Value ==1 @@ -2865,7 +2764,7 @@ function v_currentERP_change(~,~) MERPWaveViewer_plotorg{9}=str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file - + viewer_ERPDAT.Count_currentERP =5; end @@ -2875,27 +2774,18 @@ function loadproper_change(~,~) return; end try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - - try - GridValue=ERPwaviewer_apply.plot_org.Grid ; - OverlayValue=ERPwaviewer_apply.plot_org.Overlay; - PageValue=ERPwaviewer_apply.plot_org.Pages; + GridValue=gui_erp_waviewer.ERPwaviewer.plot_org.Grid ; + OverlayValue=gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + PageValue=gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch GridValue=1; OverlayValue = 2; PageValue =3; end - try - ALLERP = ERPwaviewer_apply.ALLERP; - indexerp = ERPwaviewer_apply.SelectERPIdx; - ERPsetArray = ERPwaviewer_apply.SelectERPIdx; - chanArray = ERPwaviewer_apply.chan; - binArray = ERPwaviewer_apply.bin; + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + chanArray = gui_erp_waviewer.ERPwaviewer.chan; + binArray = gui_erp_waviewer.ERPwaviewer.bin; catch beep; disp('f_ERP_plotorg_waveviewer_GUI() error: Please run the ERP wave viewer again.'); @@ -2911,16 +2801,16 @@ function loadproper_change(~,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if PageValue ~=3 MessageViewer= char(strcat('Warning: Sampling rate varies across ERPsets. We used the first option')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; GridValue=1; OverlayValue = 2; PageValue =3; - ERPwaviewer_apply.plot_org.Grid = 1; - ERPwaviewer_apply.plot_org.Overlay = 2; - ERPwaviewer_apply.plot_org.Pages = 3; - ALLERPIN = ERPwaviewer_apply.ALLERP; + gui_erp_waviewer.ERPwaviewer.plot_org.Grid = 1; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = 2; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages = 3; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); - ERPwaviewer_apply.SelectERPIdx = ERPsetArray; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = ERPsetArray; end [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); plotArray = chanArray; @@ -2945,10 +2835,10 @@ function loadproper_change(~,~) end end end - ERPwaviewer_apply.plot_org.gridlayout.data =GridinforData; - ERPwaviewer_apply.plot_org.gridlayout.rows = Numrows; - ERPwaviewer_apply.plot_org.gridlayout.columns =Numcolumns; - ERPwaviewer_apply.plot_org.gridlayout.columFormat = plotArrayFormt'; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforData; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = Numrows; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns =Numcolumns; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = plotArrayFormt'; end else gui_plotorg_waveviewer.plotorg_c2.Enable = 'on'; @@ -2956,8 +2846,6 @@ function loadproper_change(~,~) gui_plotorg_waveviewer.plotorg_c5.Enable = 'on'; gui_plotorg_waveviewer.plotorg_c6.Enable = 'on'; end - - if GridValue==1 && OverlayValue == 2&& PageValue ==3 gui_plotorg_waveviewer.plotorg_c1.Value =1; gui_plotorg_waveviewer.plotorg_c2.Value =0; @@ -3008,7 +2896,6 @@ function loadproper_change(~,~) gui_plotorg_waveviewer.LayoutFlag = [0,0,0,0,0,1]; end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,ERPsetArray); if GridValue ==1 %% if the selected Channel is "Grid" plotArray = chanArray; @@ -3050,45 +2937,43 @@ function loadproper_change(~,~) end end end - AutoValue = ERPwaviewer_apply.plot_org.gridlayout.op; + AutoValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op; if AutoValue ==1 Enable = 'off'; gui_plotorg_waveviewer.layout_auto.Value =1; gui_plotorg_waveviewer.layout_custom.Value = 0; - ERPwaviewer_apply.plot_org.gridlayout.rows =NumrowsDef; - ERPwaviewer_apply.plot_org.gridlayout.columns = NumcolumnsDef; - ERPwaviewer_apply.plot_org.gridlayout.rowgap.GTPOP=1; - ERPwaviewer_apply.plot_org.gridlayout.rowgap.GTPValue=10; - ERPwaviewer_apply.plot_org.gridlayout.rowgap.OverlayOP=0; - ERPwaviewer_apply.plot_org.gridlayout.rowgap.OverlayValue=40; - ERPwaviewer_apply.plot_org.gridlayout.columngap.GTPOP=1; - ERPwaviewer_apply.plot_org.gridlayout.columngap.GTPValue=10; - ERPwaviewer_apply.plot_org.gridlayout.columngap.OverlayOP=0; - ERPwaviewer_apply.plot_org.gridlayout.columngap.OverlayValue=40; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows =NumrowsDef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns = NumcolumnsDef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP=1; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue=10; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP=0; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue=40; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP=1; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue=10; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP=0; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue=40; else Enable = 'on'; gui_plotorg_waveviewer.layout_auto.Value =0; gui_plotorg_waveviewer.layout_custom.Value = 1; - - end try - GridLayoutAuto = ERPwaviewer_apply.plot_org.gridlayout.GridLayoutAuto; + GridLayoutAuto = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.GridLayoutAuto; catch GridLayoutAuto=0; end if GridLayoutAuto==0 - ERPwaviewer_apply.plot_org.gridlayout.data = GridinforDatadef; - ERPwaviewer_apply.plot_org.gridlayout.columFormat=plotArrayFormtdef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data = GridinforDatadef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat=plotArrayFormtdef; gui_plotorg_waveviewer.layout_custom_edit.Enable = 'off'; gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value =0; else gui_plotorg_waveviewer.layout_custom_edit.Enable = 'on'; gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value =1; - ERPwaviewer_apply.plot_org.gridlayout.columFormat=plotArrayFormtdef; - Datanew = ERPwaviewer_apply.plot_org.gridlayout.data; - ERPwaviewer_apply.plot_org.gridlayout.rows =size(Datanew,1); - ERPwaviewer_apply.plot_org.gridlayout.columns = size(Datanew,2); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat=plotArrayFormtdef; + Datanew = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows =size(Datanew,1); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns = size(Datanew,2); LabelUsedIndex = []; countlabel=0; EmptyItemStr =''; @@ -3112,15 +2997,13 @@ function loadproper_change(~,~) end end end - ERPwaviewer_apply.plot_org.gridlayout.data = Datanew; - + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data = Datanew; if ~isempty(EmptyItemStr) MessageViewer= char(strcat('Plot Organization > loadproper_change() - Undefined items in grid locations:',EmptyItemStr,32,'. Because they donot match with the selected labels')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; + return; end - - end gui_plotorg_waveviewer.layout_auto.Enable ='on'; @@ -3135,16 +3018,16 @@ function loadproper_change(~,~) gui_plotorg_waveviewer.columngapgtpcustom.Enable = Enable; gui_plotorg_waveviewer.columnoverlay.Enable = Enable; gui_plotorg_waveviewer.columngapoverlapedit.Enable = Enable; - RowNum = ERPwaviewer_apply.plot_org.gridlayout.rows; - columNum = ERPwaviewer_apply.plot_org.gridlayout.columns; + RowNum = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows; + columNum = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns; gui_plotorg_waveviewer.rownum.Value = RowNum; gui_plotorg_waveviewer.columnnum.Value = columNum; %%Row gap and overlay - rowgapValue = ERPwaviewer_apply.plot_org.gridlayout.rowgap.GTPOP; - rowgapCustom = ERPwaviewer_apply.plot_org.gridlayout.rowgap.GTPValue; - rowoverlayValue = ERPwaviewer_apply.plot_org.gridlayout.rowgap.OverlayOP; - rowoverlayCustom = ERPwaviewer_apply.plot_org.gridlayout.rowgap.OverlayValue; + rowgapValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP; + rowgapCustom = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue; + rowoverlayValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP; + rowoverlayCustom = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue; gui_plotorg_waveviewer.rowgap_auto.Value = rowgapValue; gui_plotorg_waveviewer.rowgapGTPcustom.String = num2str(rowgapCustom); gui_plotorg_waveviewer.rowoverlap.Value = rowoverlayValue; @@ -3163,10 +3046,10 @@ function loadproper_change(~,~) end %%column gap and overlay - columnGapValue = ERPwaviewer_apply.plot_org.gridlayout.columngap.GTPOP; - columnGapcustom = ERPwaviewer_apply.plot_org.gridlayout.columngap.GTPValue; - columnoverlayValue = ERPwaviewer_apply.plot_org.gridlayout.columngap.OverlayOP; - columnoverlaycustom = ERPwaviewer_apply.plot_org.gridlayout.columngap.OverlayValue; + columnGapValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP; + columnGapcustom = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue; + columnoverlayValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP; + columnoverlaycustom = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue; gui_plotorg_waveviewer.columngapgtpop.Value = columnGapValue; gui_plotorg_waveviewer.columngapgtpcustom.String = num2str(columnGapcustom); gui_plotorg_waveviewer.columnoverlay.Value = columnoverlayValue; @@ -3183,7 +3066,6 @@ function loadproper_change(~,~) gui_plotorg_waveviewer.columngapoverlapedit.Enable = 'on'; end end - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); %%save the parameters for this panel to memory file if gui_plotorg_waveviewer.plotorg_c1.Value ==1 @@ -3211,7 +3093,6 @@ function loadproper_change(~,~) MERPWaveViewer_plotorg{9}=str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file - viewer_ERPDAT.loadproper_count =5; end @@ -3230,16 +3111,8 @@ function count_twopanels_change(~,~) return; end - %%checking the numbers of rows and columns - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Plot Organization > Apply-f_ERP_plotorg_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end @@ -3255,7 +3128,7 @@ function count_twopanels_change(~,~) gui_plotorg_waveviewer.plotorg_c6.Enable = 'off'; if y_Flag~=1 && y_Flag~= 3 MessageViewer= char(strcat('Warning: Sampling rate varies across ERPsets. We used the first option')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; gui_plotorg_waveviewer.plotorg_c1.Value = 1; gui_plotorg_waveviewer.plotorg_c2.Value = 0; @@ -3264,10 +3137,9 @@ function count_twopanels_change(~,~) gui_plotorg_waveviewer.plotorg_c5.Value = 0; gui_plotorg_waveviewer.plotorg_c6.Value = 0; gui_plotorg_waveviewer.LayoutFlag = [1,0,0,0,0,0]; - ERPwaviewerin.plot_org.Grid = 1; - ERPwaviewerin.plot_org.Overlay = 2; - ERPwaviewerin.plot_org.Pages = 3; - assignin('base','ALLERPwaviewer',ERPwaviewerin); + gui_erp_waviewer.ERPwaviewer.plot_org.Grid = 1; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = 2; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages = 3; end else gui_plotorg_waveviewer.plotorg_c2.Enable = 'on'; @@ -3278,149 +3150,140 @@ function count_twopanels_change(~,~) plotorg_apply(); end - %%------------------------------------------------------------------------- %%-----------------Reset this panel with the default parameters------------ %%------------------------------------------------------------------------- function Reset_Waviewer_panel_change(~,~) - if viewer_ERPDAT.Reset_Waviewer_panel==4 - try - ERPwaviewerin = evalin('base','ALLERPwaviewer'); - ALLERP = ERPwaviewerin.ALLERP; - indexerp = ERPwaviewerin.SelectERPIdx; - catch - beep; - disp('f_ERP_plotorg_waveviewer_GUI error: Restart ERPwave Viewer'); - return; - end - gui_plotorg_waveviewer.plotorg_c1.Value = 1; - gui_plotorg_waveviewer.plotorg_c2.Value = 0; - gui_plotorg_waveviewer.plotorg_c3.Value = 0; - gui_plotorg_waveviewer.plotorg_c4.Value = 0; - gui_plotorg_waveviewer.plotorg_c5.Value = 0; - gui_plotorg_waveviewer.plotorg_c6.Value = 0; - gui_plotorg_waveviewer.LayoutFlag = [1,0,0,0,0,0]; - ERPwaviewerin.plot_org.Grid = 1; - ERPwaviewerin.plot_org.Overlay = 2; - ERPwaviewerin.plot_org.Pages = 3; - estudioworkingmemory('OverlayIndex',1); - %%check sampling rate and data type - for Numofselectederp = 1:numel(indexerp) - SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; - Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; - end - if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) - MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =4; - return; - end - gui_plotorg_waveviewer.plotorg_c2.Enable = 'on'; - gui_plotorg_waveviewer.plotorg_c4.Enable = 'on'; - gui_plotorg_waveviewer.plotorg_c5.Enable = 'on'; - gui_plotorg_waveviewer.plotorg_c6.Enable = 'on'; - ERPwaviewerin.plot_org.gridlayout.op = 1; - gui_plotorg_waveviewer.layout_auto.Value =1; - gui_plotorg_waveviewer.layout_custom.Value =0; - %%row and column numbers - plotArray = ERPwaviewerin.chan; - if isempty(plotArray) - plotArray = [1:ERPwaviewerin.ERP.nchan]; - end - plotBox = f_getrow_columnautowaveplot(plotArray); - try - NumrowsDef = plotBox(1); - NumcolumnsDef = plotBox(2); - catch - NumrowsDef = 1; - NumcolumnsDef = 1; - end - gui_plotorg_waveviewer.rownum.Value=NumrowsDef; - gui_plotorg_waveviewer.columnnum.Value=NumcolumnsDef; - gui_plotorg_waveviewer.rownum.Enable='off'; - gui_plotorg_waveviewer.columnnum.Enable='off'; - - ERPwaviewerin.plot_org.gridlayout.rows = NumrowsDef; - ERPwaviewerin.plot_org.gridlayout.columns=NumcolumnsDef; - ERPsetArray = ERPwaviewerin.SelectERPIdx; - ALLERPIN = ERPwaviewerin.ALLERP; - if max(ERPsetArray) >length(ALLERPIN) - ERPsetArray =length(ALLERPIN); - end - [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); - plotArrayStr = chanStr(plotArray); - count = 0; - for Numofrows = 1:NumrowsDef - for Numofcolumns = 1:NumcolumnsDef - count = count +1; - if count> numel(plotArray) - GridinforData{Numofrows,Numofcolumns} = ''; - else - GridinforData{Numofrows,Numofcolumns} = char(plotArrayStr(count)); - end + if viewer_ERPDAT.Reset_Waviewer_panel~=4 + return; + end + ALLERP = gui_erp_waviewer.ERPwaviewer.ALLERP; + indexerp = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + gui_plotorg_waveviewer.plotorg_c1.Value = 1; + gui_plotorg_waveviewer.plotorg_c2.Value = 0; + gui_plotorg_waveviewer.plotorg_c3.Value = 0; + gui_plotorg_waveviewer.plotorg_c4.Value = 0; + gui_plotorg_waveviewer.plotorg_c5.Value = 0; + gui_plotorg_waveviewer.plotorg_c6.Value = 0; + gui_plotorg_waveviewer.LayoutFlag = [1,0,0,0,0,0]; + gui_erp_waviewer.ERPwaviewer.plot_org.Grid = 1; + gui_erp_waviewer.ERPwaviewer.plot_org.Overlay = 2; + gui_erp_waviewer.ERPwaviewer.plot_org.Pages = 3; + estudioworkingmemory('OverlayIndex',1); + %%check sampling rate and data type + for Numofselectederp = 1:numel(indexerp) + SrateNum_mp(Numofselectederp,1) = ALLERP(indexerp(Numofselectederp)).srate; + Datype{Numofselectederp} = ALLERP(indexerp(Numofselectederp)).datatype; + end + if length(unique(Datype))~=1 || (numel(indexerp)==1 && strcmpi(char(Datype),'ERP')~=1) + MessageViewer= char(strcat('Warning: Type of data varies across ERPsets. We only plot waves for ERPset')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + return; + end + gui_plotorg_waveviewer.plotorg_c2.Enable = 'on'; + gui_plotorg_waveviewer.plotorg_c4.Enable = 'on'; + gui_plotorg_waveviewer.plotorg_c5.Enable = 'on'; + gui_plotorg_waveviewer.plotorg_c6.Enable = 'on'; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op = 1; + gui_plotorg_waveviewer.layout_auto.Value =1; + gui_plotorg_waveviewer.layout_custom.Value =0; + %%row and column numbers + plotArray = gui_erp_waviewer.ERPwaviewer.chan; + if isempty(plotArray) + plotArray = [1:gui_erp_waviewer.ERPwaviewer.ERP.nchan]; + end + plotBox = f_getrow_columnautowaveplot(plotArray); + try + NumrowsDef = plotBox(1); + NumcolumnsDef = plotBox(2); + catch + NumrowsDef = 1; + NumcolumnsDef = 1; + end + gui_plotorg_waveviewer.rownum.Value=NumrowsDef; + gui_plotorg_waveviewer.columnnum.Value=NumcolumnsDef; + gui_plotorg_waveviewer.rownum.Enable='off'; + gui_plotorg_waveviewer.columnnum.Enable='off'; + + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows = NumrowsDef; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns=NumcolumnsDef; + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + if max(ERPsetArray) >length(ALLERPIN) + ERPsetArray =length(ALLERPIN); + end + [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); + plotArrayStr = chanStr(plotArray); + count = 0; + for Numofrows = 1:NumrowsDef + for Numofcolumns = 1:NumcolumnsDef + count = count +1; + if count> numel(plotArray) + GridinforData{Numofrows,Numofcolumns} = ''; + else + GridinforData{Numofrows,Numofcolumns} = char(plotArrayStr(count)); end end - ERPwaviewerin.plot_org.gridlayout.data =GridinforData; - plotArrayFormt = plotArrayStr; - ERPwaviewerin.plot_org.gridlayout.columFormat = plotArrayFormt'; - %%Grid spacing - gui_plotorg_waveviewer.rowgap_auto.Value =1; - gui_plotorg_waveviewer.rowgapGTPcustom.String = '10'; - gui_plotorg_waveviewer.rowoverlap.Value = 0; - gui_plotorg_waveviewer.rowgapoverlayedit.String = '40'; - gui_plotorg_waveviewer.columngapgtpop.Value =1; - gui_plotorg_waveviewer.columngapgtpcustom.String = '10'; - gui_plotorg_waveviewer.columnoverlay.Value=0; - gui_plotorg_waveviewer.columngapoverlapedit.String = '40'; - gui_plotorg_waveviewer.rowgap_auto.Enable ='off'; - gui_plotorg_waveviewer.rowgapGTPcustom.Enable ='off'; - gui_plotorg_waveviewer.rowoverlap.Enable ='off'; - gui_plotorg_waveviewer.rowgapoverlayedit.Enable ='off'; - gui_plotorg_waveviewer.columngapgtpop.Enable ='off'; - gui_plotorg_waveviewer.columngapgtpcustom.Enable ='off'; - gui_plotorg_waveviewer.columnoverlay.Enable ='off'; - gui_plotorg_waveviewer.columngapoverlapedit.Enable ='off'; - - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; - ERPwaviewerin.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); - ERPwaviewerin.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; - ERPwaviewerin.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); - - gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value=0; %,'HorizontalAlignment','left' - gui_plotorg_waveviewer.layout_custom_edit.Enable='off'; - - assignin('base','ALLERPwaviewer',ERPwaviewerin); - - %%Using the default background color for "apply" and title bar - gui_plotorg_waveviewer.apply.BackgroundColor = [1 1 1]; - gui_plotorg_waveviewer.apply.ForegroundColor = [0 0 0]; - box_erpwave_viewer_plotorg.TitleColor= [0.5 0.5 0.9]; - - %%save the parameters for this panel to memory file - MERPWaveViewer_plotorg{1}=1; - MERPWaveViewer_plotorg{2}=gui_plotorg_waveviewer.layout_auto.Value; - plotBox(1) = gui_plotorg_waveviewer.rownum.Value; - plotBox(2) = gui_plotorg_waveviewer.columnnum.Value; - MERPWaveViewer_plotorg{3}=plotBox; - MERPWaveViewer_plotorg{4}= gui_plotorg_waveviewer.rowgap_auto.Value; - MERPWaveViewer_plotorg{5}=str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); - MERPWaveViewer_plotorg{6}=str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); - MERPWaveViewer_plotorg{7} = gui_plotorg_waveviewer.columngapgtpop.Value; - MERPWaveViewer_plotorg{8}=str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); - MERPWaveViewer_plotorg{9}=str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); - MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; - estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file - - %%execute next panel - viewer_ERPDAT.Reset_Waviewer_panel=5; end + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data =GridinforData; + plotArrayFormt = plotArrayStr; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat = plotArrayFormt'; + %%Grid spacing + gui_plotorg_waveviewer.rowgap_auto.Value =1; + gui_plotorg_waveviewer.rowgapGTPcustom.String = '10'; + gui_plotorg_waveviewer.rowoverlap.Value = 0; + gui_plotorg_waveviewer.rowgapoverlayedit.String = '40'; + gui_plotorg_waveviewer.columngapgtpop.Value =1; + gui_plotorg_waveviewer.columngapgtpcustom.String = '10'; + gui_plotorg_waveviewer.columnoverlay.Value=0; + gui_plotorg_waveviewer.columngapoverlapedit.String = '40'; + gui_plotorg_waveviewer.rowgap_auto.Enable ='off'; + gui_plotorg_waveviewer.rowgapGTPcustom.Enable ='off'; + gui_plotorg_waveviewer.rowoverlap.Enable ='off'; + gui_plotorg_waveviewer.rowgapoverlayedit.Enable ='off'; + gui_plotorg_waveviewer.columngapgtpop.Enable ='off'; + gui_plotorg_waveviewer.columngapgtpcustom.Enable ='off'; + gui_plotorg_waveviewer.columnoverlay.Enable ='off'; + gui_plotorg_waveviewer.columngapoverlapedit.Enable ='off'; + + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP = gui_plotorg_waveviewer.rowgap_auto.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue = str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayOP = gui_plotorg_waveviewer.rowoverlap.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue = str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP = gui_plotorg_waveviewer.columngapgtpop.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue = str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayOP = gui_plotorg_waveviewer.columnoverlay.Value; + gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue = str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); + + gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value=0; %,'HorizontalAlignment','left' + gui_plotorg_waveviewer.layout_custom_edit.Enable='off'; + + %%Using the default background color for "apply" and title bar + gui_plotorg_waveviewer.apply.BackgroundColor = [1 1 1]; + gui_plotorg_waveviewer.apply.ForegroundColor = [0 0 0]; + box_erpwave_viewer_plotorg.TitleColor= [0.5 0.5 0.9]; + + %%save the parameters for this panel to memory file + MERPWaveViewer_plotorg{1}=1; + MERPWaveViewer_plotorg{2}=gui_plotorg_waveviewer.layout_auto.Value; + plotBox(1) = gui_plotorg_waveviewer.rownum.Value; + plotBox(2) = gui_plotorg_waveviewer.columnnum.Value; + MERPWaveViewer_plotorg{3}=plotBox; + MERPWaveViewer_plotorg{4}= gui_plotorg_waveviewer.rowgap_auto.Value; + MERPWaveViewer_plotorg{5}=str2num(gui_plotorg_waveviewer.rowgapGTPcustom.String); + MERPWaveViewer_plotorg{6}=str2num(gui_plotorg_waveviewer.rowgapoverlayedit.String); + MERPWaveViewer_plotorg{7} = gui_plotorg_waveviewer.columngapgtpop.Value; + MERPWaveViewer_plotorg{8}=str2num(gui_plotorg_waveviewer.columngapgtpcustom.String); + MERPWaveViewer_plotorg{9}=str2num(gui_plotorg_waveviewer.columngapoverlapedit.String); + MERPWaveViewer_plotorg{10}=gui_plotorg_waveviewer.layout_custom_edit_checkbox.Value; + estudioworkingmemory('MERPWaveViewer_plotorg',MERPWaveViewer_plotorg);%%save parameters for this panel to memory file + %%execute next panel + viewer_ERPDAT.Reset_Waviewer_panel=5; end%%end of reset +%%----------------Press Return key to execute the function----------------- function plotorg_presskey(hObject, eventdata) keypress = eventdata.Key; if strcmp (keypress, 'return') || strcmp (keypress, 'enter') @@ -3433,4 +3296,15 @@ function plotorg_presskey(hObject, eventdata) return; end end + +%%----------change the title color and backgroundcolor for "cancel" and---- +%%--------------"Apply" if any of parameters was changed------------------- + function track_changes_title_color(~,~) + gui_plotorg_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_plotorg_waveviewer.apply.ForegroundColor = [1 1 1]; + box_erpwave_viewer_plotorg.TitleColor= [0.4940 0.1840 0.5560]; + gui_plotorg_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_plotorg_waveviewer.cancel.ForegroundColor = [1 1 1]; + end + end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_property_waveviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_property_waveviewer_GUI.m index 3dc6d2f2..e44deb8e 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_property_waveviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_property_waveviewer_GUI.m @@ -5,16 +5,13 @@ % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2022 +% 2022 && Nov 2023 function varargout = f_ERP_property_waveviewer_GUI(varargin) global gui_erp_waviewer; global viewer_ERPDAT; -% addlistener(viewer_ERPDAT,'v_currentERP_change',@Count_currentERPChanged); -% addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); - - +addlistener(viewer_ERPDAT,'Reset_Waviewer_panel_change',@Reset_Waviewer_panel_change); gui_property_waveviewer = struct(); %-----------------------------Name the title---------------------------------------------- @@ -31,7 +28,7 @@ box_erpwave_viewer_property = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Viewer Properties', 'Padding', 5,... 'FontSize', varargin{2},'BackgroundColor',ColorBviewer_def,'TitleColor',[0.5 0.5 0.9],'ForegroundColor','w'); end -gui_erp_waviewer.Window.WindowButtonMotionFcn = {@ViewerPos}; +% gui_erp_waviewer.Window.WindowButtonMotionFcn = {@Viewerpos_width}; %-----------------------------Draw the panel------------------------------------- try FonsizeDefault = varargin{2}; @@ -75,29 +72,34 @@ function drawui_plot_property(FonsizeDefault) 'callback',@viewer_TN,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % set(gui_property_waveviewer.viewer_TN_title, 'Sizes',[70 165]); - - gui_property_waveviewer.viewer_pos_title = uiextras.HBox('Parent', gui_property_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); - uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_pos_title,'String','Position:',... - 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); %1A New_pos = gui_erp_waviewer.screen_pos; - if isempty(New_pos) - New_pos = [0.01,0.01,75,75]; - erpworkingmemory('ERPWaveScreenPos',New_pos); + if isempty(New_pos) || numel(New_pos)~=2 + New_pos = [75,75]; + estudioworkingmemory('ERPWaveScreenPos',New_pos); end - New_pos1 = roundn(New_pos,-3); - New_poStr = char([num2str(New_pos1(1)),32,num2str(New_pos1(2)),32,num2str(New_pos1(3)),32,num2str(New_pos1(4))]); - - gui_property_waveviewer.parameters_pos = uicontrol('Style','edit','Parent',gui_property_waveviewer.viewer_pos_title,'String',New_poStr,... - 'callback',@Viewerpos,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % - set(gui_property_waveviewer.viewer_pos_title, 'Sizes',[70 165]); + New_pos = roundn(New_pos,-3); gui_property_waveviewer.viewer_pos_title1 = uiextras.HBox('Parent', gui_property_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); - uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_pos_title1,'String','',... + uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_pos_title1,'String','Window size:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'FontWeight','bold'); %1A + + gui_property_waveviewer.viewer_wz_title = uiextras.HBox('Parent', gui_property_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); + uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_wz_title,'String','Width:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); %1A + gui_property_waveviewer.parameters_pos_width = uicontrol('Style','edit','Parent',gui_property_waveviewer.viewer_wz_title,'String',num2str(New_pos(1)),... + 'callback',@Viewerpos_width,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % + uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_wz_title,'String','%,',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); %1A + uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_wz_title,'String','Height:',... 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); %1A - uicontrol('Style','text','Parent',gui_property_waveviewer.viewer_pos_title1,'String','(left bottom width height) in %',... - 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); % - set(gui_property_waveviewer.viewer_pos_title1, 'Sizes',[68 165]); + gui_property_waveviewer.parameters_pos_height = uicontrol('Style','edit','Parent',gui_property_waveviewer.viewer_wz_title,'String',num2str(New_pos(2)),... + 'callback',@Viewerpos_height,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % + uicontrol('Style','text','Parent', gui_property_waveviewer.viewer_wz_title,'String','%',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); %1A + + set(gui_property_waveviewer.viewer_wz_title, 'Sizes',[40 55 20 45 55 20]); + set(gui_property_waveviewer.DataSelBox ,'Sizes',[30 25 25 25]) end @@ -110,46 +112,58 @@ function drawui_plot_property(FonsizeDefault) %%-------------------------Setting for load-------------------------------- function parameters_load(~,~) - MessageViewer= char(strcat('Viewer Properties > Load')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; + try + ALLERP = evalin('base','ALLERP'); + catch + MessageViewer= char(strcat('Viewer Properties > Load: ALLERP is not available on workspace, you therfore cannot further handle')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + return; + end + if isempty(ALLERP) + MessageViewer= char(strcat('Viewer Properties > Load: ALLERP is empty on workspace, you therfore cannot further handle')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + return; + end [filename, filepath,indxs] = uigetfile({'*.mat'}, ... 'Load parametrs for "My viewer"', ... 'MultiSelect', 'off'); if isequal(filename,0) - disp('User selected Cancel'); return; end [pathstr, erpfilename, ext] = fileparts(filename) ; - if indxs==1 - ext = '.mat'; - elseif indxs==2 - ext = '.mat'; - else - ext = '.mat'; - end + ext = '.mat'; + erpFilename = char(strcat(erpfilename,ext)); try - ERPwaviewer = importdata([filepath,erpFilename]); - ERPwaviewerdef = evalin('base','ALLERPwaviewer'); - ERPwaviewer.ALLERP= ERPwaviewerdef.ALLERP; - ERPwaviewer.ERP = ERPwaviewerdef.ERP; - ERPwaviewer.CURRENTERP = ERPwaviewerdef.CURRENTERP; - ERPwaviewer.SelectERPIdx = ERPwaviewerdef.SelectERPIdx; - ERPwaviewer.PageIndex = ERPwaviewerdef.PageIndex; - assignin('base','ALLERPwaviewer',ERPwaviewer); + gui_erp_waviewer.ERPwaviewer = importdata([filepath,erpFilename]); + gui_erp_waviewer.ERPwaviewer.ALLERP= ALLERP; catch - beep; - MessageViewer=['\n\n My viewer > Viewer Propoerties > Load: Cannot load the saved parameters of My viewer ']; - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =3; + MessageViewer=['My viewer > Viewer Propoerties > Load: Cannot load the saved parameters of My viewer ']; + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; return; end + try + CURRENTERP = evalin('base','CURRENTERP'); + catch + CURRENTERP = []; + end + if isempty(CURRENTERP) || numel(CURRENTERP)~=1 || any(CURRENTERP>length(ALLERP)) + CURRENTERP = length(ALLERP); + end + gui_erp_waviewer.ERPwaviewer.ERP = ALLERP(CURRENTERP); + gui_erp_waviewer.ERPwaviewer.CURRENTERP = CURRENTERP; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = CURRENTERP; + gui_erp_waviewer.ERPwaviewer.PageIndex = 1; %%check current version ERPtooltype = erpgettoolversion('tooltype'); if strcmpi(ERPtooltype,'EStudio') @@ -179,7 +193,7 @@ function parameters_load(~,~) elseif strcmpi(ERPtooltype,'ERPLAB') MessageViewer= char(strcat('Viewer Properties > Load - This settings file was created using an older version of ERPLAB')); end - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; end @@ -187,25 +201,19 @@ function parameters_load(~,~) f_redrawERP_viewer_test(); MessageViewer= char(strcat('Viewer Properties > Load')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end %%-------------------------Setting for Save-------------------------------- function parameters_save(~,~) MessageViewer= char(strcat('Viewer Properties > Save')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n\n My viewer > Viewer Propoerties > Save: \n There is no "ALLERPwaviewer" on Workspace, Please run My Viewer again.\n\n'); - return; - end + ERPwaviewer = gui_erp_waviewer.ERPwaviewer; + pathstr = pwd; - namedef ='Viewer'; + namedef ='Advanced_ERPWave_Viewer'; erpFilename = char(strcat(namedef,'.mat')); ERPtooltype = erpgettoolversion('tooltype'); @@ -226,7 +234,6 @@ function parameters_save(~,~) end ERPwaviewer.version = erplabstudiover; - ERPwaviewer.ALLERP = []; ERPwaviewer.ERP = []; ERPwaviewer.CURRENTERP = []; @@ -235,24 +242,23 @@ function parameters_save(~,~) try save([pathstr,filesep,erpFilename],'ERPwaviewer','-v7.3'); catch - beep; - MessageViewer= char(strcat('Viewer Propoerties > Save: \n Cannot save the parameters of My viewer')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =3; + MessageViewer= char(strcat('Viewer Propoerties > Save: Cannot save the parameters of My viewer')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; return; end MessageViewer= char(strcat('Viewer Properties > Save')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end %%-------------------------Setting for Save as-------------------------------- function parameters_saveas(~,~) MessageViewer= char(strcat('Viewer Properties > Save as')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; pathstr = pwd; - namedef ='Viewer'; + namedef ='Advanced_ERPWave_Viewer'; [erpfilename, erppathname, indxs] = uiputfile({'*.mat'}, ... ['Save "','Information of My Viewer', '" as'],... fullfile(pathstr,namedef)); @@ -264,24 +270,11 @@ function parameters_saveas(~,~) return end - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n\n My viewer > Viewer Propoerties > Save as: \n There is no "ALLERPwaviewer" on Workspace, Please run My Viewer again.\n\n'); - return; - end + ERPwaviewer = gui_erp_waviewer.ERPwaviewer; - % [pathx, filename, ext] = fileparts(erpfilename); [pathstr, erpfilename, ext] = fileparts(erpfilename) ; - if indxs==1 - ext = '.mat'; - elseif indxs==2 - ext = '.mat'; - else - ext = '.mat'; - end + ext = '.mat'; + erpFilename = char(strcat(erpfilename,ext)); ERPtooltype = erpgettoolversion('tooltype'); @@ -309,13 +302,13 @@ function parameters_saveas(~,~) try save([erppathname,erpFilename],'ERPwaviewer','-v7.3'); catch - beep; - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n\n My viewer > Viewer Propoerties > Save as: \n Cannot save the parameters of My viewer.\n\n'); + MessageViewer= char(strcat('Viewer Propoerties > Save: Cannot save the parameters of My viewer')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; return; end MessageViewer= char(strcat('Viewer Properties > Save as')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -323,159 +316,199 @@ function parameters_saveas(~,~) %%------------------Title name for Wave Viewer----------------------------- function viewer_TN(source_locationname,~) MessageViewer= char(strcat('Viewer Properties > Title')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; ViewerName = source_locationname.String; if isempty(ViewerName) ViewerName = 'My Viewer'; + source_locationname.String = ViewerName; end - try - [version1 reldate] = geterplabstudioversion; - erplabstudiover = version1; - catch + + erplabstudiover = geterplabeversion; + if isempty(erplabstudiover) erplabstudiover = '??'; end + currvers = ['ERPLAB Studio ' erplabstudiover,'-',32,ViewerName]; estudioworkingmemory('viewername',ViewerName); - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n\n My Viewer > Viewer Propoerties > Title: \n There is no "ALLERPwaviewer" on Workspace, Please run My Viewer again.\n\n'); - return; - end - ERPwaviewer.figname = ViewerName; - assignin('base','ALLERPwaviewer',ERPwaviewer); + + gui_erp_waviewer.ERPwaviewer.figname = ViewerName; gui_erp_waviewer.Window.Name = currvers; viewer_ERPDAT.Process_messg =2; end - - function Viewerpos(Str,~) - New_pos = str2num(Str.String); - MessageViewer= char(strcat('Viewer Properties > Position')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =1; +%%-----------------------width for window size----------------------------- + function Viewerpos_width(Str,~) + New_pos1_width = str2num(Str.String); try - ScreenPos = get( groot, 'Screensize' ); + New_posin = estudioworkingmemory('ERPWaviewerScreenPos'); catch - ScreenPos = get( 0, 'Screensize' ); + New_posin = [75,75]; end - if isempty(New_pos) || numel(New_pos)~=4 - MessageViewer= char(strcat('Viewer Properties > Position- 4 numbers are needed for Viewer position (e.g., [1 1 1200 700])')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - % fprintf(2,['\n Warning: ',MessageViewer,'.\n']); - viewer_ERPDAT.Process_messg =4; - new_pos = gui_erp_waviewer.Window.Position; - new_pos =[ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100,ScreenPos(3)*new_pos(3)/100,ScreenPos(4)*new_pos(4)/100]; - gui_property_waveviewer.parameters_pos.String = num2str(new_pos); - return; + if isempty(New_posin) ||numel(New_posin)~=2 + New_posin = [75,75]; end - xyValue = New_pos(1:2); - WHpos = New_pos(3:4); - if min(xyValue(:))<-100 || max(xyValue(:)) >100 - MessageViewer= char(strcat('Viewer Properties > X and Y values should be between [-100 100]')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + if isempty(New_pos1_width) || numel(New_pos1_width)~=1 || any(New_pos1_width<=0) + Str.String = num2str(New_posin(1)); + MessageViewer= char(strcat('Viewer Properties > Window size > width: The width value is invalid and it must be a positive value')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; - new_pos = gui_erp_waviewer.Window.Position; - new_pos =[ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100,ScreenPos(3)*new_pos(3)/100,ScreenPos(4)*new_pos(4)/100]; - gui_property_waveviewer.parameters_pos.String = num2str(new_pos); - return; - end - if min(WHpos(:))<0 || max(WHpos(:))>100 - MessageViewer= char(strcat('Viewer Properties > width and height values should be between [0 100]')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =4; - new_pos = gui_erp_waviewer.Window.Position; - new_pos =[ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100,ScreenPos(3)*new_pos(3)/100,ScreenPos(4)*new_pos(4)/100]; - gui_property_waveviewer.parameters_pos.String = num2str(new_pos); return; end + New_pos1(1) = New_pos1_width; + New_pos1_h = str2num(gui_property_waveviewer.parameters_pos_height.String); - if New_pos(1)>90 || New_pos(1)< -90 - MessageViewer= char(strcat('Viewer Properties > Position: Left is better within [-90 90], otherwise, the main GUI will disappear.')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + if isempty(New_pos1_h) || numel(New_pos1_h)~=1 || any(New_pos1_h<=0) + gui_property_waveviewer.parameters_pos_height.String = num2str(New_posin(2)); + MessageViewer= char(strcat('Viewer Properties > Window size > width: The height value is invalid and it must be a positive value')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =4; - new_pos = gui_erp_waviewer.Window.Position; - new_pos =[ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100,ScreenPos(3)*new_pos(3)/100,ScreenPos(4)*new_pos(4)/100]; - gui_property_waveviewer.parameters_pos.String = num2str(new_pos); return; end + New_pos1(2) = New_pos1_h; - if New_pos(2)< -90 - MessageViewer= char(strcat('Viewer Properties > Position: Bottom should be larger than -90, otherwise, the main GUI will disappear.')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =4; - new_pos = gui_erp_waviewer.Window.Position; - new_pos =[ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100,ScreenPos(3)*new_pos(3)/100,ScreenPos(4)*new_pos(4)/100]; - gui_property_waveviewer.parameters_pos.String = num2str(new_pos); - return; + MessageViewer= char(strcat('Viewer Properties > Window size > width')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =1; + try + ScreenPos = get( groot, 'Screensize' ); + catch + ScreenPos = get( 0, 'Screensize' ); end - erpworkingmemory('ERPWaveScreenPos',New_pos); - gui_erp_waviewer.screen_pos = New_pos; - New_pos1 = roundn(New_pos,-3); - New_poStr = char([num2str(New_pos1(1)),32,num2str(New_pos1(2)),32,num2str(New_pos1(3)),32,num2str(New_pos1(4))]); - gui_property_waveviewer.parameters_pos.String = New_poStr; + New_posin(2) = abs(New_posin(2)); + + New_pos = gui_erp_waviewer.Window.Position; + estudioworkingmemory('ERPWaviewerScreenPos',New_pos1); + + try + POS4 = (New_pos1(2)-New_posin(2))/100; + new_pos =[New_pos(1),New_pos(2)-ScreenPos(4)*POS4,ScreenPos(3)*New_pos1(1)/100,ScreenPos(4)*New_pos1(2)/100]; + if new_pos(2)+new_pos(4) Window size > height: The height value is invalid and it must be a positive value')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + return; + end + New_pos1(2) = New_pos1_h; + New_pos1_width = str2num(gui_property_waveviewer.parameters_pos_width.String); + if isempty(New_pos1_width) || numel(New_pos1_width)~=1 || any(New_pos1_width<=0) + gui_property_waveviewer.parameters_pos_width.String = num2str(New_posin(1)); + MessageViewer= char(strcat('Viewer Properties > Window size > height: The width value is invalid and it must be a positive value')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + return; + end + New_pos1(1) = New_pos1_width; + + MessageViewer= char(strcat('Viewer Properties > Window size > height')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =1; try - ScreenPos = get( groot, 'Screensize' ); + ScreenPos = gui_erp_waviewer.monitor_size; catch ScreenPos = get( 0, 'Screensize' ); end + + New_posin(2) = abs(New_posin(2)); + + New_pos = gui_erp_waviewer.Window.Position; + + estudioworkingmemory('ERPWaviewerScreenPos',New_pos1); + try - New_pos = gui_erp_waviewer.Window.Position; + POS4 = (New_pos1(2)-New_posin(2))/100; + new_pos =[New_pos(1),New_pos(2)-ScreenPos(4)*POS4,ScreenPos(3)*New_pos1(1)/100,ScreenPos(4)*New_pos1(2)/100]; + if new_pos(2)+new_pos(4)90 || New_pos1(1)< -90 || New_pos(2)< -90 || min(New_pos1(3:4))<-100 || max(New_pos1(3:4)) >100 %% from different size of monitor - New_pos = [0.01,0.01,75,75]; - new_pos =[ScreenPos(3)*New_pos(1)/100,ScreenPos(4)*New_pos(2)/100,ScreenPos(3)*New_pos(3)/100,ScreenPos(4)*New_pos(4)/100]; - set(gui_erp_waviewer.Window, 'Position', new_pos); - - zoomSpace = 100*((gui_erp_waviewer.ViewAxes.Widths+240)-gui_erp_waviewer.Window.Position(3))/gui_erp_waviewer.Window.Position(3); - if isempty(zoomSpace) || zoomSpace<0 - zoomSpace = 0; - end - if zoomSpace ==0 - gui_erp_waviewer.ScrollVerticalOffsets=0; - gui_erp_waviewer.ScrollHorizontalOffsets=0; - end - estudioworkingmemory('zoomSpace',zoomSpace); - gui_erp_waviewer.zoom_edit.String = num2str(roundn(zoomSpace,-1)); - + ScreenPos = get( 0, 'Screensize' ); end - New_pos = roundn(New_pos,-3); - New_poStr = char([num2str(New_pos(1)),32,num2str(New_pos(2)),32,num2str(New_pos(3)),32,num2str(New_pos(4))]); + set(gui_erp_waviewer.Window, 'Position', [0 0 0.75*ScreenPos(3) 0.75*ScreenPos(4)]); + estudioworkingmemory('ERPWaviewerScreenPos',[75 75]); + gui_property_waveviewer.parameters_pos.String = num2str([75 75]); - gui_property_waveviewer.parameters_pos.String = New_poStr; - % erpworkingmemory('ERPWaveScreenPos',New_pos); - gui_erp_waviewer.screen_pos = New_pos; + %%name + ViewerName = 'My Viewer'; + try + erplab_default_values; + erplabstudiover = erplabver; + catch + erplabstudiover = '??'; + end + currvers = ['ERPLAB Studio ' erplabstudiover,'-',32,ViewerName]; + estudioworkingmemory('viewername',ViewerName); + gui_erp_waviewer.ERPwaviewer.figname = ViewerName; + gui_erp_waviewer.Window.Name = currvers; end -end \ No newline at end of file + +end + +%%---------------------ERPLAB VERSION-------------------------------------- +function erplabver1 = geterplabeversion +erplab_default_values; +erplabver1 = erplabver; +end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_timeampscal_waveviewer_GUI.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_timeampscal_waveviewer_GUI.m index 96299bff..bd09bc23 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_timeampscal_waveviewer_GUI.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ERP_timeampscal_waveviewer_GUI.m @@ -10,9 +10,8 @@ function varargout = f_ERP_timeampscal_waveviewer_GUI(varargin) global viewer_ERPDAT - +global gui_erp_waviewer; addlistener(viewer_ERPDAT,'v_currentERP_change',@v_currentERP_change); -addlistener(viewer_ERPDAT,'page_xyaxis_change',@page_xyaxis_change); addlistener(viewer_ERPDAT,'loadproper_change',@loadproper_change); addlistener(viewer_ERPDAT,'count_twopanels_change',@count_twopanels_change); addlistener(viewer_ERPDAT,'Reset_Waviewer_panel_change',@Reset_Waviewer_panel_change); @@ -52,13 +51,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; MERPWaveViewer_xaxis= estudioworkingmemory('MERPWaveViewer_xaxis');%%call the memery for this panel MERPWaveViewer_yaxis= estudioworkingmemory('MERPWaveViewer_yaxis'); - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + %%Set for x units: 1 is in Second; 0 is in millisecond try @@ -71,10 +64,9 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) xdispysecondValue = 1; MERPWaveViewer_xaxis{1} = xdispysecondValue; end - %%x scale try - timerangeAutodef = ERPwaviewer.xaxis.trangeauto; + timerangeAutodef = gui_erp_waviewer.ERPwaviewer.xaxis.trangeauto; catch timerangeAutodef =1; end @@ -95,9 +87,9 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) %%%%%%%%%%%%%%%%%Setting for X axis%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% try - ERPIN = ERPwaviewer.ERP; - timeArraydef(1) = ERPwaviewer.ERP.times(1); - timeArraydef(2) = ERPwaviewer.ERP.times(end); + ERPIN = gui_erp_waviewer.ERPwaviewer.ERP; + timeArraydef(1) = gui_erp_waviewer.ERPwaviewer.ERP.times(1); + timeArraydef(2) = gui_erp_waviewer.ERPwaviewer.ERP.times(end); [timeticksdef stepX]= default_time_ticks_studio(ERPIN, [timeArraydef(1),timeArraydef(2)]); if ~isempty(stepX) && numel(stepX) ==1 stepX = floor(stepX/2); @@ -112,7 +104,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) timeArray = timeArraydef; MERPWaveViewer_xaxis{3} = timeArray; end - if numel(timeArray)~=2 || isempty(timeArray) + if isempty(timeArray)|| numel(timeArray)~=2 || timeArray(1)>=timeArraydef(2) || timeArray(2)<=timeArraydef(1) timeArray = timeArraydef; MERPWaveViewer_xaxis{3} = timeArray; end @@ -120,6 +112,13 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) timeArray = timeArraydef; MERPWaveViewer_xaxis{3} = timeArray; end + try + [timeticks, ~]= default_time_ticks_studio(ERPIN, [timeArray(1),timeArray(2)]); + timeticksdef = timeticks; + catch + + end + if xdispysecondValue==0 timeArray = timeArray/1000; end @@ -135,19 +134,17 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) gui_erpxyaxeset_waveviewer.xmillisecond = uicontrol('Style','radiobutton','Parent', gui_erpxyaxeset_waveviewer.display_title,... 'callback',@xmilsecond,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'String','Millisecond','Value',xdispysecondValue); % gui_erpxyaxeset_waveviewer.xmillisecond.KeyPressFcn = @xyaxis_presskey; - ERPwaviewer.xaxis.tdis = gui_erpxyaxeset_waveviewer.xmillisecond.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tdis = gui_erpxyaxeset_waveviewer.xmillisecond.Value; gui_erpxyaxeset_waveviewer.xsecond = uicontrol('Style','radiobutton','Parent', gui_erpxyaxeset_waveviewer.display_title,... 'callback',@xsecond,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'String','Second','Value',~xdispysecondValue); % gui_erpxyaxeset_waveviewer.xsecond.KeyPressFcn = @xyaxis_presskey; set(gui_erpxyaxeset_waveviewer.display_title,'Sizes',[75 90 75]); if timerangeAutodef==1 - % ERPwaviewer.xaxis.tdis = 1; - erpworkingmemory('MyViewer_xaxis_second',0); - erpworkingmemory('MyViewer_xaxis_msecond',1); + estudioworkingmemory('MyViewer_xaxis_second',0); + estudioworkingmemory('MyViewer_xaxis_msecond',1); else - % ERPwaviewer.xaxis.tdis = 0; - erpworkingmemory('MyViewer_xaxis_second',1); - erpworkingmemory('MyViewer_xaxis_msecond',0); + estudioworkingmemory('MyViewer_xaxis_second',1); + estudioworkingmemory('MyViewer_xaxis_msecond',0); end %%------time range------ gui_erpxyaxeset_waveviewer.xtimerange_title = uiextras.HBox('Parent', gui_erpxyaxeset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -169,13 +166,14 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) gui_erpxyaxeset_waveviewer.timerange_edit.Enable = enableName; set(gui_erpxyaxeset_waveviewer.xtimerange_title,'Sizes',[80 100 60]); if xdispysecondValue==1 - ERPwaviewer.xaxis.timerange = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); + gui_erp_waviewer.ERPwaviewer.xaxis.timerange = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); else - ERPwaviewer.xaxis.timerange = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String))*1000; + gui_erp_waviewer.ERPwaviewer.xaxis.timerange = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String))*1000; end - ERPwaviewer.xaxis.trangeauto = gui_erpxyaxeset_waveviewer.xtimerangeauto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.trangeauto = gui_erpxyaxeset_waveviewer.xtimerangeauto.Value; %%----------------------time ticks--------------------------------- + stepX = []; try timeticksAuto= MERPWaveViewer_xaxis{4}; @@ -216,13 +214,13 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) if xdispysecondValue==1 xprecisoonName = {'0','1','2','3','4','5','6'}; - if xtick_precision<0 || xtick_precision>6 + if isempty(xtick_precision) || xtick_precision<0 || xtick_precision>6 MERPWaveViewer_xaxis{6} = 0; xtick_precision =0; end else xprecisoonName = {'1','2','3','4','5','6'}; - if xtick_precision<1 || xtick_precision>6 + if isempty(xtick_precision) || xtick_precision<1 || xtick_precision>6 MERPWaveViewer_xaxis{6} = 1; xtick_precision =1; MERPWaveViewer_xaxis{6} = xtick_precision; @@ -246,11 +244,11 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) gui_erpxyaxeset_waveviewer.timeticks_edit.Enable = enableName_tick; set(gui_erpxyaxeset_waveviewer.xtimetick_title,'Sizes',[80 100 60]); if xdispysecondValue==1 - ERPwaviewer.xaxis.timeticks = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); + gui_erp_waviewer.ERPwaviewer.xaxis.timeticks = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); else - ERPwaviewer.xaxis.timeticks = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String))*1000; + gui_erp_waviewer.ERPwaviewer.xaxis.timeticks = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String))*1000; end - ERPwaviewer.xaxis.ticksauto = gui_erpxyaxeset_waveviewer.xtimetickauto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.ticksauto = gui_erpxyaxeset_waveviewer.xtimetickauto.Value; %%--------x tick precision with decimals--------------------------- gui_erpxyaxeset_waveviewer.xtickprecision_title = uiextras.HBox('Parent', gui_erpxyaxeset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -267,9 +265,9 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); % set(gui_erpxyaxeset_waveviewer.xtickprecision_title,'Sizes',[30 65 60 80]); if xdispysecondValue==1 - ERPwaviewer.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; + gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; else - ERPwaviewer.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value; end %%-----time minor ticks-------------------------------------------- @@ -362,14 +360,14 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) 'callback',@timeminortickscustom_auto,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'String','Auto','Value',timeminorstep, 'Enable',xminorEnable_auto); % gui_erpxyaxeset_waveviewer.timeminorticks_auto.KeyPressFcn = @xyaxis_presskey; set(gui_erpxyaxeset_waveviewer.xtimeminnortick_title,'Sizes',[90 90 50]); - ERPwaviewer.xaxis.tminor.disp = gui_erpxyaxeset_waveviewer.xtimeminorauto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.disp = gui_erpxyaxeset_waveviewer.xtimeminorauto.Value; if xdispysecondValue==1 - ERPwaviewer.xaxis.tminor.step = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); else - ERPwaviewer.xaxis.tminor.step = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String))*1000; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String))*1000; end - ERPwaviewer.xaxis.tminor.auto = gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.auto = gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value; %%-----time ticks label-------------------------------------------- try @@ -398,8 +396,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) else fontenable = 'off'; end - ERPwaviewer.xaxis.label = gui_erpxyaxeset_waveviewer.xtimelabel_on.Value; - + gui_erp_waviewer.ERPwaviewer.xaxis.label = gui_erpxyaxeset_waveviewer.xtimelabel_on.Value; %%-----font, font size, and text color for time ticks-------------- try @@ -448,8 +445,8 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) 'callback',@xtimefontsize,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',fontenable,'Value',ttickLabelfontsizeV); % gui_erpxyaxeset_waveviewer.font_custom_size.KeyPressFcn = @xyaxis_presskey; set(gui_erpxyaxeset_waveviewer.xtimefont_title,'Sizes',[30 100 30 80]); - ERPwaviewer.xaxis.font = gui_erpxyaxeset_waveviewer.xtimefont_custom.Value; - ERPwaviewer.xaxis.fontsize = xfontsizeinum(gui_erpxyaxeset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.xaxis.font = gui_erpxyaxeset_waveviewer.xtimefont_custom.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.fontsize = xfontsizeinum(gui_erpxyaxeset_waveviewer.font_custom_size.Value); %%%---------------------color for x label text-------------- gui_erpxyaxeset_waveviewer.xtimelabelcolor_title = uiextras.HBox('Parent', gui_erpxyaxeset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -462,7 +459,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.xtimelabelcolor_title); uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.xtimelabelcolor_title); set(gui_erpxyaxeset_waveviewer.xtimelabelcolor_title,'Sizes',[40 100 30 70]); - ERPwaviewer.xaxis.fontcolor = gui_erpxyaxeset_waveviewer.xtimetextcolor.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.fontcolor = gui_erpxyaxeset_waveviewer.xtimetextcolor.Value; %%%----Setting for the xunits display-------------------------- try @@ -486,35 +483,32 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) gui_erpxyaxeset_waveviewer.xtimeunits_off.KeyPressFcn = @xyaxis_presskey; uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.xtimeunits_title); set(gui_erpxyaxeset_waveviewer.xtimeunits_title,'Sizes',[50 50 50 80]); - ERPwaviewer.xaxis.units = gui_erpxyaxeset_waveviewer.xtimeunits_on.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.units = gui_erpxyaxeset_waveviewer.xtimeunits_on.Value; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%Setting for Y axis%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%-----------Y scale--------- - ALLERPIN = ERPwaviewer.ALLERP; - ERPArrayin = ERPwaviewer.SelectERPIdx; - BinArrayIN = []; - ChanArrayIn = []; - plotOrg = [1 2 3]; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPArrayin = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; try - plotOrg(1) = ERPwaviewer.plot_org.Grid; - plotOrg(2) = ERPwaviewer.plot_org.Overlay; - plotOrg(3) = ERPwaviewer.plot_org.Pages; + plotOrg(1) = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; + plotOrg(2) = gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + plotOrg(3) = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch plotOrg = [1 2 3]; end try - ChanArrayIn = ERPwaviewer.chan; + ChanArrayIn = gui_erp_waviewer.ERPwaviewer.chan; catch ChanArrayIn = []; end try - BinArrayIN = ERPwaviewer.bin; + BinArrayIN = gui_erp_waviewer.ERPwaviewer.bin; catch BinArrayIN = []; end - CURRENTERPIN = ERPwaviewer.CURRENTERP; + CURRENTERPIN = gui_erp_waviewer.ERPwaviewer.CURRENTERP; yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); [x,yscales_v] = find(ERPArrayin ==CURRENTERPIN); yRangeLabel = ''; @@ -568,8 +562,8 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) end gui_erpxyaxeset_waveviewer.yrange_edit.Enable = yenableName; set(gui_erpxyaxeset_waveviewer.yrange_title ,'Sizes',[60 120 60]); - ERPwaviewer.yaxis.scales = str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); - ERPwaviewer.yaxis.scalesauto = gui_erpxyaxeset_waveviewer.yrangeauto.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.scales = str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); + gui_erp_waviewer.ERPwaviewer.yaxis.scalesauto = gui_erpxyaxeset_waveviewer.yrangeauto.Value; %%--------Y ticks-------------------------------------------------- try %%Auto for y ticks @@ -642,8 +636,8 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) end gui_erpxyaxeset_waveviewer.yticks_edit.Enable = yenableName_tick; set(gui_erpxyaxeset_waveviewer.ytick_title,'Sizes',[60 120 60]); - ERPwaviewer.yaxis.ticks = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); - ERPwaviewer.yaxis.tickauto = gui_erpxyaxeset_waveviewer.ytickauto.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.ticks = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); + gui_erp_waviewer.ERPwaviewer.yaxis.tickauto = gui_erpxyaxeset_waveviewer.ytickauto.Value; %%--------Y tick precision with decimals--------------------------- gui_erpxyaxeset_waveviewer.ytickprecision_title = uiextras.HBox('Parent', gui_erpxyaxeset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -657,7 +651,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) uicontrol('Style','text','Parent', gui_erpxyaxeset_waveviewer.ytickprecision_title,'String','# decimals',... 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); % set(gui_erpxyaxeset_waveviewer.ytickprecision_title,'Sizes',[30 65 60 80]); - ERPwaviewer.yaxis.tickdecimals = gui_erpxyaxeset_waveviewer.yticks_precision.Value-1; + gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals = gui_erpxyaxeset_waveviewer.yticks_precision.Value-1; %%-----y minor ticks----------------------------------------------- try @@ -741,9 +735,9 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) gui_erpxyaxeset_waveviewer.yminorstep_auto = uicontrol('Style','checkbox','Parent', gui_erpxyaxeset_waveviewer.yminnortick_title,... 'callback',@yminorstepauto,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'String','Auto','Value',yminorautoValue,'Enable',yminorautoLabel); % gui_erpxyaxeset_waveviewer.yminorstep_auto.KeyPressFcn = @xyaxis_presskey; - ERPwaviewer.yaxis.yminor.disp = gui_erpxyaxeset_waveviewer.yminortick.Value; - ERPwaviewer.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); - ERPwaviewer.yaxis.yminor.auto = gui_erpxyaxeset_waveviewer.yminorstep_auto.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.disp = gui_erpxyaxeset_waveviewer.yminortick.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.auto = gui_erpxyaxeset_waveviewer.yminorstep_auto.Value; set(gui_erpxyaxeset_waveviewer.yminnortick_title,'Sizes',[90 90 50]); %%-----y ticks label----------------------------------------------- @@ -773,7 +767,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) end uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.ylabel_title); set(gui_erpxyaxeset_waveviewer.ylabel_title,'Sizes',[50 50 50 80]); - ERPwaviewer.yaxis.label = gui_erpxyaxeset_waveviewer.ylabel_on.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.label = gui_erpxyaxeset_waveviewer.ylabel_on.Value; %%-----y ticklabel:font, font size, and text color for time ticks try @@ -822,8 +816,8 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) 'callback',@yaxisfontsize,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',yfontenable,'Value',ytickLabelfontsize); % gui_erpxyaxeset_waveviewer.yfont_custom_size.KeyPressFcn = @xyaxis_presskey; set(gui_erpxyaxeset_waveviewer.yfont_title,'Sizes',[30 100 30 80]); - ERPwaviewer.yaxis.font = gui_erpxyaxeset_waveviewer.yfont_custom.Value; - ERPwaviewer.yaxis.fontsize = xfontsizeinum(gui_erpxyaxeset_waveviewer.yfont_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.yaxis.font = gui_erpxyaxeset_waveviewer.yfont_custom.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.fontsize = xfontsizeinum(gui_erpxyaxeset_waveviewer.yfont_custom_size.Value); %%% color for y ticklabel text gui_erpxyaxeset_waveviewer.ylabelcolor_title = uiextras.HBox('Parent', gui_erpxyaxeset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); @@ -836,7 +830,7 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.ylabelcolor_title); uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.ylabelcolor_title); set(gui_erpxyaxeset_waveviewer.ylabelcolor_title,'Sizes',[40 100 30 70]); - ERPwaviewer.yaxis.fontcolor = gui_erpxyaxeset_waveviewer.ytextcolor.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.fontcolor = gui_erpxyaxeset_waveviewer.ytextcolor.Value; %%%-----------Setting for the units display of y axis--------------- try @@ -860,12 +854,12 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) gui_erpxyaxeset_waveviewer.yunits_off.KeyPressFcn = @xyaxis_presskey; uiextras.Empty('Parent', gui_erpxyaxeset_waveviewer.yunits_title); set(gui_erpxyaxeset_waveviewer.yunits_title,'Sizes',[50 50 50 80]); - ERPwaviewer.yaxis.units = gui_erpxyaxeset_waveviewer.yunits_on.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.units = gui_erpxyaxeset_waveviewer.yunits_on.Value; %%Apply and save the changed parameters gui_erpxyaxeset_waveviewer.help_run_title = uiextras.HBox('Parent', gui_erpxyaxeset_waveviewer.DataSelBox,'BackgroundColor',ColorBviewer_def); uiextras.Empty('Parent',gui_erpxyaxeset_waveviewer.help_run_title); - uicontrol('Style','pushbutton','Parent', gui_erpxyaxeset_waveviewer.help_run_title ,'String','Cancel',... + gui_erpxyaxeset_waveviewer.cancel = uicontrol('Style','pushbutton','Parent', gui_erpxyaxeset_waveviewer.help_run_title ,'String','Cancel',... 'callback',@xyaxis_help,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'FontWeight','bold','HorizontalAlignment','left' uiextras.Empty('Parent',gui_erpxyaxeset_waveviewer.help_run_title ); gui_erpxyaxeset_waveviewer.apply = uicontrol('Style','pushbutton','Parent',gui_erpxyaxeset_waveviewer.help_run_title ,'String','Apply',... @@ -874,9 +868,10 @@ function drawui_plot_xyaxis_viewer(FonsizeDefault) set(gui_erpxyaxeset_waveviewer.help_run_title,'Sizes',[40 70 20 70 30]); %%save the parameters - assignin('base','ALLERPwaviewer',ERPwaviewer); estudioworkingmemory('MERPWaveViewer_xaxis',MERPWaveViewer_xaxis);%% save parameters for x axis to memory file estudioworkingmemory('MERPWaveViewer_yaxis',MERPWaveViewer_yaxis);%% save parameters for y axis to memory file + + estudioworkingmemory('MyViewer_xyaxis',0); end %%*********************************************************************************************************************************%% @@ -894,8 +889,8 @@ function xmilsecond(Source,~) if ~isempty(messgStr) && viewerpanelIndex~=3 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - xSecondflag = erpworkingmemory('MyViewer_xaxis_second'); - xmSecondflag = erpworkingmemory('MyViewer_xaxis_msecond'); + xSecondflag = estudioworkingmemory('MyViewer_xaxis_second'); + xmSecondflag = estudioworkingmemory('MyViewer_xaxis_msecond'); xtick_precision = gui_erpxyaxeset_waveviewer.xticks_precision.Value; if xSecondflag==0 && xmSecondflag==1 @@ -911,26 +906,25 @@ function xmilsecond(Source,~) gui_erpxyaxeset_waveviewer.xticks_precision.Value =xtick_precision+1; estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + + track_changes_title_color(); gui_erpxyaxeset_waveviewer.xmillisecond.Value =1; %display with millisecond gui_erpxyaxeset_waveviewer.xsecond.Value =0;%display with second - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); + if xSecondflag==1 && xmSecondflag==0 %%transform the data with millisecond into second. timeArray = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray*1000); else try - if ERPwaviewerIN.plot_org.Pages==3 - ERPArray = ERPwaviewerIN.SelectERPIdx; - ERPselectedIndex = ERPwaviewerIN.PageIndex; + if gui_erp_waviewer.ERPwaviewer.plot_org.Pages==3 + ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ERPselectedIndex = gui_erp_waviewer.ERPwaviewer.PageIndex; if ERPselectedIndex> length(ERPArray) ERPselectedIndex= length(ERPArray); end - ALLERPin = ERPwaviewerIN.ALLERP; + ALLERPin = gui_erp_waviewer.ERPwaviewer.ALLERP; try TimesCurrent = ALLERPin(ERPArray(ERPselectedIndex)).times; catch @@ -960,7 +954,7 @@ function xmilsecond(Source,~) gui_erpxyaxeset_waveviewer.timeticks_edit.String = timeticks; else if ~isempty(timeArray) && numel(timeArray)==2 %%&& gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 - [timeticks stepX]= default_time_ticks_studio(ERPwaviewerIN.ERP, timeArray); + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray); if xtick_precision<0 xtick_precision=0; gui_erpxyaxeset_waveviewer.xticks_precision.Value=1; @@ -1013,8 +1007,8 @@ function xmilsecond(Source,~) end end - erpworkingmemory('MyViewer_xaxis_second',0); - erpworkingmemory('MyViewer_xaxis_msecond',1); + estudioworkingmemory('MyViewer_xaxis_second',0); + estudioworkingmemory('MyViewer_xaxis_msecond',1); end end @@ -1025,8 +1019,8 @@ function xsecond(Source,~) if ~isempty(messgStr) && viewerpanelIndex~=3 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - xSecondflag = erpworkingmemory('MyViewer_xaxis_second'); - xmSecondflag = erpworkingmemory('MyViewer_xaxis_msecond'); + xSecondflag = estudioworkingmemory('MyViewer_xaxis_second'); + xmSecondflag = estudioworkingmemory('MyViewer_xaxis_msecond'); xtick_precision = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; if xSecondflag==1 && xmSecondflag==0 gui_erpxyaxeset_waveviewer.xmillisecond.Value =0; %display with millisecond @@ -1040,27 +1034,23 @@ function xsecond(Source,~) end gui_erpxyaxeset_waveviewer.xticks_precision.Value=xtick_precision; estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.xmillisecond.Value =0; %display with millisecond gui_erpxyaxeset_waveviewer.xsecond.Value =1;%display with second - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); + if xSecondflag==0 && xmSecondflag==1 %%transform the data with millisecond into second. timeArray = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray/1000); else try - - if ERPwaviewerIN.plot_org.Pages==3 - ERPArray = ERPwaviewerIN.SelectERPIdx; - ERPselectedIndex = ERPwaviewerIN.PageIndex; + if gui_erp_waviewer.ERPwaviewer.plot_org.Pages==3 + ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ERPselectedIndex = gui_erp_waviewer.ERPwaviewer.PageIndex; if ERPselectedIndex> length(ERPArray) ERPselectedIndex= length(ERPArray); end - ALLERPin = ERPwaviewerIN.ALLERP; + ALLERPin = gui_erp_waviewer.ERPwaviewer.ALLERP; try TimesCurrent = ALLERPin(ERPArray(ERPselectedIndex)).times; catch @@ -1087,7 +1077,7 @@ function xsecond(Source,~) gui_erpxyaxeset_waveviewer.timeticks_edit.String = timeticks;%in second else if ~isempty(timeArray) && numel(timeArray)==2 %&& gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 - [timeticks stepX]= default_time_ticks_studio(ERPwaviewerIN.ERP, timeArray*1000);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray*1000);%% in millisecond timeticks = num2str(str2num(char(timeticks))/1000);%% in second timeticks= f_decimal(timeticks,xtick_precision); @@ -1140,8 +1130,8 @@ function xsecond(Source,~) end end - erpworkingmemory('MyViewer_xaxis_second',1); - erpworkingmemory('MyViewer_xaxis_msecond',0); + estudioworkingmemory('MyViewer_xaxis_second',1); + estudioworkingmemory('MyViewer_xaxis_msecond',0); end end @@ -1153,31 +1143,21 @@ function xtimerangeauto(strx_auto,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = strx_auto.Value; xdisSecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value; if Value==1 - try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer = ALLERPwaviewer; - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + gui_erpxyaxeset_waveviewer.timerange_edit.Enable = 'off'; try - if ALLERPwaviewer.plot_org.Pages==3 - ERPArray = ALLERPwaviewer.SelectERPIdx; - ERPselectedIndex = ALLERPwaviewer.PageIndex; + if gui_erp_waviewer.ERPwaviewer.plot_org.Pages==3 + ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ERPselectedIndex = gui_erp_waviewer.ERPwaviewer.PageIndex; if ERPselectedIndex> length(ERPArray) ERPselectedIndex= length(ERPArray); end - ALLERPin = ALLERPwaviewer.ALLERP; + ALLERPin = gui_erp_waviewer.ERPwaviewer.ALLERP; try TimesCurrent = ALLERPin(ERPArray(ERPselectedIndex)).times; catch @@ -1186,8 +1166,8 @@ function xtimerangeauto(strx_auto,~) timeArray(1) = TimesCurrent(1); timeArray(2) = TimesCurrent(end); else - timeArray(1) = ERPwaviewer.ERP.times(1); - timeArray(2) = ERPwaviewer.ERP.times(end); + timeArray(1) = gui_erp_waviewer.ERPwaviewer.ERP.times(1); + timeArray(2) = gui_erp_waviewer.ERPwaviewer.ERP.times(end); end catch timeArray = []; @@ -1198,10 +1178,10 @@ function xtimerangeauto(strx_auto,~) gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray); if numel(timeArray)==2 && gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 if xdisSecondValue ==0%% in second - [timeticks stepX]= default_time_ticks_studio(ERPwaviewer.ERP, timeArray*1000);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray*1000);%% in millisecond timeticks = num2str(str2num(char(timeticks))/1000); else - [timeticks stepX]= default_time_ticks_studio(ERPwaviewer.ERP, timeArray);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray);%% in millisecond end xtick_precision = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; timeticks= f_decimal(char(timeticks),xtick_precision); @@ -1219,21 +1199,13 @@ function timerangecustom(Strtimcustom,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" xdisSecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPIN = ERPwaviewer.ERP; - timeArray(1) = ERPwaviewer.ERP.times(1); - timeArray(2) = ERPwaviewer.ERP.times(end); - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end + + ERPIN = gui_erp_waviewer.ERPwaviewer.ERP; + timeArray(1) = gui_erp_waviewer.ERPwaviewer.ERP.times(1); + timeArray(2) = gui_erp_waviewer.ERPwaviewer.ERP.times(end); + timcustom = str2num(Strtimcustom.String); %%checking the inputs if xdisSecondValue==0 @@ -1241,26 +1213,24 @@ function timerangecustom(Strtimcustom,~) end if isempty(timcustom) || numel(timcustom)~=2 messgStr = strcat('Time range in "Time and Amplitude Scales" - Inputs must be two numbers!'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - % fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); Strtimcustom.String = num2str(timeArray); viewer_ERPDAT.Process_messg =4; return; end if timcustom(1) >= timcustom(2) messgStr = strcat('Time range in "Time and Amplitude Scales" - The left edge should be smaller than the right one'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); Strtimcustom.String = num2str(timeArray); viewer_ERPDAT.Process_messg =4; return; end if numel(timcustom)==2 && gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 if xdisSecondValue ==0%% in second - [timeticks stepX]= default_time_ticks_studio(ERPwaviewer.ERP, timcustom*1000);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timcustom*1000);%% in millisecond timeticks = num2str(str2num(char(timeticks))/1000); else - [timeticks stepX]= default_time_ticks_studio(ERPwaviewer.ERP, timcustom);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timcustom);%% in millisecond end if gui_erpxyaxeset_waveviewer.xmillisecond.Value==1 xtick_precision = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; @@ -1275,25 +1245,22 @@ function timerangecustom(Strtimcustom,~) %%----------------------x ticks custom------------------------------------- function timetickscustom(Str,~) - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); + [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=3 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" xdisSecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value; timeArray = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String); timeticksdef = ''; if ~isempty(timeArray) if xdisSecondValue ==0%% in second - [timeticks stepX]= default_time_ticks_studio(ERPwaviewerIN.ERP, timeArray*1000);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray*1000);%% in millisecond timeticksdef = num2str(str2num(char(timeticks))/1000); else - [timeticksdef stepX]= default_time_ticks_studio(ERPwaviewerIN.ERP, timeArray);%% in millisecond + [timeticksdef stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray);%% in millisecond end if gui_erpxyaxeset_waveviewer.xmillisecond.Value==1 xtick_precision = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; @@ -1307,14 +1274,12 @@ function timetickscustom(Str,~) %%checking the inputs if isempty(timtickcustom) messgStr = strcat('Time ticks in "Time and Amplitude Scales" - We used the default values because input are not numeric values'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; Str.String = timeticksdef; return; end - end %%-------------------------Setting for xticks auto------------------------ @@ -1324,30 +1289,21 @@ function xtimetickauto(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = Str.Value; if Value ==1 gui_erpxyaxeset_waveviewer.timeticks_edit.Enable = 'off'; gui_erpxyaxeset_waveviewer.xtimetickauto.Value =1; - try - ERPwaviewer = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end xdisSecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value; timeArray = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String); if ~isempty(timeArray) && gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1%% if xdisSecondValue ==0%% in second - [timeticks stepX]= default_time_ticks_studio(ERPwaviewer.ERP, timeArray*1000);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray*1000);%% in millisecond timeticks = num2str(str2num(char(timeticks))/1000); else - [timeticks stepX]= default_time_ticks_studio(ERPwaviewer.ERP, timeArray);%% in millisecond + [timeticks stepX]= default_time_ticks_studio(gui_erp_waviewer.ERPwaviewer.ERP, timeArray);%% in millisecond end if xdisSecondValue==0 xtick_precision = gui_erpxyaxeset_waveviewer.xticks_precision.Value; @@ -1370,10 +1326,7 @@ function xticksprecison(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" if gui_erpxyaxeset_waveviewer.xmillisecond.Value==1 xtick_precision = Source.Value-1; @@ -1394,7 +1347,6 @@ function xticksprecison(Source,~) timeticks= f_decimal(char(num2str(timeticks)),xtick_precision); gui_erpxyaxeset_waveviewer.timeticks_edit.String = timeticks; end - end %%---------------------display xtick minor or not-------------------------- @@ -1404,9 +1356,7 @@ function timeminortickslabel(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = Str.Value; if Value ==1 @@ -1457,7 +1407,6 @@ function timeminortickslabel(Str,~) if Value==1 && gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value==1 gui_erpxyaxeset_waveviewer.timeminorticks_custom.String = num2str(stepX); end - end %%--------------------------custom step for minor xtick-------------------- @@ -1467,15 +1416,12 @@ function timeminorticks_custom(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Str_xtick_minor = str2num(Str.String); if isempty(Str_xtick_minor) - messgStr = strcat('Minor ticks for "X Axs" in "Time and Amplitude Scales" - Input must be numeric '); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + messgStr = strcat('Minor ticks for "X Axs" in "Time and Amplitude Scales" - Input must be numeric'); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; return; end @@ -1489,9 +1435,7 @@ function timeminortickscustom_auto(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = Str.Value; xticks = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); @@ -1542,9 +1486,7 @@ function xtimelabelon(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.xtimelabel_on.Value = 1; gui_erpxyaxeset_waveviewer.xtimelabel_off.Value = 0; @@ -1560,9 +1502,7 @@ function xtimelabeloff(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.xtimelabel_on.Value = 0; gui_erpxyaxeset_waveviewer.xtimelabel_off.Value = 1; @@ -1581,6 +1521,8 @@ function xtimefont(Source,~) gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + gui_erpxyaxeset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erpxyaxeset_waveviewer.cancel.ForegroundColor = [1 1 1]; end %%---------------------fontsize of x labelticks---------------------------- @@ -1590,9 +1532,7 @@ function xtimefontsize(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" end %%---------------------color of x labelticks------------------------------- function xtimecolor(Source,~) @@ -1601,9 +1541,7 @@ function xtimecolor(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" end %%------------------Setting for units:on----------------------------------- @@ -1613,10 +1551,7 @@ function xtimeunitson(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.xtimeunits_on.Value = 1; gui_erpxyaxeset_waveviewer.xtimeunits_off.Value = 0; end @@ -1628,10 +1563,7 @@ function xtimeunitsoff(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.xtimeunits_on.Value = 0; gui_erpxyaxeset_waveviewer.xtimeunits_off.Value = 1; end @@ -1648,25 +1580,19 @@ function yrangecustom(yscalStr,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" yscalecustom = str2num(char(yscalStr.String)); %%checking the inputs if isempty(yscalecustom)|| numel(yscalecustom)~=2 messgStr = strcat('Y scale for "Y Axs" in "Time and Amplitude Scales" - Inputs must be two numbers '); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - % yscalStr.String = ''; + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; return; end if yscalecustom(1) >= yscalecustom(2) messgStr = strcat('Y scale for "Y Axs" in "Time and Amplitude Scales" - The left edge should be smaller than the right one '); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; return; end @@ -1699,43 +1625,30 @@ function yrangeauto(yscaleauto,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = yscaleauto.Value; if Value ==1 - try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer = ALLERPwaviewer; - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - ALLERPIN = ERPwaviewer.ALLERP; - ERPArrayin = ERPwaviewer.SelectERPIdx; - BinArrayIN = []; - ChanArrayIn = []; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPArrayin = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; plotOrg = [1 2 3]; try - plotOrg(1) = ERPwaviewer.plot_org.Grid; - plotOrg(2) = ERPwaviewer.plot_org.Overlay; - plotOrg(3) = ERPwaviewer.plot_org.Pages; + plotOrg(1) = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; + plotOrg(2) = gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + plotOrg(3) = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch plotOrg = [1 2 3]; end try - ChanArrayIn = ERPwaviewer.chan; + ChanArrayIn = gui_erp_waviewer.ERPwaviewer.chan; catch ChanArrayIn = []; end try - BinArrayIN = ERPwaviewer.bin; + BinArrayIN = gui_erp_waviewer.ERPwaviewer.bin; catch BinArrayIN = []; end - PageCurrent = ERPwaviewer.PageIndex; + PageCurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); try yRangeLabel = num2str(yylim_out(PageCurrent,:)); @@ -1768,29 +1681,24 @@ function yrangeauto(yscaleauto,~) end gui_erpxyaxeset_waveviewer.yticks_edit.String = yticksLabel; end - - end %%----------------------Y ticks-------------------------------------------- function ytickscustom(Str,~) - ERPwaviewerIN = evalin('base','ALLERPwaviewer'); - yticksLabel = ERPwaviewerIN.yaxis.ticks; + + yticksLabel = gui_erp_waviewer.ERPwaviewer.yaxis.ticks; [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=3 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" ytickcustom = str2num(char(Str.String)); %%checking the inputs if isempty(ytickcustom) messgStr = strcat('Y ticks on "Time and Amplitude Scales": Input must be a number!'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); Str.String = ''; viewer_ERPDAT.Process_messg =4; return; @@ -1800,16 +1708,14 @@ function ytickscustom(Str,~) if ~isempty(yRange) && numel(yRange) ==2 if min(ytickcustom(:))< yRange(1)%% compared with the left edge of time range messgStr = strcat('Y ticks in "Time and Amplitude Scales": Minimum of Y ticks should be larger than the left edge of y scale!'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); Str.String = ''; viewer_ERPDAT.Process_messg =4; return; end if max(ytickcustom(:))>yRange(2)%% compared with the right edge of time range messgStr = strcat('Y ticks in "Time and Amplitude Scales": Maximum of Y ticks should be smaller than the right edge of y scale!'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); Str.String = ''; viewer_ERPDAT.Process_messg =4; return; @@ -1844,9 +1750,7 @@ function ytickauto(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = Str.Value; if Value ==1 @@ -1888,9 +1792,7 @@ function yticksprecison(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" yticksLabel = gui_erpxyaxeset_waveviewer.yticks_edit.String; ytick_precision = Source.Value-1; @@ -1913,7 +1815,6 @@ function yticksprecison(Source,~) end end gui_erpxyaxeset_waveviewer.yticks_edit.String = yticksLabel; - end %%--------------------display ytick minor?--------------------------------- @@ -1923,9 +1824,7 @@ function yminordisp(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = Str.Value; if Value ==1 @@ -1980,15 +1879,12 @@ function yminorstepedit(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" ytickmin_step = str2num(Str.String); if isempty(ytickmin_step) messgStr = strcat('Minor ticks for "Y Axs" in "Time and Amplitude Scales": Input must be one number or more numbers'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; return; end @@ -2001,9 +1897,7 @@ function yminorstepauto(Str,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" Value = Str.Value;%% if Value ==1 @@ -2049,9 +1943,7 @@ function ylabelon(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.ylabel_on.Value = 1; gui_erpxyaxeset_waveviewer.ylabel_off.Value = 0; @@ -2068,9 +1960,7 @@ function yaxisfont(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" end %%------------------------fontsize of y label ticks------------------------ @@ -2080,9 +1970,7 @@ function yaxisfontsize(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" end %%------------------------color of y label ticks--------------------------- @@ -2092,9 +1980,7 @@ function yaxisfontcolor(Source,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; + track_changes_title_color();%%change title color and background color for "cancel" and "apply" end @@ -2105,10 +1991,7 @@ function ylabeloff(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.ylabel_on.Value = 0; gui_erpxyaxeset_waveviewer.ylabel_off.Value = 1; gui_erpxyaxeset_waveviewer.yfont_custom.Enable = 'off'; @@ -2126,7 +2009,8 @@ function yunitson(~,~) gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + gui_erpxyaxeset_waveviewer.cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + gui_erpxyaxeset_waveviewer.cancel.ForegroundColor = [1 1 1]; gui_erpxyaxeset_waveviewer.yunits_on.Value = 1; gui_erpxyaxeset_waveviewer.yunits_off.Value = 0; end @@ -2138,10 +2022,7 @@ function yunitsoff(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end estudioworkingmemory('MyViewer_xyaxis',1); - gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [0.4940 0.1840 0.5560]; - gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [1 1 1]; - box_erpxtaxes_viewer_property.TitleColor= [0.4940 0.1840 0.5560]; - + track_changes_title_color();%%change title color and background color for "cancel" and "apply" gui_erpxyaxeset_waveviewer.yunits_on.Value = 0; gui_erpxyaxeset_waveviewer.yunits_off.Value = 1; end @@ -2154,23 +2035,16 @@ function xyaxis_help(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - MessageViewer= char(strcat('Time and Amplitude Scales > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; changeFlag = estudioworkingmemory('MyViewer_xyaxis'); if changeFlag~=1%% Donot reset this panel if there is no change return; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Time and Amplitude Scales > Cancel-f_ERP_timeampscal_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - xdispsecondValue = ERPwaviewer_apply.xaxis.tdis; + + xdispsecondValue = gui_erp_waviewer.ERPwaviewer.xaxis.tdis; if xdispsecondValue==1%% with millisecond gui_erpxyaxeset_waveviewer.xmillisecond.Value =1; gui_erpxyaxeset_waveviewer.xsecond.Value = 0; @@ -2187,11 +2061,11 @@ function xyaxis_help(~,~) %%-------------------------time range------------------------------ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if xdispsecondValue==1 - gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(ERPwaviewer_apply.xaxis.timerange); + gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(gui_erp_waviewer.ERPwaviewer.xaxis.timerange); else - gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(ERPwaviewer_apply.xaxis.timerange/1000); + gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(gui_erp_waviewer.ERPwaviewer.xaxis.timerange/1000); end - TRFlag = ERPwaviewer_apply.xaxis.trangeauto; + TRFlag = gui_erp_waviewer.ERPwaviewer.xaxis.trangeauto; if TRFlag==1 gui_erpxyaxeset_waveviewer.xtimerangeauto.Value = 1 ; gui_erpxyaxeset_waveviewer.timerange_edit.Enable = 'off'; @@ -2199,10 +2073,10 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.xtimerangeauto.Value = 0 ; gui_erpxyaxeset_waveviewer.timerange_edit.Enable = 'on'; end - xticks_precision = ERPwaviewer_apply.xaxis.tickdecimals; + xticks_precision = gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals; %%time ticks if xdispsecondValue==1 - timeticks= ERPwaviewer_apply.xaxis.timeticks; + timeticks= gui_erp_waviewer.ERPwaviewer.xaxis.timeticks; if ~isempty(timeticks) timeticks= f_decimal(char(num2str(timeticks)),xticks_precision); else @@ -2211,7 +2085,7 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.timeticks_edit.String = timeticks; gui_erpxyaxeset_waveviewer.xticks_precision.Value = xticks_precision+1; else - timeticks= ERPwaviewer_apply.xaxis.timeticks/1000;%%Convert character array or string scalar to numeric array + timeticks= gui_erp_waviewer.ERPwaviewer.xaxis.timeticks/1000;%%Convert character array or string scalar to numeric array if ~isempty(timeticks) timeticks= f_decimal(char(num2str(timeticks)),xticks_precision); else @@ -2220,7 +2094,7 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.timeticks_edit.String = timeticks; gui_erpxyaxeset_waveviewer.xticks_precision.Value = xticks_precision; end - xtickAuto = ERPwaviewer_apply.xaxis.ticksauto; + xtickAuto = gui_erp_waviewer.ERPwaviewer.xaxis.ticksauto; gui_erpxyaxeset_waveviewer.xtimetickauto.Value=xtickAuto; if xtickAuto==1 gui_erpxyaxeset_waveviewer.timeticks_edit.Enable = 'off'; @@ -2228,8 +2102,8 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.timeticks_edit.Enable = 'on'; end %%minor for xticks - XMinorDis = ERPwaviewer_apply.xaxis.tminor.disp; - xMinorAuto = ERPwaviewer_apply.xaxis.tminor.auto; + XMinorDis = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.disp; + xMinorAuto = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.auto; gui_erpxyaxeset_waveviewer.xtimeminorauto.Value = XMinorDis; if xMinorAuto==1 gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value =1; @@ -2249,7 +2123,7 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.timeminorticks_custom.Enable = 'off'; gui_erpxyaxeset_waveviewer.timeminorticks_auto.Enable = 'off'; end - xtickMinorstep = ERPwaviewer_apply.xaxis.tminor.step; + xtickMinorstep = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step; if xdispsecondValue==0 xtickMinorstep= xtickMinorstep/1000;%%Convert character array or string scalar to numeric array end @@ -2260,20 +2134,20 @@ function xyaxis_help(~,~) end gui_erpxyaxeset_waveviewer.timeminorticks_custom.String = xtickMinorstep; %%x labels - xlabelFlag = ERPwaviewer_apply.xaxis.label; + xlabelFlag = gui_erp_waviewer.ERPwaviewer.xaxis.label; gui_erpxyaxeset_waveviewer.xtimelabel_on.Value = xlabelFlag; gui_erpxyaxeset_waveviewer.xtimelabel_off.Value = ~xlabelFlag; - gui_erpxyaxeset_waveviewer.xtimefont_custom.Value = ERPwaviewer_apply.xaxis.font; + gui_erpxyaxeset_waveviewer.xtimefont_custom.Value = gui_erp_waviewer.ERPwaviewer.xaxis.font; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; xfontsizeinum = str2num(char(fontsize)); - xlabelfontsize = ERPwaviewer_apply.xaxis.fontsize; + xlabelfontsize = gui_erp_waviewer.ERPwaviewer.xaxis.fontsize; [x_label,~] = find(xfontsizeinum==xlabelfontsize); if isempty(x_label) x_label=5; end gui_erpxyaxeset_waveviewer.font_custom_size.Value = x_label; - gui_erpxyaxeset_waveviewer.xtimetextcolor.Value = ERPwaviewer_apply.xaxis.fontcolor; + gui_erpxyaxeset_waveviewer.xtimetextcolor.Value = gui_erp_waviewer.ERPwaviewer.xaxis.fontcolor; if xlabelFlag==1 xlabelFlagEnable = 'on'; else @@ -2283,23 +2157,23 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.font_custom_size.Enable = xlabelFlagEnable; gui_erpxyaxeset_waveviewer.xtimetextcolor.Enable = xlabelFlagEnable; %%x units - xaxisunits= ERPwaviewer_apply.xaxis.units; + xaxisunits= gui_erp_waviewer.ERPwaviewer.xaxis.units; gui_erpxyaxeset_waveviewer.xtimeunits_on.Value =xaxisunits; gui_erpxyaxeset_waveviewer.xtimeunits_off.Value = ~xaxisunits; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%------------------------setting for y axes----------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - gui_erpxyaxeset_waveviewer.yrange_edit.String = num2str(ERPwaviewer_apply.yaxis.scales); - gui_erpxyaxeset_waveviewer.yrangeauto.Value = ERPwaviewer_apply.yaxis.scalesauto; + gui_erpxyaxeset_waveviewer.yrange_edit.String = num2str(gui_erp_waviewer.ERPwaviewer.yaxis.scales); + gui_erpxyaxeset_waveviewer.yrangeauto.Value = gui_erp_waviewer.ERPwaviewer.yaxis.scalesauto; if gui_erpxyaxeset_waveviewer.yrangeauto.Value==1 gui_erpxyaxeset_waveviewer.yrange_edit.Enable = 'off'; else gui_erpxyaxeset_waveviewer.yrange_edit.Enable = 'on'; end - ytickdecimals = ERPwaviewer_apply.yaxis.tickdecimals; + ytickdecimals = gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals; gui_erpxyaxeset_waveviewer.yticks_precision.Value = ytickdecimals+1; - YTicks=ERPwaviewer_apply.yaxis.ticks; + YTicks=gui_erp_waviewer.ERPwaviewer.yaxis.ticks; if ~isempty(YTicks) YTicks= f_decimal(char(num2str(YTicks)),ytickdecimals); else @@ -2307,15 +2181,15 @@ function xyaxis_help(~,~) end gui_erpxyaxeset_waveviewer.yticks_edit.String = YTicks; - gui_erpxyaxeset_waveviewer.ytickauto.Value=ERPwaviewer_apply.yaxis.tickauto ; + gui_erpxyaxeset_waveviewer.ytickauto.Value=gui_erp_waviewer.ERPwaviewer.yaxis.tickauto ; if gui_erpxyaxeset_waveviewer.ytickauto.Value==1 gui_erpxyaxeset_waveviewer.yticks_edit.Enable = 'off'; else gui_erpxyaxeset_waveviewer.yticks_edit.Enable = 'on'; end %%minor yticks - yMinorDisp= ERPwaviewer_apply.yaxis.yminor.disp; - yMinorAuto = ERPwaviewer_apply.yaxis.yminor.auto; + yMinorDisp= gui_erp_waviewer.ERPwaviewer.yaxis.yminor.disp; + yMinorAuto = gui_erp_waviewer.ERPwaviewer.yaxis.yminor.auto; if yMinorDisp==1 gui_erpxyaxeset_waveviewer.yminortick.Value=1; gui_erpxyaxeset_waveviewer.yminorstep_auto.Enable = 'on'; @@ -2330,18 +2204,18 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.yminorstepedit.Enable = 'off'; end gui_erpxyaxeset_waveviewer.yminorstep_auto.Value = yMinorAuto; - gui_erpxyaxeset_waveviewer.yminorstepedit.String = num2str(ERPwaviewer_apply.yaxis.yminor.step); + gui_erpxyaxeset_waveviewer.yminorstepedit.String = num2str(gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step); - gui_erpxyaxeset_waveviewer.ylabel_on.Value = ERPwaviewer_apply.yaxis.label; - gui_erpxyaxeset_waveviewer.ylabel_off.Value = ~ERPwaviewer_apply.yaxis.label; - gui_erpxyaxeset_waveviewer.yfont_custom.Value =ERPwaviewer_apply.yaxis.font; - ylabelFontsize = ERPwaviewer_apply.yaxis.fontsize; + gui_erpxyaxeset_waveviewer.ylabel_on.Value = gui_erp_waviewer.ERPwaviewer.yaxis.label; + gui_erpxyaxeset_waveviewer.ylabel_off.Value = ~gui_erp_waviewer.ERPwaviewer.yaxis.label; + gui_erpxyaxeset_waveviewer.yfont_custom.Value =gui_erp_waviewer.ERPwaviewer.yaxis.font; + ylabelFontsize = gui_erp_waviewer.ERPwaviewer.yaxis.fontsize; [yx_label,~] = find(xfontsizeinum==ylabelFontsize); if isempty(yx_label) yx_label=5; end gui_erpxyaxeset_waveviewer.yfont_custom_size.Value = yx_label; - gui_erpxyaxeset_waveviewer.ytextcolor.Value= ERPwaviewer_apply.yaxis.fontcolor; + gui_erpxyaxeset_waveviewer.ytextcolor.Value= gui_erp_waviewer.ERPwaviewer.yaxis.fontcolor; if gui_erpxyaxeset_waveviewer.ylabel_on.Value==1 ylabelFlagEnable = 'on'; else @@ -2351,14 +2225,16 @@ function xyaxis_help(~,~) gui_erpxyaxeset_waveviewer.yfont_custom_size.Enable = ylabelFlagEnable; gui_erpxyaxeset_waveviewer.ytextcolor.Enable = ylabelFlagEnable; - gui_erpxyaxeset_waveviewer.yunits_on.Value = ERPwaviewer_apply.yaxis.units; - gui_erpxyaxeset_waveviewer.yunits_off.Value = ~ERPwaviewer_apply.yaxis.units; + gui_erpxyaxeset_waveviewer.yunits_on.Value = gui_erp_waviewer.ERPwaviewer.yaxis.units; + gui_erpxyaxeset_waveviewer.yunits_off.Value = ~gui_erp_waviewer.ERPwaviewer.yaxis.units; gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erpxtaxes_viewer_property.TitleColor= [0.5 0.5 0.9]; + gui_erpxyaxeset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_erpxyaxeset_waveviewer.cancel.ForegroundColor = [0 0 0]; estudioworkingmemory('MyViewer_xyaxis',0); MessageViewer= char(strcat('Time and Amplitude Scales > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -2373,17 +2249,13 @@ function xyaxis_apply(~,~) gui_erpxyaxeset_waveviewer.apply.BackgroundColor = [1 1 1]; gui_erpxyaxeset_waveviewer.apply.ForegroundColor = [0 0 0]; box_erpxtaxes_viewer_property.TitleColor= [0.5 0.5 0.9]; + gui_erpxyaxeset_waveviewer.cancel.BackgroundColor = [1 1 1]; + gui_erpxyaxeset_waveviewer.cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('Time and Amplitude Scales > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Time and Amplitude Scales > Apply-f_ERP_timeampscal_waveviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end + %%time range xdispsecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value; %display with millisecond if xdispsecondValue==1 @@ -2395,22 +2267,24 @@ function xyaxis_apply(~,~) if isempty(timeRange) || numel(timeRange)~=2 - timeRange(1) = ERPwaviewer_apply.ERP.times(1); - timeRange(2) = ERPwaviewer_apply.ERP.times(end); + timeRange(1) = gui_erp_waviewer.ERPwaviewer.ERP.times(1); + timeRange(2) = gui_erp_waviewer.ERPwaviewer.ERP.times(end); messgStr = strcat('The default time range will be used because the inputs are not two numbers'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); viewer_ERPDAT.Process_messg =4; + return; end if timeRange(1) >= timeRange(2) - timeRange(1) = ERPwaviewer_apply.ERP.times(1); - timeRange(2) = ERPwaviewer_apply.ERP.times(end); - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n Time and Amplitude Scales > Apply-Time range() error.\n The left edge should not be smaller than the right one!\n Please change current values, otherwise, the default ones will be used!\n\n'); - end - ERPwaviewer_apply.xaxis.timerange = timeRange; - ERPwaviewer_apply.xaxis.trangeauto = gui_erpxyaxeset_waveviewer.xtimerangeauto.Value; - ERPwaviewer_apply.xaxis.tdis = xdispsecondValue; + timeRange(1) = gui_erp_waviewer.ERPwaviewer.ERP.times(1); + timeRange(2) = gui_erp_waviewer.ERPwaviewer.ERP.times(end); + messgStr = strcat('Time and Amplitude Scales > Apply-Time rang: The left edge should not be smaller than the right one!'); + estudioworkingmemory('ERPViewer_proces_messg',messgStr); + viewer_ERPDAT.Process_messg =4; + return; + end + gui_erp_waviewer.ERPwaviewer.xaxis.timerange = timeRange; + gui_erp_waviewer.ERPwaviewer.xaxis.trangeauto = gui_erpxyaxeset_waveviewer.xtimerangeauto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tdis = xdispsecondValue; MERPWaveViewer_xaxis{3} = timeRange; MERPWaveViewer_xaxis{2} = gui_erpxyaxeset_waveviewer.xtimerangeauto.Value; %%getting xticks @@ -2430,37 +2304,37 @@ function xyaxis_apply(~,~) end xticksArray(xticks_exm) = []; end - ERPwaviewer_apply.xaxis.timeticks = xticksArray; - ERPwaviewer_apply.xaxis.ticksauto = gui_erpxyaxeset_waveviewer.xtimetickauto.Value; - MERPWaveViewer_xaxis{4} = ERPwaviewer_apply.xaxis.ticksauto; + gui_erp_waviewer.ERPwaviewer.xaxis.timeticks = xticksArray; + gui_erp_waviewer.ERPwaviewer.xaxis.ticksauto = gui_erpxyaxeset_waveviewer.xtimetickauto.Value; + MERPWaveViewer_xaxis{4} = gui_erp_waviewer.ERPwaviewer.xaxis.ticksauto; MERPWaveViewer_xaxis{5} = xticksArray; if gui_erpxyaxeset_waveviewer.xmillisecond.Value==1 - ERPwaviewer_apply.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; + gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; else - ERPwaviewer_apply.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals = gui_erpxyaxeset_waveviewer.xticks_precision.Value; end - MERPWaveViewer_xaxis{6} = ERPwaviewer_apply.xaxis.tickdecimals; + MERPWaveViewer_xaxis{6} = gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals; %%minor for xticks - ERPwaviewer_apply.xaxis.tminor.disp = gui_erpxyaxeset_waveviewer.xtimeminorauto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.disp = gui_erpxyaxeset_waveviewer.xtimeminorauto.Value; xticckMinorstep = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); if xdispsecondValue==1 - ERPwaviewer_apply.xaxis.tminor.step = xticckMinorstep; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step = xticckMinorstep; else - ERPwaviewer_apply.xaxis.tminor.step = xticckMinorstep*1000; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step = xticckMinorstep*1000; end - ERPwaviewer_apply.xaxis.tminor.auto = gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.auto = gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value; MERPWaveViewer_xaxis{7} = gui_erpxyaxeset_waveviewer.xtimeminorauto.Value; - MERPWaveViewer_xaxis{8} = ERPwaviewer_apply.xaxis.tminor.step; + MERPWaveViewer_xaxis{8} = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step; MERPWaveViewer_xaxis{9} =gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value; %%xtick label on/off - ERPwaviewer_apply.xaxis.label = gui_erpxyaxeset_waveviewer.xtimelabel_on.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.label = gui_erpxyaxeset_waveviewer.xtimelabel_on.Value; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; xfontsizeinum = str2num(char(fontsize)); - ERPwaviewer_apply.xaxis.font = gui_erpxyaxeset_waveviewer.xtimefont_custom.Value; - ERPwaviewer_apply.xaxis.fontsize = xfontsizeinum(gui_erpxyaxeset_waveviewer.font_custom_size.Value); - ERPwaviewer_apply.xaxis.fontcolor = gui_erpxyaxeset_waveviewer.xtimetextcolor.Value; - ERPwaviewer_apply.xaxis.units = gui_erpxyaxeset_waveviewer.xtimeunits_on.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.font = gui_erpxyaxeset_waveviewer.xtimefont_custom.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.fontsize = xfontsizeinum(gui_erpxyaxeset_waveviewer.font_custom_size.Value); + gui_erp_waviewer.ERPwaviewer.xaxis.fontcolor = gui_erpxyaxeset_waveviewer.xtimetextcolor.Value; + gui_erp_waviewer.ERPwaviewer.xaxis.units = gui_erpxyaxeset_waveviewer.xtimeunits_on.Value; MERPWaveViewer_xaxis{10}=gui_erpxyaxeset_waveviewer.xtimelabel_on.Value; MERPWaveViewer_xaxis{11} = gui_erpxyaxeset_waveviewer.xtimefont_custom.Value; MERPWaveViewer_xaxis{12} = gui_erpxyaxeset_waveviewer.font_custom_size.Value; @@ -2474,29 +2348,29 @@ function xyaxis_apply(~,~) %%y scales YScales = str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); if isempty(YScales) || numel(YScales)~=2 - ALLERPIN = ERPwaviewer_apply.ALLERP; - ERPArrayin = ERPwaviewer_apply.SelectERPIdx; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPArrayin = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; BinArrayIN = []; ChanArrayIn = []; plotOrg = [1 2 3]; try - plotOrg(1) = ERPwaviewer_apply.plot_org.Grid; - plotOrg(2) = ERPwaviewer_apply.plot_org.Overlay; - plotOrg(3) = ERPwaviewer_apply.plot_org.Pages; + plotOrg(1) = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; + plotOrg(2) = gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + plotOrg(3) = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch plotOrg = [1 2 3]; end try - ChanArrayIn = ERPwaviewer_apply.chan; + ChanArrayIn = gui_erp_waviewer.ERPwaviewer.chan; catch ChanArrayIn = []; end try - BinArrayIN = ERPwaviewer_apply.bin; + BinArrayIN = gui_erp_waviewer.ERPwaviewer.bin; catch BinArrayIN = []; end - PageCurrent = ERPwaviewer_apply.PageIndex; + PageCurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); YScales = []; try @@ -2504,19 +2378,21 @@ function xyaxis_apply(~,~) catch YScales = yylim_out(1,:); end - + messgStr = ''; if isempty(YScales) messgStr = strcat('The default Y scales will be used because the inputs are empty'); elseif numel(YScales)~=2 messgStr = strcat('The default Y scales will be used because the number of inputs is not 2'); end - erpworkingmemory('ERPViewer_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - viewer_ERPDAT.Process_messg =4; + if ~ismepty(messgStr) + estudioworkingmemory('ERPViewer_proces_messg',messgStr); + fprintf(2,['\n Warning: ',messgStr,'.\n']); + viewer_ERPDAT.Process_messg =4; + end end - ERPwaviewer_apply.yaxis.scales =YScales ; - ERPwaviewer_apply.yaxis.scalesauto = gui_erpxyaxeset_waveviewer.yrangeauto.Value; - MERPWaveViewer_yaxis{1} = ERPwaviewer_apply.yaxis.scalesauto; + gui_erp_waviewer.ERPwaviewer.yaxis.scales =YScales ; + gui_erp_waviewer.ERPwaviewer.yaxis.scalesauto = gui_erpxyaxeset_waveviewer.yrangeauto.Value; + MERPWaveViewer_yaxis{1} = gui_erp_waviewer.ERPwaviewer.yaxis.scalesauto; MERPWaveViewer_yaxis{2} = YScales; %%yticks YTicks = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); @@ -2531,48 +2407,44 @@ function xyaxis_apply(~,~) end YTicks(yticks_exm) = []; end - ERPwaviewer_apply.yaxis.tickdecimals = gui_erpxyaxeset_waveviewer.yticks_precision.Value-1; - ERPwaviewer_apply.yaxis.ticks = YTicks; - ERPwaviewer_apply.yaxis.tickauto = gui_erpxyaxeset_waveviewer.ytickauto.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals = gui_erpxyaxeset_waveviewer.yticks_precision.Value-1; + gui_erp_waviewer.ERPwaviewer.yaxis.ticks = YTicks; + gui_erp_waviewer.ERPwaviewer.yaxis.tickauto = gui_erpxyaxeset_waveviewer.ytickauto.Value; MERPWaveViewer_yaxis{3} = gui_erpxyaxeset_waveviewer.ytickauto.Value; MERPWaveViewer_yaxis{4} = YTicks; - MERPWaveViewer_yaxis{5} = ERPwaviewer_apply.yaxis.tickdecimals; + MERPWaveViewer_yaxis{5} = gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals; %%minor yticks - ERPwaviewer_apply.yaxis.yminor.disp = gui_erpxyaxeset_waveviewer.yminortick.Value; - ERPwaviewer_apply.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); - ERPwaviewer_apply.yaxis.yminor.auto = gui_erpxyaxeset_waveviewer.yminorstep_auto.Value; - MERPWaveViewer_yaxis{6} = ERPwaviewer_apply.yaxis.yminor.disp ; - MERPWaveViewer_yaxis{7} = ERPwaviewer_apply.yaxis.yminor.auto; - MERPWaveViewer_yaxis{8} = ERPwaviewer_apply.yaxis.yminor.step; + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.disp = gui_erpxyaxeset_waveviewer.yminortick.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.auto = gui_erpxyaxeset_waveviewer.yminorstep_auto.Value; + MERPWaveViewer_yaxis{6} = gui_erp_waviewer.ERPwaviewer.yaxis.yminor.disp ; + MERPWaveViewer_yaxis{7} = gui_erp_waviewer.ERPwaviewer.yaxis.yminor.auto; + MERPWaveViewer_yaxis{8} = gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step; %%y labels: on/off - ERPwaviewer_apply.yaxis.label = gui_erpxyaxeset_waveviewer.ylabel_on.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.label = gui_erpxyaxeset_waveviewer.ylabel_on.Value; MERPWaveViewer_yaxis{9} = gui_erpxyaxeset_waveviewer.ylabel_on.Value; %%yticks: font and font size - ERPwaviewer_apply.yaxis.font = gui_erpxyaxeset_waveviewer.yfont_custom.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.font = gui_erpxyaxeset_waveviewer.yfont_custom.Value; yfontsizeinum = str2num(char(fontsize)); - ERPwaviewer_apply.yaxis.fontsize = yfontsizeinum(gui_erpxyaxeset_waveviewer.yfont_custom_size.Value); - MERPWaveViewer_yaxis{10} =ERPwaviewer_apply.yaxis.font; + gui_erp_waviewer.ERPwaviewer.yaxis.fontsize = yfontsizeinum(gui_erpxyaxeset_waveviewer.yfont_custom_size.Value); + MERPWaveViewer_yaxis{10} =gui_erp_waviewer.ERPwaviewer.yaxis.font; MERPWaveViewer_yaxis{11}=gui_erpxyaxeset_waveviewer.yfont_custom_size.Value; %%yticks color - ERPwaviewer_apply.yaxis.fontcolor = gui_erpxyaxeset_waveviewer.ytextcolor.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.fontcolor = gui_erpxyaxeset_waveviewer.ytextcolor.Value; MERPWaveViewer_yaxis{12}=gui_erpxyaxeset_waveviewer.ytextcolor.Value; %%y units - ERPwaviewer_apply.yaxis.units = gui_erpxyaxeset_waveviewer.yunits_on.Value; + gui_erp_waviewer.ERPwaviewer.yaxis.units = gui_erpxyaxeset_waveviewer.yunits_on.Value; MERPWaveViewer_yaxis{13}= gui_erpxyaxeset_waveviewer.yunits_on.Value; estudioworkingmemory('MERPWaveViewer_yaxis',MERPWaveViewer_yaxis);%%save the parameters for y axis to momery file - %%save the parameters - ALLERPwaviewer=ERPwaviewer_apply; - assignin('base','ALLERPwaviewer',ALLERPwaviewer); - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP=1; viewer_ERPDAT.Process_messg =2;%% complete end - %%------------change this panel based on the changed ERPsets--------------- function v_currentERP_change(~,~) - if viewer_ERPDAT.Count_currentERP == 0 + if viewer_ERPDAT.Count_currentERP ~=3 return; end [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); @@ -2581,49 +2453,47 @@ function v_currentERP_change(~,~) estudioworkingmemory('MyViewer_xyaxis',0); end - - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - try - ERPIN = ERPwaviewer_apply.ERP; - timeArray(1) = ERPwaviewer_apply.ERP.times(1); - timeArray(2) = ERPwaviewer_apply.ERP.times(end); - [timeticks stepX]= default_time_ticks_studio(ERPIN, [timeArray(1),timeArray(2)]); + ERPIN = gui_erp_waviewer.ERPwaviewer.ERP; + timeArraydef(1) = gui_erp_waviewer.ERPwaviewer.ERP.times(1); + timeArraydef(2) = gui_erp_waviewer.ERPwaviewer.ERP.times(end); + [timeticksdef stepX]= default_time_ticks_studio(ERPIN, [timeArraydef(1),timeArraydef(2)]); if ~isempty(stepX) && numel(stepX) ==1 stepX = floor(stepX/2); end catch - timeticks = []; - timeArray = []; + timeticksdef = []; + timeArraydef = []; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%----------------------------Setting for X axis------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - xSecondflag = erpworkingmemory('MyViewer_xaxis_second'); - xmSecondflag = erpworkingmemory('MyViewer_xaxis_msecond'); - % if isempty(xSecondflag) && isempty(xmSecondflag) + xSecondflag = estudioworkingmemory('MyViewer_xaxis_second'); + xmSecondflag = estudioworkingmemory('MyViewer_xaxis_msecond'); xdispysecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value;%%millisecond - % end - % if xSecondflag ==0 && xmSecondflag==1 - % xdispysecondValue =1; + timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String); + if isempty(timerange) || numel(timerange)~=2 || timerange(1) >= timeArraydef(2) || timerange(2) <= timeArraydef(1) + timerange =timeArraydef; + if xdispysecondValue==1 + gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timerange); + else + gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timerange/1000); + end + end if gui_erpxyaxeset_waveviewer.xtimerangeauto.Value==1 if xdispysecondValue==1 - gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray); - gui_erpxyaxeset_waveviewer.xticks_precision.String = {'0','1','2','3','4','5','6'}; + gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArraydef); else - gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray/1000); - gui_erpxyaxeset_waveviewer.xticks_precision.String = {'1','2','3','4','5','6'}; + gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArraydef/1000); end end - % else - % xdispysecondValue =0; - % end + if xdispysecondValue==1 + gui_erpxyaxeset_waveviewer.xticks_precision.String = {'0','1','2','3','4','5','6'}; + else + gui_erpxyaxeset_waveviewer.xticks_precision.String = {'1','2','3','4','5','6'}; + end + + if xdispysecondValue==1 xtick_precision =gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; if xtick_precision<0 @@ -2637,16 +2507,16 @@ function v_currentERP_change(~,~) gui_erpxyaxeset_waveviewer.xticks_precision.Value=1; end end - if gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 + if gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 && gui_erpxyaxeset_waveviewer.xtimerangeauto.Value==1 if xdispysecondValue==0 - timetickstrs = num2str(str2num(char(timeticks))/1000); + timetickstrs = num2str(str2num(char(timeticksdef))/1000); else - timetickstrs = timeticks; + timetickstrs = timeticksdef; end timetickstrs= f_decimal(char(timetickstrs),xtick_precision); gui_erpxyaxeset_waveviewer.timeticks_edit.String = char(timetickstrs); end - ERPwaviewer_apply.xaxis.tickdecimals = xtick_precision; + gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals = xtick_precision; %%X minor ticks stepX = []; @@ -2692,6 +2562,38 @@ function v_currentERP_change(~,~) gui_erpxyaxeset_waveviewer.timeminorticks_custom.String = num2str(stepX); end + if xdispysecondValue==1 + gui_erp_waviewer.ERPwaviewer.xaxis.timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String); + else + gui_erp_waviewer.ERPwaviewer.xaxis.timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String)*1000; + end + timeRange = gui_erp_waviewer.ERPwaviewer.xaxis.timerange ; + %%getting xticks + if xdispysecondValue==1 + xticksArray = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); + else + xticksArray = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String))*1000; + end + count_xtks = 0; + xticks_exm = []; + if ~isempty(xticksArray) && numel(timeRange) ==2 %%check if xticks exceed the defined time range + for Numofxticks = 1:numel(xticksArray) + if xticksArray(Numofxticks)< timeRange(1) || xticksArray(Numofxticks)> timeRange(2) + count_xtks =count_xtks+1; + xticks_exm(count_xtks) = Numofxticks; + end + end + xticksArray(xticks_exm) = []; + end + + xticckMinorstep = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); + if xdispysecondValue==1 + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step = xticckMinorstep; + else + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step = xticckMinorstep*1000; + end + gui_erp_waviewer.ERPwaviewer.xaxis.timeticks = xticksArray; + MERPWaveViewer_xaxis = estudioworkingmemory('MERPWaveViewer_xaxis'); if xdispysecondValue==1 MERPWaveViewer_xaxis{1}=1; @@ -2706,41 +2608,42 @@ function v_currentERP_change(~,~) end estudioworkingmemory('MERPWaveViewer_xaxis',MERPWaveViewer_xaxis);%%save the changed parameters for x axis to memory file. - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%----------------------------Setting for Y axis------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%y scale - ALLERPIN = ERPwaviewer_apply.ALLERP; - ERPArrayin = ERPwaviewer_apply.SelectERPIdx; - BinArrayIN = []; - ChanArrayIn = []; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPArrayin = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; plotOrg = [1 2 3]; try - plotOrg(1) = ERPwaviewer_apply.plot_org.Grid; - plotOrg(2) = ERPwaviewer_apply.plot_org.Overlay; - plotOrg(3) = ERPwaviewer_apply.plot_org.Pages; + plotOrg(1) = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; + plotOrg(2) = gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + plotOrg(3) = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch plotOrg = [1 2 3]; end try - ChanArrayIn = ERPwaviewer_apply.chan; + ChanArrayIn = gui_erp_waviewer.ERPwaviewer.chan; catch ChanArrayIn = []; end try - BinArrayIN = ERPwaviewer_apply.bin; + BinArrayIN = gui_erp_waviewer.ERPwaviewer.bin; catch BinArrayIN = []; end - PageCurrent = ERPwaviewer_apply.PageIndex; + PageCurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); try yRangeLabel = num2str(yylim_out(PageCurrent,:)); catch yRangeLabel = num2str(yylim_out(1,:)); end + yrange = str2num(gui_erpxyaxeset_waveviewer.yrange_edit.String); + if isempty(yrange) || numel(yrange)~=2 + yrange = str2num(yRangeLabel); + end if gui_erpxyaxeset_waveviewer.yrangeauto.Value ==1 gui_erpxyaxeset_waveviewer.yrange_edit.String = yRangeLabel; @@ -2752,7 +2655,7 @@ function v_currentERP_change(~,~) end ytick_precision= gui_erpxyaxeset_waveviewer.yticks_precision.Value-1; yticksLabel= f_decimal(char(yticksLabel),ytick_precision); - if gui_erpxyaxeset_waveviewer.ytickauto.Value ==1 + if gui_erpxyaxeset_waveviewer.ytickauto.Value ==1 && gui_erpxyaxeset_waveviewer.yrangeauto.Value ==1 gui_erpxyaxeset_waveviewer.yticks_edit.String = yticksLabel; end @@ -2760,7 +2663,7 @@ function v_currentERP_change(~,~) if gui_erpxyaxeset_waveviewer.yminorstep_auto.Value==1 yticksStr = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); stepY = []; - yscaleRange = (str2num(yRangeLabel)); + if ~isempty(yticksStr) && numel(yticksStr)>1 if numel(yticksStr)>=2 for Numofxticks = 1:numel(yticksStr)-1 @@ -2769,7 +2672,7 @@ function v_currentERP_change(~,~) %%adjust the left edge steyleft = (yticksStr(2)-yticksStr(1))/2; for ii = 1:1000 - if (yticksStr(1)- steyleft*ii)>=yscaleRange(1) + if (yticksStr(1)- steyleft*ii)>=yrange(1) stepY = [(yticksStr(1)- steyleft*ii),stepY]; else break; @@ -2778,7 +2681,7 @@ function v_currentERP_change(~,~) %%adjust the right edge steyright = (yticksStr(end)-yticksStr(end-1))/2; for ii = 1:1000 - if (yticksStr(end)+ steyright*ii)<=yscaleRange(end) + if (yticksStr(end)+ steyright*ii)<=yrange(end) stepY = [stepY,(yticksStr(end)+ steyright*ii)]; else break; @@ -2789,42 +2692,12 @@ function v_currentERP_change(~,~) gui_erpxyaxeset_waveviewer.yminorstepedit.String=char(num2str(stepY)); end - if xdispysecondValue==1 - ERPwaviewer_apply.xaxis.timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String); - else - ERPwaviewer_apply.xaxis.timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String)*1000; - end - timeRange = ERPwaviewer_apply.xaxis.timerange ; - %%getting xticks - if xdispysecondValue==1 - xticksArray = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); - else - xticksArray = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String))*1000; - end - count_xtks = 0; - xticks_exm = []; - if ~isempty(xticksArray) && numel(timeRange) ==2 %%check if xticks exceed the defined time range - for Numofxticks = 1:numel(xticksArray) - if xticksArray(Numofxticks)< timeRange(1) || xticksArray(Numofxticks)> timeRange(2) - count_xtks =count_xtks+1; - xticks_exm(count_xtks) = Numofxticks; - end - end - xticksArray(xticks_exm) = []; - end - xticckMinorstep = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); - if xdispysecondValue==1 - ERPwaviewer_apply.xaxis.tminor.step = xticckMinorstep; - else - ERPwaviewer_apply.xaxis.tminor.step = xticckMinorstep*1000; - end - ERPwaviewer_apply.xaxis.timeticks = xticksArray; %%y axis YScales = str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); if isempty(YScales) - PageCurrent = ERPwaviewer_apply.PageIndex; + PageCurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); YScales = []; try @@ -2833,7 +2706,7 @@ function v_currentERP_change(~,~) YScales = yylim_out(1,:); end end - ERPwaviewer_apply.yaxis.scales =YScales ; + gui_erp_waviewer.ERPwaviewer.yaxis.scales =YScales ; YTicks = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); count_xtks = 0; yticks_exm = []; @@ -2846,336 +2719,35 @@ function v_currentERP_change(~,~) end YTicks(yticks_exm) = []; end - ERPwaviewer_apply.yaxis.ticks = YTicks; - ERPwaviewer_apply.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); + gui_erp_waviewer.ERPwaviewer.yaxis.ticks = YTicks; + gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); %%save the parameters - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); MERPWaveViewer_yaxis = estudioworkingmemory('MERPWaveViewer_yaxis'); MERPWaveViewer_yaxis{1} = gui_erpxyaxeset_waveviewer.yrangeauto.Value; MERPWaveViewer_yaxis{2}=str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); MERPWaveViewer_yaxis{4} = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); MERPWaveViewer_yaxis{8} = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); estudioworkingmemory('MERPWaveViewer_yaxis',MERPWaveViewer_yaxis);%%save the changed parameters for y axis to memory file. - + viewer_ERPDAT.Count_currentERP =4; end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%---------------change X/Y axis based on the current Page---------------- -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - function page_xyaxis_change(~,~) - if viewer_ERPDAT.page_xyaxis==0 +%%-------------modify this panel based on the updated parameters----------- + function loadproper_change(~,~) + if viewer_ERPDAT.loadproper_count ~=3 return; end - %%execute any changes in this panel - [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); - if ~isempty(messgStr) && viewerpanelIndex==3 - xyaxis_apply(); - estudioworkingmemory('MyViewer_xyaxis',0); - end - - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI() error: Please run the ERP wave viewer again.'); - return; - end - - try - ERPIN = ERPwaviewer_apply.ERP; - timeArray(1) = ERPwaviewer_apply.ERP.times(1); - timeArray(2) = ERPwaviewer_apply.ERP.times(end); - [timeticks stepX]= default_time_ticks_studio(ERPIN, [timeArray(1),timeArray(2)]); - if ~isempty(stepX) && numel(stepX) ==1 - stepX = floor(stepX/2); - end - catch - timeticks = ''; - timeArray = []; - end - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %%----------------------------Setting for X axis------------------- - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - xSecondflag = erpworkingmemory('MyViewer_xaxis_second'); - xmSecondflag = erpworkingmemory('MyViewer_xaxis_msecond'); - if isempty(xSecondflag) && isempty(xmSecondflag) - xdispysecondValue = gui_erpxyaxeset_waveviewer.xmillisecond.Value;%%millisecond - end - if xSecondflag ==0 && xmSecondflag==1 - xdispysecondValue =1; - if gui_erpxyaxeset_waveviewer.xtimerangeauto.Value==1 - if xdispysecondValue==1 - gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray); - gui_erpxyaxeset_waveviewer.xticks_precision.String = {'0','1','2','3','4','5','6'}; - else - gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeArray/1000); - gui_erpxyaxeset_waveviewer.xticks_precision.String = {'1','2','3','4','5','6'}; - end - end - else - xdispysecondValue =0; - end - - if xdispysecondValue==1 - xtick_precision =gui_erpxyaxeset_waveviewer.xticks_precision.Value-1; - if xtick_precision<0 - xtick_precision =0; - gui_erpxyaxeset_waveviewer.xticks_precision.Value=1; - end - else - xtick_precision =gui_erpxyaxeset_waveviewer.xticks_precision.Value; - if xtick_precision<=0 - xtick_precision =1; - gui_erpxyaxeset_waveviewer.xticks_precision.Value=1; - end - end - ERPwaviewer_apply.xaxis.tickdecimals = xtick_precision; - - if gui_erpxyaxeset_waveviewer.xtimetickauto.Value ==1 - if xdispysecondValue==0 - timeticks = num2str(str2num(char(timeticks))/1000); - end - timeticks= f_decimal(char(timeticks),xtick_precision); - gui_erpxyaxeset_waveviewer.timeticks_edit.String = char(timeticks); - end - %%X minor ticks - stepX = []; - timeArray = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); - xticksStr = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); - if xdispysecondValue~=1 - xticksStr = xticksStr*1000; - timeArray = timeArray*1000; - end - if gui_erpxyaxeset_waveviewer.timeminorticks_auto.Value ==1 - if ~isempty(xticksStr) && numel(xticksStr)>1 - - if ~isempty(xticksStr) && numel(xticksStr)>1 && numel(timeArray) ==2 && (timeArray(1)< timeArray(2)) - if numel(xticksStr)>=2 - for Numofxticks = 1:numel(xticksStr)-1 - stepX(1,Numofxticks) = xticksStr(Numofxticks)+(xticksStr(Numofxticks+1)-xticksStr(Numofxticks))/2; - end - %%adjust the left edge - stexleft = (xticksStr(2)-xticksStr(1))/2; - for ii = 1:1000 - if (xticksStr(1)- stexleft*ii)>=timeArray(1) - stepX = [(xticksStr(1)- stexleft*ii),stepX]; - else - break; - end - end - %%adjust the right edge - stexright = (xticksStr(end)-xticksStr(end-1))/2; - for ii = 1:1000 - if (xticksStr(end)+ stexright*ii)<=timeArray(end) - stepX = [stepX,(xticksStr(end)+ stexright*ii)]; - else - break; - end - end - end - end - end - if xdispysecondValue==0 - stepX =stepX/1000; - end - gui_erpxyaxeset_waveviewer.timeminorticks_custom.String = num2str(stepX); - end - - MERPWaveViewer_xaxis = estudioworkingmemory('MERPWaveViewer_xaxis'); - if xdispysecondValue==1 - MERPWaveViewer_xaxis{1}=1; - MERPWaveViewer_xaxis{3} = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); - MERPWaveViewer_xaxis{5} = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); - MERPWaveViewer_xaxis{8} = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); - else - MERPWaveViewer_xaxis{1}=0; - MERPWaveViewer_xaxis{3} = str2num(char(gui_erpxyaxeset_waveviewer.timerange_edit.String)); - MERPWaveViewer_xaxis{5} = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); - MERPWaveViewer_xaxis{8} = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); - end - estudioworkingmemory('MERPWaveViewer_xaxis',MERPWaveViewer_xaxis);%%save the changed parameters for x axis to memory file. - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %%----------------------------Setting for Y axis------------------- - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %%y scale - ALLERPIN = ERPwaviewer_apply.ALLERP; - ERPArrayin = ERPwaviewer_apply.SelectERPIdx; - BinArrayIN = []; - ChanArrayIn = []; - plotOrg = [1 2 3]; - try - plotOrg(1) = ERPwaviewer_apply.plot_org.Grid; - plotOrg(2) = ERPwaviewer_apply.plot_org.Overlay; - plotOrg(3) = ERPwaviewer_apply.plot_org.Pages; - catch - plotOrg = [1 2 3]; - end - try - ChanArrayIn = ERPwaviewer_apply.chan; - catch - ChanArrayIn = []; - end - try - BinArrayIN = ERPwaviewer_apply.bin; - catch - BinArrayIN = []; - end - - PageCurrent = ERPwaviewer_apply.PageIndex; - yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); - try - yRangeLabel = num2str(yylim_out(PageCurrent,:)); - catch - yRangeLabel = num2str(yylim_out(1,:)); - end - - if gui_erpxyaxeset_waveviewer.yrangeauto.Value ==1 - gui_erpxyaxeset_waveviewer.yrange_edit.String = yRangeLabel; - end - %%y ticks - yticksLabel = ''; - if ~isempty(str2num(yRangeLabel)) - yticksLabel = default_amp_ticks_viewer(str2num(yRangeLabel)); - end - - ytick_precision= gui_erpxyaxeset_waveviewer.yticks_precision.Value-1; - yticksLabel= f_decimal(char(yticksLabel),ytick_precision); - - if gui_erpxyaxeset_waveviewer.ytickauto.Value ==1 - gui_erpxyaxeset_waveviewer.yticks_edit.String = yticksLabel; - end - - %%y minor ticks - if gui_erpxyaxeset_waveviewer.yminorstep_auto.Value==1 - yticksStr = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); - stepY = []; - yscaleRange = (str2num(yRangeLabel)); - if ~isempty(yticksStr) && numel(yticksStr)>1 - if numel(yticksStr)>=2 - for Numofxticks = 1:numel(yticksStr)-1 - stepY(1,Numofxticks) = yticksStr(Numofxticks)+(yticksStr(Numofxticks+1)-yticksStr(Numofxticks))/2; - end - %%adjust the left edge - steyleft = (yticksStr(2)-yticksStr(1))/2; - for ii = 1:1000 - if (yticksStr(1)- steyleft*ii)>=yscaleRange(1) - stepY = [(yticksStr(1)- steyleft*ii),stepY]; - else - break; - end - end - %%adjust the right edge - steyright = (yticksStr(end)-yticksStr(end-1))/2; - for ii = 1:1000 - if (yticksStr(end)+ steyright*ii)<=yscaleRange(end) - stepY = [stepY,(yticksStr(end)+ steyright*ii)]; - else - break; - end - end - end - end - gui_erpxyaxeset_waveviewer.yminorstepedit.String=char(num2str(stepY)); - end - - if xdispysecondValue==1 - ERPwaviewer_apply.xaxis.timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String); - else - ERPwaviewer_apply.xaxis.timerange = str2num(gui_erpxyaxeset_waveviewer.timerange_edit.String)*1000; - end - timeRange = ERPwaviewer_apply.xaxis.timerange; - - %%getting xticks - if xdispysecondValue==1 - xticksArray = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); - else - xticksArray = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String))*1000; - end - count_xtks = 0; - xticks_exm = []; - if ~isempty(xticksArray) && numel(timeRange) ==2 %%check if xticks exceed the defined time range - for Numofxticks = 1:numel(xticksArray) - if xticksArray(Numofxticks)< timeRange(1) || xticksArray(Numofxticks)> timeRange(2) - count_xtks =count_xtks+1; - xticks_exm(count_xtks) = Numofxticks; - end - end - xticksArray(xticks_exm) = []; - end - - xticckMinorstep = str2num(char(gui_erpxyaxeset_waveviewer.timeminorticks_custom.String)); - if xdispysecondValue==1 - ERPwaviewer_apply.xaxis.tminor.step = xticckMinorstep; - else - ERPwaviewer_apply.xaxis.tminor.step = xticckMinorstep*1000; - end - ERPwaviewer_apply.xaxis.timeticks = xticksArray; - - %%y axis - YScales = str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); - if isempty(YScales) - PageCurrent = ERPwaviewer_apply.PageIndex; - yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); - YScales = []; - try - YScales = yylim_out(PageCurrent,:); - catch - YScales = yylim_out(1,:); - end - end - ERPwaviewer_apply.yaxis.scales =YScales ; - YTicks = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); - count_xtks = 0; - yticks_exm = []; - if ~isempty(YTicks) && numel(YScales) ==2 %%check if xticks exceed the defined time range - for Numofxticks = 1:numel(YTicks) - if YTicks(Numofxticks)< YScales(1) || YTicks(Numofxticks)> YScales(2) - count_xtks =count_xtks+1; - yticks_exm(count_xtks) = Numofxticks; - end - end - YTicks(yticks_exm) = []; - end - ERPwaviewer_apply.yaxis.ticks = YTicks; - ERPwaviewer_apply.yaxis.yminor.step = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); - - MERPWaveViewer_yaxis = estudioworkingmemory('MERPWaveViewer_yaxis'); - MERPWaveViewer_yaxis{1} = gui_erpxyaxeset_waveviewer.yrangeauto.Value; - MERPWaveViewer_yaxis{2}=str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); - MERPWaveViewer_yaxis{4} = str2num(char(gui_erpxyaxeset_waveviewer.yticks_edit.String)); - MERPWaveViewer_yaxis{8} = str2num(char(gui_erpxyaxeset_waveviewer.yminorstepedit.String)); - estudioworkingmemory('MERPWaveViewer_yaxis',MERPWaveViewer_yaxis);%%save the changed parameters for y axis to memory file. - - %%save the parameters - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); - end - -%%-------------modify this panel based on the updated parameters----------- - function loadproper_change(~,~) - if viewer_ERPDAT.loadproper_count ~=3 - return; - end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - beep; - disp('f_ERP_timeampscal_waveviewer_GUI()> loadproper_change() error: Please run the ERP wave viewer again.'); - return; - end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%------------------------------X axis---------------------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%display xtick with milliseocnd or second - xdispysecondValue = ERPwaviewer_apply.xaxis.tdis; + xdispysecondValue = gui_erp_waviewer.ERPwaviewer.xaxis.tdis; gui_erpxyaxeset_waveviewer.xmillisecond.Value = xdispysecondValue; gui_erpxyaxeset_waveviewer.xsecond.Value = ~xdispysecondValue; try - ERPIN = ERPwaviewer_apply.ERP; + ERPIN = gui_erp_waviewer.ERPwaviewer.ERP; timeArraydef(1) = ERPIN.times(1); timeArraydef(2) = ERPIN.times(end); [timeticksdef stepX]= default_time_ticks_studio(ERPIN, [timeArraydef(1),timeArraydef(2)]); @@ -3189,16 +2761,15 @@ function loadproper_change(~,~) end MERPWaveViewer_xaxis{1} =1; - %%x range - timeRange = ERPwaviewer_apply.xaxis.timerange; - timeRangeAuto = ERPwaviewer_apply.xaxis.trangeauto; + timeRange = gui_erp_waviewer.ERPwaviewer.xaxis.timerange; + timeRangeAuto = gui_erp_waviewer.ERPwaviewer.xaxis.trangeauto; if timeRangeAuto~=0 && timeRangeAuto~=1 timeRangeAuto =1; end if timeRangeAuto==1 timeRange = timeArraydef; - ERPwaviewer_apply.xaxis.timerange= timeArraydef; + gui_erp_waviewer.ERPwaviewer.xaxis.timerange= timeArraydef; end if xdispysecondValue ==1 gui_erpxyaxeset_waveviewer.timerange_edit.String = num2str(timeRange); @@ -3214,12 +2785,12 @@ function loadproper_change(~,~) else gui_erpxyaxeset_waveviewer.timerange_edit.Enable = 'on'; end - timeTick = ERPwaviewer_apply.xaxis.timeticks; - timetickAuto = ERPwaviewer_apply.xaxis.ticksauto; + timeTick = gui_erp_waviewer.ERPwaviewer.xaxis.timeticks; + timetickAuto = gui_erp_waviewer.ERPwaviewer.xaxis.ticksauto; if timetickAuto==1 gui_erpxyaxeset_waveviewer.timeticks_edit.Enable = 'off'; timeTick = timeticksdef; - ERPwaviewer_apply.xaxis.timeticks = timeTick; + gui_erp_waviewer.ERPwaviewer.xaxis.timeticks = timeTick; else gui_erpxyaxeset_waveviewer.timeticks_edit.Enable = 'on'; end @@ -3228,7 +2799,7 @@ function loadproper_change(~,~) if xdispysecondValue ==0%% in second timeTick = timeTick/1000; end - xtick_precision = ERPwaviewer_apply.xaxis.tickdecimals; + xtick_precision = gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals; if xdispysecondValue==1 if xtick_precision<0 xtick_precision=1; @@ -3247,9 +2818,9 @@ function loadproper_change(~,~) timeTick= f_decimal(char(num2str(timeTick)),xtick_precision); gui_erpxyaxeset_waveviewer.timeticks_edit.String = timeTick; gui_erpxyaxeset_waveviewer.xtimetickauto.Value = timetickAuto; - timetixkMinordip = ERPwaviewer_apply.xaxis.tminor.disp; - timetixkMinorstep = ERPwaviewer_apply.xaxis.tminor.step; - timetixkMinorauto = ERPwaviewer_apply.xaxis.tminor.auto; + timetixkMinordip = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.disp; + timetixkMinorstep = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step; + timetixkMinorauto = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.auto; gui_erpxyaxeset_waveviewer.xtimeminorauto.Value = timetixkMinordip; xticks = str2num(char(gui_erpxyaxeset_waveviewer.timeticks_edit.String)); stepX = []; @@ -3291,7 +2862,7 @@ function loadproper_change(~,~) end if timetixkMinorauto==1 timetixkMinorstep = stepX; - ERPwaviewer_apply.xaxis.tminor.step= timetixkMinorstep; + gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step= timetixkMinorstep; end timetixkMinorstep= f_decimal(char(num2str(timetixkMinorstep)),xtick_precision); gui_erpxyaxeset_waveviewer.timeminorticks_custom.String = char(timetixkMinorstep); @@ -3308,20 +2879,20 @@ function loadproper_change(~,~) end end %%xticklabels - xticklabelValue = ERPwaviewer_apply.xaxis.label; + xticklabelValue = gui_erp_waviewer.ERPwaviewer.xaxis.label; gui_erpxyaxeset_waveviewer.xtimelabel_on.Value = xticklabelValue; gui_erpxyaxeset_waveviewer.xtimelabel_off.Value = ~xticklabelValue; - xticklabelfont = ERPwaviewer_apply.xaxis.font; + xticklabelfont = gui_erp_waviewer.ERPwaviewer.xaxis.font; gui_erpxyaxeset_waveviewer.xtimefont_custom.Value = xticklabelfont; - xticklabelfontsize = ERPwaviewer_apply.xaxis.fontsize; + xticklabelfontsize = gui_erp_waviewer.ERPwaviewer.xaxis.fontsize; fontsize = {'4','6','8','10','12','14','16','18','20','24','28','32','36',... '40','50','60','70','80','90','100'}; fontsize = str2num(char(fontsize)); [xsize,y] = find(fontsize ==xticklabelfontsize); gui_erpxyaxeset_waveviewer.font_custom_size.Value = xsize; - xticklabelcolor = ERPwaviewer_apply.xaxis.fontcolor; + xticklabelcolor = gui_erp_waviewer.ERPwaviewer.xaxis.fontcolor; gui_erpxyaxeset_waveviewer.xtimetextcolor.Value =xticklabelcolor; - xaxisunits = ERPwaviewer_apply.xaxis.units; + xaxisunits = gui_erp_waviewer.ERPwaviewer.xaxis.units; gui_erpxyaxeset_waveviewer.xtimeunits_on.Value =xaxisunits; gui_erpxyaxeset_waveviewer.xtimeunits_off.Value = ~xaxisunits; if xticklabelValue ==1 @@ -3343,29 +2914,27 @@ function loadproper_change(~,~) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%------------------------------Y axis---------------------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - ALLERPIN = ERPwaviewer_apply.ALLERP; - ERPArrayin = ERPwaviewer_apply.SelectERPIdx; - BinArrayIN = []; - ChanArrayIn = []; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; + ERPArrayin = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; plotOrg = [1 2 3]; try - plotOrg(1) = ERPwaviewer_apply.plot_org.Grid; - plotOrg(2) = ERPwaviewer_apply.plot_org.Overlay; - plotOrg(3) = ERPwaviewer_apply.plot_org.Pages; + plotOrg(1) = gui_erp_waviewer.ERPwaviewer.plot_org.Grid; + plotOrg(2) = gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + plotOrg(3) = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch plotOrg = [1 2 3]; end try - ChanArrayIn = ERPwaviewer_apply.chan; + ChanArrayIn = gui_erp_waviewer.ERPwaviewer.chan; catch ChanArrayIn = []; end try - BinArrayIN = ERPwaviewer_apply.bin; + BinArrayIN = gui_erp_waviewer.ERPwaviewer.bin; catch BinArrayIN = []; end - PageCurrent = ERPwaviewer_apply.PageIndex; + PageCurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; yylim_out = f_erpAutoYLim(ALLERPIN, ERPArrayin,plotOrg,BinArrayIN, ChanArrayIn); try yRangeLabel = yylim_out(PageCurrent,:); @@ -3373,12 +2942,12 @@ function loadproper_change(~,~) yRangeLabel = yylim_out(1,:); end - YScales = ERPwaviewer_apply.yaxis.scales; - YScalesAuto = ERPwaviewer_apply.yaxis.scalesauto; + YScales = gui_erp_waviewer.ERPwaviewer.yaxis.scales; + YScalesAuto = gui_erp_waviewer.ERPwaviewer.yaxis.scalesauto; if YScalesAuto==1 gui_erpxyaxeset_waveviewer.yrange_edit.Enable = 'off'; YScales =yRangeLabel; - ERPwaviewer_apply.yaxis.scales= YScales; + gui_erp_waviewer.ERPwaviewer.yaxis.scales= YScales; else gui_erpxyaxeset_waveviewer.yrange_edit.Enable = 'on'; end @@ -3386,13 +2955,13 @@ function loadproper_change(~,~) gui_erpxyaxeset_waveviewer.yrangeauto.Value = YScalesAuto; %%y ticks try - gui_erpxyaxeset_waveviewer.yticks_precision.Value =ERPwaviewer_apply.yaxis.tickdecimals; + gui_erpxyaxeset_waveviewer.yticks_precision.Value =gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals; catch gui_erpxyaxeset_waveviewer.yticks_precision.Value =1; end - yticks = ERPwaviewer_apply.yaxis.ticks; - yticksauto = ERPwaviewer_apply.yaxis.tickauto; - ytick_precision = ERPwaviewer_apply.yaxis.tickdecimals; + yticks = gui_erp_waviewer.ERPwaviewer.yaxis.ticks; + yticksauto = gui_erp_waviewer.ERPwaviewer.yaxis.tickauto; + ytick_precision = gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals; gui_erpxyaxeset_waveviewer.yticks_precision.Value = ytick_precision+1; yRangeLabel = str2num(char(gui_erpxyaxeset_waveviewer.yrange_edit.String)); if ~isempty(yRangeLabel) && numel(yRangeLabel) ==2 && (yRangeLabel(1) length(ALLERP) - SelectedIndex =length(ALLERP); - end + SelectedIndex = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; catch - beep; - disp('f_ERPsets_waviewer_GUI error: Restart ERPwave Viewer'); - return; + SelectedIndex =length(ALLERP); + end + if any(SelectedIndex(:)> length(ALLERP)) + SelectedIndex =length(ALLERP); end - [r, ~] = size(ERPdatasets); % Get size of array of ERPdatasets. r is # of ERPdatasets - % Sort the ERPdatasets!!! - ERPdatasets = sortdata(ERPdatasets); ERPwaveview_erpsetops.vBox = uiextras.VBox('Parent', ERPsets_waveviewer_box, 'Spacing', 5,'BackgroundColor',ColorBviewer_def); % VBox for everything - %%-----------------------Display tthe selected ERPsets--------------------------------------- panelshbox = uiextras.HBox('Parent', ERPwaveview_erpsetops.vBox, 'Spacing', 5,'BackgroundColor',ColorBviewer_def); dsnames = {}; - if size(ERPdatasets,1)==1 - if strcmp(ERPdatasets{1},'No ERPset loaded') - dsnames = {''}; - else - dsnames{1} = strcat(num2str(cell2mat(ERPdatasets(1,2))),'.',32,ERPdatasets{1,1}); - end - else - for Numofsub = 1:size(ERPdatasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); - end + for Numofsub = 1:size(ERPdatasets,1) + dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); end ds_length = length(ERPdatasets); ERPwaveview_erpsetops.butttons_datasets = uicontrol('Parent', panelshbox, 'Style', 'listbox', 'min', 1,'max',... - ds_length,'String', dsnames,'Value', SelectedIndex,'Callback',@selectdata,'FontSize',FonsizeDefault,'Enable','on'); + ds_length,'String', dsnames,'Value', SelectedIndex,'Callback',@selectdata,'FontSize',FonsizeDefault,'Enable','on','BackgroundColor',[1 1 1]); ERPwaveview_erpsetops.butttons_datasets.KeyPressFcn = @ERPset_keypress; %%Help and apply ERPwaveview_erpsetops.help_apply_title = uiextras.HBox('Parent', ERPwaveview_erpsetops.vBox,'BackgroundColor',ColorBviewer_def); - ERPwaveview_erpsetops.auto = uicontrol('Style', 'pushbutton','Parent', ERPwaveview_erpsetops.help_apply_title,... - 'String',' Refresh','callback',@erpselect_refresh,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); uiextras.Empty('Parent',ERPwaveview_erpsetops.help_apply_title ); - uicontrol('Style','pushbutton','Parent', ERPwaveview_erpsetops.help_apply_title ,'String','Cancel',... - 'callback',@erpset_help,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'HorizontalAlignment','left' + ERPwaveview_erpsetops.erpset_cancel = uicontrol('Style','pushbutton','Parent', ERPwaveview_erpsetops.help_apply_title ,'String','Cancel',... + 'callback',@erpset_cancel,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'HorizontalAlignment','left' uiextras.Empty('Parent',ERPwaveview_erpsetops.help_apply_title ); ERPwaveview_erpsetops.erpset_apply = uicontrol('Style','pushbutton','Parent',ERPwaveview_erpsetops.help_apply_title ,'String','Apply',... 'callback',@ERPset_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %,'HorizontalAlignment','left' - % uiextras.Empty('Parent',ERPwaveview_erpsetops.help_apply_title ); - set(ERPwaveview_erpsetops.help_apply_title ,'Sizes',[70 14 70 14 70]); - set(ERPwaveview_erpsetops.vBox, 'Sizes', [190 25]); + uiextras.Empty('Parent',ERPwaveview_erpsetops.help_apply_title ); + set(ERPwaveview_erpsetops.help_apply_title ,'Sizes',[40 70 20 70 20]); + set(ERPwaveview_erpsetops.vBox, 'Sizes', [290 25]); ERPwaveview_erpsetops.ERPLABFlag = 0; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = ERPwaveview_erpsetops.butttons_datasets.Value; + + estudioworkingmemory('MyViewer_ERPsetpanel',0); end + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%---------------------------------------------- Subfunctions --------------------------------------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %-----------------select the ERPset of interest-------------------------- - function selectdata(~,EventData) + function selectdata(Source,EventData) [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=1 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - estudioworkingmemory('MyViewer_ERPsetpanel',1); - ERPwaveview_erpsetops.erpset_apply.BackgroundColor = [0.4940 0.1840 0.5560]; - ERPwaveview_erpsetops.erpset_apply.ForegroundColor = [1 1 1]; - ERPsets_waveviewer_box.TitleColor= [0.4940 0.1840 0.5560]; - end - - -%%---------------Setting for auto option----------------------------------- - function erpselect_refresh(~,~) - % Value = Source.Value; - [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); - if ~isempty(messgStr) && viewerpanelIndex~=1 - viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; - end - ERPtooltype = erpgettoolversion('tooltype'); - - %%load the parameters from workspace - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n ERPsets > Refresh-f_ERPsets_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - - MessageViewer= char(strcat('ERPsets>" Refresh')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.Process_messg =1; - - - if strcmpi(ERPtooltype,'EStudio') || strcmpi(ERPtooltype,'ERPLAB') - if strcmpi(ERPtooltype,'ERPLAB') - try - Selected_erpset = ERPwaveview_erpsetops.butttons_datasets.Value; - try - CURRENTERPStudio = Selected_erpset(ERPwaviewer_apply.PageIndex); - catch - CURRENTERPStudio = Selected_erpset(1); - ERPwaviewer_apply.PageIndex=1; - end - catch - messgStr = strcat('Cannot get CURRENTERP from Workspace'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - viewer_ERPDAT.Process_messg =3; - return; - end - % estudioworkingmemory('PlotOrg_ERPLAB',1); + %%check if the sampling rate or time range is the same across + %%selected ERPsets-------2023 Dec. + ERPSetArray = Source.Value; + if numel(ERPSetArray)>1 + ERPSetArraydef= gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + for ii = 1:numel(ERPSetArray) + sratearray(ii) = viewer_ERPDAT.ALLERP(ERPSetArray(ii)).srate; + samplearray(ii) = viewer_ERPDAT.ALLERP(ERPSetArray(ii)).pnts; + erpstartarray(ii) = viewer_ERPDAT.ALLERP(ERPSetArray(ii)).xmin; + erpendarray(ii) = viewer_ERPDAT.ALLERP(ERPSetArray(ii)).xmax; end - try - ALLERPin = evalin('base','ALLERP'); - catch - messgStr = strcat('Cannot get ALLERP from Workspace'); - erpworkingmemory('ERPViewer_proces_messg',messgStr); - viewer_ERPDAT.Process_messg =3; + + sratearray = unique(sratearray); + if numel(sratearray)>1 + Source.Value=ERPSetArraydef; + msgboxText = ['You cannot select these ERPsets at the same time because they differ in timing parameters (sampling rate, prestimulus period, and/or epoch length).\n'... + 'You can equate the temporal parameters using the Resample ERPsets panel in ERPLAB Studio.']; + title = 'ERPLAB Studio: Advanced Wave Viewer>ERPsets'; + errorfound(sprintf(msgboxText), title); + viewer_ERPDAT.Count_currentERP = 2; return; end - if isempty(ALLERPin) - viewer_ERPDAT.Process_messg =3; - try - cprintf('red',['\n ERP Wave viewer will be closed because ALLERP is empty.\n\n']); - close(gui_erp_waviewer.Window); - catch - end - assignin('base','ALLERPwaviewer',[]); + samplearray = unique(samplearray); + if numel(samplearray)>1 + Source.Value=ERPSetArraydef; + msgboxText = ['You cannot select these ERPsets at the same time because they differ in timing parameters (sampling rate, prestimulus period, and/or epoch length).\n'... + 'You can equate the temporal parameters using the Resample ERPsets panel in ERPLAB Studio.']; + title = 'ERPLAB Studio: Advanced Wave Viewer>ERPsets'; + errorfound(sprintf(msgboxText), title); return; end - - if strcmpi(ERPtooltype,'EStudio') - Selected_erpset= estudioworkingmemory('selectederpstudio'); - CURRENTERPStudio = observe_ERPDAT.CURRENTERP; - if length(ALLERPin)==1 && strcmpi(ALLERPin(1).erpname,'No ERPset loaded') - try - cprintf('red',['\n ERP Wave viewer will be closed because ALLERP is empty.\n\n']); - close(gui_erp_waviewer.Window); - catch - end - assignin('base','ALLERPwaviewer',[]); - return; - end - end - - if isempty(Selected_erpset) || Selected_erpset> length(ALLERPin) - Selected_erpset = length(ALLERPin); - end - if isempty(CURRENTERPStudio) || CURRENTERPStudio> length(ALLERPin) - CURRENTERPStudio = Selected_erpset(1); - ERPwaviewer_apply.PageIndex=1; - end - - - ERPwaveview_erpsetops.ALLERP = ALLERPin; - ERPwaveview_erpsetops.ERP = ALLERPin(CURRENTERPStudio); - ERPwaveview_erpsetops.CURRENTERP = CURRENTERPStudio; - ERPwaveview_erpsetops.SelectERPIdx = Selected_erpset; - ERPwaveview_erpsetops.PageIndex = ERPwaviewer_apply.PageIndex; - ERPwaveview_erpsetops.ERPLABFlag = 1; - ERPdatasets = getERPDatasets(ALLERPin); % Get datasets from ALLERP - ERPdatasets = sortdata(ERPdatasets); - dsnames = {}; - if size(ERPdatasets,1)==1 - if strcmp(ERPdatasets{1},'No ERPset loaded') - dsnames = {''}; - else - dsnames{1} = strcat(num2str(cell2mat(ERPdatasets(1,2))),'.',32,ERPdatasets{1,1}); - end - else - for Numofsub = 1:size(ERPdatasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); - end - end - - ds_length = size(ERPdatasets,1); - if ds_length<=2 - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length+1; - else - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length; + erpstartarray = unique(erpstartarray); + if numel(erpstartarray)>1 + Source.Value=ERPSetArraydef; + msgboxText = ['You cannot select these ERPsets at the same time because they differ in timing parameters (sampling rate, prestimulus period, and/or epoch length).\n'... + 'You can equate the temporal parameters using the Resample ERPsets panel in ERPLAB Studio.']; + title = 'ERPLAB Studio: Advanced Wave Viewer>ERPsets'; + errorfound(sprintf(msgboxText), title); + return; end - ERPwaveview_erpsetops.butttons_datasets.String = dsnames; - ERPwaveview_erpsetops.butttons_datasets.Value = Selected_erpset; - else - return; - end - - ERPwaviewer_apply.ALLERP = ALLERPin; - ERPwaviewer_apply.ERP = ALLERPin(CURRENTERPStudio); - ERPwaviewer_apply.SelectERPIdx =Selected_erpset; - ERPwaviewer_apply.CURRENTERP = CURRENTERPStudio; - % ERPwaviewer_apply.PageIndex = 1; - estudioworkingmemory('MyViewer_ERPsetpanel',0); - ERPwaveview_erpsetops.erpset_apply.BackgroundColor = [1 1 1]; - ERPwaveview_erpsetops.erpset_apply.ForegroundColor = [0 0 0]; - ERPsets_waveviewer_box.TitleColor= [0.5 0.5 0.9]; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); - erpworkingmemory('ERPLAB_ERPWaviewer',0); - ERPset_apply(); - end - -% called datasets = sortdata(datasets), sorts datasets in order based on -% parents - function varargout = sortdata(data) - cinds = []; - ndata = {}; % Sorted data - it = 1; % Iterator for row - for i = data' % Iterate thru all datasets - if cell2mat(i(3)) == 0 % Find base datasets (child of 0 means it's not reliant on another dataset) - [~, ic] = size(cinds); - cinds(1, ic+1) = cell2mat(i(2)); % Append dataset number to list of current indexes - ndata(it,:) = i'; % Put it in - it = it + 1; + erpendarray = unique(erpendarray); + if numel(erpendarray)>1 + Source.Value=ERPSetArraydef; + msgboxText = ['You cannot select these ERPsets at the same time because they differ in timing parameters (sampling rate, prestimulus period, and/or epoch length).\n'... + 'You can equate the temporal parameters using the Resample ERPsets panel in ERPLAB Studio.']; + title = 'ERPLAB Studio: Advanced Wave Viewer>ERPsets'; + errorfound(sprintf(msgboxText), title); + return; end end - cond = true; - while cond - ninds = []; % Reset new indexes - for i = data' % Iterate thru all data - for j = cinds % Iterate thru all parents - if cell2mat(i(3)) == j % Check to see if every datapoint is a child of the current layer - [~, nic] = size(ninds); - ninds(1, nic+1) = cell2mat(i(2)); % Append dataset number to the next round of parents - [ndr, ~] = size(ndata); - for v = 1:ndr - if cell2mat(ndata(v, 2)) == j - ndata(v+2:end+1,:) = ndata(v+1:end,:); - ndata(v+1,:) = i'; - end - end - end - end - end - [~, nic] = size(ninds); - if nic == 0 % If we've gone thru all of them, there should be no new indexes - cond = false; - end - clear cinds - cinds = ninds; % Start again with ninds - end - varargout{1} = ndata; - end - - -%----------------------Get the information of the updated ERPsets---------- - function ERPdatasets = getERPDatasets(ALLERP) - ERPdatasets = {}; - if isempty(ALLERP) - beep; - disp('f_ERPsets_waveviewer_GUI>getERPDatasets error: ALLERP is empty.'); - return; - end - for Numoferpset = 1:length(ALLERP) - ERPdatasets{Numoferpset,1} = ALLERP(Numoferpset).erpname; - ERPdatasets{Numoferpset,2} = Numoferpset; - ERPdatasets{Numoferpset,3} = 0; - ERPdatasets{Numoferpset,4} = ALLERP(Numoferpset).filename; - ERPdatasets{Numoferpset,5} = ALLERP(Numoferpset).filepath; - end + estudioworkingmemory('MyViewer_ERPsetpanel',1); + ERPwaveview_erpsetops.erpset_apply.BackgroundColor = [0.4940 0.1840 0.5560]; + ERPwaveview_erpsetops.erpset_apply.ForegroundColor = [1 1 1]; + ERPsets_waveviewer_box.TitleColor= [0.4940 0.1840 0.5560]; + ERPwaveview_erpsetops.erpset_cancel.BackgroundColor = [0.4940 0.1840 0.5560]; + ERPwaveview_erpsetops.erpset_cancel.ForegroundColor = [1 1 1]; end %%-------------------------------Help-------------------------------------- - function erpset_help(~,~) + function erpset_cancel(~,~) [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) && viewerpanelIndex~=1 viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - changeFlag = estudioworkingmemory('MyViewer_ERPsetpanel'); if changeFlag~=1 return; end MessageViewer= char(strcat('ERPsets > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n ERPsets > Cancel-f_ERPsets_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - ERPwaveview_erpsetops.butttons_datasets.Enable = 'on'; - ALLERPin = ERPwaviewer_apply.ALLERP; + ALLERPin = gui_erp_waviewer.ERPwaviewer.ALLERP; ERPdatasets = getERPDatasets(ALLERPin); % Get datasets from ALLERP - ERPdatasets = sortdata(ERPdatasets); dsnames = {}; - if size(ERPdatasets,1)==1 - if strcmp(ERPdatasets{1},'No ERPset loaded') - dsnames = {''}; - else - dsnames{1} = strcat(num2str(cell2mat(ERPdatasets(1,2))),'.',32,ERPdatasets{1,1}); - end - else - for Numofsub = 1:size(ERPdatasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); - end + for Numofsub = 1:size(ERPdatasets,1) + dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); end ds_length = size(ERPdatasets,1); - if ds_length<=2 - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length+1; - else - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length; - end + ERPwaveview_erpsetops.butttons_datasets.Max = ds_length+1; ERPwaveview_erpsetops.butttons_datasets.String = dsnames; - Selected_erpset = ERPwaviewer_apply.SelectERPIdx; - if min(Selected_erpset(:))<=0 || max(Selected_erpset(:)) > length(ALLERPin) - Selected_erpset = length(ALLERPin); - ERPwaviewer_apply.SelectERPIdx = Selected_erpset; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); - f_redrawERP_viewer_test();%%Plot the waves - end - ERPwaveview_erpsetops.butttons_datasets.Value = Selected_erpset; - + ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + if isempty(ERPArray)|| min(ERPArray(:))<=0 || any(ERPArray(:) > length(ALLERPin)) + ERPArray = length(ALLERPin); + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = ERPArray; + gui_erp_waviewer.ERPwaviewer.CURRENTERP = ERPArray; + gui_erp_waviewer.ERPwaviewer.ERP = gui_erp_waviewer.ERPwaviewer.ALLERP(ERPArray); + gui_erp_waviewer.ERPwaviewer.PageIndex=1; + ERPwaveview_erpsetops.butttons_datasets.Value = ERPArray; + viewer_ERPDAT.Count_currentERP = 2; + end + ERPwaveview_erpsetops.butttons_datasets.Value = ERPArray; estudioworkingmemory('MyViewer_ERPsetpanel',0); ERPwaveview_erpsetops.erpset_apply.BackgroundColor = [1 1 1]; ERPwaveview_erpsetops.erpset_apply.ForegroundColor = [0 0 0]; ERPsets_waveviewer_box.TitleColor= [0.5 0.5 0.9]; + ERPwaveview_erpsetops.erpset_cancel.BackgroundColor = [1 1 1]; + ERPwaveview_erpsetops.erpset_cancel.ForegroundColor = [0 0 0]; MessageViewer= char(strcat('ERPsets > Cancel')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -418,61 +240,31 @@ function ERPset_apply(~,~) end MessageViewer= char(strcat('ERPsets > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n ERPsets > Apply-f_ERPsets_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); - return; - end - if ERPwaveview_erpsetops.ERPLABFlag==1 - ERPwaviewer_apply.ALLERP = ERPwaveview_erpsetops.ALLERP; - ERPwaviewer_apply.ERP = ERPwaveview_erpsetops.ERP; - ERPwaviewer_apply.CURRENTERP= ERPwaveview_erpsetops.CURRENTERP; - ERPwaviewer_apply.SelectERPIdx= ERPwaveview_erpsetops.SelectERPIdx; - ERPwaviewer_apply.PageIndex= ERPwaveview_erpsetops.PageIndex; - ERPwaveview_erpsetops.ERPLABFlag=0; - end + ERPsetArray = ERPwaveview_erpsetops.butttons_datasets.Value; CurrentERP = ERPsetArray(1); - ALLERPIN = ERPwaviewer_apply.ALLERP; + ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; for Numofselectederp = 1:numel(ERPsetArray) SrateNum_mp(Numofselectederp,1) = ALLERPIN(ERPsetArray(Numofselectederp)).srate; end - ERPwaviewer_apply.CURRENTERP = CurrentERP; - ERPwaviewer_apply.ERP = ERPwaviewer_apply.ALLERP(CurrentERP); - ERPwaviewer_apply.SelectERPIdx = ERPsetArray; - ERPtooltype = erpgettoolversion('tooltype'); - if strcmpi(ERPtooltype,'EStudio') - Geterpbinchan = estudioworkingmemory('geterpbinchan'); - if ~isempty(Geterpbinchan) - CurrentERPIndex = Geterpbinchan.Select_index; - chan_bin = Geterpbinchan.bins_chans(CurrentERPIndex); - if chan_bin ==1 - ERPwaviewer_apply.plot_org.Grid =2; - ERPwaviewer_apply.plot_org.Overlay=1; - ERPwaviewer_apply.plot_org.Pages=3; - elseif chan_bin==0 - ERPwaviewer_apply.plot_org.Grid =1; - ERPwaviewer_apply.plot_org.Overlay=2; - ERPwaviewer_apply.plot_org.Pages=3; - end - end - %%% we may need to get the grid layout automatically - end + gui_erp_waviewer.ERPwaviewer.CURRENTERP = CurrentERP; + gui_erp_waviewer.ERPwaviewer.ERP = gui_erp_waviewer.ERPwaviewer.ALLERP(CurrentERP); + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = ERPwaveview_erpsetops.butttons_datasets.Value; estudioworkingmemory('MyViewer_ERPsetpanel',0); ERPwaveview_erpsetops.erpset_apply.BackgroundColor = [1 1 1]; ERPwaveview_erpsetops.erpset_apply.ForegroundColor = [0 0 0]; + ERPwaveview_erpsetops.erpset_cancel.BackgroundColor = [1 1 1]; + ERPwaveview_erpsetops.erpset_cancel.ForegroundColor = [0 0 0]; ERPsets_waveviewer_box.TitleColor= [0.5 0.5 0.9]; - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); - viewer_ERPDAT.Count_currentERP = viewer_ERPDAT.Count_currentERP+1; + + viewer_ERPDAT.Count_currentERP = 2; f_redrawERP_viewer_test();%%Plot the waves MessageViewer= char(strcat('ERPsets > Apply')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =2; end @@ -483,46 +275,33 @@ function loadproper_change(~,~) return; end try - ERPwaviewer_up = evalin('base','ALLERPwaviewer'); - SelectedIndex = ERPwaviewer_up.SelectERPIdx; - ALLERPup = ERPwaviewer_up.ALLERP; + SelectedIndex = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + ALLERPup = gui_erp_waviewer.ERPwaviewer.ALLERP; if isempty(ALLERPup) - beep; disp('f_ERPsets_waviewer_GUI()>loadproper_change() error: ALLERP is empty.'); return; end if max(SelectedIndex(:))> length(ALLERPup) SelectedIndex =length(ALLERPup); - ERPwaviewer_up.SelectERPIdx = SelectedIndex; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx = SelectedIndex; end catch - beep; disp('f_ERPsets_waviewer_GUI()>loadproper_change() error: Restart ERPwave Viewer'); return; end Enable_label = 'on'; ERPdatasets = getERPDatasets(ALLERPup); % Get datasets from ALLERP - ERPdatasets = sortdata(ERPdatasets); dsnames = {}; - if size(ERPdatasets,1)==1 - if strcmp(ERPdatasets{1},'No ERPset loaded') - dsnames = {''}; - else - dsnames{1} = strcat(num2str(cell2mat(ERPdatasets(1,2))),'.',32,ERPdatasets{1,1}); - end - else - for Numofsub = 1:size(ERPdatasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); - end + for Numofsub = 1:size(ERPdatasets,1) + dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); end ERPwaveview_erpsetops.butttons_datasets.Enable = Enable_label; ds_length = length(ERPdatasets); - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length; + ERPwaveview_erpsetops.butttons_datasets.Max = ds_length+1; ERPwaveview_erpsetops.butttons_datasets.String = dsnames; ERPwaveview_erpsetops.butttons_datasets.Value = SelectedIndex; - assignin('base','ALLERPwaviewer',ERPwaviewer_up); viewer_ERPDAT.loadproper_count=2; end @@ -544,6 +323,22 @@ function count_twopanels_change(~,~) ERPset_apply(); end +%----------------------Get the information of the updated ERPsets---------- + function ERPdatasets = getERPDatasets(ALLERP) + ERPdatasets = {}; + if isempty(ALLERP) + disp('f_ERPsets_waveviewer_GUI>getERPDatasets error: ALLERP is empty.'); + return; + end + for Numoferpset = 1:length(ALLERP) + ERPdatasets{Numoferpset,1} = ALLERP(Numoferpset).erpname; + ERPdatasets{Numoferpset,2} = Numoferpset; + ERPdatasets{Numoferpset,3} = 0; + ERPdatasets{Numoferpset,4} = ALLERP(Numoferpset).filename; + ERPdatasets{Numoferpset,5} = ALLERP(Numoferpset).filepath; + end + end + %%Reset this panel with the default parameters function Reset_Waviewer_panel_change(~,~) @@ -552,14 +347,17 @@ function Reset_Waviewer_panel_change(~,~) if strcmpi(ERPtooltype,'EStudio') || strcmpi(ERPtooltype,'ERPLAB') if strcmpi(ERPtooltype,'ERPLAB') try - Selected_erpset = evalin('base','CURRENTERP'); - CURRENTERPStudio = Selected_erpset; + ERPArray = evalin('base','CURRENTERP'); + CURRENTERPStudio = ERPArray; catch viewer_ERPDAT.Process_messg =3; fprintf(2,'\n ERPsets error: Cannot get CURRENTERP from Workspace.\n'); return; end estudioworkingmemory('PlotOrg_ERPLAB',1); + else + ERPArray= gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + CURRENTERPStudio = gui_erp_waviewer.ERPwaviewer.CURRENTERP; end try ALLERPin = evalin('base','ALLERP'); @@ -575,113 +373,75 @@ function Reset_Waviewer_panel_change(~,~) close(gui_erp_waviewer.Window); catch end - assignin('base','ALLERPwaviewer',[]); return; end - if strcmpi(ERPtooltype,'EStudio') - Selected_erpset= estudioworkingmemory('selectederpstudio'); - CURRENTERPStudio = observe_ERPDAT.CURRENTERP; - if length(ALLERPin)==1 && strcmpi(ALLERPin(1).erpname,'No ERPset loaded') - try - cprintf('red',['\n ERP Wave viewer will be closed because ALLERP is empty.\n\n']); - close(gui_erp_waviewer.Window); - catch - end - assignin('base','ALLERPwaviewer',[]); - return; - end - end - - if isempty(Selected_erpset) || Selected_erpset> length(ALLERPin) - Selected_erpset = length(ALLERPin); + if isempty(ERPArray) || any(ERPArray(:)> length(ALLERPin)) + ERPArray = length(ALLERPin); end - if isempty(CURRENTERPStudio) || CURRENTERPStudio> length(ALLERPin) + if isempty(CURRENTERPStudio) || any(CURRENTERPStudio> length(ALLERPin)) CURRENTERPStudio = length(ALLERPin); end - [x_index,y_index] = find(Selected_erpset==CURRENTERPStudio); + [x_index,y_index] = find(ERPArray==CURRENTERPStudio); if isempty(y_index) - y_index = numel(Selected_erpset); + y_index = numel(ERPArray); end - ERPwaveview_erpsetops.ALLERP = ALLERPin; ERPwaveview_erpsetops.ERP = ALLERPin(CURRENTERPStudio); ERPwaveview_erpsetops.CURRENTERP = CURRENTERPStudio; - ERPwaveview_erpsetops.SelectERPIdx = Selected_erpset; + ERPwaveview_erpsetops.SelectERPIdx = ERPArray; ERPwaveview_erpsetops.PageIndex = y_index; ERPwaveview_erpsetops.ERPLABFlag = 1; ERPdatasets = getERPDatasets(ALLERPin); % Get datasets from ALLERP - ERPdatasets = sortdata(ERPdatasets); dsnames = {}; - if size(ERPdatasets,1)==1 - if strcmp(ERPdatasets{1},'No ERPset loaded') - dsnames = {''}; - else - dsnames{1} = strcat(num2str(cell2mat(ERPdatasets(1,2))),'.',32,ERPdatasets{1,1}); - end - else - for Numofsub = 1:size(ERPdatasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); - end + for Numofsub = 1:size(ERPdatasets,1) + dsnames{Numofsub} = char(strcat(num2str(cell2mat(ERPdatasets(Numofsub,2))),'.',32,ERPdatasets{Numofsub,1})); end - ds_length = size(ERPdatasets,1); - if ds_length<=2 - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length+1; - else - ERPwaveview_erpsetops.butttons_datasets.Max = ds_length; - end + + ERPwaveview_erpsetops.butttons_datasets.Max = ds_length+1; ERPwaveview_erpsetops.butttons_datasets.String = dsnames; - ERPwaveview_erpsetops.butttons_datasets.Value = Selected_erpset; + ERPwaveview_erpsetops.butttons_datasets.Value = ERPArray; else ERPwaveview_erpsetops.auto.Value = 0; ERPwaveview_erpsetops.custom.Value =1; ERPwaveview_erpsetops.butttons_datasets.Enable = 'on'; ERPwaveview_erpsetops.auto.Enable = 'off'; end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - ERPwaviewer_apply = []; - end - ERPwaviewer_apply.ALLERP = ERPwaveview_erpsetops.ALLERP; - ERPwaviewer_apply.ERP = ERPwaveview_erpsetops.ERP; - ERPwaviewer_apply.CURRENTERP= ERPwaveview_erpsetops.CURRENTERP; - ERPwaviewer_apply.SelectERPIdx= ERPwaveview_erpsetops.SelectERPIdx; - ERPwaviewer_apply.PageIndex= ERPwaveview_erpsetops.PageIndex; - ERPwaviewer_apply.erp_binchan_op = ERPwaveview_erpsetops.auto.Value; + + gui_erp_waviewer.ERPwaviewer.ALLERP = ERPwaveview_erpsetops.ALLERP; + gui_erp_waviewer.ERPwaviewer.ERP = ERPwaveview_erpsetops.ERP; + gui_erp_waviewer.ERPwaviewer.CURRENTERP= ERPwaveview_erpsetops.CURRENTERP; + gui_erp_waviewer.ERPwaviewer.SelectERPIdx= ERPwaveview_erpsetops.SelectERPIdx; + gui_erp_waviewer.ERPwaviewer.PageIndex= ERPwaveview_erpsetops.PageIndex; ERPwaveview_erpsetops.erpset_apply.BackgroundColor = [1 1 1]; ERPwaveview_erpsetops.erpset_apply.ForegroundColor = [0 0 0]; ERPsets_waveviewer_box.TitleColor= [0.5 0.5 0.9]; - - assignin('base','ALLERPwaviewer',ERPwaviewer_apply); viewer_ERPDAT.Reset_Waviewer_panel=2; end end -%%change the ERPset indeces when they are changed in Plot organization panel - function ERPset_Chan_bin_label_change(~,~) - if viewer_ERPDAT.ERPset_Chan_bin_label~=1 %% 1 means ERPset indeces were changed - if viewer_ERPDAT.ERPset_Chan_bin_label==2%%Update Viewer based on the change in ERPLAB - erpselect_refresh(); - end - return; - end - try - ERPwaviewer_apply = evalin('base','ALLERPwaviewer'); - catch - viewer_ERPDAT.Process_messg =3; - fprintf(2,'\n ERPsets > f_ERPsets_waviewer_GUI() error: Cannot get parameters for whole panel.\n Please run My viewer again.\n\n'); +%%---------------------current ERPset change------------------------------- + function v_currentERP_change(~,~) + if viewer_ERPDAT.Count_currentERP~=1 return; end - ERPsetArray = ERPwaviewer_apply.SelectERPIdx; - if max(ERPsetArray(:)) <= length(ERPwaveview_erpsetops.butttons_datasets.String) + ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + if isempty(ERPsetArray) || any(ERPsetArray(:) > length(ERPwaveview_erpsetops.butttons_datasets.String)) + ERPsetArray = length(ERPwaveview_erpsetops.butttons_datasets.String); + ERPwaveview_erpsetops.butttons_datasets.Value = ERPsetArray; + gui_erp_waviewer.ERPwaviewer.CURRENTERP = ERPsetArray; + gui_erp_waviewer.ERPwaviewer.ERP = gui_erp_waviewer.ERPwaviewer.ALLERP(ERPsetArray); + gui_erp_waviewer.ERPwaviewer.PageIndex=1; ERPwaveview_erpsetops.butttons_datasets.Value = ERPsetArray; end + gui_erp_waviewer.ERPwaviewer.SelectERPIdx =ERPsetArray; + viewer_ERPDAT.Count_currentERP=2; + f_redrawERP_viewer_test(); end %%execute this panel when press "return" or "Enter" diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_MarkLabels_gridlocations_ERP_Waveiwer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_MarkLabels_gridlocations_ERP_Waveiwer.m old mode 100644 new mode 100755 index 6b636054..aacfdfe3 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_MarkLabels_gridlocations_ERP_Waveiwer.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_MarkLabels_gridlocations_ERP_Waveiwer.m @@ -1,23 +1,9 @@ function [LabelStrout] = f_MarkLabels_gridlocations_ERP_Waveiwer(Gridata,usedIndex,AllabelArray) -% usedIndex = zeros(length(AllabelArray),1); -% for jj = 1:length(AllabelArray) -% for ii = 1:length(LabelStr) -% if strcmp(AllabelArray{jj},LabelStr{ii}) -% usedIndex(jj) = 1; -% end -% end -% end LabelsFlag = [0 0 0]; for ii = 1:length(AllabelArray) code1 = 0; - % for jj = 1:size(Gridata,1) - % for kk = 1:size(Gridata,2) - % if strcmp(AllabelArray{ii},Gridata{jj,kk}) - % code1 = code1+1; - % end - % end - % end + [C,IA]=ismember(Gridata,AllabelArray{ii}); C = reshape(C,size(C,1)*size(C,2),1); Xpos =find(C==1); diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_check_erpviewerpanelchanges.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_check_erpviewerpanelchanges.m old mode 100644 new mode 100755 index d0b826a3..b9d3ae84 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_check_erpviewerpanelchanges.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_check_erpviewerpanelchanges.m @@ -12,40 +12,40 @@ MyViewer_chanbin = estudioworkingmemory('MyViewer_chanbin'); -if ~isempty(MyViewer_ERPset) && MyViewer_chanbin==1 +if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 messgStr = char( 'Changes on "Channels and Bins" have not been applied'); viewerpanelIndex =2; end MyViewer_xyaxis = estudioworkingmemory('MyViewer_xyaxis'); -if ~isempty(MyViewer_ERPset) && MyViewer_xyaxis==1 +if ~isempty(MyViewer_xyaxis) && MyViewer_xyaxis==1 messgStr = char( 'Changes on "Time and Amplitude Scales" have not been applied'); viewerpanelIndex =3; end MyViewer_plotorg = estudioworkingmemory('MyViewer_plotorg'); -if ~isempty(MyViewer_ERPset) && MyViewer_plotorg==1 +if ~isempty(MyViewer_plotorg) && MyViewer_plotorg==1 messgStr = char( 'Changes on "Plot Organization" have not been applied'); viewerpanelIndex =4; end MyViewer_labels = estudioworkingmemory('MyViewer_labels'); -if ~isempty(MyViewer_ERPset) && MyViewer_labels==1 +if ~isempty(MyViewer_labels) && MyViewer_labels==1 messgStr = char( 'Changes on "Chan/Bin/ERPset Labels" have not been applied'); viewerpanelIndex =5; end MyViewer_linelegend = estudioworkingmemory('MyViewer_linelegend'); -if ~isempty(MyViewer_ERPset) && MyViewer_linelegend==1 +if ~isempty(MyViewer_linelegend) && MyViewer_linelegend==1 messgStr = char( 'Changes on "Lines & legends" have not been applied'); viewerpanelIndex =6; end MyViewer_other = estudioworkingmemory('MyViewer_other'); -if ~isempty(MyViewer_ERPset) && MyViewer_other==1 +if ~isempty(MyViewer_other) && MyViewer_other==1 messgStr = char( 'Changes on "Other" have not been applied'); viewerpanelIndex =7; end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_checktable_gridlocations_waviewer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_checktable_gridlocations_waviewer.m old mode 100644 new mode 100755 diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_decimal.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_decimal.m old mode 100644 new mode 100755 diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_display_binstr_chanstr.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_display_binstr_chanstr.m new file mode 100755 index 00000000..175b847f --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_display_binstr_chanstr.m @@ -0,0 +1,121 @@ +% PURPOSE: f_display_binstr_chanstr.m +% display the names of channels and bins for the selected ERPsets + +% Inputs: +% +%ALLERP -ALLERPset +%ERPArray -index of the selected ERPset/bin/channel(e.g., [1 4]) +%diff_mark -has two elements, 0/1; 0 represents channels/bins are +% the same across the selected ERPsets. 1 is differ from +% the selected ERPsets. + + +% *** This function is part of EStudio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2023 July + + + + +function f_display_binstr_chanstr(ALLERP, ERPArray,diff_mark) +if nargin < 2 + help f_display_binstr_chanstr + return; +end +if numel(ERPArray)==1 + help f_display_binstr_chanstr + return; +end +if min(ERPArray(:))<=0 + beep; + disp('f_display_binstr_chanstr() error: Selected ERPsets should be positive values.') + return; +end +if min(ERPArray(:))> length(ALLERP) || max(ERPArray(:))> length(ALLERP) + beep; + disp('f_display_binstr_chanstr() error: Selected ERPsets exceed the length of ALLERP.') + return; +end +if isempty(diff_mark) + diff_mark = [0 0]; +end + +%%------------------------display names for channel------------------------ +if diff_mark(1)==1 + chanNameLength = 0; + + for Numoferpset = 1:length(ERPArray) + chanNum(Numoferpset) = ALLERP(ERPArray(Numoferpset)).nchan; + for ii = 1:ALLERP(ERPArray(Numoferpset)).nchan + if length(char(ALLERP(ERPArray(Numoferpset)).chanlocs(ii).labels))>chanNameLength + chanNameLength = length(char(ALLERP(ERPArray(Numoferpset)).chanlocs(ii).labels)); + end + end + end + + fprintf( ['\n',repmat('~',1,80) '\n']); + fprintf([repmat('~',1,17),'Channel names vary across the selected ERPsets',repmat('~',1,17) '\n']) + fprintf( [repmat('~',1,80) '\n']); + hdrdists = '\n'; + for jj = 1:length(ERPArray) + hdr{jj} = ['ERPset:',num2str(ERPArray(jj))]; + hdrdists =strcat(hdrdists,'%',num2str(chanNameLength),'s'); + end + fprintf( [hdrdists,'\n'], hdr{:}); + + for Numoflist = 1:max(chanNum(:)) + hdrdists = '\n'; + for jj = 1:length(ERPArray) + try + hdr{jj} = char(ALLERP(ERPArray(jj)).chanlocs(Numoflist).labels); + catch + hdr{jj} = ''; + end + hdrdists =strcat(hdrdists,'%',num2str(chanNameLength),'s'); + end + fprintf( [hdrdists,'\n'], hdr{:}); + end + fprintf( ['\n',repmat('~',1,80) '\n\n']); +end + + +%%-------------------display names for bin--------------------------------- +if diff_mark(2)==1 + binNameLength = 0; + for Numoferpset = 1:length(ERPArray) + binNum(Numoferpset) = ALLERP(ERPArray(Numoferpset)).nbin; + for ii = 1:ALLERP(ERPArray(Numoferpset)).nbin + if length(char(ALLERP(ERPArray(Numoferpset)).bindescr{ii}))>binNameLength + binNameLength = length(char(ALLERP(ERPArray(Numoferpset)).bindescr{ii})); + end + end + end + + fprintf( ['\n',repmat('~',1,80) '\n']); + fprintf([repmat('~',1,17),'Bin names vary across the selected ERPsets',repmat('~',1,17) '\n']) + fprintf( [repmat('~',1,80) '\n']); + hdrdists = '\n'; + for jj = 1:length(ERPArray) + hdr{jj} = ['ERPset:',num2str(ERPArray(jj))]; + hdrdists =strcat(hdrdists,'%',num2str(binNameLength),'s'); + end + fprintf( [hdrdists,'\n'], hdr{:}); + + for Numoflist = 1:max(binNum(:)) + hdrdists = '\n'; + for jj = 1:length(ERPArray) + try + hdr{jj} = char(ALLERP(ERPArray(jj)).bindescr{Numoflist}); + catch + hdr{jj} = ''; + end + hdrdists =strcat(hdrdists,'%',num2str(binNameLength),'s'); + end + fprintf( [hdrdists,'\n'], hdr{:}); + end + fprintf( ['\n',repmat('~',1,80) '\n\n']); +end +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_erpwave_viewer_update_parameter.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_erpwave_viewer_update_parameter.m old mode 100644 new mode 100755 diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpdata.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpdata.m index 3629e6d6..d5a1fa8e 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpdata.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpdata.m @@ -70,7 +70,7 @@ end if nargin<4|| (ERPselectIndex>length(ERPsetArray)) - ERPselectIndex =length(ERPsetArray); + ERPselectIndex =length(ERPsetArray); end % @@ -132,9 +132,9 @@ end if numel(unique(SrateNum_mp))>1 %%Check if the sampling rate is the same across the selected ERPsets, otherwise, the "ERPsets" will be fixed as "Pages". -% msgboxText = ['EStudio says: Sampling rate varies across the selected ERPsets, we therefore set "ERPsets" to be "Pages".']; -% title = 'EStudio: f_geterpdata().'; -% errorfound(msgboxText, title); + % msgboxText = ['EStudio says: Sampling rate varies across the selected ERPsets, we therefore set "ERPsets" to be "Pages".']; + % title = 'EStudio: f_geterpdata().'; + % errorfound(msgboxText, title); if orgpar(1)==1 && (orgpar(2) ==2 || orgpar(2) ==3) orgpar = [1 2 3]; elseif orgpar(1)==2 && (orgpar(2) ==1 || orgpar(2) ==3) @@ -151,7 +151,11 @@ %%Get the data acorss ERPsets for Numofselectederp = 1:numel(ERPsetArray) ERPdata(:,:,:,Numofselectederp) = ALLERP(ERPsetArray(Numofselectederp)).bindata; - errordata = ALLERP(ERPsetArray(Numofselectederp)).binerror; + if isequal(ALLERP(ERPsetArray(Numofselectederp)).bindata,ALLERP(ERPsetArray(Numofselectederp)).binerror) + errordata = ALLERP(ERPsetArray(Numofselectederp)).binerror; + else + errordata=[]; + end if ~isempty(errordata) ERPerrordata(:,:,:,Numofselectederp) =errordata; end @@ -180,7 +184,13 @@ EpochEnd = ERP_sg.times(end); [xxx, latsamp, latdiffms] = closest(Times, [EpochStart,EpochEnd]); ERPdata(1:ERP_sg.nchan,latsamp(1):latsamp(2),1:ERP_sg.nbin,Numofselectederp) = ERP_sg.bindata; - errordata = ERP_sg.binerror; + + if isequal(ERP_sg.bindataa,ERP_sg.binerror) + errordata = ERP_sg.binerror; + else + errordata=[]; + end + if ~isempty(errordata) ERPerrordata(1:ERP_sg.nchan,latsamp(1):latsamp(2),1:ERP_sg.nbin,Numofselectederp) =errordata; end @@ -192,12 +202,16 @@ ERPdata = nan(max(chanNum_mp),SampNum_mp(ERPselectIndex),max(BinNum_mp),numel(ERPsetArray)); ERPerrordata = nan(max(chanNum_mp),SampNum_mp(ERPselectIndex),max(BinNum_mp),numel(ERPsetArray)); - ERP_sg = ALLERP(ERPsetArray(ERPselectIndex));%%The information for individual subject - ERPdata(1:chanNum_mp(ERPselectIndex),:,1:BinNum_mp(ERPselectIndex),ERPselectIndex) = ERP_sg.bindata; + ERP_sg = ALLERP(ERPsetArray(ERPselectIndex));%%The information for individual subject + ERPdata(1:chanNum_mp(ERPselectIndex),:,1:BinNum_mp(ERPselectIndex),ERPselectIndex) = ERP_sg.bindata; + if isequal(ERP_sg.bindataa,ERP_sg.binerror) errordata = ERP_sg.binerror; - if ~isempty(errordata)%%Get the error data - ERPerrordata(1:chanNum_mp(ERPselectIndex),:,1:BinNum_mp(ERPselectIndex),ERPselectIndex) =errordata; - end + else + errordata=[]; + end + if ~isempty(errordata)%%Get the error data + ERPerrordata(1:chanNum_mp(ERPselectIndex),:,1:BinNum_mp(ERPselectIndex),ERPselectIndex) =errordata; + end end end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpschanbin.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpschanbin.m index cf07318d..d6126b18 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpschanbin.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_geterpschanbin.m @@ -25,10 +25,12 @@ -function [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERP,SelectedERPIndex) +function [chanStr,binStr,diff_mark,chanStremp,binStremp] = f_geterpschanbin(ALLERP,SelectedERPIndex) diff_mark = [0 0]; chanStr = []; binStr = []; +chanStremp = []; +binStremp = []; if nargin==0 beep; help f_geterpschanbin; @@ -92,6 +94,8 @@ chanStr(Numofchan) = {['Chan',num2str(Numofchan)]}; end end + chanStremp = chanStr; + binStremp = binStr; return; end @@ -122,7 +126,7 @@ for Numofchan = 1:length(Chanlist) chanStr(Numofchan) = {char(Chanlist(Numofchan).labels)}; end - + chanStremp = chanStr; elseif numel(unique(chanNum_mp))>1%%varies across the selected ERPsets [x_chan,y_chan] = find(chanNum_mp==max(chanNum_mp(:)));%% find the position of max. value @@ -162,10 +166,16 @@ clear ERP; end diff_mark(1) = 1; - chanStr = cell(length(chanStr_max),1); + chanStremp = cell(length(chanStr_max),1); for Numofchan = 1:length(chanStr_max) chanStr(Numofchan) = {char(chanStr_max(Numofchan))}; + chansig = char(chanStr_max(Numofchan)); + if strcmp(chansig(1:2),'**') + chanStremp(Numofchan) = {''}; + else + chanStremp(Numofchan) = {char(chanStr_max(Numofchan))}; + end end end @@ -184,7 +194,7 @@ binStr(Numofbin) = {['Bin',num2str(Numofbin)]}; end end - + binStremp = binStr; elseif numel(unique(BinNum_mp))>1%%varies across the selected ERPsets [x_bin,y_bin] = find(BinNum_mp==max(BinNum_mp));%% find the position of max. value @@ -227,8 +237,15 @@ end diff_mark(2) = 1; binStr = cell(length(binStr_max),1); + binStremp = cell(length(binStr_max),1); for Numofbin = 1:length(binStr_max) binStr(Numofbin) = {char(binStr_max(Numofbin))}; + binsg = char(binStr_max(Numofbin)); + if strcmp(binsg(1:2),'**') + binStremp(Numofbin) = {''}; + else + binStremp(Numofbin) = {char(binStr_max(Numofbin))}; + end end end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ploterpserpviewer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ploterpserpviewer.m index 54fe8ebd..e817912f 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ploterpserpviewer.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_ploterpserpviewer.m @@ -112,7 +112,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, qERPArray=length(ALLERP); end -[chanStrdef,binStrdef] = f_geterpschanbin(ALLERP,[1:length(ALLERP)]); +[chanStrdef,binStrdef,diff_mark] = f_geterpschanbin(ALLERP,qERPArray); if nargin<5 qchanArray = 1:length(chanStrdef); @@ -187,17 +187,23 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, if isempty(qPLOTORG) || numel(qPLOTORG)~=3 || numel(unique(qPLOTORG)) ~=3 || min(qPLOTORG)<0 || max(qPLOTORG)>3 qPLOTORG = [1 2 3]; end - +LegenddispFlag = 1; if qPLOTORG(2) ==1 %% if the selected Channel is "Grid" OverlayArraydef = qchanArray; for Numofchan = 1:numel(qchanArray) LegendNamedef{Numofchan,1} =char(chanStrdef(qchanArray(Numofchan))); end + if diff_mark(1)==1 + LegenddispFlag =0; + end elseif qPLOTORG(2) == 2 %% if the selected Bin is "Grid" OverlayArraydef = qbinArray; for Numofbin = 1:numel(qbinArray) LegendNamedef{Numofbin,1} = char(binStrdef(qbinArray(Numofbin))); end + if diff_mark(2)==1 + LegenddispFlag =0; + end elseif qPLOTORG(2) == 3%% if the selected ERPset is "Grid" OverlayArraydef = qERPArray; for Numoferpset = 1:numel(qERPArray) @@ -212,6 +218,9 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, for Numofbin = 1:numel(qbinArray) LegendNamedef{Numofbin,1} = char(binStr(qbinArray(Numofbin))); end + if diff_mark(2)==1 + LegenddispFlag =0; + end end LineColordef = [0 0 0;1 0 0;0 0 1;0 1 0;1,0.65 0;0 1 1;1 0 1;0.5 0.5 0.5;0.94 0.50 0.50;0 0.75 1;0.57 0.93 0.57;1 0.55 0;1 0.75 0.80;1 0.84 0];%% get from:https://htmlcolorcodes.com/color-names/ @@ -343,7 +352,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%ylable font if nargin <34 - qYlabelfont = 'Geneva'; + qYlabelfont = 'Helvetica'; end %%display ylabels? @@ -401,7 +410,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%xlabel font if nargin <26 - qXlabelfont= 'Geneva'; + qXlabelfont= 'Helvetica'; end %%disply xtick labels ? @@ -492,7 +501,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%font of channel/bin/erpset label if nargin <17 - qLabelfont= 'Geneva'; + qLabelfont= 'Helvetica'; end %%location of channel/bin/erpset label @@ -507,7 +516,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%font of legend name if nargin <14 - qLegendFont = 'Geneva'; + qLegendFont = 'Helvetica'; end %%legend name @@ -621,7 +630,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, qGridposArray(Numofrows,Numofcolumns) =0; else [xpos,ypos]= find(plotArray==SingleGridpos); - qGridposArray(Numofrows,Numofcolumns) =ypos; + qGridposArray(Numofrows,Numofcolumns) =plotArray(ypos); end end end @@ -650,11 +659,17 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, if ~strcmpi(qBlc,'no') && ~strcmpi(qBlc,'none')%% when the baseline correction is "pre","post","whole" if strcmpi(qBlc,'pre') - indxtimelock = find(ERP.times==0) ; % zero-time locked + [xxx, indxtimelock, latdiffms] = closest(ERP.times,0); % zero-time locked + if isempty(indxtimelock) + indxtimelock=1; + end aa = 1; elseif strcmpi(qBlc,'post') indxtimelock = length(ERP.times); - aa = find(ERP.times==0); + [xxx, aa, latdiffms] = closest(ERP.times,0);% zero-time locked + if isempty(aa) + aa=length(ERP.times);%%ned to further confirm + end elseif strcmpi(qBlc,'all') || strcmpi(qBlc,'whole') indxtimelock = length(ERP.times); aa = 1; @@ -700,8 +715,8 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, if qCURRENTPLOT> numel(qERPArray) qCURRENTPLOT= length(qERPArray); end - bindata = ERPdatadef(qchanArray,:,qbinArray,qCURRENTPLOT); - bindataerror = ERPerrordatadef(qchanArray,:,qbinArray,qCURRENTPLOT); + bindata = ERPdatadef(sort(qchanArray),:,qbinArray,qCURRENTPLOT); + bindataerror = ERPerrordatadef(sort(qchanArray),:,qbinArray,qCURRENTPLOT); % if isempty(timeRangedef) timeRangedef = ALLERPBls(qERPArray(qCURRENTPLOT)).times; % end @@ -716,9 +731,9 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, if qCURRENTPLOT> length(qERPArray) qCURRENTPLOT= length(qERPArray); end - bindata = ERPdatadef(qchanArray,:,qbinArray,qCURRENTPLOT); + bindata = ERPdatadef(sort(qchanArray),:,qbinArray,qCURRENTPLOT); bindata = permute(bindata,[3 2 1 4]); - bindataerror = ERPerrordatadef(qchanArray,:,qbinArray,qCURRENTPLOT); + bindataerror = ERPerrordatadef(sort(qchanArray),:,qbinArray,qCURRENTPLOT); bindataerror = permute(bindataerror,[3 2 1 4]); if isempty(timeRangedef) timeRangedef = ALLERPBls(qERPArray(qCURRENTPLOT)).times; @@ -749,9 +764,9 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, if qCURRENTPLOT> numel(qbinArray) qCURRENTPLOT = numel(qbinArray); end - bindata = ERPdatadef(qchanArray,:,qbinArray(qCURRENTPLOT),:); + bindata = ERPdatadef(sort(qchanArray),:,qbinArray(qCURRENTPLOT),:); bindata = permute(bindata,[4 2 1 3]); - bindataerror = ERPerrordatadef(qchanArray,:,qbinArray(qCURRENTPLOT),:); + bindataerror = ERPerrordatadef(sort(qchanArray),:,qbinArray(qCURRENTPLOT),:); bindataerror = permute(bindataerror,[4 2 1 3]); try fs= ALLERPBls(qERPArray(end)).srate; @@ -828,7 +843,13 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%get y axis -y_scale_def = [1.1*min(bindata(:)),1.1*max(bindata(:))]; +ERP1 = ERP; +ERP1.bindata = ERP.bindata(qERPArray,:,:); +[def, minydef, maxydef] = default_amp_ticks(ERP1, qbinArray); +minydef = floor(minydef); +maxydef = ceil(maxydef); +y_scale_def = [minydef,maxydef]; + yMaxdef = ceil(max(bindata(:)))-floor(min(bindata(:))); try isyaxislabel = qGridspace(1,1); @@ -838,8 +859,8 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, Ypert = 10; end -if isempty( qYScales) - qYScales = [floor(min(bindata(:))),ceil(max(bindata(:)))]; +if isempty( qYScales) || numel(qYScales)~=2 + qYScales = y_scale_def; end if isyaxislabel==1 %% y axis GAP @@ -853,9 +874,9 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, yscaleall = 2*max(abs(qYScales)); qYScales = [-max(abs(qYScales)),max(abs(qYScales))]; end - if yscaleall < y_scale_def(2)-y_scale_def(2) - yscaleall = y_scale_def(2)-y_scale_def(2); - end + % if yscaleall < y_scale_def(2)-y_scale_def(1) + % yscaleall = y_scale_def(2)-y_scale_def(1); + % end for Numofrows = 1:Numrows OffSetY(Numofrows) = yscaleall*(Numrows-Numofrows)*(Ypert/100+1); @@ -877,9 +898,9 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, qYScales = [-max(abs(qYScales)),max(abs(qYScales))]; end - if yscaleall < y_scale_def(2)-y_scale_def(2) - yscaleall = y_scale_def(2)-y_scale_def(2); - end + % if yscaleall < y_scale_def(2)-y_scale_def(1) + % yscaleall = y_scale_def(2)-y_scale_def(1); + % end if Numrows ==1 OffSetY = 0; @@ -890,7 +911,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, OffSetY(Numrows)=0; end else - qYScales = [ceil(max(bindata(:))), floor(min(bindata(:)))]; + qYScales = y_scale_def; if Numrows ==1 OffSetY = 0; else @@ -953,7 +974,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%Get the figure name which is to be plotted -if (qPLOTORG(1)==1 && qPLOTORG(2)==2) || (qPLOTORG(1)==1 && qPLOTORG(2)==2) %% Page is ERPset +if (qPLOTORG(1)==1 && qPLOTORG(2)==2) || (qPLOTORG(1)==2 && qPLOTORG(2)==1) %% Page is ERPset ERP = ALLERPBls(qCURRENTPLOT); if isempty(ERP.filename) || strcmp(ERP.filename,'') ERP.filename = 'still_not_saved!'; @@ -981,8 +1002,6 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, end extfig =''; [pathstrfig, qFigureName, extfig] = fileparts(qFigureName) ; - - if isempty(qFigureName) fig_gui= figure('Name',['<< ' fname ' >> '],... 'NumberTitle','on','color',qFigbgColor); @@ -1000,7 +1019,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, end try outerpos = fig_gui.OuterPosition; - set(fig_gui,'outerposition',[outerpos(1),(2),qFigOutpos(1) 1.05*qFigOutpos(2)]) + set(fig_gui,'outerposition',[1,1,qFigOutpos(1) 1.05*qFigOutpos(2)]) catch set(fig_gui,'outerposition',get(0,'screensize'));%%Maximum figure end @@ -1025,7 +1044,6 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, ax.Position = [left bottom ax_width ax_height]; - %%--------------Plot ERPwave----------------- stdalpha = qTransparency; countPlot = 0; @@ -1036,11 +1054,14 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, catch plotdatalabel = 0; end - - try - labelcbe = qplotArrayStr{plotdatalabel}; - catch - labelcbe = 'no'; + if (qPLOTORG(1)==1 && qPLOTORG(2)==2) ||(qPLOTORG(1)==2 && qPLOTORG(2)==1) + plotArray1 = sort(plotArray); + else + plotArray1 = plotArray; + end + [~,plotdatalabel] = find(plotArray1 == plotdatalabel); + if isempty(plotdatalabel) + plotdatalabel = 0; end try plotbindata = bindata(plotdatalabel,:,:,:); @@ -1050,6 +1071,14 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, if plotdatalabel ~=0 && plotdatalabel<= numel(plotArray) && ~isempty(plotbindata) countPlot =countPlot +1; + try + labelcbe = qplotArrayStr{countPlot}; + if isempty(labelcbe) + labelcbe = 'Label varies across ERPsets'; + end + catch + labelcbe = 'no'; + end if qPolarityWave data4plot = squeeze(bindata(plotdatalabel,:,:,1)); else @@ -1088,8 +1117,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, end hplot(Numofoverlay) = plot(hbig,Xtimerangetrasf, bindatatrs,'LineWidth',qLineWidthspec(Numofoverlay),... 'Color', qLineColorspec(Numofoverlay,:), 'LineStyle',qLineStylespec{Numofoverlay},'Marker',qLineMarkerspec{Numofoverlay}); - % qLegendName{Numofoverlay} = strrep(qLegendName{Numofoverlay},'_','\_'); % trick for dealing with '_'. JLC - % set(hplot(Numofoverlay),'DisplayName', qLegendName{Numofoverlay}); + end if numel(OffSetY)==1 && OffSetY==0 @@ -1107,7 +1135,7 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, ylimleftedge = -abs(ceil(y_scale_def(end))); ylimrightedge = ceil(abs(y_scale_def(1)))+OffSetY(1); end - set(hbig,'ylim',[ylimleftedge,ylimrightedge]); + set(hbig,'ylim',[ylimleftedge,1.05*ylimrightedge]); end @@ -1122,7 +1150,6 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, end props.YTickLabel = cell(numel(props.YTick),1); - for Numofytick = 1:numel(props.YTick) props.YTickLabel(Numofytick) = {num2str(props.YTick(Numofytick))}; end @@ -1248,7 +1275,6 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, end end - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%----------------------Adjust x axis------------------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1345,7 +1371,6 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, end end - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%------------------channel/bin/erpset label-----------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1410,45 +1435,57 @@ function f_ploterpserpviewer(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray, %%------------------------------legend name------------------------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% try - for Numofoverlay = 1:numel(hplot) - qLegendName{Numofoverlay} = strrep(qLegendName{Numofoverlay},'_','\_'); - LegendName{Numofoverlay} = char(strcat('\color[rgb]{',num2str(qLineColorspec(Numofoverlay,:)),'}',32,qLegendName{Numofoverlay})); - end - sh = subplot(ceil(Numrows*5)+1, 1, 1,'align'); - p = get(sh,'position'); - if qlegcolor ~=1 - try - h_legend = legend(sh,hplot,LegendName);%%,'Interpreter','none' - catch + if LegenddispFlag==1 + for Numofoverlay = 1:numel(hplot) + qLegendName{Numofoverlay} = strrep(qLegendName{Numofoverlay},'_','\_'); + LegendName{Numofoverlay} = char(strcat('\color[rgb]{',num2str(qLineColorspec(Numofoverlay,:)),'}',32,qLegendName{Numofoverlay})); + end + sh = subplot(ceil(Numrows*5)+1, 1, 1,'align'); + p = get(sh,'position'); + if qlegcolor ~=1 + try + h_legend = legend(sh,hplot,LegendName);%%,'Interpreter','none' + catch + h_legend = legend(sh,hplot,qLegendName); + end + else h_legend = legend(sh,hplot,qLegendName); end + set(h_legend,'FontSize',qLegendFontsize);%% legend name fontsize + set(h_legend,'FontName',qLegendFont);%%legend name font + set(h_legend, 'position', p); + set(h_legend,'NumColumns',qlegcolumns); + + %%increase height of the legend + HeightScaleFactor = 1; + NewHeight = h_legend.Position(4) * HeightScaleFactor; + h_legend.Position(2) = h_legend.Position(2) - (NewHeight - h_legend.Position(4)); + h_legend.Position(4) = NewHeight; + legend(sh,'boxoff'); + axis(sh,'off'); else - h_legend = legend(sh,hplot,qLegendName); + h_legend = subplot(ceil(Numrows*5)+1, 1, 1,'align'); + set(h_legend, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); + if qPLOTORG(2) ==1 + legendstr = char('The channel labels are not the same across the selected ERPsets, so no channel labels are shown.; If you want to see the channel labels, please select only one ERPset (or multiple ERPsets with matching channel labels).'); + else + legendstr = char('The bin labels are not the same across the selected ERPsets, so no bin labels are shown.; If you want to see the bin labels, please select only one ERPset (or multiple ERPsets with matching bin labels).'); + end + legendstr = regexp(legendstr, '\;', 'split'); + text(h_legend,0.5,0.8,legendstr ,... + 'FontSize',qLabelfontsize+2,'HorizontalAlignment', 'center', 'Color', [1 0 0]);%'FontWeight', 'bold', end - set(h_legend,'FontSize',qLegendFontsize);%% legend name fontsize - set(h_legend,'FontName',qLegendFont);%%legend name font - set(h_legend, 'position', p); - set(h_legend,'NumColumns',qlegcolumns); - - %%increase height of the legend - HeightScaleFactor = 1; - NewHeight = h_legend.Position(4) * HeightScaleFactor; - h_legend.Position(2) = h_legend.Position(2) - (NewHeight - h_legend.Position(4)); - h_legend.Position(4) = NewHeight; - - legend(sh,'boxoff'); - axis(sh,'off'); catch beep; disp('Cannot display the legend names, please check "qGridposArray" or other parameters!'); end set(gcf,'color',qFigbgColor); -prePaperType = get(fig_gui,'PaperType'); -prePaperUnits = get(fig_gui,'PaperUnits'); -preUnits = get(fig_gui,'Units'); -prePaperPosition = get(fig_gui,'PaperPosition'); -prePaperSize = get(fig_gui,'PaperSize'); +% prePaperType = get(fig_gui,'PaperType'); +% prePaperUnits = get(fig_gui,'PaperUnits'); +% preUnits = get(fig_gui,'Units'); +% prePaperPosition = get(fig_gui,'PaperPosition'); +% prePaperSize = get(fig_gui,'PaperSize'); % Make changing paper type possible set(fig_gui,'PaperType',''); diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_preparms_erpwaviewer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_preparms_erpwaviewer.m index 852fb9f0..1115a572 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_preparms_erpwaviewer.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_preparms_erpwaviewer.m @@ -19,59 +19,48 @@ if nargin<2 History = 'gui'; end -try - ALLERPwaviewerin = evalin('base','ALLERPwaviewer'); - ERPwaviewerIN = ALLERPwaviewerin; -catch - beep; - disp('f_preparms_erpwaviewer() error: There is no "ALLERPwaviewer" on Workspace, please run the ERP wave viewer again.'); - return; -end +global gui_erp_waviewer; -ALLERPIN = ERPwaviewerIN.ALLERP; -ERPIN= ERPwaviewerIN.ERP; -CURRENTERPIN = ERPwaviewerIN.CURRENTERP; + +ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; +ERPIN= gui_erp_waviewer.ERPwaviewer.ERP; +CURRENTERPIN = gui_erp_waviewer.ERPwaviewer.CURRENTERP; if isempty(CURRENTERPIN) || CURRENTERPIN > length(ALLERPIN) %%checking index of current erpset CURRENTERPIN =length(ALLERPIN); end %%checking the indices of the selected ERPsets -ERPsetArray = ERPwaviewerIN.SelectERPIdx; +ERPsetArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; if max(ERPsetArray) >length(ALLERPIN) ERPsetArray =length(ALLERPIN); end % %%bin array and channel array -binArray = ERPwaviewerIN.bin; -chanArray = ERPwaviewerIN.chan; +binArray = gui_erp_waviewer.ERPwaviewer.bin; +chanArray = gui_erp_waviewer.ERPwaviewer.chan; PLOTORG =[1 2 3];%%The default parameters for plotting organization %%The first element is for Grid; the second one is for Overlay; The last one is for Pages. try - PLOTORG(1) = ERPwaviewerIN.plot_org.Grid ; - PLOTORG(2) = ERPwaviewerIN.plot_org.Overlay; - PLOTORG(3) = ERPwaviewerIN.plot_org.Pages; + PLOTORG(1) = gui_erp_waviewer.ERPwaviewer.plot_org.Grid ; + PLOTORG(2) = gui_erp_waviewer.ERPwaviewer.plot_org.Overlay; + PLOTORG(3) = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; catch PLOTORG = [1 2 3]; %%"Channels" is Grid; "Bins" is Overlay; "ERPsets" is Pages. end -GridLayoutop =1;%% need to further edit after discussed with Steve -try - GridLayoutop = ERPwaviewerIN.plot_org.gridlayout.op ; -catch - GridLayoutop =1; -end +[chanStr,binStr,diff_mark,chanStremp,binStremp] = f_geterpschanbin(ALLERPIN,ERPsetArray); + -[chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPsetArray); plotArrayStrdef =''; plotArray = []; if PLOTORG(1) ==1 %% if the selected Channel is "Grid" plotArray = chanArray; for Numofchan = 1:numel(chanArray) try - plotArrayStrdef{Numofchan} = chanStr{plotArray(Numofchan)}; + plotArrayStrdef{Numofchan} = chanStremp{plotArray(Numofchan)}; catch plotArrayStrdef{Numofchan} = ''; end @@ -80,7 +69,7 @@ plotArray = binArray; for Numofchan = 1:numel(plotArray) try - plotArrayStrdef{Numofchan} = binStr{plotArray(Numofchan)}; + plotArrayStrdef{Numofchan} = binStremp{plotArray(Numofchan)}; catch plotArrayStrdef{Numofchan} = ' '; end @@ -96,19 +85,13 @@ end end GridLayoutop=0; -try - plotArrayStr = ERPwaviewerIN.plot_org.gridlayout.columFormat; -catch - plotArrayStr = ''; -end -if isempty(plotArrayStr) - plotArrayStr = plotArrayStrdef; -end +LabelsName = plotArrayStrdef; % %%Getting the specific setting of each position for Grid plotBox = f_getrow_columnautowaveplot(plotArray);%% the first element is number of rows and the second element is the number of columns GridposArray = []; +LabelsdiffFlag = 0; if GridLayoutop==1 count = 0; for Numofrow = 1:plotBox(1) %%organization of Grid @@ -123,10 +106,10 @@ end elseif GridLayoutop==0 try %%try to use the user defined parameters for "Grid" - plotBox(1) = ERPwaviewerIN.plot_org.gridlayout.rows; - plotBox(2) = ERPwaviewerIN.plot_org.gridlayout.columns; - columFormat = ERPwaviewerIN.plot_org.gridlayout.columFormat; - DataDf = ERPwaviewerIN.plot_org.gridlayout.data; + plotBox(1) = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rows; + plotBox(2) = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columns; + columFormat = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columFormat; + DataDf = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.data; for Numofrows = 1:plotBox(1) for Numofcolumns = 1:plotBox(2) SingleStr = char(DataDf{Numofrows,Numofcolumns}); @@ -135,11 +118,16 @@ if IA <= length(columFormat) try GridposArray(Numofrows,Numofcolumns) = plotArray(IA); + try + if isempty(plotArrayStrdef{IA}) + LabelsdiffFlag =1; + end + catch + end + catch GridposArray(Numofrows,Numofcolumns) =0; end - % elseif IA == length(columFormat) %%%If the element is 'None' - % GridposArray(Numofrows,Numofcolumns) = 0; end else GridposArray(Numofrows,Numofcolumns) = 0; @@ -163,7 +151,7 @@ % %%---------------line color, line style, line marker,linewidth------------- -LegendName = {''}; +LegendName = {''};%%legend name will be automatically changed if PLOTORG(2) ==1 %% if the selected Channel is "Grid" OverlayArray = chanArray; for Numofchan = 1:numel(chanArray) @@ -210,8 +198,8 @@ LineMarkerspec = cell(1,numel(OverlayArray)); LineWidthspec = ones(1,numel(OverlayArray)); try - LineData = ERPwaviewerIN.Lines.data; - if ERPwaviewerIN.Lines.auto + LineData = gui_erp_waviewer.ERPwaviewer.Lines.data; + if gui_erp_waviewer.ERPwaviewer.Lines.auto LineDataColor = linecolorsrgb; else for ii = 1:size(LineData,1) @@ -292,36 +280,34 @@ TextcolorLeg = 1; Legcolumns = 1; try - for NumofOverlay =1:numel(OverlayArray) - LegendName{NumofOverlay} = char(ERPwaviewerIN.Legend.data{NumofOverlay,2}); - end - FontLegValue = ERPwaviewerIN.Legend.font; +% for NumofOverlay =1:numel(OverlayArray) +% LegendName{NumofOverlay} = char(gui_erp_waviewer.ERPwaviewer.Legend.data{NumofOverlay,2}); +% end + FontLegValue = gui_erp_waviewer.ERPwaviewer.Legend.font; FontLeg = fonttype{FontLegValue}; - FontSizeLeg = ERPwaviewerIN.Legend.fontsize; - TextcolorLeg = ERPwaviewerIN.Legend.textcolor; - Legcolumns = ERPwaviewerIN.Legend.columns; + FontSizeLeg = gui_erp_waviewer.ERPwaviewer.Legend.fontsize; + TextcolorLeg = gui_erp_waviewer.ERPwaviewer.Legend.textcolor; + Legcolumns = gui_erp_waviewer.ERPwaviewer.Legend.columns; catch end - - % %%--------------Chan/Bin/ERPset Labels, font, and fontsize----------------- CBELabels = [50 100 1]; CBEFont = 'Helvetica'; CBEFontsize=10; try - if ERPwaviewerIN.chanbinsetlabel.location.no ==1 + if gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.no ==1 CBELabels = []; CBEFont = ''; CBEFontsize=[]; - elseif ERPwaviewerIN.chanbinsetlabel.location.custom==1 - CBELabels(1) = ERPwaviewerIN.chanbinsetlabel.location.xperc; - CBELabels(2) = ERPwaviewerIN.chanbinsetlabel.location.yperc; - CBELabels(3) = ERPwaviewerIN.chanbinsetlabel.location.center; - FontlabelValue = ERPwaviewerIN.chanbinsetlabel.font; + elseif gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.custom==1 + CBELabels(1) = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.xperc; + CBELabels(2) = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.yperc; + CBELabels(3) = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.location.center; + FontlabelValue = gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.font; CBEFont = fonttype{FontlabelValue}; - CBEFontsize=ERPwaviewerIN.chanbinsetlabel.fontsize; + CBEFontsize=gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.fontsize; end catch @@ -330,7 +316,7 @@ %%label textcolor CBETcolor = [0 0 0]; try - xlabelFontcolorValue =ERPwaviewerIN.chanbinsetlabel.textcolor; + xlabelFontcolorValue =gui_erp_waviewer.ERPwaviewer.chanbinsetlabel.textcolor; switch xlabelFontcolorValue case 1 CBETcolor = [0 0 0];%% black @@ -352,14 +338,11 @@ catch end - - - % %%-----------------------------Polarity------------------------------------ PolarityWave = 1; try - PolarityWave = ERPwaviewerIN.polarity; + PolarityWave = gui_erp_waviewer.ERPwaviewer.polarity; catch end @@ -367,7 +350,7 @@ %%-----------------------------standard error------------------------------ Standerr = 0; try - StanderrValue = ERPwaviewerIN.SEM.error; + StanderrValue = gui_erp_waviewer.ERPwaviewer.SEM.error; if ~isnumeric(StanderrValue) || isempty(StanderrValue) Standerr = 0; else @@ -375,7 +358,7 @@ end catch end -if ERPwaviewerIN.SEM.active==0 +if gui_erp_waviewer.ERPwaviewer.SEM.active==0 Standerr = 0; else if Standerr<=0 @@ -386,7 +369,7 @@ %%-------------------------------Transparency------------------------------ Transparency = 0; try - TransparencyValue = ERPwaviewerIN.SEM.trans; + TransparencyValue = gui_erp_waviewer.ERPwaviewer.SEM.trans; if ~isnumeric(TransparencyValue) || isempty(TransparencyValue) Transparency = 0; else @@ -395,7 +378,7 @@ catch end -if ERPwaviewerIN.SEM.active==0 +if gui_erp_waviewer.ERPwaviewer.SEM.active==0 Transparency = 0; else @@ -408,37 +391,37 @@ %%------------------------------Grid space--------------------------------- Gridspace = [1 10;1 10]; try - Layoutop = ERPwaviewerIN.plot_org.gridlayout.op; + Layoutop = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.op; if Layoutop~=1 %%for rows - rowgapop = ERPwaviewerIN.plot_org.gridlayout.rowgap.GTPOP; + rowgapop = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPOP; if rowgapop%%gap Gridspace(1,1) = 1; - rowgapValue = ERPwaviewerIN.plot_org.gridlayout.rowgap.GTPValue; + rowgapValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.GTPValue; if isempty(rowgapValue) || numel(rowgapValue)~=1 || rowgapValue<=0 rowgapValue = 10; end Gridspace(1,2) = rowgapValue; else%%overlay Gridspace(1,1) = 2; - rowoverlayValue = ERPwaviewerIN.plot_org.gridlayout.rowgap.OverlayValue; + rowoverlayValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.rowgap.OverlayValue; if isempty(rowoverlayValue) || numel(rowoverlayValue)~=1 || rowoverlayValue<=0 || rowoverlayValue>100 rowoverlayValue = 40; end Gridspace(1,2) = rowoverlayValue; end %%for columns - columngapop = ERPwaviewerIN.plot_org.gridlayout.columngap.GTPOP; + columngapop = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPOP; if columngapop%%gap Gridspace(2,1) = 1; - columngapValue = ERPwaviewerIN.plot_org.gridlayout.columngap.GTPValue; + columngapValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.GTPValue; if isempty(columngapValue) || numel(columngapValue)~=1 || columngapValue<=0 columngapValue = 10; end Gridspace(2,2) = columngapValue; else%% overlay Gridspace(2,1) = 2; - columnoverlayValue = ERPwaviewerIN.plot_org.gridlayout.columngap.OverlayValue; + columnoverlayValue = gui_erp_waviewer.ERPwaviewer.plot_org.gridlayout.columngap.OverlayValue; if isempty(columnoverlayValue) || numel(columnoverlayValue)~=1 || columnoverlayValue<=0 || columnoverlayValue>100 columnoverlayValue = 20; end @@ -453,7 +436,7 @@ %%-----------------------------Baseline correction------------------------- Blc = 'none'; try - Blc = ERPwaviewerIN.baselinecorr; + Blc = gui_erp_waviewer.ERPwaviewer.baselinecorr; catch end @@ -461,12 +444,12 @@ %%---------------------------------x axis---------------------------------- timeRange = [];%%time range is used to plot the wave(s) try - timeRange = ERPwaviewerIN.xaxis.timerange; + timeRange = gui_erp_waviewer.ERPwaviewer.xaxis.timerange; catch end timeticks = []; try - timeticks = ERPwaviewerIN.xaxis.timeticks; + timeticks = gui_erp_waviewer.ERPwaviewer.xaxis.timeticks; catch end if ~isempty(timeRange) && ~isempty(timeticks) %%check xticks @@ -485,7 +468,7 @@ end xticklabel = 'on'; try - xticklabelValue = ERPwaviewerIN.xaxis.label; + xticklabelValue = gui_erp_waviewer.ERPwaviewer.xaxis.label; if xticklabelValue==0 xticklabel = 'off'; else @@ -496,7 +479,7 @@ xlabelFont = 'Helvetica'; try - xFontlabelValue = ERPwaviewerIN.xaxis.font; + xFontlabelValue = gui_erp_waviewer.ERPwaviewer.xaxis.font; xlabelFont = fonttype{xFontlabelValue}; catch end @@ -504,13 +487,13 @@ xlabelFontsize = 10; try - xlabelFontsize =ERPwaviewerIN.xaxis.fontsize; + xlabelFontsize =gui_erp_waviewer.ERPwaviewer.xaxis.fontsize; catch end xlabelFontcolor = [0 0 0]; try - xlabelFontcolorValue =ERPwaviewerIN.xaxis.fontcolor; + xlabelFontcolorValue =gui_erp_waviewer.ERPwaviewer.xaxis.fontcolor; switch xlabelFontcolorValue case 1 xlabelFontcolor = [0 0 0];%% black @@ -533,7 +516,7 @@ end Xunits = 'on'; try - XunitsValue = ERPwaviewerIN.xaxis.units; + XunitsValue = gui_erp_waviewer.ERPwaviewer.xaxis.units; if XunitsValue==1 Xunits = 'on'; else @@ -545,8 +528,8 @@ %%Minorticks for x axis try - MinorticksX(1) = ERPwaviewerIN.xaxis.tminor.disp; - MinorticksX(2:numel(ERPwaviewerIN.xaxis.tminor.step)+1) = ERPwaviewerIN.xaxis.tminor.step; + MinorticksX(1) = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.disp; + MinorticksX(2:numel(gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step)+1) = gui_erp_waviewer.ERPwaviewer.xaxis.tminor.step; catch MinorticksX = [0];%% off end @@ -554,7 +537,7 @@ %%Decimals for x ticklabels Xtickprecision = 0; try - Xtickprecision= ERPwaviewerIN.xaxis.tickdecimals; + Xtickprecision= gui_erp_waviewer.ERPwaviewer.xaxis.tickdecimals; catch Xtickprecision = 0; end @@ -566,19 +549,19 @@ %%display x ticks with millisecond or second? XdispFlag = 1;%% in millisecond try - XdispFlag = ERPwaviewerIN.xaxis.tdis; + XdispFlag = gui_erp_waviewer.ERPwaviewer.xaxis.tdis; catch end %%%--------------------------------y axis---------------------------------- Yscales = []; try - Yscales = ERPwaviewerIN.yaxis.scales ; + Yscales = gui_erp_waviewer.ERPwaviewer.yaxis.scales ; catch end Yticks = []; try - Yticks = ERPwaviewerIN.yaxis.ticks; + Yticks = gui_erp_waviewer.ERPwaviewer.yaxis.ticks; catch end if ~isempty(Yscales) && ~isempty(Yticks) %%check Yticks @@ -598,7 +581,7 @@ yticklabel = 'on'; try - yticklabelValue = ERPwaviewerIN.yaxis.label; + yticklabelValue = gui_erp_waviewer.ERPwaviewer.yaxis.label; if yticklabelValue==0 yticklabel = 'off'; else @@ -609,20 +592,20 @@ YlabelFont = 'Helvetica'; try - YFontlabelValue = ERPwaviewerIN.yaxis.font; + YFontlabelValue = gui_erp_waviewer.ERPwaviewer.yaxis.font; YlabelFont = fonttype{YFontlabelValue}; catch end YlabelFontsize = 12; try - YlabelFontsize =ERPwaviewerIN.yaxis.fontsize; + YlabelFontsize =gui_erp_waviewer.ERPwaviewer.yaxis.fontsize; catch end ylabelFontcolor = [0 0 0]; try - ylabelFontcolorValue =ERPwaviewerIN.yaxis.fontcolor; + ylabelFontcolorValue =gui_erp_waviewer.ERPwaviewer.yaxis.fontcolor; switch ylabelFontcolorValue case 1 ylabelFontcolor = [0 0 0];%% black @@ -646,7 +629,7 @@ yunits = 'on'; try - yunitsValue = ERPwaviewerIN.yaxis.units; + yunitsValue = gui_erp_waviewer.ERPwaviewer.yaxis.units; if yunitsValue==1 yunits = 'on'; else @@ -658,7 +641,7 @@ Ytickprecision = 1; try - Ytickprecision = ERPwaviewerIN.yaxis.tickdecimals; + Ytickprecision = gui_erp_waviewer.ERPwaviewer.yaxis.tickdecimals; catch Ytickprecision = 1; end @@ -666,8 +649,8 @@ %%Minorticks for y axis try - MinorticksY(1) = ERPwaviewerIN.yaxis.yminor.disp; - MinorticksY(2:numel(ERPwaviewerIN.yaxis.yminor.step)+1) = ERPwaviewerIN.yaxis.yminor.step; + MinorticksY(1) = gui_erp_waviewer.ERPwaviewer.yaxis.yminor.disp; + MinorticksY(2:numel(gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step)+1) = gui_erp_waviewer.ERPwaviewer.yaxis.yminor.step; catch MinorticksY = [0];%% off end @@ -677,7 +660,7 @@ %%Background color of figure figbgdColor = [1 1 1]; try - figbgdColor = ERPwaviewerIN.figbackgdcolor; + figbgdColor = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; catch figbgdColor = [1 1 1]; end @@ -687,16 +670,10 @@ end -PagesIndex = ERPwaviewerIN.PageIndex; +PagesIndex = gui_erp_waviewer.ERPwaviewer.PageIndex; if isempty(PagesIndex) PagesIndex=1; end -plotArrayStr_tr =''; -for ii = 1:length(plotArrayStr) - plotArrayStr_tr{ii} = plotArrayStr{ii}; -end -plotArrayStr = ''; -plotArrayStr = plotArrayStr_tr; try ScreenPos = get( groot, 'Screensize' ); @@ -705,7 +682,7 @@ end FigOutpos = []; try - FigOutpos=ERPwaviewerIN.FigOutpos; + FigOutpos=gui_erp_waviewer.ERPwaviewer.FigOutpos; FigOutpos = [ScreenPos(3)*FigOutpos(1)/100,ScreenPos(4)*FigOutpos(2)/100]; catch FigOutpos = ScreenPos(3:4)*3/4; @@ -715,7 +692,7 @@ %%Main function if ~isempty(FigureName) [ALLERP, erpcom] = pop_plotERPwaviewer(ALLERPIN,PagesIndex,ERPsetArray, binArray, chanArray,... - 'PLOTORG',PLOTORG,'GridposArray',GridposArray,'LabelsName',plotArrayStr, 'Blc', Blc,'Box',plotBox,'LineColor',LineColorspec,'LineStyle',LineStylespec,... + 'PLOTORG',PLOTORG,'GridposArray',GridposArray,'LabelsName',LabelsName, 'Blc', Blc,'Box',plotBox,'LineColor',LineColorspec,'LineStyle',LineStylespec,... 'LineMarker',LineMarkerspec,'LineWidth',LineWidthspec,'LegendName',LegendName,'LegendFont',FontLeg,'LegendFontsize',FontSizeLeg,... 'Labeloc',CBELabels,'Labelfont',CBEFont,'Labelfontsize',CBEFontsize,'YDir',PolarityWave,'SEM',Standerr,'Transparency', Transparency,... 'GridSpace',Gridspace,'TimeRange',timeRange,'Xticks',timeticks,'Xticklabel',xticklabel,'Xlabelfont',xlabelFont,'Xlabelfontsize',xlabelFontsize,... @@ -731,7 +708,7 @@ OutputViewerpar{4} = binArray; OutputViewerpar{5} = chanArray; OutputViewerpar{6} = GridposArray; - OutputViewerpar{7} = plotArrayStr; + OutputViewerpar{7} = LabelsName; OutputViewerpar{8} = Blc; OutputViewerpar{9} = plotBox; OutputViewerpar{10} = LineColorspec; @@ -772,6 +749,7 @@ OutputViewerpar{45} = Ytickprecision; OutputViewerpar{46} = Xtickprecision; OutputViewerpar{47} = XdispFlag; + OutputViewerpar{48} =LabelsdiffFlag; end end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_redrawERP_viewer_test.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_redrawERP_viewer_test.m index 721dd323..d48888a6 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_redrawERP_viewer_test.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_redrawERP_viewer_test.m @@ -1,15 +1,11 @@ %PURPOSE : Plot EPR waves within one axes - - % Author: Guanghui Zhang & Steve J. Luck % Center for Mind and Brain % University of California, Davis % Davis, CA % 2022 & 2023 - - function f_redrawERP_viewer_test() global viewer_ERPDAT; @@ -22,14 +18,6 @@ function f_redrawERP_viewer_test() return; end -try - ALLERPwaviewer = evalin('base','ALLERPwaviewer'); - ERPwaviewer = ALLERPwaviewer; -catch - beep; - disp('Please re-run ERP wave viewer.'); - return; -end %%save figure size:width and height try @@ -40,8 +28,8 @@ function f_redrawERP_viewer_test() FigOutposition = gui_erp_waviewer.ViewBox.OuterPosition(3:4); FigOutposition(1) = 100*FigOutposition(1)/ScreenPos(3); FigOutposition(2) = 100*FigOutposition(2)/ScreenPos(4); -ERPwaviewer.FigOutpos=FigOutposition; -assignin('base','ALLERPwaviewer',ERPwaviewer); +gui_erp_waviewer.ERPwaviewer.FigOutpos=FigOutposition; + try gui_erp_waviewer.ScrollVerticalOffsets = gui_erp_waviewer.ViewAxes.VerticalOffsets/gui_erp_waviewer.ViewAxes.Heights; gui_erp_waviewer.ScrollHorizontalOffsets = gui_erp_waviewer.ViewAxes.HorizontalOffsets/gui_erp_waviewer.ViewAxes.Widths; @@ -67,19 +55,19 @@ function f_redrawERP_viewer_test() Res = Pix_SS./Inch_SS; %%background color of figure -figbgdColor = ERPwaviewer.figbackgdcolor; +figbgdColor = gui_erp_waviewer.ERPwaviewer.figbackgdcolor; if ~isnumeric(figbgdColor) || isempty(figbgdColor) || numel(figbgdColor)~=3 || max(figbgdColor)>1 || min(figbgdColor)<0 figbgdColor =[1 1 1]; end zoomSpace = estudioworkingmemory('zoomSpace'); if isempty(zoomSpace) - zoomSpace = 0; + zoomSpace = 100; else - if zoomSpace<0 - zoomSpace =0; + if zoomSpace<100 + zoomSpace =100; end end -if zoomSpace ==0 +if zoomSpace ==100 gui_erp_waviewer.ScrollVerticalOffsets=0; gui_erp_waviewer.ScrollHorizontalOffsets=0; end @@ -95,12 +83,12 @@ function f_redrawERP_viewer_test() %%determine the page number -pagecurrentNum = ERPwaviewer.PageIndex; -pagesValue = ERPwaviewer.plot_org.Pages; -ERPArray = ERPwaviewer.SelectERPIdx; -chanArray =ERPwaviewer.chan; -binArray = ERPwaviewer.bin; -ALLERPIN = ERPwaviewer.ALLERP; +pagecurrentNum = gui_erp_waviewer.ERPwaviewer.PageIndex; +pagesValue = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; +ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; +chanArray =gui_erp_waviewer.ERPwaviewer.chan; +binArray = gui_erp_waviewer.ERPwaviewer.bin; +ALLERPIN = gui_erp_waviewer.ERPwaviewer.ALLERP; [chanStr,binStr,diff_mark] = f_geterpschanbin(ALLERPIN,ERPArray); if pagesValue==1 pageNum = numel(chanArray); @@ -118,8 +106,7 @@ function f_redrawERP_viewer_test() if pagecurrentNum>pageNum pagecurrentNum =1; - ERPwaviewer.PageIndex =1; - assignin('base','ALLERPwaviewer',ERPwaviewer); + gui_erp_waviewer.ERPwaviewer.PageIndex =1; end gui_erp_waviewer.plotgrid = uix.VBox('Parent',gui_erp_waviewer.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorBviewer_def); @@ -130,25 +117,18 @@ function f_redrawERP_viewer_test() uicontrol('Parent',gui_erp_waviewer.erpwaviewer_legend_title,'Style','text','String','','FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorBviewer_def); gui_erp_waviewer.erpwaviewer_legend = uix.ScrollingPanel( 'Parent', gui_erp_waviewer.erpwaviewer_legend_title,'BackgroundColor',figbgdColor); - - gui_erp_waviewer.plot_wav_legend = uiextras.HBox( 'Parent', gui_erp_waviewer.plotgrid,'BackgroundColor',ColorBviewer_def); -% gui_erp_waviewer.ViewAxes_legend = uix.ScrollingPanel( 'Parent', gui_erp_waviewer.plot_wav_legend,'BackgroundColor',ColorBviewer_def); - uicontrol('Parent',gui_erp_waviewer.plot_wav_legend,'Style','text','String','','FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorBviewer_def); -% gui_erp_waviewer.Resize = 0; - - -% gui_erp_waviewer.ViewAxes = uix.ScrollingPanel( 'Parent', gui_erp_waviewer.plot_wav_legend,'BackgroundColor',figbgdColor,'SizeChangedFcn',@WAviewerResize);% gui_erp_waviewer.ViewAxes = uix.ScrollingPanel( 'Parent', gui_erp_waviewer.plot_wav_legend,'BackgroundColor',figbgdColor); +gui_erp_waviewer.blank_title = uiextras.HBox( 'Parent', gui_erp_waviewer.plotgrid,'BackgroundColor',ColorBviewer_def);%%%Message +uicontrol('Parent',gui_erp_waviewer.blank_title,'Style','text','String','','FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); + -%%Changed by Guanghui Zhang Dec. 2022-------panel for display the processing procedure for some functions, e.g., filtering gui_erp_waviewer.zoomin_out_title = uiextras.HBox( 'Parent', gui_erp_waviewer.plotgrid,'BackgroundColor',ColorBviewer_def);%%%Message uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','text','String','','FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); gui_erp_waviewer.zoom_in = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','pushbutton','String','Zoom In',... 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@zoomin); - gui_erp_waviewer.zoom_edit = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','edit','String',num2str(zoomSpace),... 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@zoomedit); @@ -156,46 +136,26 @@ function f_redrawERP_viewer_test() 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@zoomout); uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','text','String','','FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); -gui_erp_waviewer.figuresaveas = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','pushbutton','String','Show Command',... - 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@Show_command); - - -gui_erp_waviewer.figuresaveas = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','pushbutton','String','Save Figure as',... - 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@figure_saveas); - -gui_erp_waviewer.figureout = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','pushbutton','String','Create Static /Exportable Plot',... - 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@figure_out); +gui_erp_waviewer.show_popup = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','popupmenu','String',{'Plot options','Show Command','Save Figure as','Create Static /Exportable Plot'},... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def,'Callback',@show_popup); gui_erp_waviewer.Reset = uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','pushbutton','String','Reset',... 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@Panel_Reset); - uicontrol('Parent',gui_erp_waviewer.zoomin_out_title,'Style','text','String','','FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); -set(gui_erp_waviewer.zoomin_out_title, 'Sizes', [10 70 50 70 -1 100 100 170 70 5]); +set(gui_erp_waviewer.zoomin_out_title, 'Sizes', [10 70 50 70 -1 150 70 5]); - -%%Changed by Guanghui Zhang Dec. 2022-------panel for display the processing procedure for some functions, e.g., filtering gui_erp_waviewer.xaxis_panel = uiextras.HBox( 'Parent', gui_erp_waviewer.plotgrid,'BackgroundColor',ColorBviewer_def);%%%Message gui_erp_waviewer.Process_messg = uicontrol('Parent',gui_erp_waviewer.xaxis_panel,'Style','text','String','','FontSize',FonsizeDefault+2,'FontWeight','bold','BackgroundColor',ColorBviewer_def); %%Setting title gui_erp_waviewer.pageinfo_str = ['Page',32,num2str(pagecurrentNum),'/',num2str(pageNum),':',PageStr{pagecurrentNum}]; - -gui_erp_waviewer.pageinfo_text = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style','text','String',gui_erp_waviewer.pageinfo_str,'FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorBviewer_def); - - -gui_erp_waviewer.pageinfo_minus = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style', 'pushbutton', 'String', '<','Callback',@page_minus,'FontSize',FonsizeDefault+5,'BackgroundColor',[1 1 1],'FontWeight','bold'); -% if S_ws_getbinchan.Select_index ==1 +gui_erp_waviewer.pageinfo_text = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style','text','String',gui_erp_waviewer.pageinfo_str,'FontSize',FonsizeDefault,'BackgroundColor',ColorBviewer_def); +gui_erp_waviewer.pageinfo_minus = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style', 'pushbutton', 'String', 'Prev.','Callback',@page_minus,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); gui_erp_waviewer.pageinfo_minus.Enable = 'off'; -% end gui_erp_waviewer.pageinfo_edit = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style', 'edit', 'String', num2str(pagecurrentNum),'Callback',@page_edit,'FontSize',FonsizeDefault+2,'BackgroundColor',[1 1 1]); - - -gui_erp_waviewer.pageinfo_plus = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style', 'pushbutton', 'String', '>','Callback',@page_plus,'FontSize',FonsizeDefault+5,'BackgroundColor',[1 1 1],'FontWeight','bold'); -% if S_ws_getbinchan.Select_index == numel(S_ws_geterpset) +gui_erp_waviewer.pageinfo_plus = uicontrol('Parent',gui_erp_waviewer.pageinfo_box,'Style', 'pushbutton', 'String', 'Next','Callback',@page_plus,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); gui_erp_waviewer.pageinfo_plus.Enable = 'off'; -% end - if pageNum ==1 Enable_minus = 'off'; @@ -226,7 +186,7 @@ function f_redrawERP_viewer_test() gui_erp_waviewer.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; set(gui_erp_waviewer.plot_wav_legend, 'Sizes', [10 -1]); set(gui_erp_waviewer.erpwaviewer_legend_title, 'Sizes', [10 -1]); -set(gui_erp_waviewer.pageinfo_box, 'Sizes', [-1 50 50 50] ); +set(gui_erp_waviewer.pageinfo_box, 'Sizes', [-1 70 50 70] ); gui_erp_waviewer.myerpviewer = axes('Parent', gui_erp_waviewer.ViewAxes,'Color','none','Box','on','FontWeight','bold'); hold(gui_erp_waviewer.myerpviewer,'on'); @@ -240,8 +200,9 @@ function f_redrawERP_viewer_test() gui_erp_waviewer.plotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high gui_erp_waviewer.plotgrid.Heights(2) = 50; % set the first element (pageinfo) to 30px high -gui_erp_waviewer.plotgrid.Heights(4) = 30; % set the second element (x axis) to 30px high +gui_erp_waviewer.plotgrid.Heights(4) = 5; gui_erp_waviewer.plotgrid.Heights(5) = 30; % set the second element (x axis) to 30px high +gui_erp_waviewer.plotgrid.Heights(6) = 30; % set the second element (x axis) to 30px high gui_erp_waviewer.plotgrid.Units = 'pixels'; if isempty(OutputViewerpar) disp('Please restart EStudio Wave Viewer'); @@ -267,23 +228,21 @@ function f_redrawERP_viewer_test() else pb_height = 0.9*pb_height; end -if zoomSpace <0 - gui_erp_waviewer.ViewAxes.Heights = splot_n*pb_height; +zoomSpace = zoomSpace-100; +if zoomSpace <=0 + gui_erp_waviewer.ViewAxes.Heights = 0.95*gui_erp_waviewer.ViewAxes.Position(4); else gui_erp_waviewer.ViewAxes.Heights = splot_n*pb_height*(1+zoomSpace/100); end widthViewer = gui_erp_waviewer.ViewAxes.Position(3)-gui_erp_waviewer.ViewAxes.Position(2); -if zoomSpace <0 +if zoomSpace <=0 gui_erp_waviewer.ViewAxes.Widths = widthViewer; else gui_erp_waviewer.ViewAxes.Widths = widthViewer*(1+zoomSpace/100); - end gui_erp_waviewer.plotgrid.Units = 'normalized'; - - %%Keep the same positions for Vertical and Horizontal scrolling bars asbefore if zoomSpace~=0 && zoomSpace>0 if gui_erp_waviewer.ScrollVerticalOffsets<=1 @@ -299,37 +258,57 @@ function f_redrawERP_viewer_test() end end end -% gui_erp_waviewer.ViewAxes.BackgroundColor = 'b'; -end % redrawDemo - +%%display the names of channels and bins if they diff across the selected +%%ERPsets +LabelsdiffFlag = OutputViewerpar{48}; +ALLERPIN = OutputViewerpar{1}; +PLOTORG = OutputViewerpar{3}; +ERPsetArray= OutputViewerpar{43}; +[chanStr,binStr,diff_mark,chanStremp,binStremp] = f_geterpschanbin(ALLERPIN,ERPsetArray); +if (diff_mark(1) ==1 || diff_mark(2)==1) && LabelsdiffFlag==1 && PLOTORG(1)~=3 + if diff_mark(1) ==1 && diff_mark(2) ==0 + MessageViewer= char(strcat('Some grid Location Labels will be empty because CHANNELS differ across the selected ERPsets')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + elseif diff_mark(1) ==0 && diff_mark(2) ==1 + MessageViewer= char(strcat('Some grid Location Labels will be empty because BINS differ across the selected ERPsets')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + + elseif diff_mark(1) ==1 && diff_mark(2) ==1 + MessageViewer= char(strcat('Some grid Location Labels will be empty because CHANNELS and BINS differ across the selected ERPsets')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =4; + end + f_display_binstr_chanstr(ALLERPIN, ERPsetArray,diff_mark) +end +end % redrawDemo -%%Resize the GUI automatically as the user changes the size of the window at run-time. -% function WAviewerResize(~,~) -% global gui_erp_waviewer; -% if gui_erp_waviewer.Resize ~= 0 -% set( gui_erp_waviewer.tabERP, 'Widths', [-4, 270]); -% f_redrawERP_viewer_test(); -% end -% end +function show_popup(Source,~) +global viewer_ERPDAT; +value = Source.Value; +if value==2 + Show_command(); +elseif value==3 + figure_saveas(); +elseif value==4 + figure_out(); +end +Source.Value=1; +end %%-------------------------------Page Editor------------------------------- function page_edit(Source,~) global viewer_ERPDAT +global gui_erp_waviewer; % addlistener(viewer_ERPDAT,'page_xyaxis',@count_page_xyaxis_change); -try - ERPwaviewer = evalin('base','ALLERPwaviewer'); -catch - beep; - disp('Error > f_redrawERP_viewer_test() > page_edit().'); - return; -end -pagesValue = ERPwaviewer.plot_org.Pages; +pagesValue = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) @@ -339,10 +318,9 @@ function page_edit(Source,~) Pagecurrent = str2num(Source.String); if ~isempty(Pagecurrent) && Pagecurrent>0 - - ERPArray = ERPwaviewer.SelectERPIdx; - chanArray =ERPwaviewer.chan; - binArray = ERPwaviewer.bin; + ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; + chanArray =gui_erp_waviewer.ERPwaviewer.chan; + binArray = gui_erp_waviewer.ERPwaviewer.bin; if pagesValue==1 pageNum = numel(chanArray); elseif pagesValue==2 @@ -352,14 +330,12 @@ function page_edit(Source,~) end if Pagecurrent<=pageNum - ERPwaviewer.PageIndex = Pagecurrent; + gui_erp_waviewer.ERPwaviewer.PageIndex = Pagecurrent; if pagesValue==3 - ERPwaviewer.ERP = ERPwaviewer.ALLERP(ERPArray(Pagecurrent)); - ERPwaviewer.CURRENTERP =ERPArray(Pagecurrent); + gui_erp_waviewer.ERPwaviewer.ERP = gui_erp_waviewer.ERPwaviewer.ALLERP(ERPArray(Pagecurrent)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPArray(Pagecurrent); end - assignin('base','ALLERPwaviewer',ERPwaviewer); - viewer_ERPDAT.page_xyaxis = viewer_ERPDAT.page_xyaxis+1; - f_redrawERP_viewer_test();%%replot the waves + viewer_ERPDAT.Count_currentERP=1; end end @@ -368,24 +344,17 @@ function page_edit(Source,~) %------------------Display the waveform for proir ERPset-------------------- function page_minus(~,~) global viewer_ERPDAT - +global gui_erp_waviewer; [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end -try - ERPwaviewer_CHANGE = evalin('base','ALLERPwaviewer'); -catch - beep; - disp('Please re-run ERP wave viewer.'); - return; -end -ERPwaviewer_CHANGE.PageIndex = ERPwaviewer_CHANGE.PageIndex-1; -pagesValue = ERPwaviewer_CHANGE.plot_org.Pages; -ERPArray = ERPwaviewer_CHANGE.SelectERPIdx; -chanArray =ERPwaviewer_CHANGE.chan; -binArray = ERPwaviewer_CHANGE.bin; +gui_erp_waviewer.ERPwaviewer.PageIndex = gui_erp_waviewer.ERPwaviewer.PageIndex-1; +pagesValue = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; +ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; +chanArray =gui_erp_waviewer.ERPwaviewer.chan; +binArray = gui_erp_waviewer.ERPwaviewer.bin; if pagesValue==1 pageNum = numel(chanArray); elseif pagesValue==2 @@ -393,19 +362,18 @@ function page_minus(~,~) else pageNum = numel(ERPArray); end -Pagecurrent = ERPwaviewer_CHANGE.PageIndex; -if ERPwaviewer_CHANGE.PageIndex<= pageNum && ERPwaviewer_CHANGE.PageIndex>0 +Pagecurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; +if gui_erp_waviewer.ERPwaviewer.PageIndex<= pageNum && gui_erp_waviewer.ERPwaviewer.PageIndex>0 if pagesValue==3 - ERPwaviewer_CHANGE.ERP = ERPwaviewer_CHANGE.ALLERP(ERPArray(Pagecurrent)); - ERPwaviewer_CHANGE.CURRENTERP =ERPArray(Pagecurrent); + gui_erp_waviewer.ERPwaviewer.ERP = gui_erp_waviewer.ERPwaviewer.ALLERP(ERPArray(Pagecurrent)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPArray(Pagecurrent); end - assignin('base','ALLERPwaviewer',ERPwaviewer_CHANGE); - MessageViewer= char(strcat('Plot prior page (<)')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); - viewer_ERPDAT.page_xyaxis = viewer_ERPDAT.page_xyaxis+1;%%change X/Y axis based on the changed pages + MessageViewer= char(strcat('Plot previous page')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); + viewer_ERPDAT.Process_messg =1; - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP=1; viewer_ERPDAT.Process_messg =2; else return; @@ -416,23 +384,17 @@ function page_minus(~,~) %------------------Display the waveform for next ERPset-------------------- function page_plus(~,~) global viewer_ERPDAT +global gui_erp_waviewer; [messgStr,viewerpanelIndex] = f_check_erpviewerpanelchanges(); if ~isempty(messgStr) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end -try - ERPwaviewer_CHANGE = evalin('base','ALLERPwaviewer'); -catch - beep; - disp('Please re-run ERP wave viewer.'); - return; -end -ERPwaviewer_CHANGE.PageIndex = ERPwaviewer_CHANGE.PageIndex+1; -pagesValue = ERPwaviewer_CHANGE.plot_org.Pages; -ERPArray = ERPwaviewer_CHANGE.SelectERPIdx; -chanArray =ERPwaviewer_CHANGE.chan; -binArray = ERPwaviewer_CHANGE.bin; +gui_erp_waviewer.ERPwaviewer.PageIndex = gui_erp_waviewer.ERPwaviewer.PageIndex+1; +pagesValue = gui_erp_waviewer.ERPwaviewer.plot_org.Pages; +ERPArray = gui_erp_waviewer.ERPwaviewer.SelectERPIdx; +chanArray =gui_erp_waviewer.ERPwaviewer.chan; +binArray = gui_erp_waviewer.ERPwaviewer.bin; if pagesValue==1 pageNum = numel(chanArray); elseif pagesValue==2 @@ -440,18 +402,16 @@ function page_plus(~,~) else pageNum = numel(ERPArray); end -Pagecurrent = ERPwaviewer_CHANGE.PageIndex; -if ERPwaviewer_CHANGE.PageIndex<= pageNum && ERPwaviewer_CHANGE.PageIndex>0%% within the page range +Pagecurrent = gui_erp_waviewer.ERPwaviewer.PageIndex; +if gui_erp_waviewer.ERPwaviewer.PageIndex<= pageNum && gui_erp_waviewer.ERPwaviewer.PageIndex>0%% within the page range if pagesValue==3 - ERPwaviewer_CHANGE.ERP = ERPwaviewer_CHANGE.ALLERP(ERPArray(Pagecurrent)); - ERPwaviewer_CHANGE.CURRENTERP =ERPArray(Pagecurrent); + gui_erp_waviewer.ERPwaviewer.ERP = gui_erp_waviewer.ERPwaviewer.ALLERP(ERPArray(Pagecurrent)); + gui_erp_waviewer.ERPwaviewer.CURRENTERP =ERPArray(Pagecurrent); end - assignin('base','ALLERPwaviewer',ERPwaviewer_CHANGE); - viewer_ERPDAT.page_xyaxis = viewer_ERPDAT.page_xyaxis+1;%%change X/Y axis based on the changed pages - MessageViewer= char(strcat('Plot next page (>)')); - erpworkingmemory('ERPViewer_proces_messg',MessageViewer); + MessageViewer= char(strcat('Plot next page')); + estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); viewer_ERPDAT.Process_messg =1; - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP=1; viewer_ERPDAT.Process_messg =2; else return; @@ -471,7 +431,7 @@ function Show_command(~,~) ViewerName = char('My Viewer'); end MessageViewer= char(strcat('Show Command')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); try viewer_ERPDAT.Process_messg =1; OutputViewerpar = f_preparms_erpwaviewer(ViewerName,'command'); @@ -493,16 +453,14 @@ function figure_saveas(~,~) viewer_ERPDAT.count_twopanels = viewer_ERPDAT.count_twopanels +1; end - MessageViewer= char(strcat('Save Figure As')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); pathstr = pwd; namedef ='Myviewer.pdf'; [erpfilename, erppathname, indxs] = uiputfile({'*.pdf';'*.svg';'*.jpg';'*.png';'*.tif';'*.bmp';'*.eps'},... 'Save as',[fullfile(pathstr,namedef)]); - if isequal(erpfilename,0) beep; viewer_ERPDAT.Process_messg =3; @@ -543,7 +501,7 @@ function figure_out(~,~) ViewerName = char('My Viewer'); end MessageViewer= char(strcat('Create Static/Exportable Plot')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); try viewer_ERPDAT.Process_messg =1; OutputViewerpar = f_preparms_erpwaviewer(ViewerName,'script'); @@ -565,19 +523,19 @@ function zoomin(~,~) end zoomSpace = estudioworkingmemory('zoomSpace'); if isempty(zoomSpace) - estudioworkingmemory('zoomSpace',0) + estudioworkingmemory('zoomSpace',100) else - if zoomSpace<0 - zoomSpace = 0; + if zoomSpace<100 + zoomSpace = 100; end - zoomSpace =zoomSpace+10; + zoomSpace =zoomSpace+50; estudioworkingmemory('zoomSpace',zoomSpace) ; end MessageViewer= char(strcat('Zoom In')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); try viewer_ERPDAT.Process_messg =1; - f_redrawERP_viewer_test(); + viewer_ERPDAT.Count_currentERP=1; viewer_ERPDAT.Process_messg =2; catch viewer_ERPDAT.Process_messg =3; @@ -594,7 +552,7 @@ function Panel_Reset(~,~) estudioworkingmemory('MERPWaveViewer_others',[]); MessageViewer= char(strcat('Reset')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); try viewer_ERPDAT.Process_messg =1; @@ -608,7 +566,7 @@ function Panel_Reset(~,~) %%Reset the window size and position new_pos = [0.01,0.01,75,75]; -erpworkingmemory('ERPWaveScreenPos',new_pos); +estudioworkingmemory('ERPWaveScreenPos',new_pos); try ScreenPos = get( groot, 'Screensize' ); catch @@ -621,8 +579,6 @@ function Panel_Reset(~,~) end - - function zoomedit(Source,~) global viewer_ERPDAT; @@ -633,8 +589,8 @@ function zoomedit(Source,~) zoomspaceEdit = str2num(Source.String); MessageViewer= char(strcat('Zoom Editor')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); -if ~isempty(zoomspaceEdit) && numel(zoomspaceEdit)==1 && zoomspaceEdit>=0 +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); +if ~isempty(zoomspaceEdit) && numel(zoomspaceEdit)==1 && zoomspaceEdit>=100 estudioworkingmemory('zoomSpace',zoomspaceEdit); try viewer_ERPDAT.Process_messg =1; @@ -656,13 +612,12 @@ function zoomedit(Source,~) viewer_ERPDAT.Process_messg =3; return; end - if zoomspaceEdit<0 - fprintf(2,['\n Zoom Editor:The input must be a positive number','.\n']); + if zoomspaceEdit<100 + fprintf(2,['\n Zoom Editor:The input must not be smaller than 100','.\n']); viewer_ERPDAT.Process_messg =3; return; end end - end %%----------------Zoom out------------------------------------------------- @@ -676,16 +631,16 @@ function zoomout(~,~) zoomSpace = estudioworkingmemory('zoomSpace'); if isempty(zoomSpace) - estudioworkingmemory('zoomSpace',0) + estudioworkingmemory('zoomSpace',100) else - zoomSpace =zoomSpace-10; - if zoomSpace <0 - zoomSpace =0; + zoomSpace =zoomSpace-50; + if zoomSpace <100 + zoomSpace =100; end estudioworkingmemory('zoomSpace',zoomSpace) ; end MessageViewer= char(strcat('Zoom Out')); -erpworkingmemory('ERPViewer_proces_messg',MessageViewer); +estudioworkingmemory('ERPViewer_proces_messg',MessageViewer); try viewer_ERPDAT.Process_messg =1; f_redrawERP_viewer_test(); @@ -710,7 +665,7 @@ function V_messg_change(~,~) end gui_erp_waviewer.Process_messg.BackgroundColor = [0.95 0.95 0.95]; gui_erp_waviewer.Process_messg.FontSize = FonsizeDefault; -Processed_Method=erpworkingmemory('ERPViewer_proces_messg'); +Processed_Method=estudioworkingmemory('ERPViewer_proces_messg'); if viewer_ERPDAT.Process_messg ==1 gui_erp_waviewer.Process_messg.String = strcat('1- ',Processed_Method,': Running....'); gui_erp_waviewer.Process_messg.ForegroundColor = [0 0 0]; @@ -720,7 +675,7 @@ function V_messg_change(~,~) elseif viewer_ERPDAT.Process_messg ==3 if ~strcmp(gui_erp_waviewer.Process_messg.String,strcat('3- ',Processed_Method,': Error (see Command Window)')) - fprintf([Processed_Method,32,32,32,datestr(datetime('now')),'\n.']); + fprintf([Processed_Method,32,32,32,datestr(datetime('now')),'\n.']); end gui_erp_waviewer.Process_messg.String = strcat('3- ',Processed_Method,': Error (see Command Window)'); gui_erp_waviewer.Process_messg.ForegroundColor = [1 0 0]; @@ -733,7 +688,7 @@ function V_messg_change(~,~) pause(0.5); gui_erp_waviewer.Process_messg.ForegroundColor = [1 0.65 0]; end -if viewer_ERPDAT.Process_messg ==1 || viewer_ERPDAT.Process_messg==2 || viewer_ERPDAT.Process_messg==3 +if viewer_ERPDAT.Process_messg ==1 || viewer_ERPDAT.Process_messg==2 %|| viewer_ERPDAT.Process_messg==3 pause(0.01); gui_erp_waviewer.Process_messg.String = ''; gui_erp_waviewer.Process_messg.BackgroundColor = ColorBviewer_def;%[0.95 0.95 0.95]; @@ -746,7 +701,7 @@ function V_messg_change(~,~) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGridposArray,plotBox,qBlc,qLineColorspec,qLineStylespec,qLineMarkerspec,qLineWidthspec,... qLegendName,qLegendFont,qLegendFontsize,qCBELabels,qLabelfont,qLabelfontsize,qPolarityWave,qSEM,qTransparency,qGridspace,qtimeRange,qXticks,qXticklabel,... - qXlabelfont,qXlabelfontsize,qXlabelcolor,qMinorTicksX,qXunits,qYScales,qYticks,qYticklabel,qYlabelfont,qYlabelfontsize,qYlabelcolor,qYunits,qMinorTicksY,qplotArrayStr,... + qXlabelfont,qXlabelfontsize,qXlabelcolor,qMinorTicksX,qXunits,qYScales,qYticks,qYticklabel,qYlabelfont,qYlabelfontsize,qYlabelcolor,qYunits,qMinorTicksY,qlabelsName,... ERPsetArray,qlegcolor,qlegcolumns,qlabelcolor,qytickprecision,qxtickprecision,qxdisFlag,myerpviewer,myerpviewerlegend) hbig = myerpviewer; @@ -765,10 +720,9 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr if max(ERPsetArray)>length(ALLERP) ERPsetArray=length(ALLERP); end - -[chanStrdef,binStrdef] = f_geterpschanbin(ALLERP,[1:length(ALLERP)]); qERPArray = ERPsetArray; +[chanStrdef,binStrdef,diff_mark,chanStremp,binStremp] = f_geterpschanbin(ALLERP,ERPsetArray); if nargin<5 qchanArray = 1:length(chanStrdef); @@ -845,17 +799,23 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr if isempty(qPLOTORG) || numel(qPLOTORG)~=3 || numel(unique(qPLOTORG)) ~=3 || min(qPLOTORG)<0 || max(qPLOTORG)>3 qPLOTORG = [1 2 3]; end - +LegenddispFlag = 1; if qPLOTORG(2) ==1 %% if the selected Channel is "Grid" OverlayArraydef = qchanArray; for Numofchan = 1:numel(qchanArray) LegendNamedef{Numofchan,1} =char(chanStrdef(qchanArray(Numofchan))); end + if diff_mark(1)==1 + LegenddispFlag =0; + end elseif qPLOTORG(2) == 2 %% if the selected Bin is "Grid" OverlayArraydef = qbinArray; for Numofbin = 1:numel(qbinArray) LegendNamedef{Numofbin,1} = char(binStrdef(qbinArray(Numofbin))); end + if diff_mark(2)==1 + LegenddispFlag =0; + end elseif qPLOTORG(2) == 3%% if the selected ERPset is "Grid" OverlayArraydef = qERPArray; for Numoferpset = 1:numel(qERPArray) @@ -870,6 +830,9 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr for Numofbin = 1:numel(qbinArray) LegendNamedef{Numofbin,1} = char(binStr(qbinArray(Numofbin))); end + if diff_mark(2)==1 + LegenddispFlag =0; + end end LineColordef = [0 0 0;1 0 0;0 0 1;0 1 0;1,0.65 0;0 1 1;1 0 1;0.5 0.5 0.5;0.94 0.50 0.50;0 0.75 1;0.57 0.93 0.57;1 0.55 0;1 0.75 0.80;1 0.84 0];%% get from:https://htmlcolorcodes.com/color-names/ @@ -883,18 +846,18 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr plotArray = qchanArray; for Numofchan = 1:numel(plotArray) try - plotArrayStrdef{Numofchan} = chanStrdef{plotArray(Numofchan)}; + plotArrayStrdef{Numofchan} = chanStremp{plotArray(Numofchan)}; catch - plotArrayStrdef{Numofchan} = 'no'; + plotArrayStrdef{Numofchan} = ''; end end elseif qPLOTORG(1) == 2 %% if the selected Bin is "Grid" plotArray = qbinArray; for Numofbin = 1:numel(plotArray) try - plotArrayStrdef{Numofbin} = binStrdef{plotArray(Numofbin)}; + plotArrayStrdef{Numofbin} = binStremp{plotArray(Numofbin)}; catch - plotArrayStrdef{Numofbin} = 'no'; + plotArrayStrdef{Numofbin} = ''; end end elseif qPLOTORG(1) == 3%% if the selected ERPset is "Grid" @@ -903,16 +866,16 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr try plotArrayStrdef{Numoferp} = ALLERP(plotArray(Numoferp)).erpname; catch - plotArrayStrdef{Numoferp} = 'no'; + plotArrayStrdef{Numoferp} = ''; end end else plotArray = qchanArray; for Numofchan = 1:numel(chanArray) try - plotArrayStrdef{Numofchan} = chanStrdef{plotArray(Numofchan)}; + plotArrayStrdef{Numofchan} = chanStremp{plotArray(Numofchan)}; catch - plotArrayStrdef{Numofchan} = 'no'; + plotArrayStrdef{Numofchan} = ''; end end end @@ -957,8 +920,8 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr qlegcolor=1; end -if nargin <39 || isempty(qplotArrayStr) - qplotArrayStr = plotArrayStrdef; +if nargin <39 || isempty(qlabelsName) + qlabelsName = plotArrayStrdef; end @@ -1304,11 +1267,17 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr if ~strcmpi(qBlc,'no') && ~strcmpi(qBlc,'none')%% when the baseline correction is "pre","post","whole" if strcmpi(qBlc,'pre') - indxtimelock = find(ERP.times==0) ; % zero-time locked + [xxx, indxtimelock, latdiffms] = closest(ERP.times,0);% zero-time locked + if isempty(indxtimelock) + indxtimelock=1; + end aa = 1; elseif strcmpi(qBlc,'post') indxtimelock = length(ERP.times); - aa = find(ERP.times==0); + [xxx, aa, latdiffms] = closest(ERP.times,0);% zero-time locked + if isempty(aa) + aa=length(ERP.times);%%ned to further confirm + end elseif strcmpi(qBlc,'all') || strcmpi(qBlc,'whole') indxtimelock = length(ERP.times); aa = 1; @@ -1602,7 +1571,7 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr end %%Get the figure name which is to be plotted -if (qPLOTORG(1)==1 && qPLOTORG(2)==2) || (qPLOTORG(1)==1 && qPLOTORG(2)==2) %% Page is ERPset +if (qPLOTORG(1)==1 && qPLOTORG(2)==2) || (qPLOTORG(1)==2 && qPLOTORG(2)==1) %% Page is ERPset ERP = ALLERPBls(qCURRENTPLOT); if isempty(ERP.filename) || strcmp(ERP.filename,'') ERP.filename = 'still_not_saved!'; @@ -1657,9 +1626,12 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr plotdatalabel = qGridposArray(Numofrows,Numofcolumns); try - labelcbe = qplotArrayStr{plotdatalabel}; + labelcbe = qlabelsName{plotdatalabel}; + if isempty(labelcbe) + labelcbe = 'Label varies across ERPsets'; + end catch - labelcbe = 'no'; + labelcbe = ''; end try plotbindata = bindata(plotdatalabel,:,:,:); @@ -2018,28 +1990,39 @@ function f_plotviewerwave(ALLERP,qCURRENTPLOT, qPLOTORG,qbinArray,qchanArray,qGr %%------------------------------legend name------------------------------%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% try - for Numofoverlay = 1:numel(hplot) - qLegendName1 = strrep(qLegendName{Numofoverlay},'_','\_'); - % qLegendName1 = qLegendName{Numofoverlay}; - LegendName{Numofoverlay} = char(strcat('\color[rgb]{',num2str(qLineColorspec(Numofoverlay,:)),'}',qLegendName1)); - end - p = get(myerpviewerlegend,'position'); - if qlegcolor ~=1 - try - h_legend = legend(myerpviewerlegend, hplot,LegendName);%,'interpreter','none' - catch + if LegenddispFlag==1 + for Numofoverlay = 1:numel(hplot) + qLegendName1 = strrep(qLegendName{Numofoverlay},'_','\_'); + % qLegendName1 = qLegendName{Numofoverlay}; + LegendName{Numofoverlay} = char(strcat('\color[rgb]{',num2str(qLineColorspec(Numofoverlay,:)),'}',qLegendName1)); + end + p = get(myerpviewerlegend,'position'); + if qlegcolor ~=1 + try + h_legend = legend(myerpviewerlegend, hplot,LegendName);%,'interpreter','none' + catch + h_legend = legend(myerpviewerlegend, hplot,qLegendName,'interpreter','none'); + end + else h_legend = legend(myerpviewerlegend, hplot,qLegendName,'interpreter','none'); end + set(h_legend,'FontSize',qLegendFontsize);%% legend name fontsize + set(h_legend, 'position', p); + set(h_legend,'FontName',qLegendFont);%%legend name font + set(h_legend,'NumColumns',qlegcolumns); + + legend(myerpviewerlegend,'boxoff'); + set(myerpviewerlegend, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); else - h_legend = legend(myerpviewerlegend, hplot,qLegendName,'interpreter','none'); + if qPLOTORG(2) ==1 + legendstr = char('The channel labels are not the same across the selected ERPsets, so no channel labels are shown.; If you want to see the channel labels, please select only one ERPset (or multiple ERPsets with matching channel labels).'); + else + legendstr = char('The bin labels are not the same across the selected ERPsets, so no bin labels are shown.; If you want to see the bin labels, please select only one ERPset (or multiple ERPsets with matching bin labels).'); + end + legendstr = regexp(legendstr, '\;', 'split'); + text(myerpviewerlegend,0.5,0.8,legendstr ,... + 'FontSize',qLabelfontsize+2,'HorizontalAlignment', 'center', 'Color', [1 0 0]);%'FontWeight', 'bold', end - set(h_legend,'FontSize',qLegendFontsize);%% legend name fontsize - set(h_legend, 'position', p); - set(h_legend,'FontName',qLegendFont);%%legend name font - set(h_legend,'NumColumns',qlegcolumns); - - legend(myerpviewerlegend,'boxoff'); - set(myerpviewerlegend, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); catch end diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_setdiffstr.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/f_setdiffstr.m old mode 100644 new mode 100755 diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/pop_plotERPwaviewer.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/pop_plotERPwaviewer.m index c0b26f0d..f6795da4 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/pop_plotERPwaviewer.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/pop_plotERPwaviewer.m @@ -65,7 +65,7 @@ %Yticks - y ticks e.g., [-6 -3 0 5 10] %Yticklabel -display yticklabels? 1 is on and 0 is off. %Ylabelfont -font for yticklabels e.g., 'Courier' -%Ylabelfontsize -fontsize for yticklabels +%Ylabelfontsize -fontsize for yticklabels e.g., 12 %Ylabelcolor -color (RGB) for yticks and yticklabels e.g., [0 0 0] %Yunits -display units for x axes. "on" or "off" %MinorTicksY - @@ -541,7 +541,7 @@ end % qERPArray = [1:length(ALLERP)]; -[chanStrdef,binStrdef] = f_geterpschanbin(ALLERP,qERPsetArray);%%get the bin strings and channel strings across the selected ERPsets +[chanStrdef,binStrdef,diff_mark,chanStremp,binStremp] = f_geterpschanbin(ALLERP,qERPsetArray);%%get the bin strings and channel strings across the selected ERPsets [ERPdatadef,legendNamedef,ERPerrordatadef,timeRangedef] = f_geterpdata(ALLERP,qERPsetArray,qPLOTORG,CURRENTPLOT); if min(qbinArray)<0 || min(qbinArray)==0 @@ -588,7 +588,7 @@ plotArray = qchanArray; for Numofchan = 1:numel(chanArray) try - LabelsNamedef{Numofchan} = chanStrdef{plotArray(Numofchan)}; + LabelsNamedef{Numofchan} = chanStremp{plotArray(Numofchan)}; catch LabelsNamedef{Numofchan} = 'none'; end @@ -597,9 +597,9 @@ plotArray = qbinArray; for Numofbin = 1:numel(plotArray) try - LabelsNamedef{Numofbin} = binStrdef{plotArray(Numofbin)}; + LabelsNamedef{Numofbin} = binStremp{plotArray(Numofbin)}; catch - LabelsNamedef{Numofbin} = 'none'; + LabelsNamedef{Numofbin} = ''; end end elseif qPLOTORG(1) == 3%% if the selected ERPset is "Grid" @@ -608,16 +608,16 @@ try LabelsNamedef{Numoferp} = ALLERP(plotArray(Numoferp)).erpname; catch - LabelsNamedef{Numoferp} = 'none'; + LabelsNamedef{Numoferp} = ''; end end else plotArray = qchanArray; for Numofchan = 1:numel(chanArray) try - LabelsNamedef{Numofchan} = chanStrdef{plotArray(Numofchan)}; + LabelsNamedef{Numofchan} = chanStremp{plotArray(Numofchan)}; catch - LabelsNamedef{Numofchan} = 'none'; + LabelsNamedef{Numofchan} = ''; end end end @@ -1119,6 +1119,9 @@ fn2res = p.Results.(fn2com); % input value if ~isempty(fn2res) if ischar(fn2res) + if strcmpi(fn2com,'History') && strcmpi(fn2res,'command') + fn2res = 'gui'; + end if ~strcmpi(fn2res,'off') erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); end @@ -1168,10 +1171,10 @@ ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); end case 3 - % implicit + % implicit case 4 displayEquiComERP(erpcom); - + otherwise %off or none erpcom = ''; return diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/v_ERPDAT.m b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/v_ERPDAT.m index 8a74fbef..7e9ccae6 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/v_ERPDAT.m +++ b/studio_functions/Functions/EStudio/ERP Tab/ERP wave viewer/v_ERPDAT.m @@ -7,8 +7,6 @@ ERP_chan ERP_bin Count_currentERP - count_legend - page_xyaxis Process_messg loadproper_count count_twopanels @@ -24,8 +22,6 @@ ERP_chan_change ERP_bin_change v_currentERP_change - legend_change - page_xyaxis_change v_messg_change loadproper_change count_twopanels_change @@ -82,20 +78,6 @@ notify(obj,'v_currentERP_change'); end - %%m8 - %capture the changes of legend - function set.count_legend(obj,value) - obj.count_legend = value; - notify(obj,'legend_change'); - end - - %%m9 - %Modify x/y axis based on the changed pages - function set.page_xyaxis(obj,value) - obj.page_xyaxis = value; - notify(obj,'page_xyaxis_change'); - end - %%%m10 %Modified bins of the selected ERP function set.Process_messg(obj,value) diff --git a/studio_functions/Functions/EStudio/ERP Tab/ERPLAB_ERP_Tab.m b/studio_functions/Functions/EStudio/ERP Tab/EStudio_ERP_Tab.m old mode 100644 new mode 100755 similarity index 64% rename from studio_functions/Functions/EStudio/ERP Tab/ERPLAB_ERP_Tab.m rename to studio_functions/Functions/EStudio/ERP Tab/EStudio_ERP_Tab.m index 0e98624d..6c1a118c --- a/studio_functions/Functions/EStudio/ERP Tab/ERPLAB_ERP_Tab.m +++ b/studio_functions/Functions/EStudio/ERP Tab/EStudio_ERP_Tab.m @@ -9,10 +9,7 @@ -function EStudio_gui_erp_totl = ERPLAB_ERP_Tab(EStudio_gui_erp_totl,ColorB_def) -% global observe_ERPDAT; -% global viewer_ERPDAT; -% global EStudio_gui_erp_totl; +function EStudio_gui_erp_totl = EStudio_ERP_Tab(EStudio_gui_erp_totl,ColorB_def) if isempty(ColorB_def) ColorB_def = [0.7020 0.77 0.85]; @@ -25,59 +22,62 @@ EStudio_gui_erp_totl.panelscroll = uix.ScrollingPanel('Parent', EStudio_gui_erp_totl.tabERP); set(EStudio_gui_erp_totl.panelscroll,'BackgroundColor',ColorB_def); -% + Adjust the main layout set( EStudio_gui_erp_totl.tabERP, 'Widths', [-4, 300]); % Viewpanel and settings panel EStudio_gui_erp_totl.panel_fonts = f_get_default_fontsize(); - EStudio_gui_erp_totl.settingLayout = uiextras.VBox('Parent', EStudio_gui_erp_totl.panelscroll,'BackgroundColor',ColorB_def); % + Create the settings window panels for ERP panel EStudio_gui_erp_totl.panel{1} = f_ERP_erpsetsGUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(1) = 280; +EStudio_gui_erp_totl.panelSizes(1) = 290; EStudio_gui_erp_totl.panel{2} = f_ERP_bin_channel_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(2) = 250; +EStudio_gui_erp_totl.panelSizes(2) = 320; EStudio_gui_erp_totl.panel{3} = f_ERP_plot_setting_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(3) = 230; - +EStudio_gui_erp_totl.panelSizes(3) = 390; EStudio_gui_erp_totl.panel{4} = f_ERP_plot_scalp_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(4) = 365; - -EStudio_gui_erp_totl.panel{5} = f_ERP_baselinecorr_detrend_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(5) = 220; -EStudio_gui_erp_totl.panel{6} = f_ERP_filtering_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(6) = 245; - -EStudio_gui_erp_totl.panel{7} = f_ERP_chanoperation_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(7) = 350; - -EStudio_gui_erp_totl.panel{8} = f_ERP_binoperation_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(8) = 310; - -EStudio_gui_erp_totl.panel{9} = f_ERP_CSD_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(9) = 450; - -EStudio_gui_erp_totl.panel{10} = f_ERP_spectral_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(10) = 125; -EStudio_gui_erp_totl.panel{11} = f_ERP_measurement_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(11) = 240; +EStudio_gui_erp_totl.panelSizes(4) = 390; +disp('ERP Tab: Launching ERPsets, Bin & Channel Selection, Plot Settings, Plot Scalp Maps,...'); +EStudio_gui_erp_totl.panel{5} = f_ERP_edit_channel_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(5) = 170; +EStudio_gui_erp_totl.panel{6} = f_ERP_chanoperation_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(6) = 330; +EStudio_gui_erp_totl.panel{7} = f_erp_informtion_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(7) = 410; +EStudio_gui_erp_totl.panel{8} = f_ERP_resample_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(8) = 190; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Edit/Delete Channels & Locations, Channel Operation, ERP & Bin Information, Sampling Rate & Epoch,...']); +EStudio_gui_erp_totl.panel{9} = f_ERP_binoperation_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(9) = 310; +EStudio_gui_erp_totl.panel{10} = f_ERP_filtering_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(10) = 230; +EStudio_gui_erp_totl.panel{11} = f_ERP_baselinecorr_detrend_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(11) = 220; EStudio_gui_erp_totl.panel{12} = f_ERP_grandaverageGUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); EStudio_gui_erp_totl.panelSizes(12) = 260; - +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Bin Operations, Filtering, Baseline Correction & Linear Detrend, Average Across ERPsets (Grand Average),...']); EStudio_gui_erp_totl.panel{13} = f_ERP_append_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); EStudio_gui_erp_totl.panelSizes(13) = 120; - -EStudio_gui_erp_totl.panel{14} = f_ERP_history_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(14) = 250; -EStudio_gui_erp_totl.panel{15} = f_erp_informtion_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(15) = 170; +EStudio_gui_erp_totl.panel{14} = f_ERP_measurement_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(14) = 230; +EStudio_gui_erp_totl.panel{15} = f_ERP_events_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(15) = 100; EStudio_gui_erp_totl.panel{16} = f_erp_dataquality_SME_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(16) = 160; - -EStudio_gui_erp_totl.panel{17} = f_ERP_simulation_panel(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); -EStudio_gui_erp_totl.panelSizes(17) = 820; - +EStudio_gui_erp_totl.panelSizes(16) = 220; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Append ERPsets, Measurement Tool, EventList, View Data Quality Metrics,...']); +EStudio_gui_erp_totl.panel{17} = f_ERP_CSD_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(17) = 190; +EStudio_gui_erp_totl.panel{18} = f_ERP_spectral_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(18) = 160; +EStudio_gui_erp_totl.panel{19} = f_ERP_simulation_panel(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(19) = 820; +EStudio_gui_erp_totl.panel{20} = f_ERP_history_GUI(EStudio_gui_erp_totl.settingLayout,EStudio_gui_erp_totl.panel_fonts); +EStudio_gui_erp_totl.panelSizes(20) = 280; +disp([32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,... + 'Convert Voltage to CSD, Spectral Analysis, Create Artificial ERP Waveform, and History panels']); set(EStudio_gui_erp_totl.settingLayout, 'Heights', EStudio_gui_erp_totl.panelSizes); EStudio_gui_erp_totl.panelscroll.Heights = sum(EStudio_gui_erp_totl.panelSizes); @@ -99,8 +99,11 @@ set( EStudio_gui_erp_totl.panel{15}, 'MinimizeFcn', {@nMinimize, 15} ); set( EStudio_gui_erp_totl.panel{16}, 'MinimizeFcn', {@nMinimize, 16} ); set( EStudio_gui_erp_totl.panel{17}, 'MinimizeFcn', {@nMinimize, 17} ); +set( EStudio_gui_erp_totl.panel{18}, 'MinimizeFcn', {@nMinimize, 18} ); +set( EStudio_gui_erp_totl.panel{19}, 'MinimizeFcn', {@nMinimize, 19} ); +set( EStudio_gui_erp_totl.panel{20}, 'MinimizeFcn', {@nMinimize, 20} ); %%shrinking Panels 4-17 to just their title-bar -whichpanel = [4:17]; +whichpanel = [3:20]; for Numofpanel = 1:length(whichpanel) minned = EStudio_gui_erp_totl.panel{whichpanel(Numofpanel)}.IsMinimized; szs = get( EStudio_gui_erp_totl.settingLayout, 'Sizes' ); @@ -118,7 +121,6 @@ %% + Create the view p = EStudio_gui_erp_totl.ViewContainer; EStudio_gui_erp_totl.ViewAxes = uiextras.HBox( 'Parent', p,'BackgroundColor',ColorB_def); - end diff --git a/studio_functions/Functions/EStudio/ERP Tab/README.md b/studio_functions/Functions/EStudio/ERP Tab/README.md deleted file mode 100755 index 48f4b88c..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# ERPLAB Studio - -![EStudio_v0 016](https://user-images.githubusercontent.com/5137405/85075567-4f6b2a00-b173-11ea-9316-6a7965cb5b81.png) - - - -http://cda.psych.uiuc.edu/matlab_programming_class_2012/guide/GUILayout_v1p10/GUILayout-v1p10/layoutHelp/User%20guide5_2.html - - - - - - -Setting:Color cvl = uisetcolor( cvl,'Value line color') ; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/dummy.erp b/studio_functions/Functions/EStudio/ERP Tab/dummy.erp deleted file mode 100755 index c21bb3bc..00000000 Binary files a/studio_functions/Functions/EStudio/ERP Tab/dummy.erp and /dev/null differ diff --git a/studio_functions/Functions/EStudio/ERP Tab/erplabstudioamnesia.m b/studio_functions/Functions/EStudio/ERP Tab/erplabstudioamnesia.m deleted file mode 100755 index d560feda..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/erplabstudioamnesia.m +++ /dev/null @@ -1,114 +0,0 @@ -% PURPOSE: erases EStudio's memory (values are those last used. Default ones are reloaded) -% -% FORMAT -% -% erplabstudioamnesia(warningop) -% -% INPUT: -% -% warningop - display warning message. 1 yes; 0 no -% -% -% *** This function is part of ERPLAB Toolbox *** -% Author: Javier Lopez-Calderon,Guanghui Zhang & Johanna Kreither -% Center for Mind and Brain -% University of California, Davis, -% Davis, CA -% 2011 & 2022 - -%b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b -% -% EStudio Toolbox -% Copyright © 2007 The Regents of the University of California -% Created by Javier Lopez-Calderon,Guanghui Zhang, and Steven Luck -% Center for Mind and Brain, University of California, Davis, -% javlopez@ucdavis.edu, ghzhang@ucdavis.edu, sjluck@ucdavis.edu -% -% This program 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. -% -% This program 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 this program. If not, see . - -function erplabstudioamnesia(warningop) -if nargin<1 - warningop = 0; -end -if warningop>0 - %Warning Message - question = ['Resetting EStudio''s working memory will\n'... - 'Clear all memory and cannot be recovered\n'... - 'Do you want to continue anyway?']; - title = 'EStudio: Reset EStudio''s working memory Confirmation'; - button = askquest(sprintf(question), title); - - if ~strcmpi(button,'yes') - disp('User selected Cancel') - return - end -end -erplab_studio_default_values % script -% check variable at workspace -try - vmemoryerp = evalin('base', 'vmemoryerp'); -catch - vmemoryerp = []; -end -if isempty(vmemoryerp) - fprintf('\n* FYI: EStudio''s working memory variable does not exist at workspace.\n') -else - if isfield(vmemoryerp, 'mshock') - mshock = vmemoryerp.mshock; - else - mshock = 0; - end - clear vmemoryerp - mshock = mshock + 1; - - % - % IMPORTANT: If this strucure (vmemoryerp) is modified then also must be modified the same line at eegplugin_erplab.m - % - vmemoryerp = struct('erplabstudiorel',erplabstudiorel,'erplabstudiover',erplabstudiover,'ColorB',ColorB,'ColorF',ColorF,'fontsizeGUI',fontsizeGUI,... - 'fontunitsGUI',fontunitsGUI,'mshock',mshock, 'errorColorF', errorColorF, 'errorColorB', errorColorB); - assignin('base','vmemoryerp',vmemoryerp); - fprintf('\n* EStudio''s working memory was reset (variable "vmemoryerp", at workspace, was rebuild with default values).\n'); -end - -% check file for memory -p = which('EStudio'); -p = p(1:findstr(p,'EStudio.m')-1); -mfile = fullfile(p,'memoryerpstudio.erpm'); - -if exist(mfile, 'file')==2 - v = load(fullfile(p,'memoryerpstudio.erpm'), '-mat'); - if isfield(v, 'mshock') - mshock = v.mshock; - else - mshock = 0; - end - - recycle on; - delete(mfile) - pause(0.1) - recycle off - mshock = mshock + 1; - fprintf('\n*** EStudio WARNING: EStudio''s working memory was wiped out. Default values will be used.\n\n') - - % - % IMPORTANT: If this file (saved variables inside memoryerp.erpm) is modified then also must be modified the same line at eegplugin_erplab.m - % - save(fullfile(p,'memoryerpstudio.erpm'),'erplabstudiorel','erplabstudiover','ColorB','ColorF','errorColorB', 'errorColorF','fontsizeGUI','fontunitsGUI','mshock'); -else - fprintf('\n* FYI: EStudio''s working memory file does not exist.\n') - return -end -if mshock>=30 && rand>0.8 - fprintf('\n\nIs it not enough???\n\n') -end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/export2csv_spectranl_analysis.m b/studio_functions/Functions/EStudio/ERP Tab/export2csv_spectranl_analysis.m index 70210e1c..710a6f83 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/export2csv_spectranl_analysis.m +++ b/studio_functions/Functions/EStudio/ERP Tab/export2csv_spectranl_analysis.m @@ -65,8 +65,10 @@ end binfilename = [ prefname1 ext ]; % ...and add ext +binfilename_save = fullfile(pathstr,binfilename); fid = fopen(fullfile(pathstr,binfilename), 'w'); - +disp(['To save spectral results, user selected',32,binfilename_save]); +disp('Your specified ERPset has been into the following file:') try % disp('Your specified bins have been separated into the following files:')fprintf(fid_text, '\n'); nbin = ERP.nbin; @@ -212,7 +214,7 @@ end fclose(fid); - + disp([ '' binfilename_save '']); catch serror = 1; %something went wrong diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.fig b/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.fig index d69e9459..6c185fba 100755 Binary files a/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.fig and b/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.fig differ diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.m b/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.m index 6d17584c..49934c73 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.m +++ b/studio_functions/Functions/EStudio/ERP Tab/f_ERP_duplicate.m @@ -50,9 +50,8 @@ function f_ERP_duplicate_OpeningFcn(hObject, eventdata, handles, varargin) try ERP = varargin{1}; - currenterp = varargin{2}; - binArray = varargin{3}; - chanArray = varargin{4}; + binArray = varargin{2}; + chanArray = varargin{3}; catch ERP.erpname = 'No erp was imported'; ERP.nbin =1; @@ -61,7 +60,6 @@ function f_ERP_duplicate_OpeningFcn(hObject, eventdata, handles, varargin) ERP.bindescr{1} = 'None'; binArray = 1; chanArray = 1; - currenterp = []; ERP.bindata = zeros(1,10,1); end @@ -72,15 +70,7 @@ function f_ERP_duplicate_OpeningFcn(hObject, eventdata, handles, varargin) erplab_studio_default_values; version = erplabstudiover; set(handles.gui_chassis,'Name', ['EStudio ' version ' - Duplicate ERPset GUI']) -set(handles.edit_erpname, 'String', ERP.erpname); -if isempty(currenterp) - set(handles.current_erp_label,'String', ['No active erpset was found'],... - 'FontWeight','Bold', 'FontSize', 16); -else - set(handles.current_erp_label,'String', ['Creat a new erpset # ' num2str(currenterp+1)],... - 'FontWeight','Bold', 'FontSize', 16) -end @@ -98,6 +88,9 @@ function f_ERP_duplicate_OpeningFcn(hObject, eventdata, handles, varargin) %%%set(handles.popupmenu_bins,'String', listb) handles.listb = listb; +if isempty(binArray) || any(binArray(:)>ERP.nbin) || any(binArray(:)<=0) + binArray = [1:ERP.nbin]; +end handles.indxlistb = binArray; @@ -117,6 +110,11 @@ function f_ERP_duplicate_OpeningFcn(hObject, eventdata, handles, varargin) listch = ''; end handles.listch = listch; + +if isempty(chanArray) || any(chanArray(:)>ERP.nchan) || any(chanArray(:)<=0) + chanArray = [1:ERP.nchan]; +end + handles.indxlistch = chanArray; set(handles.edit6_bin,'String', vect2colon(binArray, 'Delimiter', 'off')); @@ -165,21 +163,9 @@ function radio_erpname_Callback(hObject, eventdata, handles) -function edit_erpname_Callback(hObject, eventdata, handles) -erpname = strtrim(get(handles.edit_erpname, 'String')); -if isempty(erpname) - msgboxText = 'You must enter an erpname at least!'; - title = 'EStudio: Duplicate ERPset GUI - empty erpname'; - errorfound(msgboxText, title); - return -end % --- Executes during object creation, after setting all properties. -function edit_erpname_CreateFcn(hObject, eventdata, handles) -if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); -end function edit6_bin_Callback(hObject, eventdata, handles) BinString = str2num(handles.edit6_bin.String); @@ -268,7 +254,6 @@ function pushbutton_chan_browse_Callback(hObject, eventdata, handles) % Update handles structure guidata(hObject, handles); else - disp('User selected Cancel') return end else @@ -282,8 +267,6 @@ function pushbutton_chan_browse_Callback(hObject, eventdata, handles) % --- Executes on button press in pushbutton_Cancel. function pushbutton_Cancel_Callback(hObject, eventdata, handles) handles.output = []; -beep; -disp('User selected Cancel') % Update handles structure guidata(hObject, handles); uiresume(handles.gui_chassis); @@ -291,14 +274,7 @@ function pushbutton_Cancel_Callback(hObject, eventdata, handles) % --- Executes on button press in pushbutton4_okay. function pushbutton4_okay_Callback(hObject, eventdata, handles) -erpname = strtrim(get(handles.edit_erpname, 'String')); -if isempty(erpname) - msgboxText = 'You must enter an erpname at least!'; - title = 'EStudio: Duplicate ERPset GUI - empty erpname'; - errorfound(msgboxText, title); - return -end BinArray = str2num(handles.edit6_bin.String); @@ -324,20 +300,7 @@ function pushbutton4_okay_Callback(hObject, eventdata, handles) end -ERP.erpname = erpname; - -ERP.bindata = ERP.bindata(ChanArray,:,BinArray); -ERP.nbin = numel(BinArray); -ERP.nchan = numel(ChanArray); -ERP.chanlocs = ERP.chanlocs(ChanArray); -for Numofbin = 1:numel(BinArray) - Bindescr{Numofbin} = ERP.bindescr{BinArray(Numofbin)}; -end -ERP.bindescr = Bindescr; - -ERP.saved = 'no'; -ERP.filepath = ''; -handles.output = ERP; +handles.output = {BinArray,ChanArray}; % Update handles structure guidata(hObject, handles); diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_ERP_plot_wav.m b/studio_functions/Functions/EStudio/ERP Tab/f_ERP_plot_wav.m index fd17cf5f..d9dab0f6 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/f_ERP_plot_wav.m +++ b/studio_functions/Functions/EStudio/ERP Tab/f_ERP_plot_wav.m @@ -1,67 +1,31 @@ -function [new_erp_data,Amp_out,Lat_out_trals,Amp,Lat]= f_ERP_plot_wav(ERPIN) -global observe_ERPDAT; - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -S_ws_geterpplot = estudioworkingmemory('geterpplot'); - +function [new_erp_data,Amp_out,Lat_out_trals,Amp,Lat]= f_ERP_plot_wav(ERPIN,offset,ChanArray,BinArray) %%Parameter from bin and channel panel -Elecs_shown = S_ws_getbinchan.elecs_shown{S_ws_getbinchan.Select_index}; -Bins = S_ws_getbinchan.bins{S_ws_getbinchan.Select_index}; -Bin_chans = S_ws_getbinchan.bins_chans(S_ws_getbinchan.Select_index); -Elec_list = S_ws_getbinchan.elec_list{S_ws_getbinchan.Select_index}; -Matlab_ver = S_ws_getbinchan.matlab_ver; - - - -%%Parameter from plotting panel -Min_vspacing = S_ws_geterpplot.min_vspacing(S_ws_getbinchan.Select_index); -Min_time = S_ws_geterpplot.min(S_ws_getbinchan.Select_index); -Max_time = S_ws_geterpplot.max(S_ws_getbinchan.Select_index); -Yscale = S_ws_geterpplot.yscale(S_ws_getbinchan.Select_index); -Timet_low =S_ws_geterpplot.timet_low(S_ws_getbinchan.Select_index); -Timet_high =S_ws_geterpplot.timet_high(S_ws_getbinchan.Select_index); -Timet_step=S_ws_geterpplot.timet_step(S_ws_getbinchan.Select_index); -Fill = S_ws_geterpplot.fill(S_ws_getbinchan.Select_index); -Plority_plot = S_ws_geterpplot.Positive_up(S_ws_getbinchan.Select_index); - - -if Bin_chans == 0 - elec_n = S_ws_getbinchan.elec_n(S_ws_getbinchan.Select_index); - max_elec_n = ERPIN.nchan; -else - elec_n = S_ws_getbinchan.bin_n(S_ws_getbinchan.Select_index); - max_elec_n = ERPIN.nbin; -end - - -ndata = 0; -nplot = 0; -if Bin_chans == 0 - ndata = Bins; - nplot = Elecs_shown; -else - ndata = Elecs_shown; - nplot = Bins; -end - +ERP = ERPIN; +OutputViewerparerp = f_preparms_mtviewer_erptab(ERP,0); +[~, chanLabels, ~, ~, ~] = readlocs(ERP.chanlocs); +Yscale = OutputViewerparerp{6}; +positive_up = OutputViewerparerp{10}; +BinchanOverlay= OutputViewerparerp{11}; +moption= OutputViewerparerp{12}; +latency= OutputViewerparerp{13}; +Min_time = ERP.times(1); +Max_time = ERP.times(end); +Baseline = OutputViewerparerp{14}; +InterpFactor = OutputViewerparerp{15}; +Afraction=OutputViewerparerp{17}; +polpeak = OutputViewerparerp{18}; +locpeakrep= OutputViewerparerp{19}; +fracmearep= OutputViewerparerp{20}; +PeakOnset= OutputViewerparerp{21}; +Neighborhood= OutputViewerparerp{23}; + +splot_n = numel(ChanArray); + + +ndata = BinArray; [xxx, latsamp, latdiffms] = closest(ERPIN.times, [Min_time Max_time]); @@ -76,42 +40,29 @@ tmax = numel(ERPIN.times); end - -splot_n = elec_n; - plot_erp_data = nan(tmax-tmin+1,numel(ndata)); for i = 1:splot_n - if Bin_chans == 0 + if BinchanOverlay == 0 for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = ERPIN.bindata(Elecs_shown(i),tmin:tmax,Bins(i_bin))'*Plority_plot; % + plot_erp_data(:,i_bin,i) = ERPIN.bindata(ChanArray(i),tmin:tmax,BinArray(i_bin))'*positive_up; % end else for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = ERPIN.bindata(Elecs_shown(i_bin),tmin:tmax,Bins(i))'*Plority_plot; % + plot_erp_data(:,i_bin,i) = ERPIN.bindata(ChanArray(i_bin),tmin:tmax,BinArray(i))'*positive_up; % end end end - %%Transfer the original data to what can be used to plot in ERPlab Studio -%%based on the seleted channels and bins, time-window +%%based on the seleted channels and BinArray, time-window perc_lim = Yscale; percentile = perc_lim*3/2; ind_plot_height = percentile*2; -offset = []; -if Bin_chans == 0 - offset = (numel(Elecs_shown)-1:-1:0)*ind_plot_height; -else - offset = (numel(Bins)-1:-1:0)*ind_plot_height; -end [~,~,b] = size(plot_erp_data); - for i = 1:b plot_erp_data(:,:,i) = plot_erp_data(:,:,i) + ones(size(plot_erp_data(:,:,i)))*offset(i); end - - [a,c,b] = size(plot_erp_data); new_erp_data = zeros(a,b*c); for i = 1:b @@ -121,33 +72,20 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%Find the amplitude and latency based on geterpvalues%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -erp_m_t_p = estudioworkingmemory('geterpvalues'); - -if isempty(erp_m_t_p) - msgboxText = ['EStudio says: Please select the meaurement type of interest and set the related parameters from "ERP measurement tool".']; - title = 'EStudio: ERP measurement tool'; - errorfound(msgboxText, title); - return; -end - - MeasureName = {'meanbl','peakampbl', 'peaklatbl','fareatlat','fpeaklat','fninteglat','fareaplat','fareanlat',... 'areat','ninteg','areap','arean','areazt','nintegz','areazp','areazn','instabl'}; -[C,IA] = ismember_bc2({erp_m_t_p.Measure}, MeasureName); +[C,IA] = ismember_bc2({moption}, MeasureName); if ~any(IA) || isempty(IA) IA =1; end - -if isempty(erp_m_t_p.latency) +if isempty(latency) msgboxText = 'Please set a Measurement window'; title = 'ERPLAB: ERP Measurement Tool'; errorfound(msgboxText, title); return; end -moption = erp_m_t_p.Measure; -latency = erp_m_t_p.latency; + if isempty(moption) msgboxText = ['EStudio says: User must specify a type of measurement.']; title = 'EStudio: ERP measurement tool- "Measurement type".'; @@ -182,26 +120,20 @@ Amp = zeros(length(binArray), length(chanArray)); Lat = []; -erp_m_t_p.Erpsets = S_ws_geterpset; - - - - MeasureName = {'meanbl','peakampbl', 'peaklatbl','fareatlat','fpeaklat','fninteglat','fareaplat','fareanlat',... 'areat','ninteg','areap','arean','areazt','nintegz','areazp','areazn','instabl'}; -[C,IA] = ismember_bc2({erp_m_t_p.Measure}, MeasureName); +[C,IA] = ismember_bc2({moption}, MeasureName); if ~any(IA) || isempty(IA) IA =1; end -if isempty(erp_m_t_p.latency) +if isempty(latency) msgboxText = 'Please set a Measurement window'; title = 'ERPLAB: ERP Measurement Tool'; errorfound(msgboxText, title); return; end -moption = erp_m_t_p.Measure; -latency = erp_m_t_p.latency; + if isempty(moption) msgboxText = ['ERPLAB says: User must specify a type of measurement.']; title = 'EStudio: ERP measurement tool- "Measurement type".'; @@ -232,61 +164,51 @@ end end -% ALLERP = evalin('base','ALLERP'); -if isempty(erp_m_t_p.Afraction) - erp_m_t_p.Afraction =0.5; +if isempty(Afraction) || any(Afraction<=0) || any(Afraction>=0) + Afraction =0.5; end -if strcmp(erp_m_t_p.Peakpolarity,'positive')%check the polirity - polpeak =1; -else - polpeak =0; +if isempty(polpeak) || numel(polpeak)~=1 || (polpeak~=0 && polpeak~=1) + polpeak=0; end -if strcmp( erp_m_t_p.Peakreplace,'NaN') - locpeakrep=0; -else - locpeakrep =1; +if isempty(locpeakrep) || numel(locpeakrep)~=1 || (locpeakrep~=0 && locpeakrep~=1) + locpeakrep=1; end +if isempty(fracmearep) || numel(fracmearep)~=1 || (fracmearep~=0 && fracmearep~=1 && fracmearep~=2) + fracmearep=0; +end +Component = 0; -if strcmp(erp_m_t_p.Fracreplace,'NaN') - fracmearep =0; -elseif strcmp(erp_m_t_p.Fracreplace,'absolute') - fracmearep=1; -else - fracmearep =2; +if isempty(PeakOnset) || numel(PeakOnset)~=1 || (PeakOnset~=0 && PeakOnset~=1) + PeakOnset=1; +end +if isempty(Neighborhood) ||numel(Neighborhood)~=1 || any(Neighborhood<1) + Neighborhood=1; end -[Amp, Lat] = geterpvalues(ERPIN, erp_m_t_p.latency, binArray, chanArray, ... - MeasureName{IA}, erp_m_t_p.Baseline, erp_m_t_p.Component,... - polpeak, erp_m_t_p.Neighborhood, locpeakrep,... - erp_m_t_p.Afraction, fracmearep, erp_m_t_p.InterpFactor,erp_m_t_p.PeakOnset); -% [ALLERP, Amp, Lat] = pop_geterpvalues(ALLERP, erp_m_t_p.latency, binArray,chanArray,... -% 'Erpsets', Current_ERP, 'Measure',MeasureName{IA}, 'Component', erp_m_t_p.Component,... -% 'Resolution', erp_m_t_p.Resolution, 'Baseline', erp_m_t_p.Baseline, 'Binlabel', erp_m_t_p.Binlabel,... -% 'Peakpolarity',erp_m_t_p.Peakpolarity, 'Neighborhood', erp_m_t_p.Neighborhood, 'Peakreplace', erp_m_t_p.Peakreplace,... -% 'Warning',erp_m_t_p.Warning,'SendtoWorkspace', erp_m_t_p.SendtoWorkspace, 'Append', erp_m_t_p.Append,... -% 'FileFormat', erp_m_t_p.FileFormat,'Afraction', erp_m_t_p.Afraction, 'Mlabel', erp_m_t_p.Mlabel,... -% 'Fracreplace', erp_m_t_p.Fracreplace,'IncludeLat', erp_m_t_p.IncludeLat, 'InterpFactor', erp_m_t_p.InterpFactor,... -% 'PeakOnset',erp_m_t_p.PeakOnset); +[Amp, Lat] = geterpvalues(ERPIN, latency, binArray, chanArray, ... + MeasureName{IA}, Baseline, Component,... + polpeak, Neighborhood, locpeakrep,... + Afraction, fracmearep, InterpFactor,PeakOnset); Lat_out_trals = {}; for i = 1:splot_n - if Bin_chans == 0 + if BinchanOverlay == 0 for i_bin = 1:numel(ndata) - Amp_out_trans(i_bin,i) = Amp(Bins(i_bin),Elecs_shown(i))*Plority_plot; % + Amp_out_trans(i_bin,i) = Amp(BinArray(i_bin),ChanArray(i))*positive_up; % if ~isempty(Lat) - Lat_out_trals{i_bin,i} = Lat{Bins(i_bin),Elecs_shown(i)}; + Lat_out_trals{i_bin,i} = Lat{BinArray(i_bin),ChanArray(i)}; end end else for i_bin = 1:numel(ndata) - Amp_out_trans(i_bin,i) = Amp(Bins(i),Elecs_shown(i_bin))*Plority_plot; % + Amp_out_trans(i_bin,i) = Amp(BinArray(i),ChanArray(i_bin))*positive_up; % if ~isempty(Lat) - Lat_out_trals{i_bin,i} = Lat{Bins(i),Elecs_shown(i_bin)}; + Lat_out_trals{i_bin,i} = Lat{BinArray(i),ChanArray(i_bin)}; end end end @@ -300,11 +222,8 @@ elseif ismember_bc2(moption, {'peaklatbl','fpeaklat','fareatlat', 'fareaplat','fninteglat','fareanlat'}) for i = 1:b - Amp_out(:,i) = Amp_out_trans(:,i)*Plority_plot; + Amp_out(:,i) = Amp_out_trans(:,i)*positive_up; end - end - - return; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_ERPplot_Parameter.m b/studio_functions/Functions/EStudio/ERP Tab/f_ERPplot_Parameter.m deleted file mode 100755 index 4345b774..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/f_ERPplot_Parameter.m +++ /dev/null @@ -1,218 +0,0 @@ -%Purpose: This function is used to generate the parameters which are applied to get the waveforms of electrodes and bins of interest. - - -%FORMAT: -% -% f_ERPplot_Parameter(ALLERP,Index_selectedERPset) - -% INPUTS : -% -% ALLERP - structure array of ERP structures (ERPsets) -% To read the ERPset from a list in a text file, -% replace ALLERP by the whole filename. -% -% Index_selectedERPset - index of selected ERPset(s),e.g., 1 or [3,4] - -% *** This function is part of ERPLAB Studio Toolbox *** -% Author: Guanghui Zhang & Steven Luck -% Center for Mind and Brain -% University of California, Davis, -% Davis, CA -% 2022 - - - - -function S_erpplot = f_ERPplot_Parameter(ALLERP,Index_selectedERPset) - - -if nargin<1 - help f_ERPplot_Parameter - return -end - -if nargin==1 - try - Index_selectedERPset = evalin('base','CURRENTERP'); - catch - beep; - disp('No CURRENTERP can be found from Matlab workspace') - return; - end -end - - -if Index_selectedERPset > length(ALLERP) - beep; - disp('The index of the input ERPset is larger than the length of ALLERPSET !!!'); - return; -end - -if isempty(Index_selectedERPset) - beep; - disp('The ERPsets of interest can not be selected!!!'); - return; -end - -S_ws = struct(); - -% checked_ERPset_Index_bin_chan = f_checkerpsets(ALLERP,Index_selectedERPset); - -for NumofselectERP =1:length(Index_selectedERPset) - - if Index_selectedERPset(NumofselectERP)> length(ALLERP)% check if the index exceeds the length of ALLERPsets - msgboxText = 'The selected ERPset does not exsit!!!'; - title = 'EStudio: Bin and Channel Selection'; - errorfound(msgboxText, title); - return; - end - - ERP = ALLERP(Index_selectedERPset(NumofselectERP)); - - % elec_list = cell(numel(ERP.chanlocs),1); - for i=1:length(ERP.chanlocs) - elec_list_get{i} = ERP.chanlocs(i).labels; - end - - if length(elec_list_get)~= size(ERP.bindata,1) - beep; - title = 'EStudio: Bin and Channel Selection'; - msgboxText = strcat('Number of channel''s labels is not equal to number of first demension of ERP.bindata for imported datasets!!!'); - disp(); - errorfound(msgboxText, title); - return; - - end - - elec_list{NumofselectERP} = elec_list_get; - clear elec_list_get; - Check_bin_chan = [0 0]; - first_elec(NumofselectERP) = 1; - if length(ERP.chanlocs) <41 - elec_n(NumofselectERP) = numel(ERP.chanlocs); - elecs_shown{NumofselectERP} = first_elec:first_elec+elec_n(NumofselectERP)-1; - elseif length(ERP.chanlocs) >40 - elec_n(NumofselectERP) =40; - elecs_shown{NumofselectERP} = 1:40; - Check_bin_chan(1) =1; - end - - timemin(NumofselectERP) = ERP.times(1); - timemax(NumofselectERP) = ERP.times(end); - timefirst(NumofselectERP) = timemin(NumofselectERP); - - - % bins = zeros(1,ERP.nbin); - %%Dispay the first 20 bins if the number of bins is exceed 20. - if ERP.nbin<21 - bins{NumofselectERP} =1:ERP.nbin; - bin_n(NumofselectERP) = ERP.nbin; - elseif ERP.nbin>=21 - bins{NumofselectERP} =1:20; - bin_n(NumofselectERP) = 20; - Check_bin_chan(2) =1; - end - - - min(NumofselectERP) = floor(ERP.times(1)/5)*5; - max(NumofselectERP) = ceil(ERP.times(end)/5)*5; - - tmin(NumofselectERP) = (floor((min(NumofselectERP)-ERP.times(1))/2)+1); - tmax(NumofselectERP) = (numel(ERP.times)+ceil((max(NumofselectERP)-ERP.times(end))/2)); - - if tmin(NumofselectERP) < 1 - tmin(NumofselectERP) = 1; - end - - if tmax(NumofselectERP) > numel(ERP.times) - tmax(NumofselectERP) = numel(ERP.times); - - end - - if strcmpi(ERP.erpname,'No ERPset loaded') - tmax(NumofselectERP) = 1; - max(NumofselectERP) =1; - end - min_vspacing(NumofselectERP) = 1.5; - YScale = prctile((ERP.bindata(:)),95)*2/3; - if YScale>= 0&&YScale <=0.1 - prct(NumofselectERP) = 0.1; - elseif YScale< 0&& YScale > -0.1 - prct(NumofselectERP) = -0.1; - else - prct(NumofselectERP) = round(YScale); - end - timet_low(NumofselectERP) = floor(ERP.times(1)/5)*5; - if strcmpi(ERP.erpname,'No ERPset loaded') - timet_high = 1; - stepx =1; - else - timet_high(NumofselectERP) = ceil(ERP.times(end)/5)*5; - [def stepx]= default_time_ticks_studio(ERP); - end - - % timet_step(NumofselectERP) = (ceil(ERP.times(end)/5)*5-floor(ERP.times(1)/5)*5)/5; - timet_step(NumofselectERP) = stepx; - fill_index(NumofselectERP) = 1; - Positive_up_index(NumofselectERP) = 1; - bins_chans(NumofselectERP) = 0; - plot_column(NumofselectERP) = 1; -end - - - - -matlab_ver = version('-release'); -matlab_ver = str2double(matlab_ver(1:4)); - - -data_p_bin_chan = { elec_list, ... - first_elec, ... - elec_n, ... - elecs_shown, ... - timemin, ... - timemax, ... - timefirst, ... - bins, ... - bin_n, ... - matlab_ver, ... - bins_chans, ... - min, ... - max, ... - timet_low, ... - timet_high, ... - timet_step, ... - prct, ... - min_vspacing, ... - fill_index,... - Positive_up_index,... - plot_column}; - -erpvalues_variables = {'geterpplot','timemin',data_p_bin_chan{5},'timemax',data_p_bin_chan{6},'timefirst',data_p_bin_chan{7},... - 'min',data_p_bin_chan{12},'max',data_p_bin_chan{13},... - 'timet_low',data_p_bin_chan{14},'timet_high',data_p_bin_chan{15},... - 'timet_step',data_p_bin_chan{16},'yscale',data_p_bin_chan{17},... - 'min_vspacing',data_p_bin_chan{18},'fill',data_p_bin_chan{19},... - 'Positive_up',data_p_bin_chan{20},'Plot_column',data_p_bin_chan{end}}; -S_erpplot = createrplabstudioparameters(S_ws,erpvalues_variables); - -%%------------------------Chan and bin------------------------------------- - -if strcmp(ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; -else - checked_curr_index = 0; -end -checked_ERPset_Index = f_checkerpsets(ALLERP,Index_selectedERPset); - - -erpvalues_variables = {'geterpbinchan','elec_list',data_p_bin_chan{1},'first_elec',data_p_bin_chan{2},... - 'elec_n',data_p_bin_chan{3},'elecs_shown',data_p_bin_chan{4},... - 'bins',data_p_bin_chan{8},'bin_n',data_p_bin_chan{9},... - 'matlab_ver',data_p_bin_chan{10},'bins_chans',data_p_bin_chan{11},'Select_index',1,... - 'checked_ERPset_Index',checked_ERPset_Index,'checked_curr_index',checked_curr_index}; -S_erpplot = createrplabstudioparameters(S_erpplot,erpvalues_variables); - - - -return; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_checkerpsets.m b/studio_functions/Functions/EStudio/ERP Tab/f_checkerpsets.m index 7d489941..cd5a9983 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/f_checkerpsets.m +++ b/studio_functions/Functions/EStudio/ERP Tab/f_checkerpsets.m @@ -112,7 +112,7 @@ catch msgboxText = ['ERPset',32,num2str(k),32,'has a invalid number of bins/channels/samples or different data type.']; % chkerp = 4; % invalid number of bins/channel - disp(msgboxText); + % disp(msgboxText); break; end end @@ -132,7 +132,7 @@ end msgboxText = ['Number of bins across ERPsets is different!'... 'See detail at command window']; - disp(msgboxText); + % disp(msgboxText); chkerp(1) = 1; % Number of bins across ERPsets is different! % return % else @@ -151,7 +151,7 @@ end msgboxText = ['Number of channels across ERPsets is different!'... 'See detail at command window.']; - disp(msgboxText); + % disp(msgboxText); chkerp(2) = 2; % Number of channels across ERPsets is different % return else @@ -172,7 +172,7 @@ beep; msgboxText = ['Type of data across ERPsets is different!'... 'See detail at command window.']; - disp(msgboxText); + % disp(msgboxText); chkerp(3) = 3; % data type across ERPsets is different % return end @@ -189,7 +189,7 @@ end msgboxText = ['Number of samples across ERPsets is different!'... 'See detail at command window.']; - disp(msgboxText); + % disp(msgboxText); chkerp(4) = 4; % data type across ERPsets is different % return end @@ -206,7 +206,7 @@ end msgboxText = ['Start time of epoch across ERPsets is different!'... 'See detail at command window.']; - disp(msgboxText); + % disp(msgboxText); chkerp(5) = 5; % data type across ERPsets is different % return end @@ -223,7 +223,7 @@ end msgboxText = ['End time of epoch across ERPsets is different!'... 'See detail at command window.']; - disp(msgboxText); + % disp(msgboxText); chkerp(6) = 6; % data type across ERPsets is different % return end @@ -241,7 +241,7 @@ end msgboxText = ['Sampling rate across ERPsets is different!'... 'See detail at command window.']; - disp(msgboxText); + % disp(msgboxText); chkerp(7) = 7; % data type across ERPsets is different % return end diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_dq_summary.m b/studio_functions/Functions/EStudio/ERP Tab/f_dq_summary.m index df39b91c..cdddcd45 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/f_dq_summary.m +++ b/studio_functions/Functions/EStudio/ERP Tab/f_dq_summary.m @@ -14,18 +14,16 @@ end if isfield(ERP,'dataquality') == 0 -% beep; -% warning('No Dataquality measures here'); + % beep; + % warning('No Dataquality measures here'); return; end dq_measure_n = numel(ERP.dataquality); if dq_measure_n == 1 if isequal(ERP.dataquality(1).type,'empty') -% beep; -% disp('No Data Quality measures here') else - dq_subfield = 1; + dq_subfield = 1; end else for i=1:dq_measure_n @@ -34,52 +32,54 @@ if any(strcmpi(dq_names,dq_subfield_name)) dq_subfield = find(strcmpi(dq_names,dq_subfield_name) == 1); else -% beep; - disp('Could not find aSME here'); return end end ERP_summary = {0 0 0; 0 0 0; [0 0] [0 0] [0 0]; 0 0 0}; try -dq_data = ERP.dataquality(dq_subfield).data; - -if any(isnan(dq_data(:))) - beep; -% disp('Warning - NaNs in Data Quality measures') - return; -end - -if isempty(dq_data) -% beep; -% disp('Warning - No value was found in Data Quality measures') - return; -end -median_here = median(dq_data(:),'omitnan'); -[dist, median_loc_i] = min(abs(dq_data(:)-median_here)); -[med_elec,med_tw,med_bin] = ind2sub(size(dq_data),find(dq_data == dq_data(median_loc_i))); - -min_here = min(dq_data(:)); -[min_elec,min_tw,min_bin] = ind2sub(size(dq_data),find(dq_data == min_here)); - -max_here = max(dq_data(:)); -[max_elec,max_tw,max_bin] = ind2sub(size(dq_data),find(dq_data == max_here)); - -ERP_summary{1,1} = dq_data(median_loc_i); -ERP_summary{1,2} = min_here; -ERP_summary{1,3} = max_here; - -ERP_summary{2,1} = med_elec; -ERP_summary{2,2} = min_elec; -ERP_summary{2,3} = max_elec; - -ERP_summary{3,1} = [ERP.dataquality(dq_subfield).times(med_tw,1),ERP.dataquality(dq_subfield).times(med_tw,2)]; -ERP_summary{3,2} = [ERP.dataquality(dq_subfield).times(min_tw,1),ERP.dataquality(dq_subfield).times(med_tw,2)]; -ERP_summary{3,3} = [ERP.dataquality(dq_subfield).times(max_tw,1),ERP.dataquality(dq_subfield).times(max_tw,2)]; - -ERP_summary{4,1} = med_bin; -ERP_summary{4,2} = min_bin; -ERP_summary{4,3} = max_bin; - + dq_data = ERP.dataquality(dq_subfield).data; + binan = []; + count = 0; + for Numofbin = 1:size(dq_data,3) + if any(isnan(dq_data(:,:,Numofbin))) + count = count+1; + binan(count) = Numofbin; + end + end + dq_data(:,:,binan) = []; + + binleft = setdiff([1:size(dq_data,3)],binan); + + + if isempty(dq_data) + return; + end + median_here = median(dq_data(:),'omitnan'); + [dist, median_loc_i] = min(abs(dq_data(:)-median_here)); + [med_elec,med_tw,med_bin] = ind2sub(size(dq_data),find(dq_data == dq_data(median_loc_i))); + + min_here = min(dq_data(:)); + [min_elec,min_tw,min_bin] = ind2sub(size(dq_data),find(dq_data == min_here)); + + max_here = max(dq_data(:)); + [max_elec,max_tw,max_bin] = ind2sub(size(dq_data),find(dq_data == max_here)); + + ERP_summary{1,1} = dq_data(median_loc_i); + ERP_summary{1,2} = min_here(1); + ERP_summary{1,3} = max_here(1); + + ERP_summary{2,1} = med_elec(1); + ERP_summary{2,2} = min_elec(1); + ERP_summary{2,3} = max_elec(1); + + ERP_summary{3,1} = [ERP.dataquality(dq_subfield).times(med_tw(1),1),ERP.dataquality(dq_subfield).times(med_tw(1),2)]; + ERP_summary{3,2} = [ERP.dataquality(dq_subfield).times(min_tw(1),1),ERP.dataquality(dq_subfield).times(med_tw(1),2)]; + ERP_summary{3,3} = [ERP.dataquality(dq_subfield).times(max_tw(1),1),ERP.dataquality(dq_subfield).times(max_tw(1),2)]; + + ERP_summary{4,1} = binleft(med_bin(1)); + ERP_summary{4,2} = binleft(min_bin(1)); + ERP_summary{4,3} = binleft(max_bin(1)); + catch end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_erpset_geterpvalues.m b/studio_functions/Functions/EStudio/ERP Tab/f_erpset_geterpvalues.m deleted file mode 100755 index af5abba4..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/f_erpset_geterpvalues.m +++ /dev/null @@ -1,289 +0,0 @@ -% PURPOSE: Finding the users defined path to save the file - - -% [S S_out]= f_erpset_geterpvalues(varargin) - - - - - -%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com -%Center for Mind and Brain -%University of California, Davis -%Davis, CA, USA -%Feb. 2022 - -% ERPLAB Studio - - -function S_out= f_erpset_geterpvalues(varargin); - -if nargin<1 - help f_erpset_geterpvalues - return -end -S_out = {}; - -if isempty(varargin) - CurrentERPSet = evalin('base','CURRENTERP'); - Current_ERP= evalin('base','ERP'); - %Adding chanArray - erpset = num2str(CurrentERPSet); - if ~exist('S','var') - S_in = {}; - erpvalues_variables = {'geterpvalues','latency','',... - 'binArray',[1:Current_ERP.nbin],... - 'chanArray', [1:Current_ERP.nchan],... - 'Erpsets', erpset,... - 'Measure','meanb1',... - 'Component',0,... - 'Resolution', [3],... - 'Baseline', 'pre',... - 'Binlabel', 'on',... - 'Peakpolarity','positive',... - 'Neighborhood', 5,... - 'Peakreplace', 'absolute',... - 'Filename', '',... - 'Warning','on',... - 'SendtoWorkspace', 'on',... - 'Append', '',... - 'FileFormat', 'wide',... - 'Afraction',0.5,... - 'Mlabel', '',... - 'Fracreplace', 'errormsg',... - 'IncludeLat', '',... - 'InterpFactor', 1,... - 'Viewer', 'off',... - 'PeakOnset',1,... - 'History', ''}; - S_OUT = createrplabstudioparameters(S_in,erpvalues_variables); - assignin('base','S',S_OUT); - S_out = S_OUT.geterpvalues; - else %%If the S exists in the MATLAB workspace - - S_IN = evalin('base','S'); - count_geterpvalues = f_findstring(S_IN,'geterpvalues'); - - if count_geterpvalues ==1 - S_out = S_IN.geterpvalues; - else - - erpvalues_variables = {'geterpvalues','latency','',... - 'binArray',[1:Current_ERP.nbin],... - 'chanArray', [1:Current_ERP.nchan],... - 'Erpsets', erpset,... - 'Measure','meanb1',... - 'Component',0,... - 'Resolution', [3],... - 'Baseline', 'pre',... - 'Binlabel', 'on',... - 'Peakpolarity','positive',... - 'Neighborhood', 5,... - 'Peakreplace', 'absolute',... - 'Filename', '',... - 'Warning','on',... - 'SendtoWorkspace', 'on',... - 'Append', '',... - 'FileFormat', 'wide',... - 'Afraction',0.5,... - 'Mlabel', '',... - 'Fracreplace', 'errormsg',... - 'IncludeLat', '',... - 'InterpFactor', 1,... - 'Viewer', 'off',... - 'PeakOnset',1,... - 'History', '',... - 'ERPselect',1}; - S_OUT = createrplabstudioparameters(S_IN,erpvalues_variables); - assignin('base','S',S_OUT); - S_out = S_OUT.geterpvalues; - end - - end -end - -if ~isempty(varargin) - S_out = varargin{1}; -end - -f_erpset_selection = figure( 'Name', 'ERP Measurement Tool', ... - 'NumberTitle', 'off', ... - 'MenuBar', 'none', ... - 'Toolbar', 'none', ... - 'HandleVisibility', 'off'); -f_erpset_selection.Position(3:4) = [300 150]; - -Current_ERPset = evalin('base','CURRENTERP'); -ALLERP = evalin('base','ALLERP'); -ERP_selection_label = [1 0 0]; - -erpset_selection_gui() - - - function erpset_selection_gui() - b1 = uiextras.VBox( 'Parent', f_erpset_selection); - - b11 = uiextras.HBox( 'Parent', b1 ); - - b111 = uicontrol('Style','text','Parent', b11,'String','ERPset setting','fontsize',12);%,'FontWeight', 'bold'); - - %%------------------------------------------------------------------- - b12 = uiextras.HBox( 'Parent', b1 ); - - - %%--------------------------Current ERPset------------------------------ - b112= uicontrol('Style','radiobutton','Parent',b12,'String',['Current ERPSet:',32,'[',num2str(Current_ERPset),']',32,ALLERP(Current_ERPset).erpname],'callback',@currenterpset_toggle); % 1B - uiextras.Empty('Parent',b12); - - set(b12,'Sizes',[250 50]); - b_nonzero = find(ERP_selection_label); - - if ~isempty(b_nonzero) - if ~ERP_selection_label(1) - % set(b112,'enable','off', 'ForegroundColor', [.5 0.5 0.5]); - else - set(b112,'value',ERP_selection_label(1) ,'enable','on'); - end - end - %%------------------From Checked ERPsets----------------------------------- - b14 = uiextras.HBox( 'Parent', b1); - - b141 = uicontrol('Style','radiobutton','Parent', b14,'String','Checked ERPsets','callback',@erpset_checked);%,'HandleVisibility','off' - - b142 = uicontrol('Style','pushbutton','Parent', b14,'String','Options'); - if ~isempty(b_nonzero) - if ~ERP_selection_label(2) - % set(b141,'enable','off', 'ForegroundColor', [.5 0.5 0.5]); - set(b142,'enable','off', 'ForegroundColor', [.5 0.5 0.5]); - else - set(b141,'enable','on','value',ERP_selection_label(2) ); - end - end - %%----------------------------ERPsets menu--------------------------------- - b15 = uiextras.HBox( 'Parent', b1); - - b151 = uicontrol('Style','radiobutton','Parent', b15,'String','From ERPset menu','callback',@erpset_menu); - - b152 = uicontrol('Style','pushbutton','Parent', b15,'String','Options','callback',@erpset_menu_select); - - if ~isempty(b_nonzero) - if ~ERP_selection_label(3) - % set(b151,'enable','off', 'ForegroundColor', [.5 0.5 0.5]); - set(b152,'enable','off', 'ForegroundColor', [.5 0.5 0.5]); - else - set(b151,'value',ERP_selection_label(3) ,'enable','on'); - end - end - %%------------------------Cancel and Run---------------------------------- - b16 = uiextras.HBox( 'Parent', b1); - uicontrol( 'Parent', b16, 'String', 'Cancel','callback',@Local_cancel); - uicontrol( 'Parent', b16, 'String', 'Run','callback',@Local_run); - end - - -%%*********************************************************************** -%%****************** subfunctions *********************************** -%%*********************************************************************** - -%%------------------------Current ERPset----------------------------------- - function currenterpset_toggle(source_current_erp,~) - value_currenterp = source_current_erp.Value; - if value_currenterp ==1 - ERP_selection_label(1) = value_currenterp; - ERP_selection_label(2:end) =0; - elseif value_currenterp == 0 - ERP_selection_label(1:end) =0; - end - erpset_selection_gui(); - S_out.Erpsets = Current_ERPset; - end - - -%%------------------------Checked ERPset----------------------------------- - function erpset_checked(Source_checked_ERP,~) - - value_checkederp = Source_checked_ERP.Value; - - if value_checkederp ==1 - ERP_selection_label(2) = value_checkederp; - ERP_selection_label([1 3]) =0; - elseif value_checkederp == 0 - ERP_selection_label(1:end) =0; - end - erpset_selection_gui(); - - end - -%%-----------------------ERPsets from menu--------------------------------- - function erpset_menu(Source_erp_menu,~) - value_currenterp = Source_erp_menu.Value; - if value_currenterp ==1 - ERP_selection_label(3) = value_currenterp; - ERP_selection_label([1 2]) =0; - S_out.Erpsets = [1:length(ALLERP)]; - elseif value_currenterp == 0 - ERP_selection_label(1:end) =0; - end - erpset_selection_gui(); - end - -%%------------Select the ERPsets of interest from menu--------------------- - function erpset_menu_select(~,~) - - if ~isempty(ALLERP) - for Numoferpset = 1:length(ALLERP) - listb{Numoferpset}= ['Erpset',32,num2str(Numoferpset),':',32,ALLERP(Numoferpset).erpname]; - end - indxlistb = 1:length(ALLERP); - titlename = 'Select ERPset(s):'; - - chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); - - if ~isempty(chan_label_select) - S_out.Erpsets = chan_label_select; - - if length(chan_label_select) ==1 - disp(['ERPset(s):',num2str(chan_label_select),32,'will be used for next analysis']) - else - disp(['ERPset(s):',num2str(chan_label_select(1:end-1)),32,'and',32,num2str(chan_label_select(end)),32,'will be used for next analysis']) - end - else - beep; - disp('User selected Cancel') - return - end - - else - msgboxText = 'No ERPset information was found'; - title = 'EStudio: ERP measurement tool input'; - errorfound(msgboxText, title); - return; - end - end - -%%-------------------Cancel---------------------------------------------- - function Local_cancel(Source_localp_cancel,~) - Values_localp_cancel = Source_localp_cancel.Value; - if ~isempty(Values_localp_cancel) - beep; - disp('User selected Cancel'); - close(f_erpset_selection); - S.geterpvalues = S_out; - % varargout{1} = S_out; - return; - end - end -%%-----------------------Run----------------------------------------------- - function Local_run(Source_localp_run,~) - Values_localp_run = Source_localp_run.Value; - if ~isempty(Values_localp_run) - - S= evalin('base','S'); - S.geterpvalues = S_out; - assignin('base','S',S); - close(f_erpset_selection); - % return; - end - end -%%%Program end -end diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_getFFTfromERP.m b/studio_functions/Functions/EStudio/ERP Tab/f_getFFTfromERP.m index 0bdb14ba..18c806f2 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/f_getFFTfromERP.m +++ b/studio_functions/Functions/EStudio/ERP Tab/f_getFFTfromERP.m @@ -42,7 +42,7 @@ NFFT = 2.^nextpow2(4*fnyqx); NFFT = NFFT*2; fs = ERP.srate; -fnyq = fs/2; +fnyq = round(fs/2); nbin = ERP.nbin; nchan = ERP.nchan; freq = fnyq*linspace(0,1,NFFT/2); diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_preparms_erptab.m b/studio_functions/Functions/EStudio/ERP Tab/f_preparms_erptab.m new file mode 100644 index 00000000..67e133dd --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/f_preparms_erptab.m @@ -0,0 +1,449 @@ +%%this function is used to call back the parameters for plotting ERP wave + +% *** This function is part of EStudio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct 2023 + + +function OutputViewerparerp = f_preparms_erptab(ERP,matlabfig,History,FigureName) + +OutputViewerparerp = ''; +if nargin<1 + help f_preparms_erptab(); + return +end +if isempty(ERP) + disp('f_preparms_erptab(): ERP is empty'); + return; +end + +if nargin<3 + History = 'gui'; +end + +if nargin <2 + matlabfig=1; +end +if nargin <4 + FigureName = ''; +end + +%%channel array and bin array +% +%%channels +ChanArray=estudioworkingmemory('ERP_ChanArray'); +nbchan = ERP.nchan; +if isempty(ChanArray) || any(ChanArray(:)>nbchan) || any(ChanArray(:)<=0) + ChanArray = 1:nbchan; + estudioworkingmemory('ERP_ChanArray',ChanArray); +end + +% +%%bins +BinArray=estudioworkingmemory('ERP_BinArray'); +if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<=0) + BinArray = [1:ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); +end + + +% +%%Plot setting +ERPTab_plotset_pars = estudioworkingmemory('ERPTab_plotset_pars'); + +% +%%time range +timeStartdef = ERP.times(1); +timEnddef = ERP.times(end); +[def xstepdef]= default_time_ticks_studio(ERP, [ERP.times(1),ERP.times(end)]); + +try timerange = ERPTab_plotset_pars{1}; catch timerange =[timeStartdef,timEnddef]; end +try + timeStart = timerange(1); +catch + timeStart = timeStartdef; +end +if isempty(timeStart) || numel(timeStart)~=1 || any(timeStart>timEnddef) + timeStart = timeStartdef; +end + +try + timEnd = timerange(2); +catch + timEnd = timEnddef; +end +if isempty(timEnd) || numel(timEnd)~=1 || any(timEnd timEnd + timEnd = timEnddef; + timeStart = timeStartdef; +end + +try xtickstep = ERPTab_plotset_pars{2}; catch xtickstep = xstepdef; end +if isempty(xtickstep) || numel(xtickstep)~=1 || any(xtickstep<=0) || xtickstep > (timEnd-timeStart) + xtickstep = xstepdef; +end + +%%y scale +try PolarityValue=ERPTab_plotset_pars{6};catch PolarityValue=1; end +if isempty(PolarityValue) || numel(PolarityValue)~=1 || (PolarityValue~=1&&PolarityValue~=0) + PolarityValue=1; +end +if PolarityValue==1 + positive_up = 1; + PolarityWave=1; +else + positive_up = -1; + PolarityWave=0; +end +ERP1 = ERP; +ERP1.bindata = ERP.bindata(ChanArray,:,:); +[def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); +minydef = floor(minydef); +maxydef = ceil(maxydef); +if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end +elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; +end + +try yscale = ERPTab_plotset_pars{3};catch yscale= [minydef,maxydef]; end +if isempty(yscale) || numel(yscale)~=2 + yscale= [minydef,maxydef]; +end + +YtickSpace=1.5; +Fillscreen=1; + +defyticks = default_amp_ticks_viewer(yscale); +if ~isempty(defyticks) +defyticks = str2num(defyticks); +else + defyticks = []; +end +if ~isempty(defyticks) && numel(defyticks)>=2 + ytickstepdef = min(diff(defyticks)); +else + ytickstepdef = floor((yscale(2)-yscale(1))/2); +end +try yscale_step = ERPTab_plotset_pars{4};catch yscale_step=ytickstepdef; end +if isempty(yscale_step) || numel(yscale_step)~=1 || any(yscale_step<=0) + yscale_step = ytickstepdef; +end + +Yticks = []; +if yscale(2)<=0 || yscale(1)>=0 + Yticks = yscale(1); + for ii=1:1000 + ytickcheck = Yticks(end)+yscale_step; + if ytickcheck>yscale(2) + break; + else + Yticks(numel(Yticks)+1) =ytickcheck; + end + end +elseif yscale(1)<0 && yscale(2)>0 + Yticks = 0; + for ii=1:1000 + ytickcheck = Yticks(1)-yscale_step; + if ytickcheckyscale(2) + break; + else + Yticks = [Yticks,ytickcheck]; + end + end +else + Yticks = yscale; +end +if isempty(Yticks) || numel(Yticks)==1 + Yticks = yscale; +end + +%%-----------------------standard error----------------------------------- +try SEMValue = ERPTab_plotset_pars{11};catch SEMValue = [0 0 0];end + +try SEMFlag =SEMValue(1); catch SEMFlag=0; end +if isempty(SEMFlag) || (SEMFlag~=0 && SEMFlag~=1) + SEMFlag=0; +end +if SEMFlag==1 + try Standerr = SEMValue(2); catch Standerr=1; end + if isempty(Standerr) || numel(Standerr)~=1 || any(Standerr<0) || any(Standerr>10) + Standerr=1; + end + + try Transparency = SEMValue(3); catch Transparency=0.2; end + if isempty(Transparency) || numel(Transparency)~=1 || any(Transparency<0) || any(Transparency>1) + Transparency=0.2; + end +else + Standerr=0; + Transparency=0; +end + + +try columNum =ERPTab_plotset_pars{5}; catch columNum=1; end + +if isempty(columNum) || numel(columNum)~=1 || any(columNum<=0) + columNum=1; +end + + +try Binchan_Overlay = ERPTab_plotset_pars{7}; catch Binchan_Overlay=0; end +if isempty(Binchan_Overlay) || numel(Binchan_Overlay)~=1 || (Binchan_Overlay~=0 && Binchan_Overlay~=1) + Binchan_Overlay=0; +end + +try layoutDef = ERPTab_plotset_pars{9};catch layoutDef=1;end +if layoutDef==1 + ChanArray = sort(ChanArray); +end + +if Binchan_Overlay==0 + rowNumdef = numel(ChanArray); + plotArray = ChanArray; + [~, labelsdef, ~, ~, ~] = readlocs(ERP.chanlocs(ChanArray)); + PLOTORG = [1 2 3]; + nplot = numel(BinArray); + LegendName = ERP.bindescr(BinArray); +else + rowNumdef = numel(BinArray); + plotArray = BinArray; + labelsdef =ERP.bindescr(BinArray); + PLOTORG = [2 1 3]; + nplot = numel(ChanArray); + [~, chanlabels, ~, ~, ~] = readlocs(ERP.chanlocs); + if layoutDef==2 + try + chanindexnew = f_estudio_chan_frontback_left_right(ERP.chanlocs(sort(ChanArray))); + if ~isempty(chanindexnew) + ChanArray1=sort(ChanArray); + ChanArray = ChanArray1(chanindexnew); + end + catch + + end + end + LegendName = chanlabels(ChanArray); +end +try rowNum = ERPTab_plotset_pars{8};catch rowNum=rowNumdef; end + + +plotBox = [rowNum,columNum]; + +GridposArraydef = zeros(rowNum,columNum); +count = 0; +for Numofrow = 1:rowNum + for Numofcolumn = 1:columNum + count = count +1; + if count<= numel(plotArray) + GridposArraydef(Numofrow,Numofcolumn)= plotArray(count); + else + break; + end + end +end +if layoutDef==2 && Binchan_Overlay==0 + try + if isfield(ERP,'chanlocs') && ~isempty(ERP.chanlocs) + chanindexnew = f_estudio_chan_frontback_left_right(ERP.chanlocs(sort(ChanArray))); + if ~isempty(chanindexnew) + ChanArray1 = sort(ChanArray); + ChanArray = ChanArray1(chanindexnew); + end + [~, chanlabels, ~, ~, ~] = readlocs(ERP.chanlocs); + labelsdef=chanlabels(ChanArray); + end + GridposArraydef = zeros(rowNum,columNum); + count = 0; + for Numofrow = 1:rowNum + for Numofcolumn = 1:columNum + count = count +1; + if count<= numel(plotArray) + GridposArraydef(Numofrow,Numofcolumn)= ChanArray(count); + else + break; + end + end + end + catch + end +end + + +GridposArray =zeros(rowNum,columNum); +try DataDf = ERPTab_plotset_pars{10};catch DataDf = [];end +if layoutDef==1 || layoutDef==2 + GridposArray = GridposArraydef; +else + if isempty(DataDf) || size(DataDf,1)~=rowNum || size(DataDf,2)~=columNum + GridposArray = GridposArraydef; + else + for Numofrow = 1:rowNum + for Numofcolumn = 1:columNum + SingleStr = char(DataDf{Numofrow,Numofcolumn});%%find the index for each cell + if ~isempty(SingleStr) + [C,IA] = ismember_bc2(SingleStr,labelsdef); + if C==1 + try GridposArray(Numofrow,Numofcolumn)= plotArray(IA);catch GridposArray(Numofrow,Numofcolumn)= 0; end + end + end + end + end + end +end + +figSize = estudioworkingmemory('egfigsize'); +if isempty(figSize) + figSize = []; +end + +LineColorspec = get_colors(nplot); +LineWidthspec= ones(nplot,1); +for ii = 1:nplot + LineMarkerspec{ii} = 'none'; + LineStylespec{ii} = '-'; +end + +FonsizeDefault = f_get_default_fontsize(); +FontSizeLeg = FonsizeDefault; +CBEFontsize = FonsizeDefault; +LabelsName = labelsdef; + +Gridspace = [1 20;1 20]; +timeRange = [timeStart,timEnd]; +[timeticksdef stepX]= default_time_ticks_studio(ERP, timeRange); +timeticksdef = str2num(char(timeticksdef)); +qtimeRangdef = round(timeRange/100)*100; +qXticks = xtickstep+qtimeRangdef(1); +for ii=1:1000 + xtickcheck = qXticks(end)+xtickstep; + if xtickcheck>timeRange(2) + break; + else + qXticks(numel(qXticks)+1) =xtickcheck; + end +end +if isempty(qXticks)%%|| stepX==xtickstep + qXticks = timeticksdef; +end +timeticks = qXticks; +xticklabel = 'on'; +xlabelFontsize = FonsizeDefault; +xlabelFontcolor = [0 0 0]; +Xunits = 'off'; +MinorticksX = [0]; +Yscales = yscale; + +yticklabel = 'on'; +yunits = 'off'; +MinorticksY = 0; +YlabelFontsize = FonsizeDefault; +ylabelFontcolor = [0 0 0]; +TextcolorLeg = 1; + +[xxx, latsamp1, latdiffms] = closest(ERP.times, timeRange); +qtimes = ERP.times(latsamp1(1):latsamp1(2)); + +[xxx, latsamp, latdiffms] = closest(qtimes, 0); +if isempty(latsamp) || any(latsamp<=0) + labelxrange = 0; +else + labelxrange = qtimes(latsamp)-qtimes(1); +end +CBELabels = [1 100 1]; +if labelxrange<=0 + CBELabels = [1 100 1]; +else + CBELabels(1) = 100*labelxrange/(timeRange(2)-timeRange(1))+1; +end + +% CBELabels = [0 100 1]; +Legcolumns = ceil(sqrt(length(LegendName))); +CBETcolor = [0 0 0]; +XdispFlag = 1; + +new_pos = estudioworkingmemory('EStudioScreenPos'); +if isempty(new_pos) || numel(new_pos)~=2 + new_pos = [75,75]; + estudioworkingmemory('EStudioScreenPos',new_pos); +end +try + ScreenPos = get( groot, 'Screensize' ); +catch + ScreenPos = get( 0, 'Screensize' ); +end + +FigOutpos = [ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100]*8/9; +if isempty(FigureName) + FigureName = ERP.erpname; +end + +if matlabfig==1 + [ERP, erpcom] = pop_plotERPwaviewer(ERP,1,1, BinArray, ChanArray,... + 'PLOTORG',PLOTORG,'GridposArray',GridposArray,'LabelsName',LabelsName, 'Blc', 'none','Box',plotBox,'LineColor',LineColorspec,'LineStyle',LineStylespec,... + 'LineMarker',LineMarkerspec,'LineWidth',LineWidthspec,'LegendName',LegendName,'LegendFontsize',FontSizeLeg,... + 'Labeloc',CBELabels,'Labelfontsize',CBEFontsize,'YDir',PolarityWave,'SEM',Standerr,'Transparency', Transparency,... + 'GridSpace',Gridspace,'TimeRange',timeRange,'Xticks',timeticks,'Xticklabel',xticklabel,'Xlabelfontsize',xlabelFontsize,... + 'Xlabelcolor',xlabelFontcolor,'Xunits',Xunits,'MinorTicksX',MinorticksX,... + 'YScales',Yscales,'Yticks',Yticks,'Yticklabel',yticklabel,'Ylabelfontsize',YlabelFontsize,... + 'Ylabelcolor',ylabelFontcolor,'Yunits',yunits,'MinorTicksY',MinorticksY,'LegtextColor',TextcolorLeg,'Legcolumns',Legcolumns,... + 'FigureName',FigureName,'FigbgColor',[1 1 1],'Labelcolor',CBETcolor,'Ytickdecimal',1,'Xtickdecimal',0,'XtickdisFlag',XdispFlag,... + 'FigOutpos',FigOutpos,'History', History);% +else + OutputViewerparerp{1} = ChanArray; + OutputViewerparerp{2} = BinArray; + OutputViewerparerp{3} =timeStart; + OutputViewerparerp{4} =timEnd; + OutputViewerparerp{5} =xtickstep; + OutputViewerparerp{6} =yscale; + OutputViewerparerp{7} =Yticks; + OutputViewerparerp{8} =Fillscreen; + OutputViewerparerp{9} = columNum; + OutputViewerparerp{10} =positive_up; + OutputViewerparerp{11} =Binchan_Overlay; + OutputViewerparerp{12} = rowNum; + OutputViewerparerp{13} = GridposArray; + OutputViewerparerp{14} = Standerr; + OutputViewerparerp{15} = Transparency; +end + + function colors = get_colors(ncolors) + % Each color gets 1 point divided into up to 2 of 3 groups (RGB). + degree_step = 6/ncolors; + angles = (0:ncolors-1)*degree_step; + colors = nan(numel(angles),3); + for i = 1:numel(angles) + if angles(i) < 1 + colors(i,:) = [1 (angles(i)-floor(angles(i))) 0]*0.75; + elseif angles(i) < 2 + colors(i,:) = [(1-(angles(i)-floor(angles(i)))) 1 0]*0.75; + elseif angles(i) < 3 + colors(i,:) = [0 1 (angles(i)-floor(angles(i)))]*0.75; + elseif angles(i) < 4 + colors(i,:) = [0 (1-(angles(i)-floor(angles(i)))) 1]*0.75; + elseif angles(i) < 5 + colors(i,:) = [(angles(i)-floor(angles(i))) 0 1]*0.75; + else + colors(i,:) = [1 0 (1-(angles(i)-floor(angles(i))))]*0.75; + end + end + end +end diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_preparms_mtviewer_erptab.m b/studio_functions/Functions/EStudio/ERP Tab/f_preparms_mtviewer_erptab.m new file mode 100644 index 00000000..76937c1f --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/f_preparms_mtviewer_erptab.m @@ -0,0 +1,299 @@ +%%this function is used to call back the parameters for plotting ERP wave + +% *** This function is part of EStudio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Nov. 2023 + + +function OutputViewerparerp = f_preparms_mtviewer_erptab(ERP,matlabfig,History,figureName) + +OutputViewerparerp = ''; +if nargin<1 + help f_preparms_erptab(); + return +end +if isempty(ERP) + disp('f_preparms_erptab(): ERP is empty'); + return; +end + +if nargin<3 + History = 'gui'; +end + +if nargin <2 + matlabfig=1; +end +if nargin <4 + figureName = ''; +end + +%%channel array and bin array +% +%%channels +ChanArray=estudioworkingmemory('ERP_ChanArray'); +nbchan = ERP.nchan; +if isempty(ChanArray) || any(ChanArray(:)>nbchan) || any(ChanArray(:)<=0) + ChanArray = 1:nbchan; + estudioworkingmemory('ERP_ChanArray',ChanArray); +end + +ERP_chanorders = estudioworkingmemory('ERP_chanorders'); +ChanArray = reshape(ChanArray,1,[]); +try chanOrder = ERP_chanorders{1};catch chanOrder = 1; end +if isempty(chanOrder) || any(chanOrder<=0) || numel(chanOrder)~=1 || (chanOrder~=1 && chanOrder~=2 && chanOrder~=3) + chanOrder=1; +end +try + if chanOrder==2 + if isfield(ERP,'chanlocs') && ~isempty(ERP.chanlocs) + chanindexnew = f_estudio_chan_frontback_left_right(ERP.chanlocs(ChanArray)); + if ~isempty(chanindexnew) + ChanArray = ChanArray(chanindexnew); + end + end + elseif chanOrder==3 + [eloc, labels, theta, radius, indices] = readlocs(ERP.chanlocs); + chanorders = ERP_chanorders{2}; + chanorderindex = chanorders{1}; + chanorderindex1 = unique(chanorderindex); + chanorderlabels = chanorders{2}; + [C,IA]= ismember_bc2(chanorderlabels,labels); + Chanlanelsinst = labels(ChanArray); + if ~any(IA==0) && numel(chanorderindex1) == length(labels) + [C,IA1]= ismember_bc2(Chanlanelsinst,chanorderlabels); + [C,IA2]= ismember_bc2(Chanlanelsinst,labels); + ChanArray = IA2(chanorderindex(IA1)); + end + end +catch +end + +% +%%bins +BinArray=estudioworkingmemory('ERP_BinArray'); +if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<=0) + BinArray = [1:ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); +end + + +% +%%Plot setting +ERPTab_plotset_pars = estudioworkingmemory('ERPTab_plotset_pars'); + +% +%%time range +timeStartdef = ERP.times(1); +timEnddef = ERP.times(end); +[def xstepdef]= default_time_ticks_studio(ERP, [ERP.times(1),ERP.times(end)]); + +try timerange = ERPTab_plotset_pars{1}; catch timerange =[timeStartdef,timEnddef]; end +try + timeStart = timerange(1); +catch + timeStart = timeStartdef; +end +if isempty(timeStart) || numel(timeStart)~=1 || any(timeStart>timEnddef) + timeStart = timeStartdef; +end + +try + timEnd = timerange(2); +catch + timEnd = timEnddef; +end +if isempty(timEnd) || numel(timEnd)~=1 || any(timEnd timEnd + timEnd = timEnddef; + timeStart = timeStartdef; +end + +try xtickstep = ERPTab_plotset_pars{2}; catch xtickstep = xstepdef; end +if isempty(xtickstep) || numel(xtickstep)~=1 || any(xtickstep<=0) || xtickstep > (timEnd-timeStart) + xtickstep = xstepdef; +end + +%%y scale +try PolarityValue=ERPTab_plotset_pars{7};catch PolarityValue=1; end +if isempty(PolarityValue) || numel(PolarityValue)~=1 || (PolarityValue~=1&&PolarityValue~=-1) + PolarityValue=1; +end +if PolarityValue==1 + positive_up = 1; +else + positive_up = -1; +end + +YScaledef =prctile(ERP.bindata(:)*positive_up,95)*2/3; +if YScaledef>= 0&&YScaledef <=0.1 + YScaledef = 0.1; +elseif YScaledef< 0&& YScaledef > -0.1 + YScaledef = 0.1; +else + YScaledef = round(YScaledef); +end +try YtickInterval = ERPTab_plotset_pars{3};catch YtickInterval= YScaledef; end +if isempty(YtickInterval) || numel(YtickInterval)~=1 || any(YtickInterval<0.1) + YtickInterval= YScaledef; +end + +try YtickSpace =ERPTab_plotset_pars{4};catch YtickSpace=1.5; end +if isempty(YtickSpace) || numel(YtickSpace)~=1 || any(YtickSpace<=0) + YtickSpace=1.5; +end + +try Fillscreen = ERPTab_plotset_pars{5};catch Fillscreen=1; end +if isempty(Fillscreen) || numel(Fillscreen)~=1 || (Fillscreen~=0 && Fillscreen~=1) + Fillscreen=1; +end + +try columNum =ERPTab_plotset_pars{6}; catch columNum=1; end +if isempty(columNum) || numel(columNum)~=1 || any(columNum<=0) + columNum=1; +end +columNum=1; + +try Binchan_Overlay = ERPTab_plotset_pars{8}; catch Binchan_Overlay=0; end +if isempty(Binchan_Overlay) || numel(Binchan_Overlay)~=1 || (Binchan_Overlay~=0 && Binchan_Overlay~=1) + Binchan_Overlay=0; +end +Binchan_Overlay=0; + +if Binchan_Overlay==0 + rowNumdef = numel(ChanArray); + plotArray = ChanArray; + [~, labelsdef, ~, ~, ~] = readlocs(ERP.chanlocs(ChanArray)); + PLOTORG = [1 2 3]; + nplot = numel(BinArray); + LegendName = ERP.bindescr(BinArray); +else + rowNumdef = numel(BinArray); + plotArray = BinArray; + labelsdef =ERP.bindescr(BinArray); + PLOTORG = [2 1 3]; + nplot = numel(ChanArray); + [~, chanlabels, ~, ~, ~] = readlocs(ERP.chanlocs(ChanArray)); + LegendName = chanlabels(ChanArray); +end + + +try rowNum = ERPTab_plotset_pars{9};catch rowNum=rowNumdef; end +rowNum=rowNumdef; + +figSize = estudioworkingmemory('egfigsize'); +if isempty(figSize) + figSize = []; +end + + +GridposArraydef = zeros(rowNum,columNum); +count = 0; +for Numofrow = 1:rowNum + for Numofcolumn = 1:columNum + count = count +1; + if count<= numel(plotArray) + GridposArraydef(Numofrow,Numofcolumn)= plotArray(count); + else + break; + end + end +end + + + +%%----------------------------Measurement tool----------------------------- +geterpvaluesparas = estudioworkingmemory('pop_geterpvalues'); +try moption = geterpvaluesparas{7}; catch moption = 'meanbl'; end + +try latency = geterpvaluesparas{4};catch latency = []; end + +try blc = geterpvaluesparas{10}; catch blc = 'none'; end +if numel(blc)~=2 + if ~ismember_bc2(blc, {'none','pre','post','all','whole'}) + blc = 'none'; + end +end +try intfactor = geterpvaluesparas{21}; catch intfactor=1; end + +if isempty(intfactor) || numel(intfactor)~=1 || any(intfactor<=0 ) || any(intfactor>10) + intfactor=1; +end + +try Resolution = geterpvaluesparas{9};catch Resolution=3; end +if isempty(Resolution) || numel(Resolution)~=1 || any(Resolution<1) || any(Resolution>6) + Resolution =3; +end + +try Afraction = geterpvaluesparas{15};catch Afraction = 0.5;end +if isempty(Afraction) || numel(Afraction)~=1 || any(Afraction<=0) || any(Afraction>=1) + Afraction = 0.5; +end + +try polpeak = geterpvaluesparas{12};catch polpeak=0; end +if isempty(polpeak) || numel(polpeak)~=1 || (polpeak~=0 && polpeak~=1) + polpeak=0; +end + +try locpeakrep= geterpvaluesparas{14};catch locpeakrep=1; end +if isempty(locpeakrep) || numel(locpeakrep)~=1 || (locpeakrep~=0 && locpeakrep~=1) + locpeakrep=0;%%NaN +end + +% try fracmearep= geterpvaluesparas{16};catch fracmearep=1; end +% if isempty(fracmearep) || numel(fracmearep)~=1 || (fracmearep~=0 && fracmearep~=1 && fracmearep~=2) +% fracmearep=0; +% end +fracmearep=0;%%always NAN for preview: Apr 2024 GH + +try PeakOnset = geterpvaluesparas{22};catch PeakOnset=1; end +if isempty(PeakOnset) || numel(PeakOnset)~=1 || (PeakOnset~=0 && PeakOnset~=1) + PeakOnset=1; +end +matlab_ver = version('-release'); +Matlab_ver = str2double(matlab_ver(1:4)); + + +try sampeak = geterpvaluesparas{14};catch sampeak=1; end +if isempty(sampeak) ||numel(sampeak)~=1 || any(sampeak<1) + sampeak=1; +end + +if matlabfig==1 +% [EEG, eegcom] = pop_ploterptab(EEG,'ChanArray',ChanArray,'ICArray',ICArray,'Winlength',Winlength,... +% 'AmpScale',AmpScale,'ChanLabel',ChanLabel,'Submean',Submean,'EventOnset',EventOnset,... +% 'StackFlag',StackFlag,'NormFlag',NormFlag,'Startimes',Startimes,'figureName',figureName,'figSize',figSize,'History',History); +else + OutputViewerparerp{1} = ChanArray; + OutputViewerparerp{2} = BinArray; + OutputViewerparerp{3} =timeStart; + OutputViewerparerp{4} =timEnd; + OutputViewerparerp{5} =xtickstep; + OutputViewerparerp{6} =YtickInterval; + OutputViewerparerp{7} =YtickSpace; + OutputViewerparerp{8} =Fillscreen; + OutputViewerparerp{9} = columNum; + OutputViewerparerp{10} =positive_up; + OutputViewerparerp{11} =Binchan_Overlay; + OutputViewerparerp{12} =moption; + OutputViewerparerp{13} =latency; + OutputViewerparerp{14} =blc; + OutputViewerparerp{15} =intfactor; + OutputViewerparerp{16} =Resolution; + OutputViewerparerp{17} =Afraction; + OutputViewerparerp{18} =polpeak; + OutputViewerparerp{19} = locpeakrep; + OutputViewerparerp{20} =fracmearep; + OutputViewerparerp{21} =PeakOnset; + OutputViewerparerp{22} =Matlab_ver; + OutputViewerparerp{23} =sampeak; + OutputViewerparerp{24} =GridposArraydef; +end + +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP.m b/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP.m index b6b2ec98..75ef37fc 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP.m +++ b/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP.m @@ -1,186 +1,527 @@ %This function is to plot ERP waves with single or multiple columns on one page. - - -% Author: Guanghui Zhang & Steve J. Luck & Andrew Stewart +% Author: Guanghui Zhang & Steve J. Luck % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2022 +% 2022 -2024 function f_redrawERP() -% Draw a demo ERP into the axes provided global observe_ERPDAT; global EStudio_gui_erp_totl; -% addlistener(observe_ERPDAT,'Messg_change',@Count_Process_messg_change); - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); +FonsizeDefault = f_get_default_fontsize(); +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.702,0.77,0.85]; +end +if isempty(ColorB_def) + ColorB_def = [0.702,0.77,0.85]; end -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -S_ws_geterpplot = estudioworkingmemory('geterpplot'); +set(0,'units','pixels') +Pix_SS = get(0,'screensize'); +set(0,'units','inches') +Inch_SS = get(0,'screensize'); +Resolation = Pix_SS./Inch_SS; -%%Parameter from bin and channel panel -% Elecs_shown = estudioworkingmemory('ChanShow'); -Elecs_shown = S_ws_getbinchan.elecs_shown{S_ws_getbinchan.Select_index}; -% if isempty(Elecs_shown) || max(Elecs_shown)> numel(Elecs_shown_all) -% Elecs_shown = Elecs_shown_all; -% end -Bins = S_ws_getbinchan.bins{S_ws_getbinchan.Select_index}; try - Bin_chans = S_ws_getbinchan.bins_chans(S_ws_getbinchan.Select_index); + EStudio_gui_erp_totl.ScrollVerticalOffsets = EStudio_gui_erp_totl.ViewAxes.VerticalOffsets/EStudio_gui_erp_totl.ViewAxes.Heights; + EStudio_gui_erp_totl.ScrollHorizontalOffsets = EStudio_gui_erp_totl.ViewAxes.HorizontalOffsets/EStudio_gui_erp_totl.ViewAxes.Widths; catch - Bin_chans = 0; + EStudio_gui_erp_totl.ScrollVerticalOffsets=0; + EStudio_gui_erp_totl.ScrollHorizontalOffsets=0; +end +if ishandle( EStudio_gui_erp_totl.ViewAxes ) + delete( EStudio_gui_erp_totl.ViewAxes ); +end +zoomSpace = estudioworkingmemory('ERPTab_zoomSpace'); +if isempty(zoomSpace) + zoomSpace = 100; +else + if zoomSpace<100 + zoomSpace =100; + end +end +if zoomSpace ==100 + EStudio_gui_erp_totl.ScrollVerticalOffsets=0; + EStudio_gui_erp_totl.ScrollHorizontalOffsets=0; end -Elec_list = S_ws_getbinchan.elec_list{S_ws_getbinchan.Select_index}; -Matlab_ver = S_ws_getbinchan.matlab_ver; -%%Parameter from plotting panel -try - Min_vspacing = S_ws_geterpplot.min_vspacing(S_ws_getbinchan.Select_index); - Min_time = S_ws_geterpplot.min(S_ws_getbinchan.Select_index); - Max_time = S_ws_geterpplot.max(S_ws_getbinchan.Select_index); - Yscale = S_ws_geterpplot.yscale(S_ws_getbinchan.Select_index); - Timet_low =S_ws_geterpplot.timet_low(S_ws_getbinchan.Select_index); - Timet_high =S_ws_geterpplot.timet_high(S_ws_getbinchan.Select_index); - Timet_step=S_ws_geterpplot.timet_step(S_ws_getbinchan.Select_index); - Fill = S_ws_geterpplot.fill(S_ws_getbinchan.Select_index); - Plority_plot = S_ws_geterpplot.Positive_up(S_ws_getbinchan.Select_index); - % ColumnNum = S_ws_geterpplot.Plot_column; - ColumnNum = estudioworkingmemory('EStudioColumnNum'); - if isempty(ColumnNum) || numel(ColumnNum)~=1 - ColumnNum =1; +ERPArray= estudioworkingmemory('selectederpstudio'); +if ~isempty(observe_ERPDAT.ALLERP) && ~isempty(observe_ERPDAT.ERP) + if isempty(ERPArray) ||any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:)<=0) + ERPArray = length(observe_ERPDAT.ALLERP) ; + estudioworkingmemory('selectederpstudio',ERPArray); + observe_ERPDAT.CURRENTERP = ERPArray; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(ERPArray); + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','ALLERP', observe_ERPDAT.ALLERP); + assignin('base','CURRENTERP', observe_ERPDAT.CURRENTERP); end - -catch - return; + [xpos,ypos] = find(ERPArray==observe_ERPDAT.CURRENTERP); + if ~isempty(ypos) + pagecurrentNum = ypos; + pageNum = numel(ERPArray); + PageStr = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP).erpname; + else + pageNum=1; + pagecurrentNum=1; + PageStr = observe_ERPDAT.ERP.erpname; + end + Enableflag = 'on'; +else + pageNum=1; + pagecurrentNum=1; + PageStr = 'No ERPset was loaded'; + ERPArray= 1; + estudioworkingmemory('selectederpstudio',1); + Enableflag = 'off'; +end +ERP_autoplot = EStudio_gui_erp_totl.ERP_autoplot; +if ERP_autoplot==1 + Enableflag = 'on'; +else + Enableflag = 'off'; end +EStudio_gui_erp_totl.plotgrid = uix.VBox('Parent',EStudio_gui_erp_totl.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); + +%%Setting title +pageinfo_box = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def); +pageinfo_str = ['Page',32,num2str(pagecurrentNum),'/',num2str(pageNum),':',32,PageStr]; +EStudio_gui_erp_totl.pageinfo_text = uicontrol('Parent',pageinfo_box,'Style','text','String',pageinfo_str,'FontSize',FonsizeDefault); +EStudio_gui_erp_totl.pageinfo_minus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', 'Prev.','Callback',{@page_minus,EStudio_gui_erp_totl},'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); +EStudio_gui_erp_totl.pageinfo_edit = uicontrol('Parent',pageinfo_box,'Style', 'edit', 'String', num2str(pagecurrentNum),'Callback',@page_edit,'FontSize',FonsizeDefault+2,'BackgroundColor',[1 1 1]); +EStudio_gui_erp_totl.pageinfo_plus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', 'Next','Callback',{@page_plus,EStudio_gui_erp_totl},'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); +set(pageinfo_box, 'Sizes', [-1 70 50 70] ); +set(pageinfo_box,'BackgroundColor',ColorB_def); + + +%%legends +ViewAxes_legend_title = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',[1 1 1]); +EStudio_gui_erp_totl.ViewAxes_legend = uix.ScrollingPanel( 'Parent', ViewAxes_legend_title,'BackgroundColor',[1 1 1]); +%%waves +EStudio_gui_erp_totl.plot_wav_legend = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',[1 1 1]); +EStudio_gui_erp_totl.ViewAxes = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.plot_wav_legend,'BackgroundColor',[1 1 1]); +%%note that needs to go to lines 487,491, 495, 670,671 of "uix.ScrollingPanel" if change the background color of scrollingbar or this toolbox is updated -Column_label = ColumnNum; -if Bin_chans == 0 - elec_n = numel(Elecs_shown); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(S_ws_getbinchan.Select_index)).nchan; +EStudio_gui_erp_totl.blank = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message +uiextras.Empty('Parent', EStudio_gui_erp_totl.blank,'BackgroundColor',ColorB_def); % 1A + +%%save figure, command.... +commandfig_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message + +EStudio_gui_erp_totl.zoom_in = uicontrol('Parent',commandfig_panel,'Style','pushbutton','String','Zoom In',... + 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@zoomin,'Enable',Enableflag); +EStudio_gui_erp_totl.zoom_edit = uicontrol('Parent',commandfig_panel,'Style','edit','String',num2str(zoomSpace),... + 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@zoomedit,'Enable',Enableflag); + +EStudio_gui_erp_totl.zoom_out = uicontrol('Parent',commandfig_panel,'Style','pushbutton','String','Zoom Out',... + 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Callback',@zoomout,'Enable',Enableflag); +uiextras.Empty('Parent', commandfig_panel); % 1A + +if ~isempty(observe_ERPDAT.ALLERP) && ~isempty(observe_ERPDAT.ERP) + EStudio_gui_erp_totl.erp_popmenu = uicontrol('Parent',commandfig_panel,'Style','popupmenu','Callback',@popmemu_erp,'Enable','on','BackgroundColor',ColorB_def,... + 'Enable','on','String',{'Plotting Options','Automatic Plotting','Window Size','Advanced Waveform Viewer','Show Command','Save Figure as','Create Static/Exportable Plot'}); else - elec_n = S_ws_getbinchan.bin_n(S_ws_getbinchan.Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(S_ws_getbinchan.Select_index)).nbin; + EStudio_gui_erp_totl.erp_popmenu = uicontrol('Parent',commandfig_panel,'Style','popupmenu','Callback',@popmemu_erp,... + 'Enable','on','String',{'Plotting Options','Automatic Plotting','Window Size'},'Enable','on','BackgroundColor',ColorB_def); end - -% We first clear the existing axes ready to build a new one -if ishandle( EStudio_gui_erp_totl.ViewAxes ) - delete( EStudio_gui_erp_totl.ViewAxes ); +popmemu_erp = EStudio_gui_erp_totl.erp_popmenu.String; +if ERP_autoplot==1 + popmemu_erp{2} = 'Automatic Plotting: On'; +else + popmemu_erp{2} = 'Automatic Plotting: Off'; end +EStudio_gui_erp_totl.erp_popmenu.String=popmemu_erp; +EStudio_gui_erp_totl.erp_reset = uicontrol('Parent',commandfig_panel,'Style','pushbutton','String','Reset',... + 'Callback', @erptab_reset,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','on'); +uiextras.Empty('Parent', commandfig_panel); % 1A +set(commandfig_panel, 'Sizes', [70 50 70 -1 150 50 5]); + +%%message +xaxis_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message +EStudio_gui_erp_totl.Process_messg = uicontrol('Parent',xaxis_panel,'Style','text','String','','FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorB_def); + +if length(ERPArray) ==1 + Enable_minus = 'off'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [1 1 1]; + Enable_minus_BackgroundColor = [0 0 0]; +else + if pagecurrentNum ==1 + Enable_minus = 'off'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [0 0 0]; + elseif pagecurrentNum == length(ERPArray) + Enable_minus = 'on'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [0 0 0]; + Enable_minus_BackgroundColor = [0 1 0]; + else + Enable_minus = 'on'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [0 1 0]; + end +end +if ERP_autoplot==0 + Enable_minus = 'off'; + Enable_plus = 'off'; + EStudio_gui_erp_totl.pageinfo_edit.Enable = 'off'; + EStudio_gui_erp_totl.pageinfo_text.String='Plotting is disabled, to enable it, please go to "Plotting Options" at the bottom of the plotting area to active it.'; +end +EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; +EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; +EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; +EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; +set(EStudio_gui_erp_totl.pageinfo_text,'BackgroundColor',ColorB_def); +EStudio_gui_erp_totl.plotgrid.Heights(1) = 30; +EStudio_gui_erp_totl.plotgrid.Heights(2) = 70;% set the first element (pageinfo) to 30px high +EStudio_gui_erp_totl.plotgrid.Heights(4) = 5; +EStudio_gui_erp_totl.plotgrid.Heights(5) = 30; +EStudio_gui_erp_totl.plotgrid.Heights(6) = 30;% set the second element (x axis) to 30px high +EStudio_gui_erp_totl.plotgrid.Units = 'pixels'; + +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) || ERP_autoplot==0 + EStudio_gui_erp_totl.erptabwaveiwer = axes('Parent', EStudio_gui_erp_totl.ViewAxes,'Color','none','Box','on','FontWeight','normal'); + set(EStudio_gui_erp_totl.erptabwaveiwer, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none'); +end -% Get chan labels -S_chan.chan_label = cell(1,max_elec_n); -S_chan.chan_label_place = zeros(1,max_elec_n); +if ~isempty(observe_ERPDAT.ALLERP) && ~isempty(observe_ERPDAT.ERP) && ERP_autoplot==1 + EStudio_gui_erp_totl.erptabwaveiwer = axes('Parent', EStudio_gui_erp_totl.ViewAxes,'Color','none','Box','on','FontWeight','normal'); + hold(EStudio_gui_erp_totl.erptabwaveiwer,'on'); + EStudio_gui_erp_totl.erptabwaveiwer_legend = axes('Parent', EStudio_gui_erp_totl.ViewAxes_legend,'Color','none','Box','off'); + hold(EStudio_gui_erp_totl.erptabwaveiwer_legend,'on'); + set(EStudio_gui_erp_totl.erptabwaveiwer_legend, 'XTick', [], 'YTick', []); + ERP = observe_ERPDAT.ERP; + OutputViewerparerp = f_preparms_erptab(ERP,0); + + % %%Plot the eeg waves + if ~isempty(OutputViewerparerp) + f_plotaberpwave(ERP,OutputViewerparerp{1},OutputViewerparerp{2},... + OutputViewerparerp{3},OutputViewerparerp{4},OutputViewerparerp{5},... + OutputViewerparerp{6},OutputViewerparerp{9},OutputViewerparerp{10},OutputViewerparerp{11},... + OutputViewerparerp{12},OutputViewerparerp{13},OutputViewerparerp{14},OutputViewerparerp{15},... + EStudio_gui_erp_totl.erptabwaveiwer,EStudio_gui_erp_totl.erptabwaveiwer_legend,OutputViewerparerp{7}); + else + return; + end + pb_height = 1*Resolation(4); %px + + Fill=1; + splot_n = OutputViewerparerp{12}; + if isempty(splot_n) || any(splot_n<=0) + splot_n = size(OutputViewerparerp{13},1); + end + if splot_n*pb_height<(EStudio_gui_erp_totl.plotgrid.Position(4)-EStudio_gui_erp_totl.plotgrid.Heights(1))&&Fill + pb_height = 0.9*(EStudio_gui_erp_totl.plotgrid.Position(4)-EStudio_gui_erp_totl.plotgrid.Heights(1)-EStudio_gui_erp_totl.plotgrid.Heights(2))/splot_n; + else + pb_height = 0.9*pb_height; + end + zoomSpace = zoomSpace-100; + if zoomSpace <=0 + EStudio_gui_erp_totl.ViewAxes.Heights = 0.95*EStudio_gui_erp_totl.ViewAxes.Position(4); + else + EStudio_gui_erp_totl.ViewAxes.Heights = splot_n*pb_height*(1+zoomSpace/100); + end + + widthViewer = EStudio_gui_erp_totl.ViewAxes.Position(3)-EStudio_gui_erp_totl.ViewAxes.Position(2); + if zoomSpace <=0 + EStudio_gui_erp_totl.ViewAxes.Widths = widthViewer; + else + EStudio_gui_erp_totl.ViewAxes.Widths = widthViewer*(1+zoomSpace/100); + end + + %%Keep the same positions for Vertical and Horizontal scrolling bars asbefore + if zoomSpace~=0 && zoomSpace>0 + if EStudio_gui_erp_totl.ScrollVerticalOffsets<=1 + try + EStudio_gui_erp_totl.ViewAxes.VerticalOffsets= EStudio_gui_erp_totl.ScrollVerticalOffsets*EStudio_gui_erp_totl.ViewAxes.Heights; + catch + end + end + if EStudio_gui_erp_totl.ScrollHorizontalOffsets<=1 + try + EStudio_gui_erp_totl.ViewAxes.HorizontalOffsets =EStudio_gui_erp_totl.ScrollHorizontalOffsets*EStudio_gui_erp_totl.ViewAxes.Widths; + catch + end + end + end +end +EStudio_gui_erp_totl.ViewAxes.Children.Title.Color = [1 0 0]; +end +%%------------------------------------------------------------------------- +%%-----------------------------Subfunctions-------------------------------- +%%------------------------------------------------------------------------- -if Bin_chans == 0 - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.chanlocs(Elecs_shown(i)).labels; +function popmemu_erp(Source,~) +global EStudio_gui_erp_totl; +Value = Source.Value; +if Value==2 + + app = feval('EStudio_plot_set_waves',EStudio_gui_erp_totl.ERP_autoplot,2); + waitfor(app,'Finishbutton',1); + try + plotSet = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.01); %wait for app to leave + catch + return; + end + if isempty(plotSet)||numel(plotSet)~=1 || (plotSet~=0&&plotSet~=1) + plotSet=1; + end + popmemu_eegString = EStudio_gui_erp_totl.erp_popmenu.String; + if plotSet==1 + popmemu_eegString{2} = 'Automatic Plotting: On'; + else + popmemu_eegString{2} = 'Automatic Plotting: Off'; end + EStudio_gui_erp_totl.erp_popmenu.String=popmemu_eegString; + EStudio_gui_erp_totl.ERP_autoplot = plotSet; + f_redrawERP(); + +elseif Value==3 + EStudiowinsize(); +elseif Value==4 + Advanced_viewer(); +elseif Value==5 + Show_command(); +elseif Value==6 + figure_saveas(); +elseif Value==7 + figure_out(); +end +Source.Value=1; +end + + + +%%----------------Zoom in------------------------------------------------- +function zoomin(~,~) +global observe_ERPDAT; + +[messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); +if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1; +end +zoomSpace = estudioworkingmemory('ERPTab_zoomSpace'); +if isempty(zoomSpace) + estudioworkingmemory('ERPTab_zoomSpace',0); else - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.bindescr(Bins(i)); + if zoomSpace<100 + zoomSpace = 100; end + zoomSpace =zoomSpace+50; + estudioworkingmemory('ERPTab_zoomSpace',zoomSpace) ; +end +MessageViewer= char(strcat('Zoom In')); +estudioworkingmemory('f_ERP_proces_messg',MessageViewer); +try + observe_ERPDAT.Process_messg =1; + f_redrawERP(); + observe_ERPDAT.Process_messg =2; +catch + observe_ERPDAT.Process_messg =3; +end end -%Sets the units of your root object (screen) to pixels -set(0,'units','pixels') -%Obtains this pixel information -Pix_SS = get(0,'screensize'); -%Sets the units of your root object (screen) to inches -set(0,'units','inches') -%Obtains this inch information -Inch_SS = get(0,'screensize'); -%Calculates the resolution (pixels per inch) -Res = Pix_SS./Inch_SS; +function zoomedit(Source,~) +global observe_ERPDAT; +[messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); +if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1; +end -pb_height = Min_vspacing*Res(4); %px +zoomspaceEdit = str2num(Source.String); +MessageViewer= char(strcat('Zoom Editor')); +estudioworkingmemory('f_ERP_proces_messg',MessageViewer); +if ~isempty(zoomspaceEdit) && numel(zoomspaceEdit)==1 && zoomspaceEdit>=100 + estudioworkingmemory('ERPTab_zoomSpace',zoomspaceEdit); + try + observe_ERPDAT.Process_messg =1; + f_redrawERP(); + observe_ERPDAT.Process_messg =2; + return; + catch + observe_ERPDAT.Process_messg =3; + return; + end +else + if isempty(zoomspaceEdit) + estudioworkingmemory('f_ERP_proces_messg',['\n Zoom Editor:The input must be a number']); + observe_ERPDAT.Process_messg =4; + return; + end + if numel(zoomspaceEdit)>1 + estudioworkingmemory('f_ERP_proces_messg',['Zoom Editor:The input must be a single number']); + observe_ERPDAT.Process_messg =4; + return; + end + if zoomspaceEdit<100 + estudioworkingmemory('f_ERP_proces_messg',[' Zoom Editor:The input must not be smaller than 100.']); + observe_ERPDAT.Process_messg =4; + return; + end +end +end -% Plot data in the main viewer fig -splot_n = elec_n; -tsize = 13; +%%----------------Zoom out------------------------------------------------- +function zoomout(~,~) +global observe_ERPDAT; -clear pb r_ax plotgrid; -try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color -catch - ColorB_def = [0.95 0.95 0.95]; +[messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); +if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1; end -if isempty(ColorB_def) - ColorB_def = [0.95 0.95 0.95]; + +zoomSpace = estudioworkingmemory('ERPTab_zoomSpace'); +if isempty(zoomSpace) + estudioworkingmemory('ERPTab_zoomSpace',0) +else + zoomSpace =zoomSpace-50; + if zoomSpace <100 + zoomSpace =100; + end + estudioworkingmemory('ERPTab_zoomSpace',zoomSpace) ; +end +MessageViewer= char(strcat('Zoom Out')); +estudioworkingmemory('f_ERP_proces_messg',MessageViewer); +observe_ERPDAT.Process_messg =1; +f_redrawERP(); +observe_ERPDAT.Process_messg =2; end -EStudio_gui_erp_totl.plotgrid = uix.VBox('Parent',EStudio_gui_erp_totl.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); -pageinfo_box = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def); -EStudio_gui_erp_totl.plot_wav_legend = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',[1 1 1]); -EStudio_gui_erp_totl.ViewAxes_legend = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.plot_wav_legend,'BackgroundColor',ColorB_def); -EStudio_gui_erp_totl.ViewAxes = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.plot_wav_legend,'BackgroundColor',[1 1 1]); +%%--------------------Setting for EStudio window size---------------------- +function EStudiowinsize(~,~) +global EStudio_gui_erp_totl; +global observe_ERPDAT; +try + ScreenPos= EStudio_gui_erp_totl.ScreenPos; +catch + ScreenPos = get( 0, 'Screensize' ); +end +try + New_pos = EStudio_gui_erp_totl.Window.Position; +catch + return; +end +try + New_posin = estudioworkingmemory('EStudioScreenPos'); +catch + New_posin = [75,75]; +end +if isempty(New_posin) ||numel(New_posin)~=2 + New_posin = [75,75]; +end +New_posin(2) = abs(New_posin(2)); -%%Changed by Guanghui Zhang 2 August 2022-------panel for display the processing procedure for some functions, e.g., filtering -xaxis_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message -EStudio_gui_erp_totl.Process_messg = uicontrol('Parent',xaxis_panel,'Style','text','String','','FontSize',20,'FontWeight','bold','BackgroundColor',ColorB_def); +app = feval('EStudio_pos_gui',New_posin); +waitfor(app,'Finishbutton',1); +try + New_pos1 = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.5); %wait for app to leave +catch + disp('User selected Cancel'); + return; +end +try New_pos1(2) = abs(New_pos1(2));catch; end; -% erpworkingmemory('EStudio_proces_messg',EStudio_gui_erp_totl); +if isempty(New_pos1) || numel(New_pos1)~=2 + estudioworkingmemory('f_ERP_proces_messg',['The defined Window Size for EStudio is invalid and it must be two numbers']); + observe_ERPDAT.Process_messg =4; + return; +end +estudioworkingmemory('EStudioScreenPos',New_pos1); +try + POS4 = (New_pos1(2)-New_posin(2))/100; + new_pos =[New_pos(1),New_pos(2)-ScreenPos(4)*POS4,ScreenPos(3)*New_pos1(1)/100,ScreenPos(4)*New_pos1(2)/100]; + if new_pos(2) < -abs(new_pos(4))%%if + + end + set(EStudio_gui_erp_totl.Window, 'Position', new_pos); +catch + estudioworkingmemory('f_ERP_proces_messg',['The defined Window Size for EStudio is invalid and it must be two numbers']); + observe_ERPDAT.Process_messg =4; + set(EStudio_gui_erp_totl.Window, 'Position', [0 0 0.75*ScreenPos(3) 0.75*ScreenPos(4)]); + estudioworkingmemory('EStudioScreenPos',[75 75]); +end +f_redrawEEG_Wave_Viewer(); +f_redrawERP(); +EStudio_gui_erp_totl.context_tabs.TabSize = (new_pos(3)-20)/2; +% EStudio_gui_erp_totl.context_tabs.TabSize = (new_pos(3)-20)/3; +end -%%Setting title -EStudio_gui_erp_totl.pageinfo_minus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '<','Callback',{@page_minus,EStudio_gui_erp_totl},'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index ==1 - EStudio_gui_erp_totl.pageinfo_minus.Enable = 'off'; +%------------------Display the waveform for proir ERPset------------------- +function page_minus(~,~,EStudio_gui_erp_totl) +global observe_ERPDAT; +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; end -EStudio_gui_erp_totl.pageinfo_edit = uicontrol('Parent',pageinfo_box,'Style', 'edit', 'String', num2str(S_ws_getbinchan.Select_index),'Callback',{@page_edit,EStudio_gui_erp_totl},'FontSize',20,'BackgroundColor',[1 1 1]); +ERPArray= estudioworkingmemory('selectederpstudio'); +if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); +end -if S_ws_getbinchan.Select_index ==1 - EStudio_gui_erp_totl.pageinfo_edit.Enable = 'on'; +Pagecurrent = str2num(EStudio_gui_erp_totl.pageinfo_edit.String); +pageNum = numel(ERPArray); +if ~isempty(Pagecurrent) && numel(Pagecurrent)~=1 %%if two or more numbers are entered + Pagecurrent =1; +elseif isempty(Pagecurrent) + [xpos, ypos] = find(ERPArray==observe_ERPDAT.CURRENTERP); + if isempty(ypos) + Pagecurrent=1; + else + Pagecurrent = ypos; + end end -EStudio_gui_erp_totl.pageinfo_plus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '>','Callback',{@page_plus,EStudio_gui_erp_totl},'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index == numel(S_ws_geterpset) - EStudio_gui_erp_totl.pageinfo_plus.Enable = 'off'; +Pagecurrent = Pagecurrent-1; +if Pagecurrent>0 && Pagecurrent<=pageNum +else + Pagecurrent=1; end -pageinfo_str = ['Page',32,num2str(S_ws_getbinchan.Select_index),'/',num2str(numel(S_ws_geterpset)),':',32,observe_ERPDAT.ERP.erpname]; +Current_erp_Index = ERPArray(Pagecurrent); +EStudio_gui_erp_totl.pageinfo_edit.String = num2str(Pagecurrent); -pageinfo_text = uicontrol('Parent',pageinfo_box,'Style','text','String',pageinfo_str,'FontSize',14,'FontWeight','bold'); +observe_ERPDAT.CURRENTERP = Current_erp_Index; +observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); -if length(S_ws_geterpset) ==1 +% f_redrawERP(); +if length(ERPArray) ==1 Enable_minus = 'off'; Enable_plus = 'off'; - Enable_plus_BackgroundColor = [1 1 1]; + Enable_plus_BackgroundColor = [0 0 0]; Enable_minus_BackgroundColor = [0 0 0]; else - if S_ws_getbinchan.Select_index ==1 + if Pagecurrent ==1 Enable_minus = 'off'; Enable_plus = 'on'; Enable_plus_BackgroundColor = [0 1 0]; Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) + elseif Pagecurrent == length(ERPArray) Enable_minus = 'on'; Enable_plus = 'off'; Enable_plus_BackgroundColor = [0 0 0]; @@ -196,596 +537,806 @@ function f_redrawERP() EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -% EStudio_gui_erp_totl.pageinfo_edit.ForegroundColor = [1 1 1]; -set(pageinfo_box, 'Sizes', [50 50 50 -1] ); -set(pageinfo_box,'BackgroundColor',ColorB_def); -set(pageinfo_text,'BackgroundColor',ColorB_def); -%Setting title. END,'BackgroundColor',ColorB_def +MessageViewer= char(strcat('Plot previous page (<)')); +estudioworkingmemory('f_ERP_proces_messg',MessageViewer); +observe_ERPDAT.Process_messg =1; +observe_ERPDAT.Count_currentERP = 1; +end -%for i=1:splot_n -% -%%------------Setting the number of data and plotting--------------------- -ndata = 0; -nplot = 0; -if Bin_chans == 0 %if channels with bin overlay - ndata = Bins; - nplot = Elecs_shown; -else %if bins with channel overlay - ndata = Elecs_shown; - nplot = Bins; +%%--------------------Edit the index of ERPsets---------------------------- +function page_edit(Str,~) +global observe_ERPDAT; +global EStudio_gui_erp_totl; +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; +end +ERPArray= estudioworkingmemory('selectederpstudio'); +if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); end -% -timeor = observe_ERPDAT.ERP.times; % original time vector -timex = timeor; -[xxx, latsamp, latdiffms] = closest(timex, [Min_time Max_time]); -tmin = latsamp(1); -tmax = latsamp(2); - -if tmin < 1 - tmin = 1; +Pagecurrent = str2num(Str.String); +if isempty(Pagecurrent) || numel(Pagecurrent)~=1 || any(Pagecurrent>numel(ERPArray)) || any(Pagecurrent<1) + [xpos, ypos] = find(ERPArray==observe_ERPDAT.CURRENTERP); + if isempty(ypos) + Pagecurrent=1; + else + Pagecurrent = ypos; + end + observe_ERPDAT.CURRENTERP = ERPArray(Pagecurrent); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(ERPArray(Pagecurrent)); +end +EStudio_gui_erp_totl.pageinfo_edit.String = num2str(Pagecurrent); +Current_erp_Index = ERPArray(Pagecurrent); +observe_ERPDAT.CURRENTERP = Current_erp_Index; +observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); +if length(ERPArray) ==1 + Enable_minus = 'off'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [0 0 0]; + Enable_minus_BackgroundColor = [0 0 0]; +else + if Pagecurrent ==1 + Enable_minus = 'off'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [1 1 1]; + elseif Pagecurrent == length(ERPArray) + Enable_minus = 'on'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [0 0 0]; + Enable_minus_BackgroundColor = [0 1 0]; + else + Enable_minus = 'on'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [0 1 0]; + end end +EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; +EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; +EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; +EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -if tmax > numel(observe_ERPDAT.ERP.times) - tmax = numel(observe_ERPDAT.ERP.times); +observe_ERPDAT.Count_currentERP = 1; +observe_ERPDAT.Process_messg =2; end -[xtick_time, Bindata] = f_get_erp_xticklabel_time(observe_ERPDAT.ERP, [Min_time Max_time],[Timet_low,Timet_high]); +%------------------Display the waveform for next ERPset-------------------- +function page_plus(~,~,EStudio_gui_erp_totl) +global observe_ERPDAT; -% plot_erp_data = nan(tmax-tmin+1,numel(ndata)); -plot_erp_data = []; -for i = 1:splot_n - if Bin_chans == 0 - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = Bindata(Elecs_shown(i),:,Bins(i_bin))'*Plority_plot; % - end - else - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = Bindata(Elecs_shown(i_bin),:,Bins(i))'*Plority_plot; % - end - end +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; end -if Yscale==0 - Yscale = max(abs(Bindata(:))); -end -perc_lim = Yscale; -percentile = perc_lim*3/2; -[~,~,b] = size(plot_erp_data); - - -% -%%%------------Setting xticklabels for each row of each wave-------------- -xstep_label = estudioworkingmemory('erp_xtickstep'); -if isempty(xstep_label) - xstep_label =0; -end -if ~xstep_label - [def Timet_step]= default_time_ticks_studio(observe_ERPDAT.ERP, [Timet_low,Timet_high]); - if ~isempty(def) - xticks_clomn = str2num(def{1,1}); - while xticks_clomn(end)<=Timet_high - xticks_clomn(numel(xticks_clomn)+1) = xticks_clomn(end)+Timet_step; - if xticks_clomn(end)>Timet_high - xticks_clomn = xticks_clomn(1:end-1); - break; - end - end +ERPArray= estudioworkingmemory('selectederpstudio'); +if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); +end +Pagecurrent = str2num(EStudio_gui_erp_totl.pageinfo_edit.String); +pageNum = numel(ERPArray); +if ~isempty(Pagecurrent) && numel(Pagecurrent)~=1 %%if two or more numbers are entered + Pagecurrent =1; +elseif isempty(Pagecurrent) + [xpos, ypos] = find(ERPArray==observe_ERPDAT.CURRENTERP); + if isempty(ypos) + Pagecurrent=1; else - xticks_clomn = (Timet_low:Timet_step:Timet_high); + Pagecurrent = ypos; end -else - xticks_clomn = (Timet_low:Timet_step:Timet_high); end - -if strcmpi(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - xticks_clomn = [0:1]; +Pagecurrent = Pagecurrent+1; +if Pagecurrent>0 && Pagecurrent<=pageNum +else + Pagecurrent = pageNum; end +Current_erp_Index = ERPArray(Pagecurrent); +EStudio_gui_erp_totl.pageinfo_edit.String = num2str(Pagecurrent); -Timet_step_p = ceil(Timet_step/(1000/observe_ERPDAT.ERP.srate));%% Time points of the gap between columns -if ~strcmpi(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - % - %%----------------------Modify the data into multiple-columns--------------------------------------- - rowNum = ceil(b/Column_label); - plot_erp_data_new = NaN(size(plot_erp_data,1),size(plot_erp_data,2),rowNum*Column_label); - - plot_erp_data_new(:,:,1:size(plot_erp_data,3)) = plot_erp_data; - plot_erp_data_new_trans = []; - - - if Column_label==1 - for Numofrow = 1:rowNum - plot_erp_data_new_trans(:,:,:,Numofrow) = plot_erp_data_new(:,:,(Numofrow-1)*Column_label+1:Numofrow*Column_label); - end - - clear plot_erp_data; - plot_erp_data_new_trans = permute(plot_erp_data_new_trans,[1,3,2,4]) ; - plot_erp_data = reshape(plot_erp_data_new_trans,size(plot_erp_data_new_trans,1)*size(plot_erp_data_new_trans,2),size(plot_erp_data_new_trans,3),size(plot_erp_data_new_trans,4)); - - elseif Column_label>1 - - plot_erp_data_trans_clumns = NaN(size(plot_erp_data_new,1)*Column_label+(Column_label-1)*Timet_step_p,size(plot_erp_data_new,2),rowNum); - for Numofrow = 1:rowNum - Data_column = plot_erp_data_new(:,:,(Numofrow-1)*Column_label+1:Numofrow*Column_label); - for Numofcolumn = 1:Column_label - low_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+1+(Numofcolumn-1)*Timet_step_p; - high_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+(Numofcolumn-1)*Timet_step_p+size(plot_erp_data_new,1); - plot_erp_data_trans_clumns(low_interval:high_interval,:,Numofrow) = squeeze(Data_column(:,:,Numofcolumn)); - end - end - plot_erp_data = plot_erp_data_trans_clumns; +observe_ERPDAT.CURRENTERP = Current_erp_Index; +observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); +estudioworkingmemory('selectederpstudio',ERPArray); +if length(ERPArray) ==1 + Enable_minus = 'off'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [0 0 0]; + Enable_minus_BackgroundColor = [0 0 0]; +else + if Pagecurrent ==1 + Enable_minus = 'off'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [1 1 1]; + elseif Pagecurrent == length(ERPArray) + Enable_minus = 'on'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [0 0 0]; + Enable_minus_BackgroundColor = [0 1 0]; + else + Enable_minus = 'on'; + Enable_plus = 'on'; + Enable_plus_BackgroundColor = [0 1 0]; + Enable_minus_BackgroundColor = [0 1 0]; end - - ind_plot_height = percentile*2; % Height of each individual subplot - - offset = []; - if Bin_chans == 0 - offset = (size(plot_erp_data,3)-1:-1:0)*ind_plot_height; +end +EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; +EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; +EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; +EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; +observe_ERPDAT.Count_currentERP = 1; +end + + + +%%--------------------------show the command------------------------------- +function Show_command(~,~) +global observe_ERPDAT; +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; +end +[messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); +if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel +end +estudioworkingmemory('f_ERP_proces_messg','Show Command'); +observe_ERPDAT.Process_messg =1; +f_preparms_erptab(observe_ERPDAT.ERP,1,'command'); +observe_ERPDAT.Process_messg =2; +end + +%%----------------------------save figure as------------------------------- +function figure_saveas(~,~) +global observe_ERPDAT; +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; +end +[messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); +if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel +end + +estudioworkingmemory('f_ERP_proces_messg','Save figure as'); +observe_ERPDAT.Process_messg =1; +pathstr = pwd; +namedef =[observe_ERPDAT.ERP.erpname,'.pdf']; +[erpfilename, erppathname, indxs] = uiputfile({'*.pdf';'*.svg';'*.jpg';'*.png';'*.tif';'*.bmp';'*.eps'},... + 'Save as',[fullfile(pathstr,namedef)]); + + +if isequal(erpfilename,0) + beep; + observe_ERPDAT.Process_messg =3; + disp('User selected Cancel') + return +end + +History = 'off'; +[pathstr, erpfilename1, ext] = fileparts(erpfilename) ; + +if isempty(ext) + figurename = fullfile(erppathname,char(strcat(erpfilename,'.pdf'))); +else + figurename = fullfile(erppathname,erpfilename); +end + +f_preparms_erptab(observe_ERPDAT.ERP,1,History,figurename); +observe_ERPDAT.Process_messg =2; +end + +%%--------------------Create static/eportable plot------------------------- +function figure_out(~,~) +global observe_ERPDAT; +if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; +end +[messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); +if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel +end + +MessageViewer= char(strcat('Create Static/Exportable Plot')); +estudioworkingmemory('f_ERP_proces_messg',MessageViewer); +observe_ERPDAT.Process_messg =1; +try + figurename = observe_ERPDAT.ERP.erpname; +catch + figurename = ''; +end +History = 'off'; +f_preparms_erptab(observe_ERPDAT.ERP,1,History,figurename); +observe_ERPDAT.Process_messg =2; +end + + +%%------------------------Reset parameters--------------------------------- +function erptab_reset(~,~) +global observe_ERPDAT; +global EStudio_gui_erp_totl; +global observe_EEGDAT; + +estudioworkingmemory('ViewerFlag', 0); + +MessageViewer= char(strcat('Reset parameters for ERP panels ')); +estudioworkingmemory('f_ERP_proces_messg',MessageViewer); +app = feval('estudio_reset_paras',[0 0 1 0]); +waitfor(app,'Finishbutton',1); +reset_paras = [0 0 0 0]; +try + reset_paras = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave +catch + return; +end +if isempty(reset_paras) + return; +end +EStudio_gui_erp_totl.ERP_autoplot=1; +EStudio_gui_erp_totl.EEG_autoplot = 1; +%%---------------------------EEG Tab--------------------------------------- +if reset_paras(2)==1 + EStudio_gui_erp_totl.clear_alleeg = 1; +else + EStudio_gui_erp_totl.clear_alleeg = 0; +end + +if reset_paras(1)==1 + if ~isempty(observe_EEGDAT.EEG) && ~isempty(observe_EEGDAT.ALLEEG) + observe_EEGDAT.Reset_eeg_paras_panel=1; + end + if EStudio_gui_erp_totl.clear_alleeg == 0 + f_redrawEEG_Wave_Viewer(); else - offset = (size(plot_erp_data,3)-1:-1:0)*ind_plot_height; + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + estudioworkingmemory('EEGArray',1); + observe_EEGDAT.count_current_eeg =1; end - [~,~,b] = size(plot_erp_data); - for i = 1:b - plot_erp_data(:,:,i) = plot_erp_data(:,:,i) + ones(size(plot_erp_data(:,:,i)))*offset(i); +else + if EStudio_gui_erp_totl.clear_alleeg == 1 + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + estudioworkingmemory('EEGArray',1); + observe_EEGDAT.count_current_eeg =1; end - - - - r_ax = axes('Parent', EStudio_gui_erp_totl.ViewAxes,'Color','none','Box','on','FontWeight','bold'); - hold(r_ax,'on'); - set(EStudio_gui_erp_totl.plot_wav_legend,'Sizes',[80 -10]); - r_ax_legend = axes('Parent', EStudio_gui_erp_totl.ViewAxes_legend,'Color','none','Box','off'); - hold(r_ax_legend,'on'); - - - try - f_bin = 1000/observe_ERPDAT.ERP.srate; - catch - f_bin = 1; +end + + +%%---------------- -------------erp tab------------------------------------ +if reset_paras(4)==1 + EStudio_gui_erp_totl.clear_allerp = 1; +else + EStudio_gui_erp_totl.clear_allerp = 0; +end +observe_ERPDAT.Process_messg =1; +if reset_paras(3)==1 + if ~isempty(observe_ERPDAT.ERP) && ~isempty(observe_ERPDAT.ALLERP) + observe_ERPDAT.Reset_erp_paras_panel = 1; + end + if EStudio_gui_erp_totl.clear_allerp == 0 + f_redrawERP(); + else + observe_ERPDAT.ALLERP = []; + observe_ERPDAT.ERP = []; + observe_ERPDAT.CURRENTERP = 1; + estudioworkingmemory('selectederpstudio',1); end - ts = xtick_time; - ts_colmn = ts; - - % - %%------------------Adjust the data into multiple/single columns------------ - if Column_label>1 % Plotting waveforms with munltiple-columns - xticks_org = xticks_clomn; - for Numofcolumn = 1:Column_label-1 - xticks_clomn_add = [1:numel(ts)+Timet_step_p].*f_bin+(ts_colmn(end).*ones(1,numel(ts)+Timet_step_p)); - ts_colmn = [ts_colmn,xticks_clomn_add]; - end - - X_zero_line(1) =ts(1); - for Numofcolumn = 1:Column_label-1 - if Numofcolumn ==1 - X_zero_line(Numofcolumn+1) = X_zero_line(Numofcolumn)+ ts(end)-ts(1)+f_bin + (Timet_step_p/2)*f_bin; - else - X_zero_line(Numofcolumn+1) = X_zero_line(Numofcolumn)+ ts(end)-ts(1)+f_bin + (Timet_step_p)*f_bin; - end - end +else + if EStudio_gui_erp_totl.clear_allerp == 1 - [xticks,xticks_labels] = f_geterpxticklabel(observe_ERPDAT.ERP,xticks_clomn,Column_label,[Timet_low,Timet_high],Timet_step); - ts = ts_colmn; - Timet_low= ts(1); - Timet_high= ts(end); - for ii =1:100 - if Timet_high observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; +end +BinArray= estudioworkingmemory('ERP_BinArray'); +if isempty(BinArray) || any(BinArray<1) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; +end +ERPArray= estudioworkingmemory('selectederpstudio'); +if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); +end +ERPLAB_ERP_Viewer(observe_ERPDAT.ALLERP,ERPArray,BinArray,ChanArray); +observe_ERPDAT.Process_messg =2; +end + + + + +function f_plotaberpwave(ERP,ChanArray,BinArray,timeStart,timEnd,xtickstep,yscale,columNum,... + positive_up,BinchanOverlay,rowNums,GridposArray,Standerr,Transparency,waveview,legendview,Yticks) + +FonsizeDefault = f_get_default_fontsize(); +%%matlab version +matlab_ver = version('-release'); +Matlab_ver = str2double(matlab_ver(1:4)); + + +qtimeRange = [timeStart timEnd]; +if BinchanOverlay==0 + qPLOTORG = [1 2 3]; + [~, qplotArrayStr, ~, ~, ~] = readlocs(ERP.chanlocs(ChanArray)); + qLegendName= ERP.bindescr(BinArray); +else + qPLOTORG = [2 1 3]; + [~, qLegendName, ~, ~, ~] = readlocs(ERP.chanlocs(ChanArray)); + qplotArrayStr = ERP.bindescr(BinArray); +end +[ERPdatadef,legendNamedef,ERPerrordatadef,timeRangedef] = f_geterpdata(ERP,1,qPLOTORG,1); +if qPLOTORG(1)==1 && qPLOTORG(2)==2 %% Array is plotnum by samples by datanum + bindata = ERPdatadef(sort(ChanArray),:,sort(BinArray),1); + bindataerror= ERPerrordatadef(sort(ChanArray),:,sort(BinArray),1); + plotArray = ChanArray; +elseif qPLOTORG(1)==2 && qPLOTORG(2)==1 + bindata = ERPdatadef(sort(ChanArray),:,sort(BinArray),1); + bindata = permute(bindata,[3 2 1 4]); + bindataerror= ERPerrordatadef(sort(ChanArray),:,sort(BinArray),1); + bindataerror = permute(bindataerror,[3 2 1 4]); + plotArray = BinArray; +end +if isempty(Standerr) || numel(Standerr)~=1 || any(Standerr<0) || any(Standerr>10) + Standerr=1; +end + +if isempty(Transparency) || numel(Transparency)~=1 || any(Transparency<0)|| any(Transparency>1) + Transparency=0.2; +end + + +if isempty(timeRangedef) + timeRangedef = ERP.times; +end +fs= ERP.srate; +qYScales = yscale; +Ypert =15; +%%get y axis +ERP1 = ERP; +ERP1.bindata = ERP.bindata(ChanArray,:,:); +[def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); +minydef = floor(minydef); +maxydef = ceil(maxydef); +if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end +elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; +end + +y_scale_def = [minydef,maxydef]; +if isempty(qYScales) || numel(qYScales)~=2 + qYScales = y_scale_def; +end +if numel(qYScales)==2 + yscaleall = qYScales(end)-qYScales(1); +else + yscaleall = 2*max(abs(qYScales)); + qYScales = [-max(abs(qYScales)),max(abs(qYScales))]; +end +% if yscaleall < y_scale_def(2)-y_scale_def(1) +% yscaleall = y_scale_def(2)-y_scale_def(1); +% end +for Numofrows = 1:rowNums + OffSetY(Numofrows) = yscaleall*(rowNums-Numofrows)*(Ypert/100+1); +end + +qYticksdef = str2num(char(default_amp_ticks_viewer(qYScales))); +qYticks = Yticks; +if isempty(qYticks) || numel(qYticks)<2 + qYticks = qYticksdef; +end + + +%%gap between columns +Xpert = 10; +try + StepX = (ERP.times(end)-ERP.times(1))*(Xpert/100); +catch + beep; + disp('ERP.times only has one element.'); + return; +end +StepXP = ceil(StepX/(1000/fs)); + +qPolarityWave = positive_up; + +NumOverlay = size(bindata,3); +isxaxislabel=1; + +%%line color +qLineColorspec = get_colors(NumOverlay); +%%xticks +[timeticksdef stepX]= default_time_ticks_studio(ERP, qtimeRange); +timeticksdef = str2num(char(timeticksdef)); +qtimeRangedef = round(qtimeRange/100)*100; +qXticks = xtickstep+qtimeRangedef(1); +for ii=1:1000 + xtickcheck = qXticks(end)+xtickstep; + if xtickcheck>qtimeRange(2) + break; + else + qXticks(numel(qXticks)+1) =xtickcheck; + end +end +if isempty(qXticks) + qXticks = timeticksdef; +end + +[xxx, latsamp1, latdiffms] = closest(ERP.times, qtimeRange); +qtimes = ERP.times(latsamp1(1):latsamp1(2)); + + +[xxx, latsamp, latdiffms] = closest(qtimes, 0); +if isempty(latsamp) || any(latsamp<=0) + labelxrange = 0; +else + labelxrange = qtimes(latsamp)-qtimes(1); +end +if labelxrange<=0 + CBELabels = [1 100 1]; +else + CBELabels(1) = 100*labelxrange/(qtimeRange(2)-qtimeRange(1))+1; +end + +%%remove the margins of a plot +ax = waveview; +outerpos = ax.OuterPosition; +ti = ax.TightInset; +left = outerpos(1) + ti(1); +bottom = outerpos(2) + ti(2); +ax_width = outerpos(3) - ti(1) - ti(3); +ax_height = outerpos(4) - ti(2) - ti(4); +ax.Position = [left bottom ax_width ax_height]; + +%%check elements in qGridposArray +plotArray = reshape(plotArray,1,[]); +for Numofrows = 1:size(GridposArray,1) + for Numofcolumns = 1:size(GridposArray,2) + SingleGridpos = GridposArray(Numofrows,Numofcolumns); + if SingleGridpos~=0 + ExistGridops = f_existvector(plotArray,SingleGridpos); + if ExistGridops==1 + GridposArray(Numofrows,Numofcolumns) =0; else - break; + [xpos,ypos]= find(plotArray==SingleGridpos); + GridposArray(Numofrows,Numofcolumns) =plotArray(ypos); end end - - else%% Plotting waveforms with single-column - %%%------------getting xticklabels for each row of each wave-------------- - xticks =xticks_clomn; - X_zero_line(1) =ts(1); - for Numofxlabel = 1:numel(xticks) - xticks_labels{Numofxlabel} = num2str(xticks(Numofxlabel)); - end - end - - - splot_n = size(plot_erp_data,3);%%Adjust the columns - - set(r_ax,'XLim',[Timet_low,Timet_high]); - - [a,c,b] = size(plot_erp_data); - new_erp_data = zeros(a,b*c); - for i = 1:b - new_erp_data(:,((c*(i-1))+1):(c*i)) = plot_erp_data(:,:,i); end - - - line_colors = erpworkingmemory('PWColor'); - if size(line_colors,1)~= numel(ndata) - if numel(ndata)> size(line_colors,1) - line_colors = get_colors(numel(ndata)); +end +fontnames = 'Helvetica'; + +hplot = []; +countPlot = 0; +for Numofrows = 1:rowNums + for Numofcolumns = 1:columNum + try + plotdatalabel = GridposArray(Numofrows,Numofcolumns); + catch + plotdatalabel = 0; + end + if (qPLOTORG(1)==1 && qPLOTORG(2)==2) ||(qPLOTORG(1)==2 && qPLOTORG(2)==1) + plotArray1 = sort(plotArray); else - line_colors = line_colors(1:numel(ndata),:,:); + plotArray1 = plotArray; + end + [xpos,plotdatalabel] = find(plotArray1 == plotdatalabel); + if isempty(plotdatalabel) + plotdatalabel = 0; + end + try + plotbindata = bindata(plotdatalabel,:,:,:); + catch + plotbindata = []; end - end - - if isempty(line_colors) - line_colors = get_colors(numel(ndata)); - end - - line_colors = repmat(line_colors,[splot_n 1]); %repeat the colors once for every plot - - % - %%------------Setting xticklabels for each row -------------- - x_axs = ones(size(new_erp_data,1),1); - for jj = 1:numel(offset)-1 - plot(r_ax,ts,x_axs.*offset(end),'color',[1 1 1],'LineWidth',1); - set(r_ax,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); - myX_Crossing = offset(jj); - props = get(r_ax); - tick_bottom = -props.TickLength(1)*diff(props.YLim); - if abs(tick_bottom) > abs(Yscale)/5 + if plotdatalabel ~=0 && plotdatalabel<= numel(plotArray) && ~isempty(plotbindata) + countPlot =countPlot +1; try - tick_bottom = - abs(Yscale)/5; + labelcbe = qplotArrayStr{countPlot}; + if isempty(labelcbe) + labelcbe = 'No label'; + end catch - tick_bottom = tick_bottom; + labelcbe = 'no'; end - elseif abs(tick_bottom)1 - if numel(offset)==jj - kkkk = 1; + + if qPolarityWave==1 + data4plot = squeeze(bindata(plotdatalabel,:,:,1)); else - if abs(Timet_low - xticks(1)) > 1000/observe_ERPDAT.ERP.srate - kkkk = 1; + data4plot = squeeze(bindata(plotdatalabel,:,:,1))*(-1); + end + + data4plot = reshape(data4plot,numel(timeRangedef),NumOverlay); + for Numofoverlay = 1:NumOverlay + [Xtimerange, bindatatrs] = f_adjustbindtabasedtimedefd(squeeze(data4plot(:,Numofoverlay)), timeRangedef,qtimeRange,fs); + PosIndexsALL = [Numofrows,columNum]; + if isxaxislabel==2 + [~,XtimerangetrasfALL,~,~,~] = f_adjustdata_xyrange_xyticks_overlay(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexsALL,StepXP); + else + [~,XtimerangetrasfALL,~] = f_adjustdata_xyrange_xyticks(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexsALL,StepX,fs); + end + aerror = isnan(squeeze(bindataerror(plotdatalabel,:,Numofoverlay,1))); + [Xerror,yerro] = find(aerror==0); + PosIndexs = [Numofrows,Numofcolumns]; + if ~isempty(yerro) && Standerr>=1 &&Transparency>0 %SEM + [Xtimerange, bindataerrtrs] = f_adjustbindtabasedtimedefd(squeeze(bindataerror(plotdatalabel,:,Numofoverlay,1)), timeRangedef,qtimeRange,fs); + if isxaxislabel==2 + [bindatatrs1,Xtimerangetrasf,qXtickstransf,TimeAdjustOut,XtimerangeadjustALL] = f_adjustdata_xyrange_xyticks_overlay(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexs,StepXP); + else + [bindatatrs1,Xtimerangetrasf,qXtickstransf] = f_adjustdata_xyrange_xyticks(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexs,StepX,fs); + end + yt1 = bindatatrs1 - bindataerrtrs.*Standerr; + yt2 = bindatatrs1 + bindataerrtrs.*Standerr; + fill(waveview,[Xtimerangetrasf fliplr(Xtimerangetrasf)],[yt2 fliplr(yt1)], qLineColorspec(Numofoverlay,:), 'FaceAlpha', Transparency, 'EdgeColor', 'none'); + end + if isxaxislabel==2 + [bindatatrs,Xtimerangetrasf,qXtickstransf,TimeAdjustOut,XtimerangeadjustALL] = f_adjustdata_xyrange_xyticks_overlay(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexs,StepXP); else - kkkk = 2; + [bindatatrs,Xtimerangetrasf,qXtickstransf] = f_adjustdata_xyrange_xyticks(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexs,StepX,fs); end + hplot(Numofoverlay) = plot(waveview,Xtimerangetrasf, bindatatrs,'LineWidth',1,... + 'Color', qLineColorspec(Numofoverlay,:)); + end - for iCount = kkkk:nTicks - xtick_label = (props.XTickLabel(iCount, :)); - text(r_ax,props.XTick(iCount), tick_bottom + myX_Crossing, ... - xtick_label, ... - 'HorizontalAlignment', 'Center', ... - 'VerticalAlignment', 'Top', ... - 'FontSize', 12, ... - 'FontName', props.FontName, ... - 'FontAngle', props.FontAngle, ... - 'FontUnits', props.FontUnits, ... - 'FontWeight', 'bold'); + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%----------------------Adjust y axis------------------------%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + props = get(waveview); + if qPolarityWave==1 + props.YTick = qYticks+OffSetY(Numofrows); + else + props.YTick = fliplr (-1*qYticks)+OffSetY(Numofrows); end - end - end - - - % - %%----------------Start:Remove xticks for the columns without waves in the last row------------------------- - Element_left = numel(nplot) - (ceil(numel(nplot)/Column_label)-1)*Column_label; - plot(r_ax,ts,x_axs.*offset(end),'color', [1 1 1],'LineWidth',1); - set(r_ax,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); - myX_Crossing = offset(end); - props = get(r_ax); - - tick_bottom = -props.TickLength(1)*diff(props.YLim); - if abs(tick_bottom) > abs(Yscale)/5 - try - tick_bottom = - abs(Yscale)/5; - catch - tick_bottom = tick_bottom; - end - elseif abs(tick_bottom)1 - for iCount = 1:ceil(nTicks/Column_label*Element_left) - xtick_label = (props.XTickLabel(iCount, :)); - text(r_ax,props.XTick(iCount), tick_bottom + myX_Crossing, ... - xtick_label, ... - 'HorizontalAlignment', 'Center', ... - 'VerticalAlignment', 'Top', ... - 'FontSize', 12, ... - 'FontName', props.FontName, ... - 'FontAngle', props.FontAngle, ... - 'FontUnits', props.FontUnits, ... - 'FontWeight', 'bold'); - end - end - %%--------------------------End:Remove xticks for the columns without waves in the last row------------------------- - - % - %%-----------------Get zeroline for each row----------------------------- - row_baseline = NaN(numel(ts),splot_n); - count = 0; - for Numofsplot = 0:splot_n-1 - for Numofcolumn = 1:Column_label - count = count +1; - if count> numel(nplot) - break; + props.YTickLabel = cell(numel(props.YTick),1); + + + for Numofytick = 1:numel(props.YTick) + props.YTickLabel(Numofytick) = {num2str(props.YTick(Numofytick))}; end - low_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+1+(Numofcolumn-1)*Timet_step_p; - high_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+(Numofcolumn-1)*Timet_step_p+size(plot_erp_data_new,1); - row_baseline(low_interval:high_interval,Numofsplot+1) = ones(numel(low_interval:high_interval),1).*offset(Numofsplot+1); - end - end - - - % - %%-------------------------Plotting ERP waves----------------------------- - pb_here = plot(r_ax,ts, [new_erp_data],'LineWidth',1.5); - - set(r_ax, 'XTick', [], 'XTickLabel', []); - - % - %%----------------Marking 0 point (event-locked)-------------------------- - [xxx, latsamp_0, latdiffms_0] = closest(xticks, [0]); - if numel(offset)>1 - if latdiffms_0 ==0 - for Numofcolumn = 1:Column_label - xline(r_ax,xticks((Numofcolumn-1)*numel(xticks_clomn)+latsamp_0),'k-.','LineWidth',1);%%'Color',Marking start time point for each column + + [x,y_0] = find(Xtimerange==0); + if isempty(y_0) + y_0 = 1; end - end - elseif numel(offset)==1 - - for Numofcolumn = 1:numel(nplot) - xline(r_ax,xticks((Numofcolumn-1)*numel(xticks_clomn)+latsamp_0),'k-.','LineWidth',1);%%'Color',Marking start time point for each column - end - end - % - yticks = -perc_lim:perc_lim:((2*percentile*b)-(2*perc_lim)); - ylabs = repmat([-perc_lim 0 perc_lim],[1,b]); - oldlim = [-percentile yticks(end)-perc_lim+percentile]; - top_vspace = max( max( new_erp_data))-oldlim(2); - bot_vspace = min( min( new_erp_data))-oldlim(1); - if top_vspace < 0 - top_vspace = 0; - end - - if bot_vspace > 0 - bot_vspace = 0; - end - newlim = oldlim + [bot_vspace top_vspace]; - set(r_ax,'XLim',[Timet_low,Timet_high],'Ylim',newlim); - - - % - %%--------------Setting color for each wave-------------------------- - % if Column_label>1 - % for i = 0:splot_n-1 - % r_ax.Children(end-i).Color = [1 1 1]; - % end - % end - - % for i = splot_n+1:numel(pb_here) - % pb_here(i).Color = line_colors((i-splot_n),:); - % end - for i = 1:numel(pb_here) - pb_here(i).Color = line_colors(i,:); - end - % - % for i = 1:splot_n-1 - % pb_here(i).Color = [0 0 0]; - % pb_here(i).LineWidth=.01; - % end - - - - - %%------------Marking start time point for each column--------------------- - if Column_label>1 - for ii = 2:numel(X_zero_line) - xline(r_ax,X_zero_line(ii), 'y--','LineWidth',2); - end - end - - for Numofplot = 1:size(row_baseline,2) - plot(r_ax,ts,row_baseline(:,Numofplot),'color',[0 0 0],'LineWidth',1.5); - end - ylabs = [fliplr(-perc_lim:-perc_lim:newlim(1)) ylabs(2:end-1) (yticks(end):perc_lim:newlim(2))-yticks(end)+perc_lim]; - yticks = [fliplr(-perc_lim:-perc_lim:newlim(1)) yticks(2:end-1) yticks(end):perc_lim:newlim(2)]; - - % - %%-------------Name of bin/channel for each subplot-------------------------- - if Column_label==1 - if numel(offset)>1 - count = 0; - for i = 0:numel(offset)-1 - leg_str = ''; - - count = count+1; + myY_Crossing = Xtimerangetrasf(y_0); + tick_top = 0; + + if countPlot ==1 + ytick_bottom = -props.TickLength(1)*diff(props.XLim); + ytick_bottomratio = abs(ytick_bottom)/diff(props.XLim); + else try - if Bin_chans == 0 - leg_str = sprintf('%s',strrep(Elec_list{Elecs_shown(count)},'_','\_')); - else - leg_str = sprintf('%s',strrep(observe_ERPDAT.ERP.bindescr{Bins(count)},'_','\_')); + ytick_bottom = ytick_bottom; + ytick_bottomratio = ytick_bottomratio; + catch + ytick_bottom = -props.TickLength(1)*diff(props.XLim); + ytick_bottomratio = abs(ytick_bottom)/diff(props.XLim); + end + end + %%add yunits + if ~isempty(props.YTick) + ytick_y = repmat(props.YTick, 2, 1); + ytick_x = repmat([tick_top;ytick_bottom] +myY_Crossing, 1, length(props.YTick)); + line(waveview,ytick_x(:,:), ytick_y(:,:), 'color', 'k','LineWidth',1); + try + [~,y_below0] =find(qYticks<0); + if isempty(y_below0) && qYScales(1)<0 + line(waveview,ytick_x(:,:), ones(2,1)*(qYScales(1)+OffSetY(Numofrows)), 'color', 'k','LineWidth',1); + end + [~,y_over0] =find(qYticks>0); + if isempty(y_over0) && qYScales(2)>0 + line(waveview,ytick_x(:,:), ones(2,1)*(qYScales(2)+OffSetY(Numofrows)), 'color', 'k','LineWidth',1); end catch - leg_str = ''; end - text(r_ax,ts(1),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); end - end - - try - if Bin_chans == 0 - leg_str = sprintf('%s',strrep(Elec_list{Elecs_shown(end)},'_','\_')); + + if ~isempty(qYScales) && numel(qYScales)==2 %qYScales(end))+OffSetY(1) + if qPolarityWave~=1 + qYScalestras = fliplr (-1*qYScales); + else + qYScalestras = qYScales; + end + plot(waveview,ones(numel(qYScalestras),1)*myY_Crossing, qYScalestras+OffSetY(Numofrows),'k','LineWidth',1); else - leg_str = sprintf('%s',strrep(observe_ERPDAT.ERP.bindescr{Bins(end)},'_','\_')); - end - catch%% - leg_str = ''; - end - - try - text(r_ax,ts(1),offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - catch - text(r_ax,ts(1),Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); - end - else%% Getting y ticks and legends for multiple-columns - if numel(offset)>1 - count = 0; - for i = 0:numel(offset)-1 - leg_str = ''; - for Numofcolumn = 1: Column_label - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',strrep(Elec_list{Elecs_shown(count)},'_','\_')); - else - leg_str = sprintf('%s',strrep(observe_ERPDAT.ERP.bindescr{Bins(count)},'_','\_')); - end - catch - leg_str = ''; - end - if Numofcolumn ==1 - text(r_ax,X_zero_line(Numofcolumn),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); + if ~isempty(y_scale_def) && numel(unique(y_scale_def))==2 + if qPolarityWave==0 + qYScalestras = fliplr (-1*y_scale_def); else - text(r_ax,X_zero_line(Numofcolumn)+Timet_step/2,offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); + qYScalestras = y_scale_def; end + plot(waveview,ones(numel(qYScales),1)*myY_Crossing, qYScalestras+OffSetY(Numofrows),'k','LineWidth',1); + else end end - end - - - count = (numel(offset)-1)*Column_label; - leg_str = ''; - for Numofcolumn = 1:Column_label - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',strrep(Elec_list{Elecs_shown(count)},'_','\_')); + + qYtickdecimal=1; + nYTicks = length(props.YTick); + for iCount = 1:nYTicks + if qPolarityWave==1 + ytick_label= sprintf(['%.',num2str(qYtickdecimal),'f'],str2num(char(props.YTickLabel(iCount, :)))-OffSetY(Numofrows)); else - leg_str = sprintf('%s',strrep(observe_ERPDAT.ERP.bindescr{Bins(count)},'_','\_')); + qyticktras = fliplr(-1*qYticks); + ytick_label= sprintf(['%.',num2str(qYtickdecimal),'f'],-qyticktras(iCount)); + end + % end + if str2num(char(ytick_label)) ==0 || (str2num(char(ytick_label))<0.0001 && str2num(char(ytick_label))>0) || (str2num(char(ytick_label))>-0.0001 && str2num(char(ytick_label))<0) + ytick_label = ''; end - catch%% - leg_str = ''; + text(waveview,myY_Crossing-2*abs(ytick_bottom),props.YTick(iCount), ... + ytick_label, ... + 'HorizontalAlignment', 'right', ... + 'VerticalAlignment', 'middle', ... + 'FontSize', FonsizeDefault, ... + 'FontAngle', props.FontAngle, ... + 'FontUnits', props.FontUnits,... + 'FontName', fontnames, ... + 'Color',[0 0 0]);% end - try - - if Numofcolumn ==1 - text(r_ax,X_zero_line(Numofcolumn),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - else - text(r_ax,X_zero_line(Numofcolumn)+Timet_step/2,offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%----------------------Adjust x axis------------------------%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + props.XTick = qXtickstransf; + props.XTickLabel = cell(numel(qXticks),1); + for Numofytick = 1:numel(props.XTick) + props.XTickLabel(Numofytick) = {num2str(qXticks(Numofytick))}; + end + myX_Crossing = OffSetY(Numofrows); + if countPlot ==1 + xtick_bottom = -props.TickLength(2)*max(props.YLim); + if abs(xtick_bottom)/max(props.YLim) > ytick_bottomratio + xtick_bottom = -ytick_bottomratio*max(props.YLim); end - catch - - if Numofcolumn ==1 - text(r_ax,X_zero_line(Numofcolumn),Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); + else + try + xtick_bottom = xtick_bottom; + catch + xtick_bottom = -props.TickLength(2)*max(props.YLim); + if abs(xtick_bottom)/max(props.YLim) > ytick_bottomratio + xtick_bottom = -ytick_bottomratio*max(props.YLim); + end + end + end + if ~isempty(props.XTick) + xtick_x = repmat(props.XTick, 2, 1); + xtick_y = repmat([xtick_bottom; tick_top]*0.5 + myX_Crossing, 1, length(props.XTick)); + line(waveview,xtick_x, xtick_y, 'color', 'k','LineWidth',1); + end + [x_xtick,y_xtick] = find(props.XTick==0); + if ~isempty(y_xtick) + props.XTick(y_xtick) = 2*xtick_bottom; + end + plot(waveview,Xtimerangetrasf, myX_Crossing.*ones(numel(Xtimerangetrasf),1),'k','LineWidth',1); + nxTicks = length(props.XTick); + qXticklabel = 'on'; + for iCount = 1:nxTicks + xtick_label = (props.XTickLabel(iCount, :)); + if strcmpi(qXticklabel,'on') + if strcmpi(xtick_label,'0') + xtick_label = ''; + end else - text(r_ax,X_zero_line(Numofcolumn)+Timet_step/2,Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); + xtick_label = ''; end - % text(r_ax,X_zero_line(Numofcolumn),Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); + text(waveview,props.XTick(iCount), xtick_bottom*0.5 + myX_Crossing, ... + xtick_label, ... + 'HorizontalAlignment', 'Center', ... + 'VerticalAlignment', 'Top', ... + 'FontSize', FonsizeDefault, ... + 'FontAngle', props.FontAngle, ... + 'FontUnits', props.FontUnits,... + 'FontName', fontnames, ... + 'Color',[0 0 0]);%'FontName', qXlabelfont, ... end - end - - end - % - - - % - %%-------------Setting x/yticks and ticklabels-------------------------------- - Ylabels_new = ylabs.*Plority_plot; - [~,Y_label] = find(Ylabels_new == -0); - Ylabels_new(Y_label) = 0; - % xticks = (Min_time:Timet_step:Max_time); - % some options currently only work post Matlab R2016a ,'XLim',[Min_time Max_time],'XLim',[Min_time Max_time] - if Matlab_ver >= 2016 - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','origin',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels); - else - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','bottom',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim, 'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels); - hline(0,'k'); % backup xaxis - end - % if Column_label>1 - % set(r_ax,'XGrid','on','YGrid','on');%,'XDir','reverse' - % end - set(r_ax, 'XTick', [], 'XTickLabel', [],'FontWeight', 'bold'); - r_ax.YAxis.LineWidth = 1.5; - hold(r_ax,'off'); - - - % - %%--------------------------Setting legend--------------------------------- - line_colors_ldg = erpworkingmemory('PWColor'); - if isempty(line_colors_ldg) - line_colors_ldg = get_colors(numel(ndata)); - end - - if size(line_colors_ldg,1)~= numel(ndata) - if numel(ndata)> size(line_colors_ldg,1) - line_colors_ldg = get_colors(numel(ndata)); + %%-----------------minor X--------------- + set(waveview,'xlim',[Xtimerange(1),Xtimerangetrasf(end)]); + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%------------------channel/bin/erpset label-----------------%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + ypercentage =100; + ypos_LABEL = (qYScalestras(end)-qYScalestras(1))*(ypercentage)/100+qYScalestras(1); + xpercentage = CBELabels(1); + xpos_LABEL = (Xtimerangetrasf(end)-Xtimerangetrasf(1))*xpercentage/100 + Xtimerangetrasf(1); + labelcbe = strrep(char(labelcbe),'_','\_'); + try + labelcbe = regexp(labelcbe, '\;', 'split'); + catch + end + text(waveview,xpos_LABEL,ypos_LABEL+OffSetY(Numofrows), char(labelcbe),'FontName', fontnames,'HorizontalAlignment', 'left');%'FontWeight', 'bold', else - line_colors_ldg = line_colors_ldg(1:numel(ndata),:,:); end - end - - for Numofplot = 1:size(plot_erp_data,2) - plot(r_ax_legend,[0 0],'Color',line_colors_ldg(Numofplot,:,:),'LineWidth',3) - end + try + if 2 length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); -% f_redrawERP(); -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; -EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; -EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -EStudio_gui_erp_totl.pageinfo_edit.String = num2str(S_ws_getbinchan.Select_index); - -MessageViewer= char(strcat('Plot prior page (<)')); -erpworkingmemory('f_ERP_proces_messg',MessageViewer); -observe_ERPDAT.Process_messg =1; -try - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; -catch - observe_ERPDAT.Process_messg =3; -end -observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; -end - -%%Edit the index of ERPsets -function page_edit(Str,~,EStudio_gui_erp_totl) -CurrentERPindex = str2num(Str.String); -global observe_ERPDAT; -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -if ~isempty(CurrentERPindex) && numel(CurrentERPindex)==1 && (CurrentERPindex<= numel(S_ws_geterpset)) - S_ws_getbinchan.Select_index = CurrentERPindex; - Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); - % EStudio_gui_erp_totl.pageinfo_edit.String = num2str(S_ws_getbinchan.Select_index); - if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; - end - observe_ERPDAT.CURRENTERP = Current_erp_Index; - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); - estudioworkingmemory('geterpbinchan',S_ws_getbinchan); - if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; - else - if CurrentERPindex ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [1 1 1]; - elseif CurrentERPindex == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end - end - EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; - EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; - EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; - EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - - MessageViewer= char(strcat('Page Editor')); - erpworkingmemory('f_ERP_proces_messg',MessageViewer); - observe_ERPDAT.Process_messg =1; - try - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - catch - observe_ERPDAT.Process_messg =3; - end -end -observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; -end - - -%------------------Display the waveform for next ERPset-------------------- -function page_plus(~,~,EStudio_gui_erp_totl) -global observe_ERPDAT; -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index+1; -try - Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -catch - return; -end -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end -EStudio_gui_erp_totl.pageinfo_edit.String = num2str(S_ws_getbinchan.Select_index); -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [1 1 1]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; -EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; -EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - -MessageViewer= char(strcat('Plot next page (>)')); -erpworkingmemory('f_ERP_proces_messg',MessageViewer); -observe_ERPDAT.Process_messg =1; -try - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; -catch - observe_ERPDAT.Process_messg =3; -end -observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP_mt_viewer.m b/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP_mt_viewer.m deleted file mode 100755 index 39440c5e..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP_mt_viewer.m +++ /dev/null @@ -1,1533 +0,0 @@ -%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com -%Center for Mind and Brain -%University of California, Davis -%Davis, CA, USA -%Feb. 2022 - -% ERPLAB Studio - - - - - -function f_redrawERP_mt_viewer() -% Draw a demo ERP into the axes provided -% global EStudio_gui_erp_totl; -global observe_ERPDAT; -global EStudio_gui_erp_totl; -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -Select_index = S_ws_getbinchan.Select_index; -S_ws_geterpplot = estudioworkingmemory('geterpplot'); - - -S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); -try - - Viewer_Label = S_ws_geterpvalues.Viewer; -catch - mnamex = '"Viewer" was not selected for the measured ERPset.'; - question = [ '%s\n\n Please select "On" for "Viewer" on the "ERP Measurement Tool" panel .\n']; - title = 'ERPLAB Studio: ERP Measurement Tool'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - return; -end - -if isempty(Viewer_Label) || ~strcmp(Viewer_Label,'on') - mnamex = '"Off" was selected for "Viewer" on the "ERP Measurement Tool" panel.'; - question = [ '%s\n\n Please check "S" on Workspace of Matlab.\n']; - title = 'ERPLAB Studio: ERP Measurement Tool'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - return; -end - - -try - moption = S_ws_geterpvalues.Measure; -catch - mnamex = 'Measurement type was not selected on the "ERP Measurement Tool" panel.'; - question = [ '%s\n\n Please select anyone of measurement types from pop menu of "Measurement Type".\n']; - title = 'ERPLAB Studio: ERP Measurement Tool'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - return; -end - - -try - latency = S_ws_geterpvalues.latency; -catch - mnamex = 'Measurement window was not defined on the "ERP Measurement Tool" panel.'; - question = [ '%s\n\n Please set measurement window on "Measurement window".\n']; - title = 'ERPLAB Studio: ERP Measurement Tool'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - return; -end - -Times_erp_curr = observe_ERPDAT.ERP.times; - -if numel(latency) ==1 - if latency(1)< Times_erp_curr(1) - msgboxText = ['For latency range, lower time limit must be larger than',32,num2str(Times_erp_curr(1)),'.\n']; - title = 'EStudio: ERP measurement tool- Viewer "on". '; - errorfound(sprintf(msgboxText), title); - return - - elseif latency(1)> Times_erp_curr(end) - msgboxText = ['For latency range, upper time limit must be smaller than',32,num2str(Times_erp_curr(end)),'.\n']; - title = 'EStudio: ERP measurement tool- Viewer "on". '; - errorfound(sprintf(msgboxText), title); - return - end - - -else - - if latency(1) < Times_erp_curr(1) - msgboxText = ['For latency range, lower time limit must be larger than',32,num2str(Times_erp_curr(1)),'.\n']; - title = 'EStudio: ERP measurement tool- Viewer "on". '; - errorfound(sprintf(msgboxText), title); - return - - elseif latency(end) > Times_erp_curr(end) - msgboxText = ['For latency range, upper time limit must be smaller than',32,num2str(Times_erp_curr(end)),'.\n']; - title = 'EStudio: ERP measurement tool- Viewer "on". '; - errorfound(sprintf(msgboxText), title); - return - end -end - -%%Parameter from bin and channel panel -Elecs_shown = S_ws_getbinchan.elecs_shown{Select_index}; -Bins = S_ws_getbinchan.bins{Select_index}; -Bin_chans = S_ws_getbinchan.bins_chans(Select_index); -Elec_list = S_ws_getbinchan.elec_list{Select_index}; -Matlab_ver = S_ws_getbinchan.matlab_ver; - - - -%%Parameter from plotting panel -Min_vspacing = S_ws_geterpplot.min_vspacing(Select_index); -Min_time = S_ws_geterpplot.min(Select_index); -Max_time = S_ws_geterpplot.max(Select_index); -Yscale = S_ws_geterpplot.yscale(Select_index); -Timet_low =S_ws_geterpplot.timet_low(Select_index); -Timet_high =S_ws_geterpplot.timet_high(Select_index); -Timet_step=S_ws_geterpplot.timet_step(Select_index); -Fill = S_ws_geterpplot.fill(Select_index); -Plority_plot = S_ws_geterpplot.Positive_up(Select_index); - - -if Bin_chans == 0 - elec_n = S_ws_getbinchan.elec_n(Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(Select_index)).nchan; -else - elec_n = S_ws_getbinchan.bin_n(Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(Select_index)).nbin; -end - -% We first clear the existing axes ready to build a new one -if ishandle( EStudio_gui_erp_totl.ViewAxes ) - delete( EStudio_gui_erp_totl.ViewAxes ); -end - - -% Get chan labels -S_chan.chan_label = cell(1,max_elec_n); -S_chan.chan_label_place = zeros(1,max_elec_n); - - -if Bin_chans == 0 - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.chanlocs(Elecs_shown(i)).labels; - end -else - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.bindescr(Bins(i)); - end -end - - -%Sets the units of your root object (screen) to pixels -set(0,'units','pixels') -%Obtains this pixel information -Pix_SS = get(0,'screensize'); -%Sets the units of your root object (screen) to inches -set(0,'units','inches') -%Obtains this inch information -Inch_SS = get(0,'screensize'); -%Calculates the resolution (pixels per inch) -Res = Pix_SS./Inch_SS; - - -pb_height = Min_vspacing*Res(4); %px - - -% Plot data in the main viewer fig -splot_n = elec_n; -tsize = 13; - -%%Get the background color -try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color -catch - ColorB_def = [0. 95 0.95 0.95]; -end -if isempty(ColorB_def) - ColorB_def = [0. 95 0.95 0.95]; -end - -clear pb r_ax plotgrid -EStudio_gui_erp_totl.plotgrid = uiextras.VBox('Parent',EStudio_gui_erp_totl.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); - -pageinfo_box = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def); - -EStudio_gui_erp_totl.plot_wav_legend = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',[1 1 1]); -EStudio_gui_erp_totl.ViewAxes_legend = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.plot_wav_legend,'BackgroundColor',ColorB_def); -EStudio_gui_erp_totl.ViewAxes = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.plot_wav_legend,'BackgroundColor',[1 1 1]); -EStudio_gui_erp_totl.ERP_M_T_Viewer = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def); -%%-------------------Display the processing procedure----------------------- -%%Changed by Guanghui Zhang 2 August 2022-------panel for display the processing procedure for some functions, e.g., filtering -xaxis_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid );%%%Message -EStudio_gui_erp_totl.Process_messg = uicontrol('Parent',xaxis_panel,'Style','text','String','','FontSize',20,'FontWeight','bold','BackgroundColor',ColorB_def); - - -%%Setting title -EStudio_gui_erp_totl.pageinfo_minus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '<','Callback',{@page_minus,EStudio_gui_erp_totl},'FontSize',30,'BackgroundColor',[1 1 1]); -if Select_index ==1 - EStudio_gui_erp_totl.pageinfo_minus.Enable = 'off'; -end - -EStudio_gui_erp_totl.pageinfo_edit = uicontrol('Parent',pageinfo_box,'Style', 'edit', 'String', num2str(S_ws_getbinchan.Select_index),'Callback',{@page_edit,EStudio_gui_erp_totl},'FontSize',20,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index ==1 - EStudio_gui_erp_totl.pageinfo_edit.Enable = 'on'; -end - - -EStudio_gui_erp_totl.pageinfo_plus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '>','Callback',{@page_plus,EStudio_gui_erp_totl},'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index == numel(S_ws_geterpset) - EStudio_gui_erp_totl.pageinfo_plus.Enable = 'off'; -end - -pageinfo_str = ['Page',32,num2str(Select_index),'/',num2str(numel(S_ws_geterpset)),':',32,observe_ERPDAT.ERP.erpname]; -pageinfo_text = uicontrol('Parent',pageinfo_box,'Style','text','String',pageinfo_str,'FontSize',14,'FontWeight','bold'); - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [1 1 1]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; -EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; -EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - -set(pageinfo_box, 'Sizes', [50 50 50 -1] ); -set(pageinfo_box,'BackgroundColor',ColorB_def); -set(pageinfo_text,'BackgroundColor',ColorB_def); -%Setting title. END - -%for i=1:splot_n - -ndata = 0; -nplot = 0; -if Bin_chans == 0 - ndata = Bins; - nplot = Elecs_shown; -else - ndata = Elecs_shown; - nplot = Bins; -end - -%Both equation is incorrect. - -pnts = observe_ERPDAT.ERP.pnts; -timeor = observe_ERPDAT.ERP.times; % original time vector -p1 = timeor(1); -p2 = timeor(end); - -try - intfactor = S_ws_geterpvalues.InterpFactor; -catch - intfactor =1; -end - -if intfactor~=1 - timex = linspace(p1,p2,round(pnts*intfactor)); -else - timex = timeor; -end - - -[xxx, latsamp, latdiffms] = closest(timex, [Min_time Max_time]); -tmin = latsamp(1); -tmax = latsamp(2); - -if tmin < 1 - tmin = 1; -end - -if tmax > numel(timex) - tmax = numel(timex); -end - -try - blc = S_ws_geterpvalues.Baseline; -catch - blc = 'none'; -end - -if intfactor~=1 - Plot_erp_data_TRAN = []; - for Numoftwo = 1:size(observe_ERPDAT.ERP.bindata,3) - for Numofone = 1:size(observe_ERPDAT.ERP.bindata,1) - data = squeeze(observe_ERPDAT.ERP.bindata(Numofone,:,Numoftwo)); - data = spline(timeor, data, timex); % re-sampled data - blv = blvalue2(data, timex, blc); - data = data - blv; - Plot_erp_data_TRAN(Numofone,:,Numoftwo) = data; - end - end - Bindata = Plot_erp_data_TRAN; -else - Bindata = observe_ERPDAT.ERP.bindata; -end - -plot_erp_data = nan(tmax-tmin+1,numel(ndata)); -for i = 1:splot_n - if Bin_chans == 0 - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = Bindata(Elecs_shown(i),tmin:tmax,Bins(i_bin))'*Plority_plot; % - end - else - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = Bindata(Elecs_shown(i_bin),tmin:tmax,Bins(i))'*Plority_plot; % - end - end -end - -perc_lim = Yscale; -percentile = perc_lim*3/2; -%How to get x unique colors? -line_colors = erpworkingmemory('PWColor'); -if size(line_colors,1)~= numel(ndata) - if numel(ndata)> size(line_colors,1) - line_colors = get_colors(numel(ndata)); - else - line_colors = line_colors(1:numel(ndata),:,:); - end -end - -if isempty(line_colors) - line_colors = get_colors(numel(ndata)); -end - -line_colors = repmat(line_colors,[splot_n 1]); %repeat the colors once for every plot - -ind_plot_height = percentile*2; % Height of each individual subplot - -offset = []; -if Bin_chans == 0 - offset = (numel(Elecs_shown)-1:-1:0)*ind_plot_height; -else - offset = (numel(Bins)-1:-1:0)*ind_plot_height; -end -[~,~,Num_plot] = size(plot_erp_data); - -for i = 1:Num_plot - plot_erp_data(:,:,i) = plot_erp_data(:,:,i) + ones(size(plot_erp_data(:,:,i)))*offset(i); -end - -if ~strcmpi(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - %pb_ax = uipanel('Parent',EStudio_gui_erp_totl.plotgrid); - r_ax = axes('Parent', EStudio_gui_erp_totl.ViewAxes,'Color',[1 1 1],'Box','on'); - hold(r_ax,'on'); - set(EStudio_gui_erp_totl.plot_wav_legend,'Sizes',[80 -10]); - r_ax_legend = axes('Parent', EStudio_gui_erp_totl.ViewAxes_legend,'Color','none','Box','off'); - hold(r_ax_legend,'on'); - - - set(r_ax,'XLim',[Min_time Max_time]); - ts = timex(tmin:tmax); - [a,Num_data,Num_plot] = size(plot_erp_data); - new_erp_data = zeros(a,Num_plot*Num_data); - for i = 1:Num_plot - new_erp_data(:,((Num_data*(i-1))+1):(Num_data*i)) = plot_erp_data(:,:,i); - end - - % plot_erp_data_fin = [repmat((1:numel(nplot)-1)*ind_plot_height,[numel(ts) 1]) new_erp_data]; - - % pb_here = plot(r_ax,ts,plot_erp_data_fin,'LineWidth',1); - pb_here = plot(r_ax,ts,new_erp_data,'LineWidth',1.5); - hold(r_ax,'on');%Same function as hold on; - r_ax.LineWidth=1.5; - yticks = -perc_lim:perc_lim:((2*percentile*Num_plot)-(2*perc_lim)); - - oldlim = [-percentile yticks(end)-perc_lim+percentile]; - top_vspace = max( max( new_erp_data ) )-oldlim(2); - bot_vspace = min( min( new_erp_data ) )-oldlim(1); - - newlim = oldlim + [bot_vspace top_vspace]; - ylabs = repmat([-perc_lim 0 perc_lim],[1,Num_plot]); - ylabs = [fliplr(-perc_lim:-perc_lim:newlim(1)) ylabs(2:end-1) (yticks(end):perc_lim:newlim(2))-yticks(end)+perc_lim]; - yticks = [fliplr(-perc_lim:-perc_lim:newlim(1)) yticks(2:end-1) yticks(end):perc_lim:newlim(2)]; - - %%%------------Setting xticklabels for each row of each wave-------------- - xstep_label = estudioworkingmemory('erp_xtickstep'); - if isempty(xstep_label) - xstep_label =0; - end - if ~xstep_label - [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [Timet_low,Timet_high]); - xticks = str2num(def{1,1}); - else - xticks = (Timet_low:Timet_step:Timet_high); - end - % estudioworkingmemory('erp_xtickstep',0); - x_axs = ones(size(new_erp_data,1),1); - xticks_label = []; - count = 0; - for jjj = 1:numel(xticks) - if xticks(jjj)< Min_time || xticks(jjj)> Max_time - count = count +1; - xticks_label(count) = jjj; - end - end - % if ~isempty(xticks_label) - % xticks(xticks_label) = []; - % end - for Numofxlabel = 1:numel(xticks) - xticks_labels{Numofxlabel} = num2str(xticks(Numofxlabel)); - end - - try - moption = S_ws_geterpvalues.Measure; - catch - moption = 'meanbl'; - end - - - for jj = 1:numel(offset) - plot(r_ax,ts,x_axs.*offset(end),'color',[1 1 1],'LineWidth',3); - set(r_ax,'XLim',[Timet_low,Timet_high]); - set(r_ax,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); - myX_Crossing = offset(jj); - props = get(r_ax); - - tick_bottom = -props.TickLength(1)*diff(props.YLim); - if abs(tick_bottom) > abs(Yscale)/5 - try - tick_bottom = - abs(Yscale)/5; - catch - tick_bottom = tick_bottom; - end - end - tick_top = 0; - - line(r_ax,props.XLim, [0 0] + myX_Crossing, 'color', 'k','LineWidth',1.5); - - if ~isempty(props.XTick) - xtick_x = repmat(props.XTick, 2, 1); - xtick_y = repmat([tick_bottom; tick_top] + myX_Crossing, 1, length(props.XTick)); - h_ticks = line(r_ax,xtick_x, xtick_y, 'color', 'k','LineWidth',1.5); - end - set(r_ax, 'XTick', [], 'XTickLabel', []); - % tick_bottom = -props.TickLength(1)*diff(props.YLim); - nTicks = length(props.XTick); - h_ticklabels = zeros(size(props.XTick)); - if nTicks>1 - if numel(offset)==jj - kkkk = 1; - else - if abs(Timet_low - xticks(1)) > 1000/observe_ERPDAT.ERP.srate - kkkk = 1; - else - kkkk = 2; - end - end - for iCount = kkkk:nTicks - xtick_label = (props.XTickLabel(iCount, :)); - text(r_ax,props.XTick(iCount), tick_bottom + myX_Crossing, ... - xtick_label, ... - 'HorizontalAlignment', 'Center', ... - 'VerticalAlignment', 'Top', ... - 'FontSize', 12, ... - 'FontName', props.FontName, ... - 'FontAngle', props.FontAngle, ... - 'FontUnits', props.FontUnits, ... - 'FontWeight', 'bold'); - end - end - end - % end - - %%%Mark the area/latency/amplitude of interest within the defined window. - ERP_mark_area_latency(r_ax,timex(tmin:tmax),moption,plot_erp_data,latency,line_colors,offset,Plority_plot);%cwm = [0 0 0];% white: Background color for measurement window - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - % set(r_ax,'XLim',[Timet_low,Timet_high]); - - %%%%%%%%----------------------------- - - [xxx, latsamp,cdiff] = closest(timex, 0); - if cdiff<1000/observe_ERPDAT.ERP.srate - xline(r_ax,timex(latsamp),'k-.','LineWidth',1);%%Marking start time point for each column - end - - if top_vspace < 0 - top_vspace = 0; - end - - if bot_vspace > 0 - bot_vspace = 0; - end - set(r_ax,'XLim',[Timet_low,Timet_high],'Ylim',newlim); - - for i = 1:numel(pb_here) - pb_here(i).Color = line_colors(i,:); - end - - - Ylabels_new = ylabs.*Plority_plot; - [~,Y_label] = find(Ylabels_new == -0); - Ylabels_new(Y_label) = 0; - - - if numel(offset)>1 - count = 0; - for i = 0:numel(offset)-1 - leg_str = ''; - - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',strrep(Elec_list{Elecs_shown(count)},'_','\_')); - else - leg_str = sprintf('%s',strrep(observe_ERPDAT.ERP.bindescr{Bins(count)},'_','\_')); - end - catch - leg_str = ''; - end - text(r_ax,Timet_low,offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - - end - end - - try - if Bin_chans == 0 - leg_str = sprintf('%s',strrep(Elec_list{Elecs_shown(end)},'_','\_')); - else - leg_str = sprintf('%s',strrep(observe_ERPDAT.ERP.bindescr{Bins(end)},'_','\_')); - end - catch%% - leg_str = ''; - end - - try - text(r_ax,Timet_low,offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - catch - text(r_ax,Timet_low,Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); - end - - - % xticks = (Min_time:Timet_step:Max_time); - % some options currently only work post Matlab R2016a - if Matlab_ver >= 2016 - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','origin',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim,'XTick',xticks, ... - 'box','off', 'Color','none','XLim',[Timet_low Timet_high]); - else - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','bottom',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim, 'XTick',xticks,... - 'box','off', 'Color','none','XLim',[Timet_low Timet_high]); - hline(0,'k'); % backup xaxis - end - hold(r_ax,'off'); - % if numel(offset)>1 - set(r_ax, 'XTick', [], 'XTickLabel', []); - % end - %%%%%%%%%%%% - % r_ax.Position(1) =r_ax.Position(1)+0.5; - line_colors_ldg = erpworkingmemory('PWColor'); - if isempty(line_colors_ldg) - line_colors_ldg = get_colors(numel(ndata)); - end - if size(line_colors_ldg,1)~= numel(ndata) - if numel(ndata)> size(line_colors_ldg,1) - line_colors_ldg = get_colors(numel(ndata)); - else - line_colors_ldg = line_colors_ldg(1:numel(ndata),:,:); - end - end - - - for Numofplot = 1:size(plot_erp_data,2) - plot(r_ax_legend,[0 0],'Color',line_colors_ldg(Numofplot,:,:),'LineWidth',3) - end - - if Bin_chans == 0 - Leg_Name = ''; - for Numofbin = 1:numel(Bins) - Leg_Name{Numofbin} = strcat('Bin',num2str(Bins(Numofbin))); - end - - else - for Numofchan = 1:numel(Elecs_shown) - Leg_Name{Numofchan} = strrep(Elec_list{Elecs_shown(Numofchan)},'_','\_'); - end - end - here_lgd = legend(r_ax_legend,Leg_Name,'FontSize',14,'TextColor','blue'); - legend(r_ax_legend,'boxoff'); - - - - %end - EStudio_gui_erp_totl.plotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high - EStudio_gui_erp_totl.plotgrid.Heights(3) = 30; % set the second element (x axis) to 30px high - EStudio_gui_erp_totl.plotgrid.Heights(4) = 30; % set the second element (x axis) to 30px high - EStudio_gui_erp_totl.plotgrid.Units = 'pixels'; - if splot_n*pb_height<(EStudio_gui_erp_totl.plotgrid.Position(4)-EStudio_gui_erp_totl.plotgrid.Heights(1))&&Fill - pb_height = (EStudio_gui_erp_totl.plotgrid.Position(4)-EStudio_gui_erp_totl.plotgrid.Heights(1)-EStudio_gui_erp_totl.plotgrid.Heights(2))/splot_n; - end - - EStudio_gui_erp_totl.ViewAxes.Heights = splot_n*pb_height; - % EStudio_gui_erp_totl.ViewAxes.Widths = -10; - EStudio_gui_erp_totl.plotgrid.Units = 'normalized'; - EStudio_gui_erp_totl.plotgrid.Heights =[30 -1 80 30]; - %%%-------------------Display results obtained from "Measurement Tool" Panel--------------------------------- - [~,~,~,Amp,Lat]= f_ERP_plot_wav(observe_ERPDAT.ERP); - try - Resolution =S_ws_geterpvalues.Resolution; - catch - Resolution =3; - end - try - moption =S_ws_geterpvalues.Measure; - catch - beep; - disp('Please select one of Measurement type'); - return; - end - - %%Get name for the selected rows (i.e.,bins) and columns (i.e., channels) - RowName = {}; - for Numofbin = 1:numel(Bins) - RowName{Numofbin} = strcat('Bin',num2str(Bins(Numofbin)));%'',':',32,observe_ERPDAT.ERP.bindescr{Bins(Numofbin)} - end - ColumnName = {}; - for Numofsel_chan = 1:numel(Elecs_shown) - ColumnName{Numofsel_chan} = ['',num2str(Elecs_shown(Numofsel_chan)),'.',32,Elec_list{Elecs_shown(Numofsel_chan)}]; - end - - % txt_title = uicontrol('Parent',EStudio_gui_erp_totl.ERP_M_T_Viewer,'Style', 'text', 'String', 'My Example Title'); - try - if ismember_bc2(moption, {'instabl','peaklatbl','fpeaklat','fareatlat','fninteglat','fareaplat','fareanlat','meanbl','peakampbl','areat','ninteg','areap','arean','ninteg','areazt','nintegz','areazp','areazn'}) - Data_display = Amp(Bins,Elecs_shown); - else - Data_display = Lat(Bins,Elecs_shown); - end - - if ismember_bc2(moption,{'arean','areazn'}) - Data_display= -1.*Data_display; - end - - Data_display_tra = {}; - for Numofone = 1:size(Data_display,1) - for Numoftwo = 1:size(Data_display,2) - if ~isnan(Data_display(Numofone,Numoftwo)) - if Bin_chans == 0 - Data_display_tra{Numofone,Numoftwo} = sprintf(['%.',num2str(Resolution),'f'], Data_display(Numofone,Numoftwo)); - else - Data_display_tra{Numoftwo,Numofone} = sprintf(['%.',num2str(Resolution),'f'], Data_display(Numofone,Numoftwo)); - end - - else - if Bin_chans == 0 - Data_display_tra{Numofone,Numoftwo} = ['NaN']; - else - Data_display_tra{Numoftwo,Numofone} = ['NaN']; - end - end - end - end - - EStudio_gui_erp_totl.ERP_M_T_Viewer_table = uitable(EStudio_gui_erp_totl.ERP_M_T_Viewer,'Data',Data_display_tra,'Units','Normalize'); - if Bin_chans == 0 - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.RowName = RowName; - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ColumnName = ColumnName; - else - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.RowName = ColumnName; - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ColumnName = RowName; - end - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.BackgroundColor = line_colors_ldg; - - - if size(Data_display_tra,2)<12 - ColumnWidth = {}; - for Numofchan =1:size(Data_display_tra,2) - ColumnWidth{Numofchan} = EStudio_gui_erp_totl.ERP_M_T_Viewer.Position(3)/size(Data_display_tra,2); - end - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ColumnWidth = ColumnWidth; - elseif size(Data_display_tra,2) ==1 - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ColumnWidth = {EStudio_gui_erp_totl.ERP_M_T_Viewer.Position(3)}; - end - - catch - for Numofbin = 1:observe_ERPDAT.ERP.nbin - Data_display{Numofbin,1} = ''; - end - - RowName = {}; - for Numofbin = 1:observe_ERPDAT.ERP.nbin - RowName{Numofbin} = strcat('Bin',num2str((Numofbin))); - end - EStudio_gui_erp_totl.ERP_M_T_Viewer_table = uitable(EStudio_gui_erp_totl.ERP_M_T_Viewer,'Data',Data_display); - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.RowName = RowName; - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ColumnName = {'No data are avalible'}; - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ColumnWidth = {EStudio_gui_erp_totl.ERP_M_T_Viewer.Position(3)}; - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.BackgroundColor = line_colors_ldg; - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.ForegroundColor = [1 1 1]; - end - - EStudio_gui_erp_totl.ERP_M_T_Viewer_table.FontSize = 12; -else - set(EStudio_gui_erp_totl.plot_wav_legend,'Sizes',[80 -10]); - EStudio_gui_erp_totl.plotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high - EStudio_gui_erp_totl.plotgrid.Heights(3) = 30; % set the second element (x axis) to 30px high - EStudio_gui_erp_totl.plotgrid.Heights(4) = 30; - -end -end % redrawDemo - - -function colors = get_colors(ncolors) -% Each color gets 1 point divided into up to 2 of 3 groups (RGB). -degree_step = 6/ncolors; -angles = (0:ncolors-1)*degree_step; -colors = nan(numel(angles),3); -for i = 1:numel(angles) - if angles(i) < 1 - colors(i,:) = [1 (angles(i)-floor(angles(i))) 0]*0.75; - elseif angles(i) < 2 - colors(i,:) = [(1-(angles(i)-floor(angles(i)))) 1 0]*0.75; - elseif angles(i) < 3 - colors(i,:) = [0 1 (angles(i)-floor(angles(i)))]*0.75; - elseif angles(i) < 4 - colors(i,:) = [0 (1-(angles(i)-floor(angles(i)))) 1]*0.75; - elseif angles(i) < 5 - colors(i,:) = [(angles(i)-floor(angles(i))) 0 1]*0.75; - else - colors(i,:) = [1 0 (1-(angles(i)-floor(angles(i))))]*0.75; - end -end -end - - -%------------------Display the waveform for proir ERPset-------------------- -function page_minus(~,~,EStudio_gui_erp_totl) -global observe_ERPDAT; -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index-1; -Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; -EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; -f_redrawERP_mt_viewer(); -EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - -MessageViewer= char(strcat('Plot prior page (<)')); -erpworkingmemory('f_ERP_proces_messg',MessageViewer); -observe_ERPDAT.Process_messg =1; -try - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; -catch - observe_ERPDAT.Process_messg =3; -end -observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; -end - - - -%%Edit the index of ERPsets -function page_edit(Str,~,EStudio_gui_erp_totl) -CurrentERPindex = str2num(Str.String); -global observe_ERPDAT; -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -if ~isempty(CurrentERPindex) && numel(CurrentERPindex)==1 && (CurrentERPindex<= numel(S_ws_geterpset)) - S_ws_getbinchan.Select_index = CurrentERPindex; - Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); - % EStudio_gui_erp_totl.pageinfo_edit.String = num2str(S_ws_getbinchan.Select_index); - if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; - end - observe_ERPDAT.CURRENTERP = Current_erp_Index; - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); - estudioworkingmemory('geterpbinchan',S_ws_getbinchan); - if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; - else - if CurrentERPindex ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [1 1 1]; - elseif CurrentERPindex == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end - end - EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; - EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; - EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; - EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - - MessageViewer= char(strcat('Page Editor')); - erpworkingmemory('f_ERP_proces_messg',MessageViewer); - observe_ERPDAT.Process_messg =1; - try - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - catch - observe_ERPDAT.Process_messg =3; - end -end -observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; -end - - -%------------------Display the waveform for next ERPset-------------------- -function page_plus(~,~,EStudio_gui_erp_totl) -global observe_ERPDAT; -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index+1; -Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [1 1 1]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - - - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -EStudio_gui_erp_totl.pageinfo_minus.Enable = Enable_minus; -EStudio_gui_erp_totl.pageinfo_plus.Enable = Enable_plus; -EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - -MessageViewer= char(strcat('Plot next page (>)')); -erpworkingmemory('f_ERP_proces_messg',MessageViewer); -observe_ERPDAT.Process_messg =1; -try - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; -catch - observe_ERPDAT.Process_messg =3; -end -observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; -end - - -%%Mark the area or latency/amplitude of interest within defined latecies%%% -function ERP_mark_area_latency(r_ax,timex,moption,plot_erp_data,latency,line_colors,offset,Plority_plot) -try - cwm_backgb = erpworkingmemory('MWColor'); -catch - cwm_backgb=[0.7 0.7 0.7]; -end -if isempty(cwm_backgb) - cwm_backgb=[0.7 0.7 0.7]; -end - -try - cwm = erpworkingmemory('MTLineColor'); -catch - cwm =[0 0 0]; -end -if isempty(cwm) - cwm=[0 0 0]; -end - -global observe_ERPDAT; - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Plot area within the defined time-window%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%Set area within the defined time-window for 1.Fractional area latency, 2. Numerical integration/Area between two fixed latencies -mearea = { 'areat', 'areap', 'arean','areazt','areazp','areazn', 'ninteg','nintegz'}; - -[~,Num_data,Num_plot] = size(plot_erp_data); - -if ismember_bc2(moption, mearea) || ismember_bc2(moption, {'fareatlat', 'fareaplat','fninteglat','fareanlat'}) - if numel(latency) ==2 - latx = latency; - [xxx, latsamp] = closest(timex, latx); - datax = plot_erp_data(latsamp(1):latsamp(2),:,:); - end - Time_res = timex(2)-timex(1); - - if ismember_bc2(moption, {'areap', 'fareaplat'}) % positive area - - for Numofstione = 1:size(datax,3) - for Numofstitwo = 1:size(datax,2) - timexx = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check = dataxx-offset(Numofstione); - if Plority_plot==1 - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - elseif Plority_plot ==-1 - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - else - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - end - - if ~isempty(dataxx) && numel(dataxx)>=2 - %%Check isolated point - Check_outlier =[]; - count = 0; - - if (timexx(2)-timexx(1)>Time_res) - count= count +1; - Check_outlier(count) = 1; - end - if numel(dataxx)>=3 - for Numofsample = 2:length(timexx)-1 - if (timexx(Numofsample+1)-timexx(Numofsample)>Time_res) && (timexx(Numofsample)-timexx(Numofsample-1)< Time_res) - count = count+1; - Check_outlier(count) = Numofsample; - end - end - end - dataxx(Check_outlier) = []; - timexx(Check_outlier) = []; - - Check_isolated =[]; - count = 0; - for Numofsample = 1:length(timexx)-1 - if timexx(Numofsample+1)-timexx(Numofsample)>Time_res - count = count+1; - Check_isolated(count) = Numofsample; - end - end - if numel(Check_isolated) ==1 - inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; - inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionX2 = [timexx(Check_isolated(1)+1:end),fliplr(timexx(Check_isolated(1)+1:end))]; - inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(1)+1:end))))]; - fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - elseif numel(Check_isolated) >1 - for Numofrange = 1:numel(Check_isolated)-1 - - inBetweenRegionX = [timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; - inBetweenRegionY = [squeeze(dataxx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - end - inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; - inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionX2 = [timexx(Check_isolated(Numofrange+1)+1:end),fliplr(timexx(Check_isolated(Numofrange+1)+1:end))]; - inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange+1)+1:end))))]; - fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - else - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end - - end - - end - elseif ismember_bc2(moption, {'arean', 'fareanlat'}) % negative area - for Numofstione = 1:size(datax,3) - for Numofstitwo = 1:size(datax,2) - timexx = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check = dataxx-offset(Numofstione); - if Plority_plot==1 - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - elseif Plority_plot ==-1 - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - else - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - end - - %%Check isolated point - if ~isempty(dataxx) && numel(dataxx)>=2 - Check_outlier =[]; - count = 0; - - if (timexx(2)-timexx(1)>Time_res) - count= count +1; - Check_outlier(count) = 1; - end - if numel(dataxx)>=3 - for Numofsample = 2:length(timexx)-1 - if (timexx(Numofsample+1)-timexx(Numofsample)>Time_res) && (timexx(Numofsample)-timexx(Numofsample-1)< Time_res) - count = count+1; - Check_outlier(count) = Numofsample; - end - end - end - dataxx(Check_outlier) = []; - timexx(Check_outlier) = []; - - Check_isolated =[]; - count = 0; - for Numofsample = 1:length(timexx)-1 - if timexx(Numofsample+1)-timexx(Numofsample)>Time_res - count = count+1; - Check_isolated(count) = Numofsample; - end - end - if numel(Check_isolated) ==1 - inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; - inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionX2 = [timexx(Check_isolated(1)+1:end),fliplr(timexx(Check_isolated(1)+1:end))]; - inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(1)+1:end))))]; - fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - elseif numel(Check_isolated) >1 - for Numofrange = 1:numel(Check_isolated)-1 - - inBetweenRegionX = [timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; - inBetweenRegionY = [squeeze(dataxx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - end - inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; - inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionX2 = [timexx(Check_isolated(Numofrange+1)+1:end),fliplr(timexx(Check_isolated(Numofrange+1)+1:end))]; - inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange+1)+1:end))))]; - fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - else - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end - end - end - - - elseif ismember_bc2(moption, {'ninteg', 'fninteglat'}) % integration(area for negative substracted from area for positive) - for Numofstione = 1:size(datax,3) - for Numofstitwo = 1:size(datax,2) - timexxp = timex(latsamp(1):latsamp(2)); - dataxxp = squeeze(datax(:,Numofstitwo,Numofstione)); - timexxn = timex(latsamp(1):latsamp(2)); - dataxxn = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check = dataxxn-offset(Numofstione); - if Plority_plot==1 - dataxxp(data_check<0) = []; - timexxp(data_check<0) = []; - dataxxn(data_check>0) = []; - timexxn(data_check>0) = []; - - elseif Plority_plot ==-1 - dataxxp(data_check>0) = []; - timexxp(data_check>0) = []; - dataxxn(data_check<0) = []; - timexxn(data_check<0) = []; - else - dataxxp(data_check<0) = []; - timexxp(data_check<0) = []; - dataxxn(data_check>0) = []; - timexxn(data_check>0) = []; - end - - - if ~isempty(dataxxp) && numel(dataxxp)>=2 - %%Check isolated point - Check_outlierp =[]; - count = 0; - - if (timexxp(2)-timexxp(1)>Time_res) - count= count +1; - Check_outlierp(count) = 1; - end - if numel(dataxxp)>=3 - for Numofsample = 2:length(timexxp)-1 - if (timexxp(Numofsample+1)-timexxp(Numofsample)>Time_res) && (timexxp(Numofsample)-timexxp(Numofsample-1)< Time_res) - count = count+1; - Check_outlierp(count) = Numofsample; - end - end - end - dataxxp(Check_outlierp) = []; - timexxp(Check_outlierp) = []; - - Check_isolated =[]; - count = 0; - for Numofsample = 1:length(timexxp)-1 - if timexxp(Numofsample+1)-timexxp(Numofsample)>Time_res - count = count+1; - Check_isolated(count) = Numofsample; - end - end - if numel(Check_isolated) ==1 - inBetweenRegionXp1 = [timexxp(1:Check_isolated(1)),fliplr(timexxp(1:Check_isolated(1)))]; - inBetweenRegionYp1 = [squeeze(dataxxp(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionXp1, inBetweenRegionYp1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionXp2 = [timexxp(Check_isolated(1)+1:end),fliplr(timexxp(Check_isolated(1)+1:end))]; - inBetweenRegionYp2 = [squeeze(dataxxp(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(Check_isolated(1)+1:end))))]; - fill(r_ax,inBetweenRegionXp2, inBetweenRegionYp2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - elseif numel(Check_isolated) >1 - for Numofrange = 1:numel(Check_isolated)-1 - - inBetweenRegionX = [timexxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; - inBetweenRegionY = [squeeze(dataxxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - end - inBetweenRegionX1 = [timexxp(1:Check_isolated(1)),fliplr(timexxp(1:Check_isolated(1)))]; - inBetweenRegionY1 = [squeeze(dataxxp(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionX2 = [timexxp(Check_isolated(Numofrange+1)+1:end),fliplr(timexxp(Check_isolated(Numofrange+1)+1:end))]; - inBetweenRegionY2 = [squeeze(dataxxp(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(Check_isolated(Numofrange+1)+1:end))))]; - fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - else - inBetweenRegionX = [timexxp,fliplr(timexxp)]; - inBetweenRegionY = [squeeze(dataxxp)',fliplr(offset(Numofstione)*ones(1,numel(timexxp)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end%Positive part end - - if ~isempty(dataxxn) && numel(dataxxn)>=2 - %%Check isolated point - Check_outliern =[]; - count = 0; - - if (timexxn(2)-timexxn(1)>Time_res) - count= count +1; - Check_outliern(count) = 1; - end - if numel(dataxxn)>=3 - for Numofsample = 2:length(timexxn)-1 - if (timexxn(Numofsample+1)-timexxn(Numofsample)>Time_res) && (timexxn(Numofsample)-timexxn(Numofsample-1)< Time_res) - count = count+1; - Check_outliern(count) = Numofsample; - end - end - end - dataxxn(Check_outliern) = []; - timexxn(Check_outliern) = []; - - Check_isolated =[]; - count = 0; - for Numofsample = 1:length(timexxn)-1 - if timexxn(Numofsample+1)-timexxn(Numofsample)>Time_res - count = count+1; - Check_isolated(count) = Numofsample; - end - end - if numel(Check_isolated) ==1 - inBetweenRegionXp1 = [timexxn(1:Check_isolated(1)),fliplr(timexxn(1:Check_isolated(1)))]; - inBetweenRegionYp1 = [squeeze(dataxxn(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionXp1, inBetweenRegionYp1,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionXp2 = [timexxn(Check_isolated(1)+1:end),fliplr(timexxn(Check_isolated(1)+1:end))]; - inBetweenRegionYp2 = [squeeze(dataxxn(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(Check_isolated(1)+1:end))))]; - fill(r_ax,inBetweenRegionXp2, inBetweenRegionYp2,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - elseif numel(Check_isolated) >1 - for Numofrange = 1:numel(Check_isolated)-1 - - inBetweenRegionX = [timexxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; - inBetweenRegionY = [squeeze(dataxxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - end - inBetweenRegionX1 = [timexxn(1:Check_isolated(1)),fliplr(timexxn(1:Check_isolated(1)))]; - inBetweenRegionY1 = [squeeze(dataxxn(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(1:Check_isolated(1)))))]; - fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - inBetweenRegionX2 = [timexxn(Check_isolated(Numofrange+1)+1:end),fliplr(timexxn(Check_isolated(Numofrange+1)+1:end))]; - inBetweenRegionY2 = [squeeze(dataxxn(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(Check_isolated(Numofrange+1)+1:end))))]; - fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - else - inBetweenRegionX = [timexxn,fliplr(timexxn)]; - inBetweenRegionY = [squeeze(dataxxn)',fliplr(offset(Numofstione)*ones(1,numel(timexxn)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end%%Negative part end - end - end - - elseif ismember_bc2(moption, {'areat', 'fareatlat'})% negative values become positive - - for Numofstione = 1:size(datax,3) - for Numofstitwo = 1:size(datax,2) - timexx = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end - - elseif ismember_bc2(moption, {'areazt','areazp','areazn', 'nintegz'}) - [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(observe_ERPDAT.ERP); - if strcmp(moption,'areazt')%% all area were included - - for Numofstione = 1:size(plot_erp_data,3) - for Numofstitwo = 1:size(plot_erp_data,2) - latx = Lat{Numofstitwo,Numofstione}; - [xxx, latsamp] = closest(timex, latx); - datax = plot_erp_data(latsamp(1):latsamp(2),:,:); - timexx = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end - - elseif strcmp(moption,'areazp')%% Only positive area was included - - for Numofstione = 1:size(plot_erp_data,3) - for Numofstitwo = 1:size(plot_erp_data,2) - latx = Lat{Numofstitwo,Numofstione}; - [xxx, latsamp] = closest(timex, latx); - datax = plot_erp_data(latsamp(1):latsamp(2),:,:); - timexx = timex(latsamp(1):latsamp(2)); - timexx_unsl = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check_unsl = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check = dataxx -offset(Numofstione); - if Plority_plot==1 - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - data_check_unsl(data_check>0) =[]; - timexx_unsl(data_check>0) = []; - elseif Plority_plot ==-1 - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - data_check_unsl(data_check<0) =[]; - timexx_unsl(data_check<0) = []; - else - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - data_check_unsl(data_check>0) =[]; - timexx_unsl(data_check>0) = []; - end - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - inBetweenRegionX_unsl = [timexx_unsl,fliplr(timexx_unsl)]; - inBetweenRegionY_unsl = [squeeze(data_check_unsl)',fliplr(offset(Numofstione)*ones(1,numel(timexx_unsl)))]; - fill(r_ax,inBetweenRegionX_unsl, inBetweenRegionY_unsl,[1 1 1],'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - end - end - - - elseif strcmp(moption,'areazn')%% Only positive area was included - - for Numofstione = 1:size(plot_erp_data,3) - for Numofstitwo = 1:size(plot_erp_data,2) - latx = Lat{Numofstitwo,Numofstione}; - [xxx, latsamp] = closest(timex, latx); - datax = plot_erp_data(latsamp(1):latsamp(2),:,:); - timexx = timex(latsamp(1):latsamp(2)); - timexx_unsl = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check_unsl = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check = dataxx -offset(Numofstione); - if Plority_plot==1 - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - data_check_unsl(data_check<0) =[]; - timexx_unsl(data_check<0) = []; - elseif Plority_plot ==-1 - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - data_check_unsl(data_check>0) =[]; - timexx_unsl(data_check>0) = []; - else - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - data_check_unsl(data_check<0) =[]; - timexx_unsl(data_check<0) = []; - end - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - inBetweenRegionX_unsl = [timexx_unsl,fliplr(timexx_unsl)]; - inBetweenRegionY_unsl = [squeeze(data_check_unsl)',fliplr(offset(Numofstione)*ones(1,numel(timexx_unsl)))]; - fill(r_ax,inBetweenRegionX_unsl, inBetweenRegionY_unsl,[1 1 1],'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - end - end - - elseif strcmp(moption,'nintegz')%% Only positive area was included - - for Numofstione = 1:size(plot_erp_data,3) - for Numofstitwo = 1:size(plot_erp_data,2) - latx = Lat{Numofstitwo,Numofstione}; - [xxx, latsamp] = closest(timex, latx); - datax = plot_erp_data(latsamp(1):latsamp(2),:,:); - timexx = timex(latsamp(1):latsamp(2)); - timexx_unsl = timex(latsamp(1):latsamp(2)); - dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check_unsl = squeeze(datax(:,Numofstitwo,Numofstione)); - data_check = dataxx -offset(Numofstione); - if Plority_plot==1 - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - data_check_unsl(data_check>0) =[]; - timexx_unsl(data_check>0) = []; - elseif Plority_plot ==-1 - dataxx(data_check>0) = []; - timexx(data_check>0) = []; - data_check_unsl(data_check<0) =[]; - timexx_unsl(data_check<0) = []; - else - dataxx(data_check<0) = []; - timexx(data_check<0) = []; - data_check_unsl(data_check>0) =[]; - timexx_unsl(data_check>0) = []; - end - inBetweenRegionX = [timexx,fliplr(timexx)]; - inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; - fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - inBetweenRegionX_unsl = [timexx_unsl,fliplr(timexx_unsl)];% - inBetweenRegionY_unsl = [squeeze(data_check_unsl)',fliplr(offset(Numofstione)*ones(1,numel(timexx_unsl)))]; - fill(r_ax,inBetweenRegionX_unsl, inBetweenRegionY_unsl,line_colors(Numofstitwo,:,:)*0.5,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); - - end - end - - - end - end -end - - -if length(latency)==1 - if ismember_bc2(moption, {'areazt','areazp','areazn', 'nintegz'})%% Four options for Numerical integration/Area between two (automatically detected)zero-crossing latencies - xline(r_ax,latency, 'Color', cwm,'LineWidth' ,1); - - else - xline(r_ax,latency, 'Color', cwm,'LineWidth' ,1); - end - if ismember_bc2(moption, 'instabl') - [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(observe_ERPDAT.ERP); - - for Numofstione = 1:Num_plot - for Numofstitwo = 1:Num_data - plot(r_ax,latency,squeeze(Amp_out(Numofstitwo,Numofstione)),'Color',line_colors(Numofstitwo,:,:),'Marker','x'); - end - end - - end -elseif length(latency)==2 - Max_values = max(abs(plot_erp_data(:))); - plot_area_up = area(r_ax,[latency latency(2) latency(1)],[-2*Max_values-500,Max_values*2 -2*Max_values-500,Max_values*2]); - plot_area_low = area(r_ax,[latency latency(2) latency(1)],[0,-Max_values*2 0,-Max_values*2]); - - set(plot_area_up,'FaceAlpha',0.2, 'EdgeAlpha', 0.1, 'EdgeColor', cwm,'FaceColor',cwm_backgb); - set(plot_area_low,'FaceAlpha',0.2, 'EdgeAlpha', 0.1, 'EdgeColor', cwm,'FaceColor',cwm_backgb); - - if ismember_bc2(moption, {'peakampbl'})%Local Peak amplitude - - [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(observe_ERPDAT.ERP); - for Numofstione = 1:Num_plot - for Numofstitwo = 1:Num_data - line(r_ax, [Lat{Numofstitwo,Numofstione} Lat{Numofstitwo,Numofstione}],[offset(Numofstione),squeeze(Amp_out(Numofstitwo,Numofstione))],'Color',line_colors(Numofstitwo,:,:),'LineWidth',3,'LineStyle','--','Marker','x'); - end - end - - elseif ismember_bc2(moption, { 'fareatlat', 'fareaplat','fninteglat','fareanlat'})%fractional area latency - - - [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(observe_ERPDAT.ERP); - for Numofstione = 1:Num_plot - for Numofstitwo = 1:Num_data - Amp_all = squeeze(plot_erp_data(:,Numofstitwo,Numofstione)); - if ~isnan(Amp_out(Numofstitwo,Numofstione)) - [xxx, latsamp, latdiffms] = closest(timex, Amp_out(Numofstitwo,Numofstione)); - line(r_ax, [Amp_out(Numofstitwo,Numofstione) Amp_out(Numofstitwo,Numofstione)],[offset(Numofstione),Amp_all(latsamp)],'Color',line_colors(Numofstitwo,:,:),'LineWidth',3,'LineStyle','--','Marker','x'); - end - end - end - - elseif ismember_bc2(moption, {'peaklatbl','fpeaklat'}) % fractional peak latency && Local peak latency - - [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(observe_ERPDAT.ERP); - for Numofstione = 1:Num_plot - for Numofstitwo = 1:Num_data - Amp_all = squeeze(plot_erp_data(:,Numofstitwo,Numofstione)); - if ~isnan(Amp_out(Numofstitwo,Numofstione)) - [xxx, latsamp, latdiffms] = closest(timex, Amp_out(Numofstitwo,Numofstione)); - line(r_ax, [Amp_out(Numofstitwo,Numofstione) Amp_out(Numofstitwo,Numofstione)],[offset(Numofstione),Amp_all(latsamp)],'Color',line_colors(Numofstitwo,:,:),'LineWidth',3,'LineStyle','--','Marker','x'); - end - end - end - - end -end - -end diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP_try.m b/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP_try.m deleted file mode 100755 index 87e813f0..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/f_redrawERP_try.m +++ /dev/null @@ -1,942 +0,0 @@ -%This function is to plot ERP wave with single or multiple columns on one page. - - - -% Author: Guanghui Zhang & Steve J. Luck & Andrew Stewart -% Center for Mind and Brain -% University of California, Davis, -% Davis, CA -% 2022 - - - -function f_redrawERP_try() -% Draw a demo ERP into the axes provided -global gui_erp; -global observe_ERPDAT; - - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); - -S_ws_geterpplot = estudioworkingmemory('geterpplot'); - - -%%Parameter from bin and channel panel -Elecs_shown = S_ws_getbinchan.elecs_shown{S_ws_getbinchan.Select_index}; -Bins = S_ws_getbinchan.bins{S_ws_getbinchan.Select_index}; -Bin_chans = S_ws_getbinchan.bins_chans(S_ws_getbinchan.Select_index); -Elec_list = S_ws_getbinchan.elec_list{S_ws_getbinchan.Select_index}; -Matlab_ver = S_ws_getbinchan.matlab_ver; - - - -%%Parameter from plotting panel -try - Min_vspacing = S_ws_geterpplot.min_vspacing(S_ws_getbinchan.Select_index); - Min_time = S_ws_geterpplot.min(S_ws_getbinchan.Select_index); - Max_time = S_ws_geterpplot.max(S_ws_getbinchan.Select_index); - Yscale = S_ws_geterpplot.yscale(S_ws_getbinchan.Select_index); - Timet_low =S_ws_geterpplot.timet_low(S_ws_getbinchan.Select_index); - Timet_high =S_ws_geterpplot.timet_high(S_ws_getbinchan.Select_index); - Timet_step=S_ws_geterpplot.timet_step(S_ws_getbinchan.Select_index); - Fill = S_ws_geterpplot.fill(S_ws_getbinchan.Select_index); - Plority_plot = S_ws_geterpplot.Positive_up(S_ws_getbinchan.Select_index); - ColumnNum = S_ws_geterpplot.Plot_column; -catch - return; -end - -Column_label = ColumnNum(S_ws_getbinchan.Select_index); - -if Bin_chans == 0 - elec_n = S_ws_getbinchan.elec_n(S_ws_getbinchan.Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(S_ws_getbinchan.Select_index)).nchan; -else - elec_n = S_ws_getbinchan.bin_n(S_ws_getbinchan.Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(S_ws_getbinchan.Select_index)).nbin; -end - -% We first clear the existing axes ready to build a new one -if ishandle( gui_erp.ViewAxes ) - delete( gui_erp.ViewAxes ); -end - - -% Get chan labels -S_chan.chan_label = cell(1,max_elec_n); -S_chan.chan_label_place = zeros(1,max_elec_n); - - -if Bin_chans == 0 - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.chanlocs(Elecs_shown(i)).labels; - end -else - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.bindescr(Bins(i)); - end -end - - -%Sets the units of your root object (screen) to pixels -set(0,'units','pixels') -%Obtains this pixel information -Pix_SS = get(0,'screensize'); -%Sets the units of your root object (screen) to inches -set(0,'units','inches') -%Obtains this inch information -Inch_SS = get(0,'screensize'); -%Calculates the resolution (pixels per inch) -Res = Pix_SS./Inch_SS; - - -pb_height = Min_vspacing*Res(4); %px - - -% Plot data in the main viewer fig -splot_n = elec_n; -tsize = 13; - - -clear pb r_ax plotgrid; -try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color -catch - ColorB_def = [0.95 0.95 0.95]; -end -if isempty(ColorB_def) - ColorB_def = [0.95 0.95 0.95]; -end -gui_erp.plotgrid = uix.VBox('Parent',gui_erp.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); - -pageinfo_box = uiextras.HBox( 'Parent', gui_erp.plotgrid,'BackgroundColor',ColorB_def); - -gui_erp.plot_wav_legend = uiextras.HBox( 'Parent', gui_erp.plotgrid,'BackgroundColor',[1 1 1]); -gui_erp.ViewAxes_legend = uix.ScrollingPanel( 'Parent', gui_erp.plot_wav_legend,'BackgroundColor',ColorB_def); - -gui_erp.ViewAxes = uix.ScrollingPanel( 'Parent', gui_erp.plot_wav_legend,'BackgroundColor',[1 1 1]); - - -%%Changed by Guanghui Zhang 2 August 2022-------panel for display the processing procedure for some functions, e.g., filtering -xaxis_panel = uiextras.HBox( 'Parent', gui_erp.plotgrid,'BackgroundColor',ColorB_def);%%%Message -gui_erp.Process_messg = uicontrol('Parent',xaxis_panel,'Style','text','String','','FontSize',20,'FontWeight','bold','BackgroundColor',ColorB_def); - - -%%Setting title -gui_erp.pageinfo_minus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '<','Callback',@page_minus,'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index ==1 - gui_erp.pageinfo_minus.Enable = 'off'; -end - -gui_erp.pageinfo_plus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '>','Callback',@page_plus,'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index == numel(S_ws_geterpset) - gui_erp.pageinfo_plus.Enable = 'off'; -end - -pageinfo_str = ['Page',32,num2str(S_ws_getbinchan.Select_index),'/',num2str(numel(S_ws_geterpset)),':',32,observe_ERPDAT.ERP.erpname]; - -pageinfo_text = uicontrol('Parent',pageinfo_box,'Style','text','String',pageinfo_str,'FontSize',14,'FontWeight','bold'); - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [1 1 1]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -gui_erp.pageinfo_minus.Enable = Enable_minus; -gui_erp.pageinfo_plus.Enable = Enable_plus; -gui_erp.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -gui_erp.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - -set(pageinfo_box, 'Sizes', [50 50 -1] ); -set(pageinfo_box,'BackgroundColor',ColorB_def); -set(pageinfo_text,'BackgroundColor',ColorB_def); -%Setting title. END,'BackgroundColor',ColorB_def - -%for i=1:splot_n - -% -%%------------Setting the number of data and plotting--------------------- -ndata = 0; -nplot = 0; -if Bin_chans == 0 %if channels with bin overlay - ndata = Bins; - nplot = Elecs_shown; -else %if bins with channel overlay - ndata = Elecs_shown; - nplot = Bins; -end - -% -timeor = observe_ERPDAT.ERP.times; % original time vector -timex = timeor; -[xxx, latsamp, latdiffms] = closest(timex, [Min_time Max_time]); -tmin = latsamp(1); -tmax = latsamp(2); - -if tmin < 1 - tmin = 1; -end - -if tmax > numel(observe_ERPDAT.ERP.times) - tmax = numel(observe_ERPDAT.ERP.times); -end - -plot_erp_data = nan(tmax-tmin+1,numel(ndata)); -for i = 1:splot_n - if Bin_chans == 0 - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = observe_ERPDAT.ERP.bindata(Elecs_shown(i),tmin:tmax,Bins(i_bin))'*Plority_plot; % - end - else - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = observe_ERPDAT.ERP.bindata(Elecs_shown(i_bin),tmin:tmax,Bins(i))'*Plority_plot; % - end - end -end - -perc_lim = Yscale; -percentile = perc_lim*3/2; - -[~,~,b] = size(plot_erp_data); - - -% -%%%------------Setting xticklabels for each row of each wave-------------- -xstep_label = estudioworkingmemory('erp_xtickstep'); -if isempty(xstep_label) - xstep_label =0; -end -if ~xstep_label - [def Timet_step]= default_time_ticks_studio(observe_ERPDAT.ERP, [Min_time,Max_time]); - if ~isempty(def{1,1}) - xticks_clomn = str2num(def{1,1}); - while xticks_clomn(end)<=Max_time - xticks_clomn(numel(xticks_clomn)+1) = xticks_clomn(end)+Timet_step; - if xticks_clomn(end)>Max_time - xticks_clomn = xticks_clomn(1:end-1); - break; - end - end - else - xticks_clomn = (Min_time:Timet_step:Max_time); - end -else - - - xticks_clomn = (Min_time:Timet_step:Max_time); -end -Timet_step_p = ceil(Timet_step/(1000/observe_ERPDAT.ERP.srate));%% Time points of the gap between columns - -% -%%----------------------Modify the data into multiple-columns--------------------------------------- -rowNum = ceil(b/Column_label); -plot_erp_data_new = NaN(size(plot_erp_data,1),size(plot_erp_data,2),rowNum*Column_label); - -plot_erp_data_new(:,:,1:size(plot_erp_data,3)) = plot_erp_data; -plot_erp_data_new_trans = []; - - -if Column_label==1 - for Numofrow = 1:rowNum - plot_erp_data_new_trans(:,:,:,Numofrow) = plot_erp_data_new(:,:,(Numofrow-1)*Column_label+1:Numofrow*Column_label); - end - - clear plot_erp_data; - plot_erp_data_new_trans = permute(plot_erp_data_new_trans,[1,3,2,4]) ; - plot_erp_data = reshape(plot_erp_data_new_trans,size(plot_erp_data_new_trans,1)*size(plot_erp_data_new_trans,2),size(plot_erp_data_new_trans,3),size(plot_erp_data_new_trans,4)); - -elseif Column_label>1 - - plot_erp_data_trans_clumns = NaN(size(plot_erp_data_new,1)*Column_label+(Column_label-1)*Timet_step_p,size(plot_erp_data_new,2),rowNum); - for Numofrow = 1:rowNum - Data_column = plot_erp_data_new(:,:,(Numofrow-1)*Column_label+1:Numofrow*Column_label); - for Numofcolumn = 1:Column_label - low_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+1+(Numofcolumn-1)*Timet_step_p; - high_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+(Numofcolumn-1)*Timet_step_p+size(plot_erp_data_new,1); - plot_erp_data_trans_clumns(low_interval:high_interval,:,Numofrow) = squeeze(Data_column(:,:,Numofcolumn)); - end - end - plot_erp_data = plot_erp_data_trans_clumns; -end - -ind_plot_height = percentile*2; % Height of each individual subplot - -offset = []; -if Bin_chans == 0 - offset = (size(plot_erp_data,3)-1:-1:0)*ind_plot_height; -else - offset = (size(plot_erp_data,3)-1:-1:0)*ind_plot_height; -end -[~,~,b] = size(plot_erp_data); -for i = 1:b - plot_erp_data(:,:,i) = plot_erp_data(:,:,i) + ones(size(plot_erp_data(:,:,i)))*offset(i); -end - - - -r_ax = axes('Parent', gui_erp.ViewAxes,'Color','none','Box','on','FontWeight','bold'); -hold(r_ax,'on'); -set(gui_erp.plot_wav_legend,'Sizes',[80 -10]); -r_ax_legend = axes('Parent', gui_erp.ViewAxes_legend,'Color','none','Box','off'); -hold(r_ax_legend,'on'); - - -try - f_bin = 1000/observe_ERPDAT.ERP.srate; -catch - f_bin = 1; -end - -ts = observe_ERPDAT.ERP.times(tmin:tmax); -ts_colmn = ts; - -% -%%------------------Adjust the data into multiple/single columns------------ -if Column_label>1 % Plotting waveforms with munltiple-columns - xticks_org = xticks_clomn; - - for Numofcolumn = 1:Column_label-1 - xticks_clomn_add = [1:numel(ts)+Timet_step_p].*f_bin+(ts_colmn(end).*ones(1,numel(ts)+Timet_step_p)); - ts_colmn = [ts_colmn,xticks_clomn_add]; - end - - X_zero_line(1) =ts(1); - for Numofcolumn = 1:Column_label-1 - if Numofcolumn ==1 - X_zero_line(Numofcolumn+1) = X_zero_line(Numofcolumn)+ ts(end)-ts(1)+f_bin + (Timet_step_p/2)*f_bin; - else - X_zero_line(Numofcolumn+1) = X_zero_line(Numofcolumn)+ ts(end)-ts(1)+f_bin + (Timet_step_p)*f_bin; - end - end - - [xticks,xticks_labels] = f_geterpxticklabel(observe_ERPDAT.ERP,xticks_clomn,Column_label,[Min_time Max_time],Timet_step); - ts = ts_colmn; - Min_time = ts(1); - Max_time = ts(end); - -else%% Plotting waveforms with single-column - %%%------------getting xticklabels for each row of each wave-------------- - xticks =xticks_clomn; - X_zero_line(1) =ts(1); - for Numofxlabel = 1:numel(xticks) - xticks_labels{Numofxlabel} = num2str(xticks(Numofxlabel)); - end -end - - -splot_n = size(plot_erp_data,3);%%Adjust the columns - -set(r_ax,'XLim',[Min_time Max_time]); - -[a,c,b] = size(plot_erp_data); -new_erp_data = zeros(a,b*c); -for i = 1:b - new_erp_data(:,((c*(i-1))+1):(c*i)) = plot_erp_data(:,:,i); -end - - -line_colors = erpworkingmemory('PWColor'); -if size(line_colors,1)~= numel(ndata) - if numel(ndata)> size(line_colors,1) - line_colors = get_colors(numel(ndata)); - else - line_colors = line_colors(1:numel(ndata),:,:); - end -end - -if isempty(line_colors) - line_colors = get_colors(numel(ndata)); -end - -line_colors = repmat(line_colors,[splot_n 1]); %repeat the colors once for every plot - - -% -%%------------Setting xticklabels for each row -------------- -x_axs = ones(size(new_erp_data,1),1); -for jj = 1:numel(offset)-1 - plot(r_ax,ts,x_axs.*offset(end),'color',[1 1 1],'LineWidth',1); - set(r_ax,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); - myX_Crossing = offset(jj); - props = get(r_ax); - - tick_bottom = -props.TickLength(1)*diff(props.YLim); - if abs(tick_bottom) > abs(Yscale)/5 - try - tick_bottom = - abs(Yscale)/5; - catch - tick_bottom = tick_bottom; - end - elseif abs(tick_bottom)1 - if numel(offset)==jj - kkkk = 1; - else - kkkk = 2; - end - for iCount = kkkk:nTicks - xtick_label = (props.XTickLabel(iCount, :)); - text(r_ax,props.XTick(iCount), tick_bottom + myX_Crossing, ... - xtick_label, ... - 'HorizontalAlignment', 'Center', ... - 'VerticalAlignment', 'Top', ... - 'FontSize', 12, ... - 'FontName', props.FontName, ... - 'FontAngle', props.FontAngle, ... - 'FontUnits', props.FontUnits, ... - 'FontWeight', 'bold'); - end - end - -end - -% -%%----------------Start:Remove xticks for the columns without waves in the last row------------------------- -Element_left = numel(nplot) - (ceil(numel(nplot)/Column_label)-1)*Column_label; -x_axset = plot(r_ax,ts,x_axs.*offset(end),'color', [1 1 1],'LineWidth',1); -set(r_ax,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); -myX_Crossing = offset(end); -props = get(r_ax); - -tick_bottom = -props.TickLength(1)*diff(props.YLim); -if abs(tick_bottom) > abs(Yscale)/5 - try - tick_bottom = - abs(Yscale)/5; - catch - tick_bottom = tick_bottom; - end -elseif abs(tick_bottom)1 - for iCount = 1:ceil(nTicks/Column_label*Element_left) - xtick_label = (props.XTickLabel(iCount, :)); - text(r_ax,props.XTick(iCount), tick_bottom + myX_Crossing, ... - xtick_label, ... - 'HorizontalAlignment', 'Center', ... - 'VerticalAlignment', 'Top', ... - 'FontSize', 12, ... - 'FontName', props.FontName, ... - 'FontAngle', props.FontAngle, ... - 'FontUnits', props.FontUnits, ... - 'FontWeight', 'bold'); - end -end -%%--------------------------End:Remove xticks for the columns without waves in the last row------------------------- - -% -%%-----------------Get zeroline for each row----------------------------- -row_baseline = NaN(numel(ts),splot_n); -count = 0; -for Numofsplot = 0:splot_n-1 - for Numofcolumn = 1:Column_label - count = count +1; - if count> numel(nplot) - - break; - - end - low_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+1+(Numofcolumn-1)*Timet_step_p; - high_interval = size(plot_erp_data_new,1)*(Numofcolumn-1)+(Numofcolumn-1)*Timet_step_p+size(plot_erp_data_new,1); - row_baseline(low_interval:high_interval,Numofsplot+1) = ones(numel(low_interval:high_interval),1).*offset(Numofsplot+1); - end -end - - -% -%%-------------------------Plotting ERP waves----------------------------- -pb_here = plot(r_ax,ts, [new_erp_data],'LineWidth',1.5); - -set(r_ax, 'XTick', [], 'XTickLabel', []); - -% -%%----------------Marking 0 point (event-locked)-------------------------- -[xxx, latsamp_0, latdiffms_0] = closest(xticks, [0]); -if numel(offset)>1 - if latdiffms_0 ==0 - for Numofcolumn = 1:Column_label - xline(r_ax,xticks((Numofcolumn-1)*numel(xticks_clomn)+latsamp_0),'k-.','LineWidth',1);%%'Color',Marking start time point for each column - end - end -elseif numel(offset)==1 - - for Numofcolumn = 1:numel(nplot) - xline(r_ax,xticks((Numofcolumn-1)*numel(xticks_clomn)+latsamp_0),'k-.','LineWidth',1);%%'Color',Marking start time point for each column - end -end -% -yticks = -perc_lim:perc_lim:((2*percentile*b)-(2*perc_lim)); -ylabs = repmat([-perc_lim 0 perc_lim],[1,b]); -oldlim = [-percentile yticks(end)-perc_lim+percentile]; -top_vspace = max( max( new_erp_data))-oldlim(2); -bot_vspace = min( min( new_erp_data))-oldlim(1); -if top_vspace < 0 - top_vspace = 0; -end - -if bot_vspace > 0 - bot_vspace = 0; -end -newlim = oldlim + [bot_vspace top_vspace]; -set(r_ax,'XLim',[Min_time Max_time],'Ylim',newlim); - - -% -%%--------------Setting color for each wave-------------------------- -% if Column_label>1 -% for i = 0:splot_n-1 -% r_ax.Children(end-i).Color = [1 1 1]; -% end -% end - -% for i = splot_n+1:numel(pb_here) -% pb_here(i).Color = line_colors((i-splot_n),:); -% end -for i = 1:numel(pb_here) - pb_here(i).Color = line_colors(i,:); -end -% -% for i = 1:splot_n-1 -% pb_here(i).Color = [0 0 0]; -% pb_here(i).LineWidth=.01; -% end - - - - -%%------------Marking start time point for each column--------------------- -if Column_label>1 - for ii = 2:numel(X_zero_line) - xline(r_ax,X_zero_line(ii), 'y--','LineWidth',2); - end -end - -for Numofplot = 1:size(row_baseline,2) - plot(r_ax,ts,row_baseline(:,Numofplot),'color',[0 0 0],'LineWidth',1.5); -end -ylabs = [fliplr(-perc_lim:-perc_lim:newlim(1)) ylabs(2:end-1) (yticks(end):perc_lim:newlim(2))-yticks(end)+perc_lim]; -yticks = [fliplr(-perc_lim:-perc_lim:newlim(1)) yticks(2:end-1) yticks(end):perc_lim:newlim(2)]; - - - -% -%%-------------Name of bin/channel for each subplot-------------------------- -if Column_label==1 - if numel(offset)>1 - count = 0; - for i = 0:numel(offset)-1 - leg_str = ''; - - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',Elec_list{Elecs_shown(count)}); - else - leg_str = sprintf('%s',observe_ERPDAT.ERP.bindescr{Bins(count)}); - end - catch - leg_str = ''; - end - text(r_ax,ts(1),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - end - end - - try - if Bin_chans == 0 - leg_str = sprintf('%s',Elec_list{Elecs_shown(end)}); - else - leg_str = sprintf('%s',observe_ERPDAT.ERP.bindescr{Bins(end)}); - end - catch%% - leg_str = ''; - end - - try - text(r_ax,ts(1),offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - catch - text(r_ax,ts(1),Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); - end -else%% Getting y ticks and legends for multiple-columns - if numel(offset)>1 - count = 0; - for i = 0:numel(offset)-1 - leg_str = ''; - for Numofcolumn = 1: Column_label - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',Elec_list{Elecs_shown(count)}); - else - leg_str = sprintf('%s',observe_ERPDAT.ERP.bindescr{Bins(count)}); - end - catch - leg_str = ''; - end - if Numofcolumn ==1 - text(r_ax,X_zero_line(Numofcolumn),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - else - text(r_ax,X_zero_line(Numofcolumn)+Timet_step/2,offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - end - end - end - end - - - count = (numel(offset)-1)*Column_label; - leg_str = ''; - for Numofcolumn = 1:Column_label - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',Elec_list{Elecs_shown(count)}); - else - leg_str = sprintf('%s',observe_ERPDAT.ERP.bindescr{Bins(count)}); - end - catch%% - leg_str = ''; - end - try - - if Numofcolumn ==1 - text(r_ax,X_zero_line(Numofcolumn),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - else - text(r_ax,X_zero_line(Numofcolumn)+Timet_step/2,offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 14); - end - catch - - if Numofcolumn ==1 - text(r_ax,X_zero_line(Numofcolumn),Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); - else - text(r_ax,X_zero_line(Numofcolumn)+Timet_step/2,Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); - end - % text(r_ax,X_zero_line(Numofcolumn),Yscale/2,leg_str,'FontWeight','bold','FontSize', 14); - end - end - -end -% - - -% -%%-------------Setting x/yticks and ticklabels-------------------------------- -Ylabels_new = ylabs.*Plority_plot; -[~,Y_label] = find(Ylabels_new == -0); -Ylabels_new(Y_label) = 0; -% xticks = (Min_time:Timet_step:Max_time); -% some options currently only work post Matlab R2016a ,'XLim',[Min_time Max_time],'XLim',[Min_time Max_time] -if Matlab_ver >= 2016 - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','origin',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim,'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels); -else - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','bottom',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim, 'XTick',xticks, ... - 'box','off', 'Color','none','xticklabels',xticks_labels); - hline(0,'k'); % backup xaxis -end -if Column_label>1 - set(r_ax,'XGrid','on','YGrid','on');%,'XDir','reverse' -end -set(r_ax, 'XTick', [], 'XTickLabel', [],'FontWeight', 'bold'); -r_ax.YAxis.LineWidth = 1.5; - -hold(r_ax,'off'); -% - - - -% -%%--------------------------Setting legend--------------------------------- -line_colors_ldg = erpworkingmemory('PWColor'); -if isempty(line_colors_ldg) - line_colors_ldg = get_colors(numel(ndata)); -end - -if size(line_colors_ldg,1)~= numel(ndata) - if numel(ndata)> size(line_colors_ldg,1) - line_colors_ldg = get_colors(numel(ndata)); - else - line_colors_ldg = line_colors_ldg(1:numel(ndata),:,:); - end -end - -for Numofplot = 1:size(plot_erp_data,2) - plot(r_ax_legend,[0 0],'Color',line_colors_ldg(Numofplot,:,:),'LineWidth',3) -end - -if Bin_chans == 0 - - Leg_Name = {}; - - for Numofbin = 1:numel(Bins) - Leg_Name{Numofbin} = strcat('Bin',num2str(Bins(Numofbin))); - end -else - for Numofchan = 1:numel(Elecs_shown) - Leg_Name{Numofchan} = Elec_list{Numofchan}; - end -end -legend(r_ax_legend,Leg_Name,'FontSize',14,'TextColor','blue'); -legend(r_ax_legend,'boxoff'); -% - -%-------fix scaling shrinkage-------------- -pos_fix = r_ax.Position; -pos_fix(2) = 1; % Start at the bottom -pos_fix(4) = pb_height - 1; % fill the height; - -gui_erp.plotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high -gui_erp.plotgrid.Heights(3) = 30; % set the second element (x axis) to 30px high -gui_erp.plotgrid.Units = 'pixels'; -if splot_n*pb_height<(gui_erp.plotgrid.Position(4)-gui_erp.plotgrid.Heights(1))&&Fill - pb_height = (gui_erp.plotgrid.Position(4)-gui_erp.plotgrid.Heights(1)-gui_erp.plotgrid.Heights(2))/splot_n; -end - -gui_erp.ViewAxes.Heights = splot_n*pb_height; -gui_erp.plotgrid.Units = 'normalized'; - -end % redrawDemo - - -function colors = get_colors(ncolors) -% Each color gets 1 point divided into up to 2 of 3 groups (RGB). -degree_step = 6/ncolors; -angles = (0:ncolors-1)*degree_step; -colors = nan(numel(angles),3); -for i = 1:numel(angles) - if angles(i) < 1 - colors(i,:) = [1 (angles(i)-floor(angles(i))) 0]*0.75; - elseif angles(i) < 2 - colors(i,:) = [(1-(angles(i)-floor(angles(i)))) 1 0]*0.75; - elseif angles(i) < 3 - colors(i,:) = [0 1 (angles(i)-floor(angles(i)))]*0.75; - elseif angles(i) < 4 - colors(i,:) = [0 (1-(angles(i)-floor(angles(i)))) 1]*0.75; - elseif angles(i) < 5 - colors(i,:) = [(angles(i)-floor(angles(i))) 0 1]*0.75; - else - colors(i,:) = [1 0 (1-(angles(i)-floor(angles(i))))]*0.75; - end -end -end - - - -%------------------Display the waveform for proir ERPset-------------------- -function page_minus(~,~) -global observe_ERPDAT; -global gui_erp; - - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); - - -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index-1; -Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end - -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); - - -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); - - -observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -gui_erp.pageinfo_minus.Enable = Enable_minus; -gui_erp.pageinfo_plus.Enable = Enable_plus; -% f_redrawERP_mt_viewer(); -gui_erp.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -gui_erp.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -end - - - - - -%------------------Display the waveform for next ERPset-------------------- -function page_plus(~,~) -global observe_ERPDAT; -global gui_erp; - - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); - - - - -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index+1; -Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end - -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); - -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); - -observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [1 1 1]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - - - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -gui_erp.pageinfo_minus.Enable = Enable_minus; -gui_erp.pageinfo_plus.Enable = Enable_plus; -gui_erp.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -gui_erp.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -end - - diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_spectral_analysis_advance.fig b/studio_functions/Functions/EStudio/ERP Tab/f_spectral_analysis_advance.fig deleted file mode 100755 index b1502ebb..00000000 Binary files a/studio_functions/Functions/EStudio/ERP Tab/f_spectral_analysis_advance.fig and /dev/null differ diff --git a/studio_functions/Functions/EStudio/ERP Tab/f_spectral_analysis_advance.m b/studio_functions/Functions/EStudio/ERP Tab/f_spectral_analysis_advance.m deleted file mode 100755 index c11257e0..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/f_spectral_analysis_advance.m +++ /dev/null @@ -1,814 +0,0 @@ -% -% Author: Guanghui Zhang & Steven Luck -% Center for Mind and Brain -% University of California, Davis, -% Davis, CA -% 2022 - -%b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b -% -% Copyright (C) 2022 Guanghui ZHANG & Steven Luck, -% Center for Mind and Brain, University of California, Davis, -% ghzhang@ucdavis.edu, sjluck@ucdavis.edu -% -% This program 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. -% -% This program 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 this program. If not, see . - -function varargout = f_spectral_analysis_advance(varargin) - -% Begin initialization code - DO NOT EDIT -gui_Singleton = 1; -gui_State = struct('gui_Name', mfilename, ... - 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @f_spectral_analysis_advance_OpeningFcn, ... - 'gui_OutputFcn', @f_spectral_analysis_advance_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 - -%-------------------------------------------------------------------------- -function f_spectral_analysis_advance_OpeningFcn(hObject, eventdata, handles, varargin) - -% Choose default command line output for f_spectral_analysis_advance -handles.output = []; -try - ERP = varargin{1}; -catch - ERP = []; - ERP = buildERPstruct([]); - ERP.xmin = 0; - ERP.xmax = 0; - ERP.nbin = 1; - ERP.nchan = 1; - -end -handles.ERP = ERP; - -try - def = varargin{2}; -catch - def = {1,[], [], [1 16], 1, 1,1,0}; -end - -bin_chan_label = def{1}; -BinArray = def{2}; -ChanArray = def{3}; -freqRange = def{4}; -Auto_freq = def{5}; -RowNum = def{6}; -ColumnNum = def{7}; - -listb = {''}; -nbin = ERP.nbin; % Total number of bins -try - for b=1:nbin - listb{b}= ['BIN' num2str(b) ' = ' ERP.bindescr{b} ]; - end -catch - listb = {}; -end - - -%%%set(handles.popupmenu_bins,'String', listb) -handles.listb = listb; -handles.indxlistb = BinArray; - - -nchan = ERP.nchan; % Total number of channels -if ~isfield(ERP.chanlocs,'labels') - for e=1:nchan - ERP.chanlocs(e).labels = ['Ch' num2str(e)]; - end -end -listch = {''}; -for ch =1:nchan - listch{ch} = [num2str(ch) ' = ' ERP.chanlocs(ch).labels ]; -end -handles.listch = listch; -handles.indxlistch = ChanArray; - -for Numofrow = 1:256 - FramString{Numofrow}= num2str(Numofrow); -end - -set(handles.popupmenu_row_num,'String',FramString); -set(handles.popupmenu_column_num,'String',FramString); - -set(handles.popupmenu_row_num,'Value',nchan); - -if bin_chan_label ==1 - set(handles.radiobutton_all_bin_chan,'Value',1); - set(handles.radiobutton_selected_bin_chan,'Value',0); - set(handles.radiobutton_Custom_bin_chan,'Value',0); - set(handles.pushbutton_browse_bin,'Enable','off'); - set(handles.pushbutton_browse_chan,'Enable','off'); - set(handles.edit_bin_custom,'String',num2str(vect2colon([1:ERP.nbin],'Sort', 'on'))); - set(handles.edit_channel_custom,'String',num2str(vect2colon([1:ERP.nchan],'Sort', 'on'))); -elseif bin_chan_label ==2 - set(handles.radiobutton_all_bin_chan,'Value',0); - set(handles.radiobutton_selected_bin_chan,'Value',1); - set(handles.radiobutton_Custom_bin_chan,'Value',0); - set(handles.pushbutton_browse_bin,'Enable','off'); - set(handles.pushbutton_browse_chan,'Enable','off'); - [chk, msgboxText] = chckbinandchan(ERP, BinArray, ChanArray); - if chk(1) - BinString = [1:ERP.nbin]; - else - BinString = BinArray; - end - if chk(2) - ChanString = [1:ERP.nchan]; - else - ChanString = ChanArray; - end - - set(handles.edit_bin_custom,'String',num2str(vect2colon(BinString,'Sort', 'on'))); - set(handles.edit_channel_custom,'String',num2str(vect2colon(ChanString,'Sort', 'on'))); - -elseif bin_chan_label ==3 - set(handles.radiobutton_all_bin_chan,'Value',0); - set(handles.radiobutton_selected_bin_chan,'Value',0); - set(handles.radiobutton_Custom_bin_chan,'Value',1); - set(handles.pushbutton_browse_bin,'Enable','on'); - set(handles.pushbutton_browse_chan,'Enable','on'); -else - set(handles.radiobutton_all_bin_chan,'Value',1); - set(handles.radiobutton_selected_bin_chan,'Value',0); - set(handles.radiobutton_Custom_bin_chan,'Value',0); - set(handles.pushbutton_browse_bin,'Enable','off'); - set(handles.pushbutton_browse_chan,'Enable','off'); - set(handles.edit_bin_custom,'String',num2str(vect2colon([1:ERP.nbin],'Sort', 'on'))); - set(handles.edit_channel_custom,'String',num2str(vect2colon([1:ERP.nchan],'Sort', 'on'))); -end -set(handles.checkbox_freq_ticks_auto,'Value',1); -set(handles.edit_freq_tick_auto,'Enable','off'); - -set(handles.edit_freq_range,'String',num2str(freqRange)); - - - -erplab_studio_default_values; -version = erplabstudiover; -set(handles.gui_chassis,'Name', ['EStudio',version,' - Plot and save spectrum for the selected ERP GUI ']) -handles = painterplabstudio(handles); -handles = setfonterplabestudio(handles); - -% helpbutton - -% -% Color GUI -% -% handles = painterplab(handles); - -% -% Set font size -% -% handles = setfonterplab(handles); - -% Update handles structure -guidata(hObject, handles); - -% help -% helpbutton - -% UIWAIT makes f_spectral_analysis_advance wait for user response (see UIRESUME) -uiwait(handles.gui_chassis); - -%-------------------------------------------------------------------------- -function varargout = f_spectral_analysis_advance_OutputFcn(hObject, eventdata, handles) - -% Get default command line output from handles structure -varargout{1} = handles.output; - -% The figure can be deleted now -delete(handles.gui_chassis); - -% --- Executes on button press in radiobutton_all_bin_chan. -function radiobutton_all_bin_chan_Callback(hObject, eventdata, handles) -set(handles.radiobutton_Custom_bin_chan,'Value',0); -set(handles.radiobutton_selected_bin_chan,'Value',0); -set(handles.radiobutton_all_bin_chan,'Value',1); -set(handles.pushbutton_browse_bin,'Enable','off'); -set(handles.pushbutton_browse_chan,'Enable','off'); -BinString = handles.ERP.nbin; -ChanString = handles.ERP.nchan; - -set(handles.edit_bin_custom,'String',num2str(vect2colon(1:BinString,'Sort', 'on'))); -set(handles.edit_channel_custom,'String',num2str(vect2colon(1:ChanString,'Sort', 'on'))); - -% --- Executes on button press in radiobutton_selected_bin_chan. -function radiobutton_selected_bin_chan_Callback(hObject, eventdata, handles) -set(handles.radiobutton_Custom_bin_chan,'Value',0); -set(handles.radiobutton_selected_bin_chan,'Value',1); -set(handles.radiobutton_all_bin_chan,'Value',0); -set(handles.pushbutton_browse_bin,'Enable','off'); -set(handles.pushbutton_browse_chan,'Enable','off'); - -ERP = handles.ERP; - -BinString = handles.indxlistb; -ChanString = handles.indxlistch; -if isempty(BinString) - BinString =[1:ERP.nbin]; -end -if isempty(ChanString) - ChanString =[1:ERP.nchan]; -end -[chk, msgboxText] = chckbinandchan(ERP, BinString, ChanString); -if chk(1) - BinString = 1:ERP.nbin; -end -if chk(2) - ChanString = 1:ERP.nchan; -end -set(handles.edit_bin_custom,'String',num2str(vect2colon(BinString,'Sort', 'on'))); -set(handles.edit_channel_custom,'String',num2str(vect2colon(ChanString,'Sort', 'on'))); - - -% --- Executes on button press in radiobutton_Custom_bin_chan. -function radiobutton_Custom_bin_chan_Callback(hObject, eventdata, handles) -set(handles.radiobutton_Custom_bin_chan,'Value',1); -set(handles.radiobutton_selected_bin_chan,'Value',0); -set(handles.radiobutton_all_bin_chan,'Value',0); -set(handles.pushbutton_browse_bin,'Enable','on'); -set(handles.pushbutton_browse_chan,'Enable','on'); - - -function edit_bin_custom_Callback(hObject, eventdata, handles) -BinString = str2num(handles.edit_bin_custom.String); -ERP = handles.ERP; -% [chk, msgboxText] = chckbinandchan(ERP, BinString, []); -[chk, msgboxText] = f_ERP_chckbinandchan(ERP, BinString, [],1); - -if chk(1) - title = 'EStudio: Spectral analysis GUI input'; - errorfound(msgboxText, title); - return; -end - - - -% --- Executes during object creation, after setting all properties. -function edit_bin_custom_CreateFcn(hObject, eventdata, handles) -if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); -end - - - -function edit_channel_custom_Callback(hObject, eventdata, handles) -ChanString = str2num(handles.edit_channel_custom.String); -ERP = handles.ERP; -[chk, msgboxText] = chckbinandchan(ERP, [], ChanString); - - -if chk(2) - title = 'EStudio: Spectral analysis GUI input'; - errorfound(msgboxText, title); - return; -end - -chanArray = ChanString; -ColumnNum = get(handles.popupmenu_column_num, 'Value'); -RowNum = ceil((numel(chanArray))/ColumnNum); -ColumnNum = ceil((numel(chanArray))/RowNum); -if RowNum<=0 - RowNum=1; -end -set(handles.popupmenu_row_num, 'Value', RowNum); -set(handles.popupmenu_column_num, 'Value', ColumnNum); - -% --- Executes during object creation, after setting all properties. -function edit_channel_custom_CreateFcn(hObject, eventdata, handles) -if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); -end - -%-------------------------------------------------------------------------- -function pushbutton_browse_bin_Callback(hObject, eventdata, handles) -listb = handles.listb; -indxlistb = handles.indxlistb; -indxlistb = indxlistb(indxlistb<=length(listb)); -titlename = 'Select Bin(s)'; - -if get(hObject, 'Value') - %set(handles.pushbutton_browsechan, 'Enable', 'off') - if ~isempty(listb) - bin = browsechanbinGUI(listb, indxlistb, titlename); - if ~isempty(bin) - set(handles.edit_bin_custom, 'String', vect2colon(bin, 'Delimiter', 'off')); - handles.indxlistb = bin; - % Update handles structure - guidata(hObject, handles); - else - disp('User selected Cancel') - return - end - else - msgboxText = 'No bin information was found'; - title = 'EStudio: Spectral analysis GUI input'; - errorfound(msgboxText, title); - return - end - -end - - - -% --- Executes on button press in pushbutton_browse_chan. -function pushbutton_browse_chan_Callback(hObject, eventdata, handles) -listch = handles.listch; -indxlistch = handles.indxlistch; -indxlistch = indxlistch(indxlistch<=length(listch)); -titlename = 'Select Channel(s)'; - -if get(hObject, 'Value') - if ~isempty(listch) - ch = browsechanbinGUI(listch, indxlistch, titlename); - if ~isempty(ch) - set(handles.edit_channel_custom, 'String', vect2colon(ch, 'Delimiter', 'off')); - handles.indxlistch = ch; - - chanArray = ch; - ColumnNum = get(handles.popupmenu_column_num, 'Value'); - RowNum = ceil((numel(chanArray))/ColumnNum); - if RowNum<=0 - RowNum=1; - end - set(handles.popupmenu_row_num, 'Value', RowNum); - - % Update handles structure - guidata(hObject, handles); - else - disp('User selected Cancel') - return - end - else - msgboxText = 'No channel information was found'; - title = 'EStudio: Spectral analysis GUI input'; - errorfound(msgboxText, title); - return - end -end - -%Freq. range [min max] in Hz -function edit_freq_range_Callback(hObject, eventdata, handles) -freqx = str2num(get(handles.edit_freq_range, 'String')); -if isempty(freqx) - msgboxText = 'Invalid input for frequency range of interest'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end -if length(freqx)~=2 - msgboxText = 'Please, enter two values'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end - - -if freqx(1)>= freqx(2) - msgboxText = 'The first value must be smaller than the second one!'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end -ERP = handles.ERP; -try - freq_half = ERP.srate/2; -catch - freq_half =freqx(2); -end - -if freqx(2)> freq_half - msgboxText = ['Second value must be smaller than',32,num2str(ERP.srate/2)]; - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(msgboxText, title); - return -end - -Auto_tick = get(handles.checkbox_freq_ticks_auto,'Value'); - -if ~Auto_tick - def_ticks = default_time_ticks(handles.ERP, freqx); - set(handles.edit_freq_tick_auto,'String',num2str(def_ticks{1})); -end - - -% --- Executes during object creation, after setting all properties. -function edit_freq_range_CreateFcn(hObject, eventdata, handles) -if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) - set(hObject,'BackgroundColor','white'); -end - - - -% --- Executes on button press in checkbox_freq_ticks_auto. -function checkbox_freq_ticks_auto_Callback(hObject, eventdata, handles) -if get(hObject, 'Value') - set(handles.edit_freq_tick_auto,'Enable','off'); - set(handles.edit_freq_tick_auto,'String',''); -else - set(handles.edit_freq_tick_auto,'Enable','on'); - - freqx = str2num(get(handles.edit_freq_range, 'String')); % XL - if isempty(freqx) - msgboxText = 'Invalid input for frequency range of interest on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return - end - if length(freqx)~=2 - msgboxText = 'Please, enter two values on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return - end - - - if freqx(1)>= freqx(2) - msgboxText = 'The first value must be smaller than the second one on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return - end - if freqx(1)<0 - msgboxText = 'The first value must be larger than 0Hz on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return - end - - ERP = handles.ERP; - if freqx(2)> ERP.srate/2 - msgboxText = ['Second value must be smaller than',32,num2str(observe_ERPDAT.ERP.srate/2),'Hz',32,'on "Freq. range [min max] in Hz"']; - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(msgboxText, title); - return - end - - - def_ticks = default_time_ticks(handles.ERP, freqx); - if ~isempty(def_ticks) - set(handles.edit_freq_tick_auto,'String',num2str(def_ticks{1})); - end -end - - - - - -function edit_freq_tick_auto_Callback(hObject, eventdata, handles) -answer = get(handles.edit_freq_tick_auto,'String'); -nanswer = str2num(strtrim(char(answer))); -if isempty(nanswer) - msgboxText = 'Invalid range of values on freq. ticks!\n'; - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(sprintf(msgboxText), title); - return -end - - - - - - -% --- Executes during object creation, after setting all properties. -function edit_freq_tick_auto_CreateFcn(hObject, eventdata, handles) -% hObject handle to edit_freq_tick_auto (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 - - -% --- Executes on selection change in popupmenu_row_num. -function popupmenu_row_num_Callback(hObject, eventdata, handles) -chanArraystr = get(handles.edit_channel_custom, 'String'); -chanArray = str2num(chanArraystr); -if isempty(chanArray) - chanArray = [1:handles.ERP.nchan]; -end -RowNum= get(handles.popupmenu_row_num, 'Value'); -ColumnNum = ceil((numel(chanArray))/RowNum); -if ColumnNum<=0 - ColumnNum=1; -end -set(handles.popupmenu_column_num, 'Value', ColumnNum); - - -% --- Executes during object creation, after setting all properties. -function popupmenu_row_num_CreateFcn(hObject, eventdata, handles) -% hObject handle to popupmenu_row_num (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 popupmenu_column_num. -function popupmenu_column_num_Callback(hObject, eventdata, handles) - -chanArraystr = get(handles.edit_channel_custom, 'String'); -chanArray = str2num(chanArraystr); - -if isempty(chanArray) - chanArray = [1:handles.ERP.nchan]; -end -ColumnNum = get(handles.popupmenu_column_num, 'Value'); -RowNum = ceil((numel(chanArray))/ColumnNum); -if RowNum<=0 - RowNum=1; -end -set(handles.popupmenu_row_num, 'Value', RowNum); - - -% --- Executes during object creation, after setting all properties. -function popupmenu_column_num_CreateFcn(hObject, eventdata, handles) -% hObject handle to popupmenu_column_num (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 pushbutton_cancel_Callback(hObject, eventdata, handles) - -handles.output = []; -disp('User selected Cancel'); -guidata(hObject, handles); -uiresume(handles.gui_chassis); - -% %-------------------------------------------------------------------------- -% function pushbutton_help_Callback(hObject, eventdata, handles) -% % doc pop_export2text -% web 'https://github.com/lucklab/erplab/wiki/Exporting,-Editing,-and-Importing-EVENTLISTS' -browser -%-------------------------------------------------------------------------- -function pushbutton_apply_Callback(hObject, eventdata, handles) - -BinArray = str2num(handles.edit_bin_custom.String); -ChanArray = str2num(handles.edit_channel_custom.String); -ERP = handles.ERP; -[chk, msgboxText] = chckbinandchan(ERP, BinArray, ChanArray); -if chk(1) - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(sprintf(msgboxText), title); - return; -end -if chk(2) - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(sprintf(msgboxText), title); - return; -end - - - -freqRange = str2num(get(handles.edit_freq_range, 'String')); % XL -if isempty(freqRange) - msgboxText = 'Invalid input for frequency range of interest on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end -if length(freqRange)~=2 - msgboxText = 'Please, enter two values on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end - - -if freqRange(1)>= freqRange(2) - msgboxText = 'The first value must be smaller than the second one on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end -if freqRange(1)<0 - msgboxText = 'The first value must be larger than 0Hz on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end - - -if freqRange(2)> ERP.srate/2 - msgboxText = ['Second value must be smaller than',32,num2str(observe_ERPDAT.ERP.srate/2),'Hz',32,'on "Freq. range [min max] in Hz"']; - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(msgboxText, title); - return -end - - - - -if handles.checkbox_freq_ticks_auto.Value - Auto_freq = []; -else - Auto_freq_String = handles.edit_freq_tick_auto.String; - Auto_freq = str2num(Auto_freq_String); -end - -RowNum = handles.popupmenu_row_num.Value; -ColumnNum = handles.popupmenu_column_num.Value; - -if handles.radiobutton_all_bin_chan.Value - bin_chan_label = 1; -elseif handles.radiobutton_selected_bin_chan.Value - bin_chan_label = 2; -elseif handles.radiobutton_Custom_bin_chan.Value - bin_chan_label = 3; -end - - -Save_label = handles.pushbutton_save.Value; - -answer = {bin_chan_label,BinArray, ChanArray,freqRange,Auto_freq,RowNum,ColumnNum,Save_label}; -handles.output = answer; - -% Update handles structure -guidata(hObject, handles); -uiresume(handles.gui_chassis); - - -% --- Executes on button press in pushbutton_save. -function pushbutton_save_Callback(hObject, eventdata, handles) -BinArray = str2num(handles.edit_bin_custom.String); -ChanArray = str2num(handles.edit_channel_custom.String); -ERP = handles.ERP; -[chk, msgboxText] = chckbinandchan(ERP, BinArray, ChanArray); -if chk(1) - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(sprintf(msgboxText), title); - return; -end -if chk(2) - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(sprintf(msgboxText), title); - return; -end - -freqRange = str2num(get(handles.edit_freq_range, 'String')); % XL -if isempty(freqRange) - msgboxText = 'Invalid input for frequency range of interest on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end -if length(freqRange)~=2 - msgboxText = 'Please, enter two values on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end - - -if freqRange(1)>= freqRange(2) - msgboxText = 'The first value must be smaller than the second one on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end -if freqRange(1)<0 - msgboxText = 'The first value must be larger than 0Hz on "Freq. range [min max] in Hz"'; - title = 'EStudio: f_spectral_analysis_advance().'; - errorfound(msgboxText, title); - return -end - - -if freqRange(2)> ERP.srate/2 - msgboxText = ['Second value must be smaller than',32,num2str(observe_ERPDAT.ERP.srate/2),'Hz',32,'on "Freq. range [min max] in Hz"']; - title = 'ERPLAB Studio: f_ERP_spectral_advance_GUI() error'; - errorfound(msgboxText, title); - return -end - - - - -if handles.checkbox_freq_ticks_auto.Value - Auto_freq = []; -else - Auto_freq_String = handles.edit_freq_tick_auto.String; - Auto_freq = str2num(Auto_freq_String); -end - -RowNum = handles.popupmenu_row_num.Value; -ColumnNum = handles.popupmenu_column_num.Value; - -if handles.radiobutton_all_bin_chan.Value - bin_chan_label = 1; -elseif handles.radiobutton_selected_bin_chan.Value - bin_chan_label = 2; -elseif handles.radiobutton_Custom_bin_chan.Value - bin_chan_label = 3; -end - - -Save_label = handles.pushbutton_save.Value; - -answer = {bin_chan_label,BinArray, ChanArray,freqRange,Auto_freq,RowNum,ColumnNum,Save_label}; -handles.output = answer; - -% Update handles structure -guidata(hObject, handles); -uiresume(handles.gui_chassis); - - - -%-------------------------------------------------------------------------- -function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) -if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') - handles.output = []; - %Update handles structure - guidata(hObject, handles); - uiresume(handles.gui_chassis); -else - % The GUI is no longer waiting, just close it - delete(handles.gui_chassis); -end - - - - - -function [chk, msgboxText] = chckbinandchan(ERP, binArray, chanArray) -chk=[0 0]; -msgboxText = ''; -if isempty(binArray) - msgboxText = 'You have not specified any bin'; - chk(1) = 1; - % return -end -if any(binArray<=0) - msgboxText = sprintf('Invalid bin index.\nPlease specify only positive integer values.'); - chk(1) = 1; - return -end -if any(binArray>ERP.nbin) - msgboxText = sprintf('Bin index out of range!\nYou only have %g bins in this ERPset',ERP.nbin); - chk(1) = 1; - return -end -if length(binArray)~=length(unique_bc2(binArray)) - msgboxText = 'You have specified repeated bins for plotting.'; - chk(1) = 1; - return -end -if isempty(chanArray) - msgboxText = 'You have not specified any channel'; - chk(2) = 1; - return -end -if any(chanArray<=0) - msgboxText = sprintf('Invalid channel index.\nPlease specify only positive integer values.'); - chk(2) = 1; - return -end -if any(chanArray>ERP.nchan) - msgboxText = sprintf('Channel index out of range!\nYou only have %g channels in this ERPset', ERP.nchan); - chk(2) = 1; - return -end -if length(chanArray)~=length(unique_bc2(chanArray)) - msgboxText = 'You have specified repeated channels for plotting.'; - chk(2) = 1; - return -end diff --git a/studio_functions/Functions/EStudio/ERP Tab/geterplabstudiodef.m b/studio_functions/Functions/EStudio/ERP Tab/geterplabstudiodef.m index 670920f5..f12a1a53 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/geterplabstudiodef.m +++ b/studio_functions/Functions/EStudio/ERP Tab/geterplabstudiodef.m @@ -12,10 +12,10 @@ function [version reldate,ColorB_def,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef -erplab_studio_default_values; -version = erplabstudiover; -reldate = erplabstudiorel; +erplab_default_values; +version = erplabver; +reldate = erplabrel; ColorB_def =ColorB; ColorF_def=ColorF; errorColorF_def = errorColorF; -ColorBviewer_def = ColorBviewer; \ No newline at end of file +ColorBviewer_def = [0.8 0.8 0.9]; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/mini_viewer.m b/studio_functions/Functions/EStudio/ERP Tab/mini_viewer.m deleted file mode 100755 index f94ce9db..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/mini_viewer.m +++ /dev/null @@ -1,434 +0,0 @@ -% -% We need a very fancy data structure system. We've got an array of our -% 'pages'. Each page is a structure. Each page has a property 'data'. In order to graph effectively it's 2 -% dimensional. It's a series of X by Y matrices compounded horizontally. -% Each column represents one line of data. Each 'chunk' (Length Y) -% represents one of three things: A bin, a channel, or an ERPset. If we -% were to look at one bin as a chunk, each column could either represent a -% channel or an ERPset. -% -% We can change to this system fairly easily. Replace 'nchan' with -% 'nlines', 'nbin' with 'nplots', etc. Then create a func to turn ERP -% structure into local data structure based on the 3 way intersection of -% channels, bins, and ERPsets. -% - -% [ 1 2 3 1 2 3 -% 1 2 3 1 2 3 -% 1 2 3 1 2 3 ] - -function varargout = mini_viewer(varargin) - parent = uiextras.Empty(); - boxpan = uiextras.Empty(); - inpd = []; - data = []; - olddata = []; - child_vs = {}; - floating = 0<1; - havedat = 0<1; - - % Lines, Plots, Pages - % 1 = Chans, 2 = Bins, 3 = ERPsets - ord = [2 1 3]; - - if nargin == 0 - havedat = 0>1; - elseif nargin == 1 - fig = figure( 'Name', 'ERP Explorer', ... - 'NumberTitle', 'off', ... - 'MenuBar', 'none', ... - 'Toolbar', 'none', ... - 'HandleVisibility', 'off'); - parent = fig; - data = cell2mat(varargin(1)); - else - data = cell2mat(varargin(1)); - parent = [varargin{2}]; - floating = 1<0; - end - erp_tabs = uiextras.TabPanel('Parent', parent, 'Padding', 5); - - olddata = data; - - data = erp2loc(data); - - data = data{:}; - - drawUI() - ret_v = struct('tabs', erp_tabs, 'data', olddata); - varargout{1} = ret_v; - - function drawUI() - - havedat = numel(data)>0; - - delete(erp_tabs.Children); - if havedat - tabnames = cell(size(data)); - tabs = zeros(size(data)); - [~,a] = size(data); - for i = 1:a - tabs(i) = uix.HBoxFlex( 'Parent', erp_tabs, 'Spacing', 10 ); - dat = data(i); - tabnames(i) = {dat.name}; - end - - erp_tabs.TabNames = tabnames; - erp_tabs.SelectedChild = 1; - erp_tabs.TabSize = 120; - for tabn = 1:numel(tabs) - TAB = tabs(tabn); - cdat = data(tabn); - hbox = uiextras.HBox('Parent', TAB); - boxpan = uiextras.BoxPanel('Parent', hbox); - [d1,d2,d3] = size(cdat.data); - plot_erp_data = cdat.data; -% for i = 1:cdat.nlin -% ndata = 1:cdat.nplot; -% for i_bin = 1:numel(ndata) -% el_shown = 1:cdat.nlin; -% -% plot_erp_data(:,(i_bin+((i-1)*numel(ndata)))) = cdat.data(el_shown(i),1:d2,d3)'; % + (i+1)*S.display_offset; -% end -% end - offset = (repmat(kron(1:cdat.nplot,ones(1,cdat.nlin)),[500 1])-1)*30; - plot_erp_data = plot_erp_data + offset; - drawERP(plot_erp_data,boxpan,cdat) - vpanels = uiextras.VBox('Parent', hbox); - dat_sel = uiextras.BoxPanel('Parent', vpanels,'Title','Data Selector'); - pl_ops = uiextras.BoxPanel('Parent', vpanels,'Title','Plotting Options'); - - % Data Selector - ds_vb = uiextras.VBox('Parent',dat_sel); - ds_grid = uiextras.Grid('Parent',ds_vb); - - uicontrol('Style','text','String','Chans','Parent',ds_grid); - cs = {cdat.channames}; - chan_sel = uicontrol('Style','listbox','Parent',ds_grid,'String',[{'ALL'}, cs{:}],'callback',@temp,'Max',2,'Min',0); - - uicontrol('Style','text','String','Bins','Parent',ds_grid); - bs = cdat.binnames; - bin_sel = uicontrol('Style','listbox','Parent',ds_grid,'String',[{'ALL'}, bs{:}],'callback',@temp,'Max',2,'Min',0); - - set( ds_grid, 'ColumnSizes', [-1 -1], 'RowSizes', [25, -1] ); - - b_c = uicontrol('Style','popupmenu','Parent',ds_vb,'String',{'Channels by Bins','Bins by Channels'},'callback',@temp); - - set( ds_vb, 'Sizes', [-1, 20] ); - - % Plotting Options - pl_grid = uiextras.Grid('Parent',pl_ops); - - tr_pn = uipanel('Parent',pl_grid); - uicontrol('Parent', tr_pn, 'Style','text','String','Range','Position',[0 0 65 25]); - uicontrol('Parent',pl_grid,'Style','text','String','Min'); - uicontrol('Parent',pl_grid,'Style','edit','String','0'); - uicontrol('Parent',pl_grid,'Style','text','String','Max'); - uicontrol('Parent',pl_grid,'Style','edit','String','1000'); - uiextras.Empty('Parent', pl_grid); - uiextras.Empty('Parent', pl_grid); - - tt_pn = uipanel('Parent',pl_grid); - uicontrol('Parent', tt_pn, 'Style','text','String','X Scale','Position',[0 0 65 25]); - uicontrol('Parent',pl_grid,'Style','text','String','Min'); - uicontrol('Parent',pl_grid,'Style','edit','String','0'); - uicontrol('Parent',pl_grid,'Style','text','String','Max'); - uicontrol('Parent',pl_grid,'Style','edit','String','1000'); - uicontrol('Parent',pl_grid,'Style','text','String','Step'); - uicontrol('Parent',pl_grid,'Style','edit','String','200'); - - mc_pn = uipanel('Parent',pl_grid); - uicontrol('Parent', mc_pn, 'Style','text','String','Misc.','Position',[0 0 65 25]); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - - if floating - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - else - tn = tabn; - uicontrol('Parent',pl_grid,'Style','pushbutton','String','Detach','callback',{@detach,tabn}); - uicontrol('Parent',pl_grid,'Style','pushbutton','String','Retach','callback',@retach); - end - - set( pl_grid, 'ColumnSizes', [-1 -1 -1], 'RowSizes', [35 20 25 20 25 20 25] ); - - set( vpanels, 'Sizes', [-1 190] ); - set( hbox, 'Sizes', [-1 200] ); - end - else - empty_tab = uix.HBoxFlex( 'Parent', erp_tabs, 'Spacing', 10 ); - erp_tabs.TabNames = {'Empty'}; - erp_tabs.TabSize = 120; - erp_tabs.SelectedChild = 1; - - hbox = uiextras.HBox('Parent', empty_tab); - boxpan = uiextras.BoxPanel('Parent', hbox); - - vpanels = uiextras.VBox('Parent', hbox); - dat_sel = uiextras.BoxPanel('Parent', vpanels,'Title','Data Selector'); - pl_ops = uiextras.BoxPanel('Parent', vpanels,'Title','Plotting Options'); - - % Data Selector - ds_vb = uiextras.VBox('Parent',dat_sel); - ds_grid = uiextras.Grid('Parent',ds_vb); - - uicontrol('Style','text','String','Chans','Parent',ds_grid); - chan_sel = uicontrol('Style','listbox','Parent',ds_grid,'String',{'ALL'},'callback',@temp,'Max',2,'Min',0); - - uicontrol('Style','text','String','Bins','Parent',ds_grid); - bin_sel = uicontrol('Style','listbox','Parent',ds_grid,'String',{'ALL'},'callback',@temp,'Max',2,'Min',0); - - set( ds_grid, 'ColumnSizes', [-1 -1], 'RowSizes', [25, -1] ); - - b_c = uicontrol('Style','popupmenu','Parent',ds_vb,'String',{'Channels by Bins','Bins by Channels'},'callback',@temp); - - set( ds_vb, 'Sizes', [-1, 20] ); - - % Plotting Options - pl_grid = uiextras.Grid('Parent',pl_ops); - - tr_pn = uipanel('Parent',pl_grid); - uicontrol('Parent', tr_pn, 'Style','text','String','Range','Position',[0 0 65 25]); - uicontrol('Parent',pl_grid,'Style','text','String','Min'); - uicontrol('Parent',pl_grid,'Style','edit','String','0'); - uicontrol('Parent',pl_grid,'Style','text','String','Max'); - uicontrol('Parent',pl_grid,'Style','edit','String','1000'); - uiextras.Empty('Parent', pl_grid); - uiextras.Empty('Parent', pl_grid); - - tt_pn = uipanel('Parent',pl_grid); - uicontrol('Parent', tt_pn, 'Style','text','String','X Scale','Position',[0 0 65 25]); - uicontrol('Parent',pl_grid,'Style','text','String','Min'); - uicontrol('Parent',pl_grid,'Style','edit','String','0'); - uicontrol('Parent',pl_grid,'Style','text','String','Max'); - uicontrol('Parent',pl_grid,'Style','edit','String','1000'); - uicontrol('Parent',pl_grid,'Style','text','String','Step'); - uicontrol('Parent',pl_grid,'Style','edit','String','200'); - - mc_pn = uipanel('Parent',pl_grid); - uicontrol('Parent', mc_pn, 'Style','text','String','Misc.','Position',[0 0 65 25]); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','text','String','a'); - uicontrol('Parent',pl_grid,'Style','pushbutton','String','Detach','callback',@temp); - uicontrol('Parent',pl_grid,'Style','pushbutton','String','Retach','callback',@retach); - - set( pl_grid, 'ColumnSizes', [-1 -1 -1], 'RowSizes', [35 20 25 20 25 20 25] ); - - set( vpanels, 'Sizes', [-1 190] ); - set( hbox, 'Sizes', [-1 200] ); - end - end - - function drawERP(dat,p,terp) - ax = axes('Parent',p,'Color','none','Box','on'); - %set( ax, 'XLim', [min max] ) - ts = terp.times; - [a,c,b] = size(dat); - new_erp_data = zeros(a,b*c); - for j = 1:b - new_erp_data(:,((c*(j-1))+1):(c*j)) = dat(:,:,j); - end - this_plot = plot(ax,ts,new_erp_data); - %boxpan - end - - function detach(~,~,tabn) - %tabn = erp_tabs.SelectedChild; - ddat = data(tabn); - data(tabn) = []; - drawUI(); - child_vs(end+1) = {mini_viewer(ddat)}; - end - - function retach(~,~) - for j = child_vs - j = [j{1}]; - data(end+1) = j.data; - delete(j.tabs.Parent); - end - drawUI(); - child_vs = {}; - end - - function loc = erp2loc(erps) - news = nan(size(erps)); - nerps = numel(erps); - - cs = [erps(1).chanlocs.urchan]; - bs = 1:numel(erps(1).bindescr); - es = {}; - [d1,d2,d3] = size(erps(1).bindata); - for i = erps - [td1,td2,td3] = size(i.bindata); - if td1>d1 - d1=td1; - end - if td2>d2 - d2=td2; - end - if td3>d3 - d3=td3; - end - end - ltdata = nan(d1,d2,d3,0); - for i = erps - for j = [i.chanlocs.urchan] - if ~ismember(j,cs) - cs(end+1) = j; - end - end - for j = 1:numel(i.bindescr) - if ~ismember(j,bs) - bs(end+1) = j; - end - end - es(end+1) = {i.erpname}; - t = i.bindata; - try - if t(d1,d2,d3) == 0 - beep; - end - catch - t(d1,d2,d3) = 0; - end - ltdata(:,:,:,end+1) = t; - end - - nbs = {}; - for i = 1:numel(bs) - tes = {}; - ttes = {}; - for j = 1:numel(erps) - if erps(j).nbin >= i - ttes(end+1) = {erps(j)}; - tes(end+1) = es(j); - end - end - - tcs = []; - for j = ttes - j1 = cell2mat(j); - for k = 1:j1.nchan - if ~ismember(k,tcs) - tcs(end+1) = k; - end - end - end - ttes1 = cell2mat(ttes(1)); - nbs(end+1) = {struct('e',{tes},'b',bs(i),'c',tcs,'n',cell2mat(ttes1.bindescr(i)))}; - end - - ncs = {}; - for i = 1:numel(cs) - tes = {}; - ttes = {}; - for j = 1:numel(erps) - if erps(j).nchan >= i - ttes(end+1) = {erps(j)}; - tes(end+1) = es(j); - end - end - - tbs = []; - for j = ttes - j1 = cell2mat(j); - for k = 1:j1.nbin - if ~ismember(k,tbs) - tbs(end+1) = k; - end - end - end - ttes1 = cell2mat(ttes(1)); - tlb = {ttes1.chanlocs.labels}; - ncs(end+1) = {struct('e',{tes},'b',tbs,'c',cs(i),'n',cell2mat(tlb(i)))}; - end - - nes = {}; - for i = 1:numel(es) - nes(end+1) = {struct('e',es(i),'b',1:erps(i).nbin,'c',1:erps(i).nchan,'n',es(i))}; - end - - % Take [chans bins erpsets] and apply a filter of [2 1 3] or - % something to create desired permutation such as [bins chans - % erpsets]. Now we have [lines plots pages]! - nar = [numel(cs) numel(bs) numel(es)]; - nop = nar(ord); - - ar = {cs bs es}; - op = nar(ord); - - dar = {ncs nbs nes}; - dop = dar(ord); - - s = cell(1,nop(3)); - - for i = 1:nop(3) - % Iterate through all pages here - - % Our data will be - % - % [ a1 a2 a3 b1 b2 b3 - % a1 a2 a3 b1 b2 b3 - % a1 a2 a3 b1 b2 b3 ] - % - - temp1 = dop(3); - temp = temp1{:}{i}; - - % WARN IF BIN OR CHAN DOES NOT EXIST FOR ERPSET - todata = ltdata(temp.c,:,temp.b,find(strcmp(es,temp.e))); - t_s = [0 0 0]; - t_s(ord) = [nop(1) nop(2) 1]; - t_ds_o = ones(1,4); - t_ds = zeros(1,4); - t_ds_o(1:numel(size(todata))) = size(todata); - t_ds(1:numel(size(todata))) = size(todata); - if t_s(1) ~= t_ds(1) - ss = t_ds_o; - ss(1) = t_s(1); - todata(ss(1),ss(2),ss(3),ss(4)) = 0; - end - if t_s(2) ~= t_ds(3) - ss = t_ds_o; - ss(3) = t_s(2); - todata(ss(1),ss(2),ss(3),ss(4)) = 0; - end - if t_s(3) ~= t_ds(4) - ss = t_ds_o; - ss(4) = t_s(3); - todata(ss(1),ss(2),ss(3),ss(4)) = 0; - end - - %if size(todata) ~= [ta tb tc ] - ntdata = reshape(todata,numel(erps(1).times),nop(1)*nop(2)); - - - referp = dop(3); - referp = [referp{:}]; - referp = referp{i}; - - nerp = erps(1); - for j = erps - if j.nbin > nerp.nbin - nerp = j; - end - end - - cl = {nerp.chanlocs.labels}; - - s(i) = {struct('nlin',nop(1),'nplot',nop(2),'data',ntdata,'name',temp.n,'channames',{cl(referp.c)},'binnames',{nerp.bindescr(referp.b)},'erpnames',{referp.e},'times',nerp.times)}; - clear cl nerp j temp1 t_s referp - end - - loc = s; - end - - function temp( src, ~ ) - beep; - end -end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/ms_to_sample.m b/studio_functions/Functions/EStudio/ERP Tab/ms_to_sample.m deleted file mode 100755 index 3657779d..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/ms_to_sample.m +++ /dev/null @@ -1,67 +0,0 @@ -% FORMAT: -% -% sampval = ms_to_sample(timems,fs,EpochStart, rounding) -% -% INPUTS: -% -% timems - time value in milliseconds -% fs - sampling rate -% -% Optional inputs: -% -% rounding - 1 means round the result {default}, 0 means do not round -% EpochStart - the left interval of epoch in ERP data (in milliseconds). Default 0 -% -% OUTPUT: -% -% sampval - time in samples -% -% EXAMPLES: -% -% 1) For a time serie recorded from 0 to 5 secs, at fs=500 sps, get the sample index at the time 674 ms. -% -%>> sampval = ms_to_sample(674, 500) -% -%sampval = -% -% 338 -% -% 2) For a time serie recorded from -1 to 5 secs, at fs=500 sps, get the sample index at the time 674 ms. -%>> sampval674 = ms_to_sample(674, 500, -1000) -% -%sampval_all = -% -% 838 -% -% -% Author: Guanghui ZHANG -% Center for Mind and Brain -% University of California, Davis, -% Davis, CA -% 2022 - -function sampval = ms_to_sample(timems,fs,offset) -if nargin<1 - help ms_to_sample - return -end -% if nargin<4 -% rounding = 3; -% end -if nargin<3 - offset = 0; -end -if nargin<2 - error('Two inputs are requiered at least.') -% return; -end - -if timems < offset - beep; - error('Input time shoule be larger than offset!!!') -% return; -end - -% offset = round(offset/50)*50; - -sampval = round((timems-offset)*fs/1000)+1; \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_ERP_spectralanalysis.m b/studio_functions/Functions/EStudio/ERP Tab/pop_ERP_spectralanalysis.m new file mode 100644 index 00000000..33520a7d --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_ERP_spectralanalysis.m @@ -0,0 +1,420 @@ +% *** This function is part of ERPLAB Toolbox *** +% Author: Guanghui +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + +%b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b +% +% ERPLAB Studio Toolbox +% Copyright © 2007 The Regents of the University of California +% Created by Javier Lopez-Calderon and Steven Luck +% Center for Mind and Brain, University of California, Davis, +% javlopez@ucdavis.edu, sjluck@ucdavis.edu +% +% This program 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. +% +% This program 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 this program. If not, see . + +function [ERP, erpcom] = pop_ERP_spectralanalysis(ERP, varargin) +erpcom = ''; +if nargin < 1 + help pop_ERP_spectralanalysis + return +end +if isfield(ERP(1), 'datatype') + datatype = ERP.datatype; +else + datatype = 'ERP'; +end +if nargin==1 + title_msg = 'ERPLAB: pop_ERP_spectralanalysis() error:'; + if isempty(ERP) + ERP = preloadERP; + if isempty(ERP) + msgboxText = 'No ERPset was found!'; + + errorfound(msgboxText, title_msg); + return + end + end + if isempty(ERP.bindata) + msgboxText = 'cannot work with an empty ERP erpset'; + errorfound(msgboxText, title_msg); + return + end + if ~strcmpi(datatype, 'ERP') + msgboxText = 'This ERPset is already converted into frequency domain!'; + errorfound(msgboxText, title_msg); + return + end + + % + % FFT points will be as much as needed + % to get 1 point each 0.25 Hz, at least. + % Users can change this value using scripting. Jav + % + def = estudioworkingmemory('pop_ERP_spectralanalysis'); + if isempty(def) + def = {1,1,[0,floor(ERP.srate/2)],ERP.srate}; + + end + + app = feval('ERP_spectral_analysis_GUI.mlapp',def{1},def{2},def{3},def{4},ERP); + waitfor(app,'Finishbutton',1); + try + def = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + if isempty(def) + return; + end + Amptypev = def{1}; + if Amptypev==2 + Amptype = 'phase'; + elseif Amptypev==3 + Amptype = 'power'; + elseif Amptypev==4 + Amptype = 'db'; + else + Amptype = 'amp'; + end + + if def{2}==1 + TaperWindow = 'on'; + else + TaperWindow = 'off'; + end + estudioworkingmemory('pop_ERP_spectralanalysis',def); + freqrange = def{3}; + if isempty(freqrange) || numel(freqrange)~=2 || any(freqrange(:)>floor(ERP.srate/2)) || any(freqrange(:)<0) + freqrange = [0 floor(ERP.srate/2)]; + end + + ChanArray = def{6}; + if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; + end + BinArray = def{5}; + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = 1:ERP.nbin; + end + + erpcom = pop_ERP_spectralanalysis(ERP, 'Amptype',Amptype,'TaperWindow',TaperWindow,... + 'freqrange',freqrange,'BinArray',BinArray,'ChanArray',ChanArray,'Plotwave','on',... + 'Saveas', 'off','History','gui'); + return +end + + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ERP'); +% option(s) +p.addParamValue('TaperWindow', 'on', @ischar); % 'ERP': compute the average of epochs per bin; +p.addParamValue('Amptype', 'amp', @ischar); +p.addParamValue('freqrange', [], @isnumeric); +p.addParamValue('BinArray', [], @isnumeric); +p.addParamValue('ChanArray', [], @isnumeric); +p.addParamValue('Plotwave', 'on', @ischar); +p.addParamValue('Saveas', 'off', @ischar); % 'on', 'off' +p.addParamValue('Warning', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ERP, varargin{:}); + +if iseegstruct(ERP) + if length(ERP)>1 + msgboxText = 'ERPLAB says: Unfortunately, this function does not work with multiple ERPsets'; + error(msgboxText); + end +end + + +% NFFT, iswindowed +if strcmpi(p.Results.TaperWindow,'off') + iswindowed = 0; +elseif strcmpi(p.Results.TaperWindow,'on') + iswindowed = 1; +else + if ~isempty(p.Results.TaperWindow) && ischar(p.Results.TaperWindow) + iswindowed = p.Results.TaperWindow; + else + error('Unknow value for "TaperWindow"') + end +end + +if ismember_bc2({p.Results.Saveas}, {'on','yes'}) + issaveas = 1; +elseif ismember_bc2({p.Results.Saveas}, {'csv'}) + issaveas = 2; +else + issaveas = 0; +end + +ERP = f_getFFTfromERP(ERP,iswindowed); + +%%--------------------------------display type----------------------------- +Amptype = p.Results.Amptype; +if strcmpi(Amptype,'phase') + ERP.bindata = angle(ERP.bindata); + figure_name = ['Spectral analysis - Phase for ',32,ERP.erpname]; +elseif strcmpi(Amptype,'power') + ERP.bindata = abs(ERP.bindata).^2; + figure_name = ['Spectral analysis - Power for ',32,ERP.erpname]; +elseif strcmpi(Amptype,'db') + ERP.bindata = 20*log10(abs(ERP.bindata)); + figure_name = ['Spectral analysis - dB for ',32,ERP.erpname]; +else + ERP.bindata = abs(ERP.bindata); + figure_name = ['Spectral analysis - Amplitude for ',32,ERP.erpname]; +end + + +freqrange = p.Results.freqrange; + +if isempty(freqrange) || numel(freqrange)~=2 || any(freqrange(:)>floor(ERP.srate/2)) || any(freqrange(:)<0) + freqrange = [0 floor(ERP.srate/2)]; +end + +%% +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; +end + +%% +BinArray = p.Results.BinArray; +if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = 1:ERP.nbin; +end + + +[xxx, latsamp, latdiffms] = closest(ERP.times, freqrange); +tmin = latsamp(1); +tmax = latsamp(2); +ERP.bindata = ERP.bindata(ChanArray,tmin:tmax,BinArray); +ERP.nbin = numel(BinArray); +ERP.bindescr = ERP.bindescr(BinArray); +ERP.times = ERP.times(tmin:tmax); +ERP.nchan =numel(ChanArray); +ERP.chanlocs = ERP.chanlocs(ChanArray); + +if strcmpi(p.Results.Plotwave,'on') + fig = figure('Name',figure_name); + % set(fig,'outerposition',get(0,'screensize')); + + FonsizeDefault = f_get_default_fontsize(); + FreqTick = default_time_ticks(ERP, freqrange); + FreqTick = str2num(FreqTick{1}); + pbox = f_getrow_columnautowaveplot(ChanArray); + try + RowNum = pbox(1)+1; + ColumnNum = pbox(2); + catch + RowNum = numel(ChanArray)+1; + ColumnNum = 1; + end + count = 0; + for Numofcolumn = 1:ColumnNum + for Numofrow = 1:RowNum + count = count+1; + if ColumnNum*RowNum<5 + pause(1); + end + if count>ERP.nchan + break; + end + p_ax = subplot(RowNum,ColumnNum,count); + set(gca,'fontsize',FonsizeDefault); + hold on; + temp = squeeze(ERP.bindata); + for Numofplot = 1:ERP.nbin + h_p(Numofplot) = plot(p_ax,ERP.times,squeeze(ERP.bindata(count,:,Numofplot)),'LineWidth',1); + end + axis(p_ax,[floor(ERP.times(1)),ceil(ERP.times(end)), 1.1*min(temp(:)) 1.1*max(temp(:))]); + xticks(p_ax,FreqTick); + if count == 1 + title(p_ax,char(strrep(ERP.chanlocs(count).labels,'_','\_')),'FontSize',FonsizeDefault,'FontWeight','normal','Color','k','Interpreter','none'); %#ok<*NODEF> + else + title(p_ax,ERP.chanlocs(count).labels,'FontSize',FonsizeDefault,'FontWeight','normal','Color','k','Interpreter','none'); + end + xlabel(p_ax,'Frequency/Hz','FontSize',FonsizeDefault,'FontWeight','normal','Color','k'); + + if strcmpi(Amptype,'phase') + ylabel(p_ax,'Angle/degree','FontSize',FonsizeDefault,'FontWeight','normal','Color','k'); + elseif strcmpi(Amptype,'power') + ylabel(p_ax,'Power/\muV^2','FontSize',FonsizeDefault,'FontWeight','normal','Color','k'); + elseif strcmpi(Amptype,'db') + ylabel(p_ax,'Decibels/dB','FontSize',FonsizeDefault,'FontWeight','normal','Color','k'); + else + ylabel(p_ax,'Amplitude/\muV','FontSize',FonsizeDefault,'FontWeight','normal','Color','k'); + end + + for NUmoflabel = 1:length(ERP.times) + X_label{NUmoflabel} = []; + end + set(gca,'TickDir','out'); + set(gca,'LineWidth',1); + set(gca,'Color','w',... + 'XColor','k',... + 'YColor','k',... + 'ZColor','k'); + end + end + sh = subplot(RowNum+1, ColumnNum,[RowNum*ColumnNum+1:(RowNum+1)*ColumnNum],'align'); + axis(sh,'off'); + pos = get(sh,'position'); + h_legend = legend(sh,h_p,ERP.bindescr); + legend(sh,'boxoff'); + set(h_legend, 'position', pos); + qlegcolumns = ceil(sqrt(length(ERP.bindescr))); + set(h_legend,'NumColumns',qlegcolumns); + set(h_legend,'FontSize',FonsizeDefault); + set(fig,'Color','w'); +end + + + +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + +% +% subroutine +% + +% +% History +% +skipfields = {'ERP', 'History'}; +fn = fieldnames(p.Results); +erpcom = sprintf('%s = pop_ERP_spectralanalysis( %s ', inputname(1), inputname(1)); + +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ERPset +% +if issaveas==1 + [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'implicit'); + if issave>0 + if issave==2 + erpcom = sprintf('%s\n%s', erpcom, erpcom_save); + msgwrng = '*** Your ERPset was saved on your hard drive.***'; + else + msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; + end + else + msgwrng = 'ERPLAB Warning: Your changes were not saved'; + end + try cprintf([1 0.52 0.2], '%s\n\n', msgwrng); catch,fprintf('%s\n\n', msgwrng);end ; + +elseif issaveas==2 + def = estudioworkingmemory('f_export2csvGUI'); + if isempty(def) + def = {1, 1, 1, 3, ''}; + end + ERPtooltype = erpgettoolversion('tooltype'); + if strcmpi(ERPtooltype,'estudio') + pathName = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName) + pathName =[pwd,filesep]; + end + else + pathName = [pwd,filesep]; + end + def{5} = fullfile(pathName,ERP.filename); + answer_export = f_export2csvGUI(ERP,def); + estudioworkingmemory('f_export2csvGUI',answer_export); + if isempty(answer_export) + return; + end + BinArray = [1:ERP.nbin]; + decimal_num = answer_export{4}; + istime =answer_export{1} ; + electrodes=answer_export{2} ; + transpose=answer_export{3}; + filenamei = answer_export{5}; + [pathx, filename, ext] = fileparts(filenamei); + ext = '.csv'; + if isempty(pathx) + pathx =cd; + end + filename = [filename ext]; + mkdir([pathx,filesep]); + try + export2csv_spectranl_analysis(ERP,fullfile(pathx,filename), BinArray,istime, electrodes,transpose, decimal_num); + catch + disp('Fail to save selected ERPset as ".csv"!!!'); + end + +end +% get history from script. ERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + ERP = erphistory(ERP, [], erpcom, 1); + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end + +% +% Completion statement +% +msg2end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_duplicaterp.m b/studio_functions/Functions/EStudio/ERP Tab/pop_duplicaterp.m new file mode 100644 index 00000000..11c7f150 --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_duplicaterp.m @@ -0,0 +1,225 @@ +% PURPOSE: pop_duplicaterp.m +% duplicate ERPset +% + +% FORMAT: +% [ERP, erpcom] = pop_duplicaterp( ERP, 'ChanArray',ChanArray, 'BinArray',BinArray,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ERP -ERP structure +%ChanArray -index(es) of channels +%BinArray -index(es) of bins + + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2024 + + + + +function [ERP, erpcom] = pop_duplicaterp(ERP, varargin) +erpcom = ''; + +if nargin < 1 + help pop_duplicaterp + return +end +if isempty(ERP) + msgboxText = 'Cannot duplicate an empty erpset'; + title = 'ERPLAB: pop_duplicaterp() error'; + errorfound(msgboxText, title); + return +end +if isempty(ERP(1).bindata) + msgboxText = 'Cannot duplicate an empty erpset'; + title = 'ERPLAB: pop_duplicaterp() error'; + errorfound(msgboxText, title); + return +end + +datatype = checkdatatype(ERP(1)); +if ~strcmpi(datatype, 'ERP') + msgboxText = 'Cannot duplicate Power Spectrum waveforms!'; + title = 'ERPLAB: pop_duplicaterp() error'; + errorfound(msgboxText, title); + return +end + +if length(ERP)>1 + msgboxText = 'Cannot duplicate multiple ERPsets!'; + title = 'ERPLAB: pop_duplicaterp() error'; + errorfound(msgboxText, title); + return +end +if nargin==1 + + def = erpworkingmemory('pop_duplicaterp'); + if isempty(def) + def = {[],[]}; + end + BinArray = def{1}; + ChanArray =def{2}; + + def = f_ERP_duplicate(ERP,BinArray,ChanArray); + if isempty(def) + return; + end + ChanArray = def{2}; + BinArray = def{1}; + erpworkingmemory('pop_duplicaterp',def); + % + % Somersault + % + [ERP, erpcom] = pop_duplicaterp( ERP, 'ChanArray',ChanArray, 'BinArray',BinArray,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ERP'); +% option(s) +p.addParamValue('ChanArray', [],@isnumeric); +p.addParamValue('BinArray', [], @isnumeric); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ERP, varargin{:}); + +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<=0) + ChanArray = [1:ERP.nchan]; +end + +BinArray= p.Results.BinArray; +BinArray = unique(BinArray); +if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<=0) + BinArray = [1:ERP.nbin]; +end + + +ERP.bindata = ERP.bindata(ChanArray,:,BinArray); +if ~isempty(ERP.binerror) + ERP.binerror = ERP.binerror(ChanArray,:,BinArray); +end +try + ERP.ntrials.accepted = ERP.ntrials.accepted(BinArray); + ERP.ntrials.rejected = ERP.ntrials.rejected(BinArray); + ERP.ntrials.invalid = ERP.ntrials.invalid(BinArray); + ERP.ntrials.arflags = ERP.ntrials.arflags(BinArray,:); +catch +end +ERP.nbin = numel(BinArray); +ERP.nchan = numel(ChanArray); +ERP.chanlocs = ERP.chanlocs(ChanArray); +for Numofbin = 1:numel(BinArray) + Bindescr{Numofbin} = ERP.bindescr{BinArray(Numofbin)}; +end +ERP.bindescr = Bindescr; + +%%---------------------empty eventlist------------------------------------- +ERP.EVENTLIST = []; + +%%---------------------dataquality----------------------------------------- +try + for ii = 1:3 + if ~isempty( ERP.dataquality(ii).data) + ERP.dataquality(ii).data = ERP.dataquality(ii).data(ChanArray,:,BinArray); + end + end +catch +end + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + +ERP.saved = 'no'; + +% +% History +% + +skipfields = {'ERP', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_duplicaterp( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + else + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ERPset from GUI +% +if issaveas + [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); +end + + + +% get history from script. ERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + ERP = erphistory(ERP, [], erpcom, 1); + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_erp_ar_summary.m b/studio_functions/Functions/EStudio/ERP Tab/pop_erp_ar_summary.m new file mode 100644 index 00000000..c37707aa --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_erp_ar_summary.m @@ -0,0 +1,66 @@ +%%This function is to display the summary of trial information +% +% FORMAT : +% +% pop_erp_ar_summary(ALLERP,ERPArray); +% +% ALLERP - structure array of EEG structures +% ERPArray -index of erpsets +%EEGNames -EEGset names + + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Apr. 2024 + + + +function erpcom = pop_erp_ar_summary(ALLERP,ERPArray,EEGNames) + +erpcom = ''; +if nargin < 1 || nargin >3 + help pop_erp_ar_summary + return +end +if nargin < 2 + ERPArray = [1:length(ALLERP)]; +end +if isempty(ALLERP) + msgboxText = ['ALLERP is empty.']; + title = 'ERPLAB Studio: pop_erp_ar_summary() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + +if isempty(ERPArray) || any(ERPArray(:)>length(ALLERP)) || any(ERPArray(:)<1) + ERPArray = [1:length(ALLERP)]; +end + +if nargin < 3 + EEGNames = ''; +end + + +if ~isempty(ERPArray) + app = feval('dq_trial_rejection',ALLERP,ERPArray,EEGNames); +% waitfor(app,'Finishbutton',1); +end +ERPArraystr= vect2colon(ERPArray); +if ~isempty(EEGNames) + erpcom = sprintf('erpcom = pop_erp_ar_summary(ALLERP,%s',ERPArraystr); + + nn = length(EEGNames); + erpcom = sprintf( '%s, {''%s'' ', erpcom, EEGNames{1}); + for ff=2:nn + erpcom = sprintf( '%s, ''%s'' ', erpcom, EEGNames{ff}); + end + erpcom = sprintf( '%s});', erpcom); + +else + erpcom = sprintf('erpcom = pop_erp_ar_summary(ALLERP,%s);',ERPArraystr); +end +end \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_erp_eventlist_view.m b/studio_functions/Functions/EStudio/ERP Tab/pop_erp_eventlist_view.m new file mode 100644 index 00000000..2fe11775 --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_erp_eventlist_view.m @@ -0,0 +1,166 @@ +% PURPOSE: pop_erp_eventlist_view.m +% display eventlist + +% FORMAT: +% [ALLERP, erpcom] = pop_erp_eventlist_view( ALLERP, 'ERPArray',ERPArray,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ALLERP -ALLERP structure +%ERPArray -index(es) of eegsets + + + +% *** This function is part of ALLERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% May 2024 + + + + +function [ALLERP, erpcom] = pop_erp_eventlist_view(ALLERP, varargin) +erpcom = ''; + +if nargin < 1 + help pop_erp_eventlist_view + return +end +if isempty(ALLERP) + msgboxText = 'Cannot handle an empty EEGset'; + title = 'ERPLAB: pop_erp_eventlist_view() error'; + errorfound(msgboxText, title); + return +end +if isempty(ALLERP(1)) + msgboxText = 'Cannot handle an empty EEGset'; + title = 'ERPLAB: pop_erp_eventlist_view() error'; + errorfound(msgboxText, title); + return +end + + + +if nargin==1 + ERPArray = [1:length(ALLERP)]; + [ALLERP, erpcom] = pop_erp_eventlist_view( ALLERP, 'ERPArray',ERPArray,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLERP'); +% option(s) +p.addParamValue('ERPArray', [],@isnumeric); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLERP, varargin{:}); + + +ERPArray = p.Results.ERPArray; + +if isempty(ERPArray) || any(ERPArray(:)>length(ALLERP)) || any(ERPArray(:)<1) + ERPArray = [1:length(ALLERP)]; +end + + +feval("ERP_evenlist_gui",ALLERP(ERPArray)); + + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + + +% +% History +% + +skipfields = {'ALLERP', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_erp_eventlist_view( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') && ~strcmpi(fn2res,'no') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + erpcom = sprintf( '%s, ''%s'', %s', erpcom, fn2com, vect2colon(fn2res,'Repeat','on')); + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ALLERPset from GUI +% +if issaveas + for ii = 1:length(ALLERP) + ERP = ALLERP(ii); + [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); + if issave>0 + % erpcom = sprintf( '%s = pop_filterp( %s, %s, %s, %s, %s, ''%s'', %s);', inputname(1), inputname(1),... + % chanArraystr, num2str(locutoff), num2str(hicutoff),... + % num2str(filterorder), lower(fdesign), num2str(remove_dc)); + % erpcom = sprintf('%s\n%s', erpcom, erpcom_save); + if issave==2 + erpcom = sprintf('%s\n%s', erpcom, erpcom_save); + msgwrng = '*** Your ERPset was saved on your hard drive.***'; + %mcolor = [0 0 1]; + else + msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; + %mcolor = [1 0.52 0.2]; + end + else + % ERP = ERPaux; + msgwrng = 'ERPLAB Warning: Your changes were not saved'; + %mcolor = [1 0.22 0.2]; + end + try cprintf([1 0.52 0.2], '%s\n\n', msgwrng); catch,fprintf('%s\n\n', msgwrng);end ; + end +end + + +% get history from script. ALLERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for i=1:length(ERPArray) + ALLERP(ERPArray(i)) = erphistory(ALLERP((ERPArray)), [], erpcom, 1); + end + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_renamerp.m b/studio_functions/Functions/EStudio/ERP Tab/pop_renamerp.m new file mode 100644 index 00000000..13cbeca6 --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_renamerp.m @@ -0,0 +1,187 @@ +% PURPOSE: pop_renamerp.m +% rename ALLERPset +% + +% FORMAT: +% [ALLERP, erpcom] = pop_renamerp( ALLERP, 'erpnames',erpnames,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ALLERP -ALLERP structure +%erpnames -strings for erpsets + + + +% *** This function is part of ALLERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2024 + + + + +function [ALLERP, erpcom] = pop_renamerp(ALLERP, varargin) +erpcom = ''; + +if nargin < 1 + help pop_renamerp + return +end +if isempty(ALLERP) + msgboxText = 'Cannot rename an empty ALLERPset'; + title = 'ALLERPLAB: pop_renamerp() error'; + errorfound(msgboxText, title); + return +end +if isempty(ALLERP(1).bindata) + msgboxText = 'Cannot rename an empty ALLERPset'; + title = 'ALLERPLAB: pop_renamerp() error'; + errorfound(msgboxText, title); + return +end + +datatype = checkdatatype(ALLERP(1)); +if ~strcmpi(datatype, 'ERP') + msgboxText = 'Cannot rename Power Spectrum waveforms!'; + title = 'ALLERPLAB: pop_renamerp() error'; + errorfound(msgboxText, title); + return +end + +if nargin==1 + + app = feval('ERP_Tab_rename_gui',ALLERP,1:length(ALLERP)); + waitfor(app,'Finishbutton',1); + try + erpnames = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + if isempty(erpnames) + return; + end + % + % Somersault + % + [ALLERP, erpcom] = pop_renamerp( ALLERP, 'erpnames',erpnames,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLERP'); +% option(s) +p.addParamValue('erpnames', '',@iscell); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLERP, varargin{:}); + + + +erpnames = p.Results.erpnames; +if ischar(erpnames) && numel(ALLERP)==1 + ALLERP.erpname = erpnames; + ALLERP.saved = 'no'; +elseif iscell(erpnames) + for Numoferp = 1:numel(ALLERP) + newName = erpnames{Numoferp}; + [~, newName, ~] = fileparts(newName) ; + if ~isempty(newName) + ALLERP(Numoferp).erpname = newName; + ALLERP(Numoferp).saved = 'no'; + else + ALLERP(Numoferp).saved = 'no'; + end + end +end + + + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + + +% +% History +% + +skipfields = {'ALLERP', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_renamerp( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', {''%s'' ', erpcom, fn2com, fn2res{1}); + end + else + if iscell(fn2res) + nn = length(fn2res); + erpcom = sprintf( '%s, ''%s'', {''%s'' ', erpcom, fn2com, fn2res{1}); + for ff=2:nn + erpcom = sprintf( '%s, ''%s'' ', erpcom, fn2res{ff}); + end + erpcom = sprintf( '%s}', erpcom); + end + + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ALLERPset from GUI +% +if issaveas + for ii = 1:length(ALLERP) + [ALLERP(ii), issave, erpcom_save] = pop_savemyerp(ALLERP(ii),'gui','erplab', 'History', 'off'); + end +end + + + +% get history from script. ALLERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for ii = 1:length(ALLERP) + ALLERP(ii) = erphistory(ALLERP(ii), [], erpcom, 1); + end + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_resamplerp.m b/studio_functions/Functions/EStudio/ERP Tab/pop_resamplerp.m new file mode 100644 index 00000000..b0e3159c --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_resamplerp.m @@ -0,0 +1,305 @@ +% PURPOSE: pop_resamplerp.m +% resample ERPsets +% + +% FORMAT: +% [ERP, erpcom] = pop_resamplerp( ERP, 'Freq2resamp',Freq2resamp, 'TimeRange',TimeRange,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ERP -ERP structure +%Freq2resamp -new sampling rate e.g., 200 Hz +%TimeRange -new time range e.g., [-300 900]ms + + + +% *** This function is part of ERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2023 + +function [ERP, erpcom] = pop_resamplerp(ERP, varargin) +erpcom = ''; + +if nargin < 1 + help pop_resamplerp + return +end +if isempty(ERP) + msgboxText = 'Cannot resample an empty erpset'; + title = 'ERPLAB: pop_resamplerp() error'; + errorfound(msgboxText, title); + return +end +if isempty(ERP(1).bindata) + msgboxText = 'Cannot resample an empty erpset'; + title = 'ERPLAB: pop_resamplerp() error'; + errorfound(msgboxText, title); + return +end + +datatype = checkdatatype(ERP(1)); +if ~strcmpi(datatype, 'ERP') + msgboxText = 'Cannot resample Power Spectrum waveforms!'; + title = 'ERPLAB: pop_resamplerp() error'; + errorfound(msgboxText, title); + return +end + +if nargin==1 + + Freq2resamp = ERP.srate; + TimeRange = [ERP.times(1),ERP.times(end)]; + % + % Somersault + % + [ERP, erpcom] = pop_resamplerp( ERP, 'Freq2resamp',Freq2resamp, 'TimeRange',TimeRange,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ERP'); +% option(s) +p.addParamValue('Freq2resamp', [],@isnumeric); +p.addParamValue('TimeRange', [], @isnumeric); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ERP, varargin{:}); + +Freq2resamp = p.Results.Freq2resamp; +if isempty(Freq2resamp) || numel(Freq2resamp)~=1 || any(Freq2resamp<=0) + Freq2resamp = ERP.srate; +end + +TimeRange= p.Results.TimeRange; +TimeRange = unique(TimeRange); +if isempty(TimeRange) || numel(TimeRange)~=2 || TimeRange(1)>=ERP.times(end) || TimeRange(2)<=ERP.times(1) + TimeRange = [ERP.times(1),ERP.times(end)]; +end +if TimeRange(1)>=0 + msgboxText = ['The left number of the new time range should be smaller than 0']; + title = 'ERPLAB: pop_resamplerp() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + +if TimeRange(2)<=0 + msgboxText = ['The right number of the new time range should be larger than 0']; + title = 'ERPLAB: pop_resamplerp() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + +%%-------------------------adjust the left edge---------------------------- +if roundn(TimeRange(1),-2)>= roundn(ERP.times(1),-2) + [xxx, latsamp, latdiffms] = closest(ERP.times, TimeRange(1)); + ERP.times = ERP.times(latsamp:end); + ERP.xmin = ERP.times(1)/1000; + ERP.bindata = ERP.bindata(:,latsamp:end,:); +else + TimesNew = ERP.times; + timeint = 1000/ERP.srate; + count=0; + for ii=1:10000 + timeStart = TimesNew(1)-timeint; + if timeStart>=TimeRange(1) + count = count+1; + TimesNew = [timeStart,TimesNew]; + else + break; + end + end + if count~=0 + ERP.times = TimesNew; + ERP.xmin = ERP.times(1)/1000; + datadd= zeros(size(ERP.bindata,1),count); + for ii = 1:size(ERP.bindata,3) + newdata(:,:,ii) = [datadd,squeeze(ERP.bindata(:,:,ii))]; + end + ERP.bindata = newdata; + end +end +%%-------------------------adjust the right edge--------------------------- +if roundn(TimeRange(2),-2)<= roundn(ERP.times(end),-2) + [xxx, latsamp, latdiffms] = closest(ERP.times, TimeRange(2)); + ERP.times = ERP.times(1:latsamp); + ERP.xmax = ERP.times(end)/1000; + ERP.bindata = ERP.bindata(:,1:latsamp,:); +else + TimesNew = ERP.times; + timeint = 1000/ERP.srate; + count=0; + for ii=1:10000 + timend = TimesNew(end)+timeint; + if timend<=TimeRange(2) + count = count+1; + TimesNew = [TimesNew,timend]; + else + break; + end + end + if count~=0 + newdata = []; + ERP.times = TimesNew; + ERP.xmax = ERP.times(end)/1000; + datadd= zeros(size(ERP.bindata,1),count); + for ii = 1:size(ERP.bindata,3) + newdata(:,:,ii) = [squeeze(ERP.bindata(:,:,ii)),datadd]; + end + ERP.bindata = newdata; + end +end + +count = 0; +check_left = []; +for ii = 1:numel(ERP.times) + if roundn(ERP.times(ii),-2)< roundn(TimeRange(1),-2) || roundn(ERP.times(ii),-2)> roundn(TimeRange(2),-2) + count = count+1; + check_left(count) = ii; + end +end +ERP.bindata(:,check_left,:) =[]; +ERP.times(check_left) = []; +ERP.pnts = size(ERP.bindata,2); +ERP.xmax = ERP.times(end)/1000; +ERP.xmin = ERP.times(1)/1000; + +if ERP.srate~=Freq2resamp + EEG = eeg_emptyset(); + EEG.nbchan = ERP.nchan; + EEG.pnts = ERP.pnts; + EEG.trials = size(ERP.bindata,3); + EEG.srate = ERP.srate; + EEG.xmin = ERP.xmin; + EEG.xmax = ERP.xmax; + EEG.data = ERP.bindata; + EEG.times = ERP.times; + %%resampling data based on eeglab routine + EEG = pop_resample( EEG, Freq2resamp); + ERP.srate= EEG.srate; + ERP.xmin= EEG.xmin; + ERP.xmax = EEG.xmax; + ERP.bindata = EEG.data; + ERP.times = EEG.times; + ERP.pnts= EEG.pnts; +end + +ERP.EVENTLIST.eventinfo = []; +ERP.binerror = []; + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + +ERP.saved = 'no'; +% +% History +% +% +% Completion statement +% +% msg2end + +% +% History +% + +skipfields = {'ERP', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_resamplerp( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + if ischar([fn2res{:}]) + fn2resstr = sprintf('''%s'' ', fn2res{:}); + else + fn2resstr = vect2colon(cell2mat(fn2res), 'Sort','on'); + end + fnformat = '{%s}'; + else + fn2resstr = vect2colon(fn2res, 'Sort','on'); + fnformat = '%s'; + end + if strcmpi(fn2com,'Criterion') + if p.Results.Criterion<100 + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + else + erpcom = sprintf( ['%s, ''%s'', ' fnformat], erpcom, fn2com, fn2resstr); + end + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ERPset from GUI +% +% if issaveas +% [ERP, issave, erpcom_save] = pop_savemyerp(ERP,'gui','erplab', 'History', 'off'); +% if issave>0 +% % erpcom = sprintf( '%s = pop_filterp( %s, %s, %s, %s, %s, ''%s'', %s);', inputname(1), inputname(1),... +% % chanArraystr, num2str(locutoff), num2str(hicutoff),... +% % num2str(filterorder), lower(fdesign), num2str(remove_dc)); +% % erpcom = sprintf('%s\n%s', erpcom, erpcom_save); +% if issave==2 +% erpcom = sprintf('%s\n%s', erpcom, erpcom_save); +% msgwrng = '*** Your ERPset was saved on your hard drive.***'; +% %mcolor = [0 0 1]; +% else +% msgwrng = '*** Warning: Your ERPset was only saved on the workspace.***'; +% %mcolor = [1 0.52 0.2]; +% end +% else +% ERP = ERPaux; +% msgwrng = 'ERPLAB Warning: Your changes were not saved'; +% %mcolor = [1 0.22 0.2]; +% end +% try cprintf([1 0.52 0.2], '%s\n\n', msgwrng); catch,fprintf('%s\n\n', msgwrng);end ; +% end +% get history from script. ERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + ERP = erphistory(ERP, [], erpcom, 1); + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/pop_suffixerp.m b/studio_functions/Functions/EStudio/ERP Tab/pop_suffixerp.m new file mode 100644 index 00000000..993a927c --- /dev/null +++ b/studio_functions/Functions/EStudio/ERP Tab/pop_suffixerp.m @@ -0,0 +1,172 @@ +% PURPOSE: pop_suffixerp.m +% add suffix to ALLERP names +% + +% FORMAT: +% [ALLERP, erpcom] = pop_suffixerp( ALLERP, 'suffixstr',suffixstr,... +% 'Saveas', 'off', 'History', 'gui'); + +% Inputs: +% +%ALLERP -ALLERP structure +%suffixstr -strings for erpsets + + + +% *** This function is part of ALLERPLAB Studio *** +% Author: Guanghui Zhang & Steven Luck +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Dec. 2024 + + + + +function [ALLERP, erpcom] = pop_suffixerp(ALLERP, varargin) +erpcom = ''; + +if nargin < 1 + help pop_suffixerp + return +end +if isempty(ALLERP) + msgboxText = 'Cannot rename an empty ALLERPset'; + title = 'ERPLAB: pop_suffixerp() error'; + errorfound(msgboxText, title); + return +end +if isempty(ALLERP(1).bindata) + msgboxText = 'Cannot rename an empty ALLERPset'; + title = 'ERPLAB: pop_suffixerp() error'; + errorfound(msgboxText, title); + return +end + +datatype = checkdatatype(ALLERP(1)); +if ~strcmpi(datatype, 'ERP') + msgboxText = 'Cannot rename Power Spectrum waveforms!'; + title = 'ERPLAB: pop_suffixerp() error'; + errorfound(msgboxText, title); + return +end + +if nargin==1 + + suffixstr = f_ERP_suffix_gui('Suffix'); + + if isempty(suffixstr) + return; + end + % + % Somersault + % + [ALLERP, erpcom] = pop_suffixerp( ALLERP, 'suffixstr',suffixstr,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLERP'); +% option(s) +p.addParamValue('suffixstr', '',@ischar); +p.addParamValue('Saveas', 'off', @ischar); +p.addParamValue('History', 'script', @ischar); % history from scripting + +p.parse(ALLERP, varargin{:}); + + + +suffixstr = p.Results.suffixstr; + +for Numoferp = 1:numel(ALLERP) + ALLERP(Numoferp).erpname = [ALLERP(Numoferp).erpname,'_',suffixstr]; + ALLERP(Numoferp).saved = 'no'; + +end + + + + +if strcmpi(p.Results.Saveas,'on') + issaveas = 1; +else + issaveas = 0; +end +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + + + +% +% History +% + +skipfields = {'ALLERP', 'Saveas','History'}; +fn = fieldnames(p.Results); +erpcom = sprintf( '%s = pop_suffixerp( %s ', inputname(1), inputname(1) ); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') + erpcom = sprintf( '%s, ''%s'', ''%s'' ', erpcom, fn2com, fn2res); + end + else + if iscell(fn2res) + nn = length(fn2res); + erpcom = sprintf( '%s, ''%s'', {''%s'' ', erpcom, fn2com, fn2res{1}); + for ff=2:nn + erpcom = sprintf( '%s, ''%s'' ', erpcom, fn2res{ff}); + end + erpcom = sprintf( '%s}', erpcom); + end + + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% +% Save ALLERPset from GUI +% +if issaveas + for ii = 1:length(ALLERP) + [ALLERP(ii), issave, erpcom_save] = pop_savemyerp(ALLERP(ii),'gui','erplab', 'History', 'off'); + end +end + + + +% get history from script. ALLERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for ii = 1:length(ALLERP) + ALLERP(ii) = erphistory(ALLERP(ii), [], erpcom, 1); + end + case 3 + % implicit + otherwise %off or none + erpcom = ''; + return +end +return \ No newline at end of file diff --git a/studio_functions/Functions/EStudio/ERP Tab/redrawERP.m b/studio_functions/Functions/EStudio/ERP Tab/redrawERP.m deleted file mode 100755 index 53c05ffd..00000000 --- a/studio_functions/Functions/EStudio/ERP Tab/redrawERP.m +++ /dev/null @@ -1,769 +0,0 @@ -function redrawERP() -% Draw a demo ERP into the axes provided -global gui_erp; -global observe_ERPDAT; - - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); - -S_ws_geterpplot = estudioworkingmemory('geterpplot'); - - -%%Parameter from bin and channel panel -Elecs_shown = S_ws_getbinchan.elecs_shown{S_ws_getbinchan.Select_index}; -Bins = S_ws_getbinchan.bins{S_ws_getbinchan.Select_index}; -Bin_chans = S_ws_getbinchan.bins_chans(S_ws_getbinchan.Select_index); -Elec_list = S_ws_getbinchan.elec_list{S_ws_getbinchan.Select_index}; -Matlab_ver = S_ws_getbinchan.matlab_ver; - - - -%%Parameter from plotting panel -try - Min_vspacing = S_ws_geterpplot.min_vspacing(S_ws_getbinchan.Select_index); - Min_time = S_ws_geterpplot.min(S_ws_getbinchan.Select_index); - Max_time = S_ws_geterpplot.max(S_ws_getbinchan.Select_index); - Yscale = S_ws_geterpplot.yscale(S_ws_getbinchan.Select_index); - Timet_low =S_ws_geterpplot.timet_low(S_ws_getbinchan.Select_index); - Timet_high =S_ws_geterpplot.timet_high(S_ws_getbinchan.Select_index); - Timet_step=S_ws_geterpplot.timet_step(S_ws_getbinchan.Select_index); - Fill = S_ws_geterpplot.fill(S_ws_getbinchan.Select_index); - Plority_plot = S_ws_geterpplot.Positive_up(S_ws_getbinchan.Select_index); - ColumnNum = S_ws_geterpplot.Plot_column; -catch - return; -end - -if Bin_chans == 0 - elec_n = S_ws_getbinchan.elec_n(S_ws_getbinchan.Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(S_ws_getbinchan.Select_index)).nchan; -else - elec_n = S_ws_getbinchan.bin_n(S_ws_getbinchan.Select_index); - max_elec_n = observe_ERPDAT.ALLERP(S_ws_geterpset(S_ws_getbinchan.Select_index)).nbin; -end - -% We first clear the existing axes ready to build a new one -if ishandle( gui_erp.ViewAxes ) - delete( gui_erp.ViewAxes ); -end - - -% Get chan labels -S_chan.chan_label = cell(1,max_elec_n); -S_chan.chan_label_place = zeros(1,max_elec_n); - - -if Bin_chans == 0 - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.chanlocs(Elecs_shown(i)).labels; - end -else - for i = 1:elec_n - S_chan.chan_label{i} = observe_ERPDAT.ERP.bindescr(Bins(i)); - end -end - - -%Sets the units of your root object (screen) to pixels -set(0,'units','pixels') -%Obtains this pixel information -Pix_SS = get(0,'screensize'); -%Sets the units of your root object (screen) to inches -set(0,'units','inches') -%Obtains this inch information -Inch_SS = get(0,'screensize'); -%Calculates the resolution (pixels per inch) -Res = Pix_SS./Inch_SS; - - -pb_height = Min_vspacing*Res(4); %px - - -% Plot data in the main viewer fig -splot_n = elec_n; -tsize = 13; - - -clear pb r_ax plotgrid; -try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color -catch - ColorB_def = [0.95 0.95 0.95]; -end -if isempty(ColorB_def) - ColorB_def = [0.95 0.95 0.95]; -end -gui_erp.plotgrid = uix.VBox('Parent',gui_erp.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); - -pageinfo_box = uiextras.HBox( 'Parent', gui_erp.plotgrid,'BackgroundColor',ColorB_def); - -gui_erp.plot_wav_legend = uiextras.HBox( 'Parent', gui_erp.plotgrid,'BackgroundColor',[1 1 1]); -gui_erp.ViewAxes_legend = uix.ScrollingPanel( 'Parent', gui_erp.plot_wav_legend,'BackgroundColor',ColorB_def); - -gui_erp.ViewAxes = uix.ScrollingPanel( 'Parent', gui_erp.plot_wav_legend,'BackgroundColor',[1 1 1]); - - -%%Changed by Guanghui Zhang 2 August 2022-------panel for display the processing procedure for some functions, e.g., filtering -xaxis_panel = uiextras.HBox( 'Parent', gui_erp.plotgrid,'BackgroundColor',ColorB_def);%%%Message -gui_erp.Process_messg = uicontrol('Parent',xaxis_panel,'Style','text','String','','FontSize',20,'FontWeight','bold','BackgroundColor',ColorB_def); - - -%%Setting title -gui_erp.pageinfo_minus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '<','Callback',@page_minus,'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index ==1 - gui_erp.pageinfo_minus.Enable = 'off'; -end - -gui_erp.pageinfo_plus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', '>','Callback',@page_plus,'FontSize',30,'BackgroundColor',[1 1 1]); -if S_ws_getbinchan.Select_index == numel(S_ws_geterpset) - gui_erp.pageinfo_plus.Enable = 'off'; -end - -pageinfo_str = ['Page',32,num2str(S_ws_getbinchan.Select_index),'/',num2str(numel(S_ws_geterpset)),':',32,observe_ERPDAT.ERP.erpname]; - -pageinfo_text = uicontrol('Parent',pageinfo_box,'Style','text','String',pageinfo_str,'FontSize',20,'FontWeight','bold'); - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [1 1 1]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -gui_erp.pageinfo_minus.Enable = Enable_minus; -gui_erp.pageinfo_plus.Enable = Enable_plus; -gui_erp.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -gui_erp.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; - -set(pageinfo_box, 'Sizes', [50 50 -1] ); -set(pageinfo_box,'BackgroundColor',ColorB_def); -set(pageinfo_text,'BackgroundColor',ColorB_def); -%Setting title. END,'BackgroundColor',ColorB_def - -%for i=1:splot_n - -ndata = 0; -nplot = 0; -if Bin_chans == 0 - ndata = Bins; - nplot = Elecs_shown; -else - ndata = Elecs_shown; - nplot = Bins; -end - -% -timeor = observe_ERPDAT.ERP.times; % original time vector -timex = timeor; -[xxx, latsamp, latdiffms] = closest(timex, [Min_time Max_time]); -tmin = latsamp(1); -tmax = latsamp(2); - -if tmin < 1 - tmin = 1; -end - -if tmax > numel(observe_ERPDAT.ERP.times) - tmax = numel(observe_ERPDAT.ERP.times); -end - -plot_erp_data = nan(tmax-tmin+1,numel(ndata)); -for i = 1:splot_n - if Bin_chans == 0 - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = observe_ERPDAT.ERP.bindata(Elecs_shown(i),tmin:tmax,Bins(i_bin))'*Plority_plot; % - end - else - for i_bin = 1:numel(ndata) - plot_erp_data(:,i_bin,i) = observe_ERPDAT.ERP.bindata(Elecs_shown(i_bin),tmin:tmax,Bins(i))'*Plority_plot; % - end - end -end - -perc_lim = Yscale; -percentile = perc_lim*3/2; - -[~,~,b] = size(plot_erp_data); - -%How to get x unique colors? - - -%%----------------------Modify the data into multiple-columns--------------------------------------- -rowNum = ceil(b/ColumnNum(S_ws_getbinchan.Select_index)); -plot_erp_data_new = zeros(size(plot_erp_data,1),size(plot_erp_data,2),rowNum*ColumnNum(S_ws_getbinchan.Select_index)); - -plot_erp_data_new(:,:,1:size(plot_erp_data,3)) = plot_erp_data; -plot_erp_data_new_trans = []; -for Numofrow = 1:rowNum - plot_erp_data_new_trans(:,:,:,Numofrow) = plot_erp_data_new(:,:,(Numofrow-1)*ColumnNum(S_ws_getbinchan.Select_index)+1:Numofrow*ColumnNum(S_ws_getbinchan.Select_index)); -end - -clear plot_erp_data; - -plot_erp_data_new_trans = permute(plot_erp_data_new_trans,[1,3,2,4]) ; -plot_erp_data = reshape(plot_erp_data_new_trans,size(plot_erp_data_new_trans,1)*size(plot_erp_data_new_trans,2),size(plot_erp_data_new_trans,3),size(plot_erp_data_new_trans,4)); - -% Min_time = Min_time*ColumnNum(S_ws_getbinchan.Select_index); -% Max_time = Max_time*ColumnNum(S_ws_getbinchan.Select_index); -ind_plot_height = percentile*2; % Height of each individual subplot - -offset = []; -if Bin_chans == 0 - offset = (size(plot_erp_data,3)-1:-1:0)*ind_plot_height; -else - offset = (size(plot_erp_data,3)-1:-1:0)*ind_plot_height; -end -[~,~,b] = size(plot_erp_data); - -for i = 1:b - plot_erp_data(:,:,i) = plot_erp_data(:,:,i) + ones(size(plot_erp_data(:,:,i)))*offset(i); -end - - - -r_ax = axes('Parent', gui_erp.ViewAxes,'Color','none','Box','on'); -hold(r_ax,'on'); -set(gui_erp.plot_wav_legend,'Sizes',[80 -10]); -r_ax_legend = axes('Parent', gui_erp.ViewAxes_legend,'Color','none','Box','off'); -hold(r_ax_legend,'on'); - - -Min_time_onecolm = S_ws_geterpplot.min(S_ws_getbinchan.Select_index); -Max_time_onecolm = S_ws_geterpplot.max(S_ws_getbinchan.Select_index); - -try - f_bin = 1000/observe_ERPDAT.ERP.srate; -catch - f_bin = 1; -end - -ts = observe_ERPDAT.ERP.times(tmin:tmax); -ts_colmn = ts; -xticks_clomn = (Min_time:Timet_step:Max_time); -xticks = (Min_time:Timet_step:Max_time); -if ColumnNum(S_ws_getbinchan.Select_index)>1 % Plotting waveforms with munltiple-columns - - for Numofcolumn = 1:ColumnNum(S_ws_getbinchan.Select_index)-1 - ts_colmn = [ts_colmn,ts+ones(1,numel(ts))*(ts_colmn(end)+f_bin-ts(1))]; - xticks_clomn = [xticks_clomn,xticks(2:end)]; - end - X_zero_line(1) =ts(1); - for Numofcolumn = 1:ColumnNum(S_ws_getbinchan.Select_index)-1 - X_zero_line(Numofcolumn+1) = X_zero_line(Numofcolumn)+ ts(end)-ts(1)+f_bin; - end - - ts = ts_colmn; - - Min_time = ts(1); - Max_time = ts(end); - xticks = xticks_clomn; - -else%% Plotting waveforms with single-column - xticks = (Min_time:Timet_step:Max_time); - X_zero_line(1) =ts(1); -end - -for Numofxlabel = 1:numel(xticks) - xticks_labels{Numofxlabel} = num2str(xticks(Numofxlabel)); -end - -splot_n = size(plot_erp_data,3);%%Adjust the columns - -set(r_ax,'XLim',[Min_time Max_time]); - -[a,c,b] = size(plot_erp_data); -new_erp_data = zeros(a,b*c); -for i = 1:b - new_erp_data(:,((c*(i-1))+1):(c*i)) = plot_erp_data(:,:,i); -end - - -line_colors = erpworkingmemory('PWColor'); -if size(line_colors,1)~= numel(ndata) - if numel(ndata)> size(line_colors,1) - line_colors = get_colors(numel(ndata)); - else - line_colors = line_colors(1:numel(ndata),:,:); - end -end - -if isempty(line_colors) - line_colors = get_colors(numel(ndata)); -end - -line_colors = repmat(line_colors,[splot_n 1]); %repeat the colors once for every plot - -if ColumnNum(S_ws_getbinchan.Select_index)>1 - for ii = 1:numel(X_zero_line) - xline_p = xline(r_ax,X_zero_line(ii),'--','Color', [0 0 0],'LineWidth',1.5);%%Marking start time point for each column - xline_p.FontSize = 18; - end - - -end - - -%%%------------Setting xticklabels for each row of each wave-------------- -x_axs = ones(size(new_erp_data,1),1); -if numel(offset)>1 - - for jj = 1:numel(offset) - x_axset = plot(r_ax,ts,x_axs.*offset(jj),'k','LineWidth',1); - set(r_ax,'XTick',[Min_time:Timet_step:Max_time], ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); - end - -end -if numel(offset)>1 - - for jj = 1:numel(offset) - x_axset = plot(r_ax,ts,x_axs.*offset(end-1),'k','LineWidth',1); - set(r_ax,'XTick',[Min_time:Timet_step:Max_time], ... - 'box','off', 'Color','none','xticklabels',xticks_labels,'FontWeight','bold'); - myX_Crossing = offset(jj); - props = get(r_ax); - - tick_bottom = -props.TickLength(1)*diff(props.YLim); - if abs(tick_bottom) > abs(Yscale)/5 - try - tick_bottom = - abs(Yscale)/5; - catch - tick_bottom = tick_bottom; - end - end - tick_top = 0; - - h_xaxis = line(r_ax,props.XLim, [0 0] + myX_Crossing, 'color', 'k'); - - if ~isempty(props.XTick) - xtick_x = repmat(props.XTick, 2, 1); - xtick_y = repmat([tick_bottom; tick_top] + myX_Crossing, 1, length(props.XTick)); - h_ticks = line(r_ax,xtick_x, xtick_y, 'color', 'k'); - end - set(r_ax, 'XTick', [], 'XTickLabel', []); - % tick_bottom = -props.TickLength(1)*diff(props.YLim); - nTicks = length(props.XTick); - h_ticklabels = zeros(size(props.XTick)); - if nTicks>1 - if numel(offset)==jj - kkkk = 1; - else - kkkk = 2; - end - for iCount = kkkk:nTicks - xtick_label = (props.XTickLabel(iCount, :)); - text(r_ax,props.XTick(iCount), tick_bottom + myX_Crossing, ... - xtick_label, ... - 'HorizontalAlignment', 'Center', ... - 'VerticalAlignment', 'Top', ... - 'FontSize', 12, ... - 'FontName', props.FontName, ... - 'FontAngle', props.FontAngle, ... - 'FontUnits', props.FontUnits, ... - 'FontWeight', 'bold'); - end - end - - end -end -%%%%%%%%----------------------------- - -% set(r_ax,'XDir','reverse') - -pb_here = plot(r_ax,ts, [repmat((1:numel(nplot)-1)*ind_plot_height,[numel(ts) 1]) new_erp_data],'LineWidth',1); -r_ax.LineWidth=1.5; -set(r_ax, 'XTick', [], 'XTickLabel', []) - -% -yticks = -perc_lim:perc_lim:((2*percentile*b)-(2*perc_lim)); -ylabs = repmat([-perc_lim 0 perc_lim],[1,b]); -oldlim = [-percentile yticks(end)-perc_lim+percentile]; -top_vspace = max( max( new_erp_data))-oldlim(2); -bot_vspace = min( min( new_erp_data))-oldlim(1); -if top_vspace < 0 - top_vspace = 0; -end - -if bot_vspace > 0 - bot_vspace = 0; -end -newlim = oldlim + [bot_vspace top_vspace]; -set(r_ax,'XLim',[Min_time Max_time],'Ylim',newlim); - - -for i = 0:numel(nplot)-2 - r_ax.Children(end-i).Color = [0 0 0]; -end - - -for i = numel(nplot):numel(pb_here) - pb_here(i).Color = line_colors((i-numel(nplot)+1),:); - -end - -for i = 1:numel(nplot)-1 - pb_here(i).Color = [0 0 0]; -end - - - -ylabs = [fliplr(-perc_lim:-perc_lim:newlim(1)) ylabs(2:end-1) (yticks(end):perc_lim:newlim(2))-yticks(end)+perc_lim]; -yticks = [fliplr(-perc_lim:-perc_lim:newlim(1)) yticks(2:end-1) yticks(end):perc_lim:newlim(2)]; - - - -Ylabels_new = ylabs.*Plority_plot; -[~,Y_label] = find(Ylabels_new == -0); -Ylabels_new(Y_label) = 0; -if ColumnNum(S_ws_getbinchan.Select_index)==1 - % Ylabels_fin = {}; - % count = 0; - % for Numofylabel = numel(Ylabels_new):-1:1 - % - % if Ylabels_new(Numofylabel)==0 - % count =count+1; - % - % if Bin_chans == 0 - % Ylabels_fin{Numofylabel} = strcat(Elec_list{Elecs_shown(count)},'(',num2str(Elecs_shown(count)),')'); - % else - % Ylabels_fin{Numofylabel} = ['Bin',num2str(Bins(count))]; - % end - % else - % Ylabels_fin{Numofylabel} = num2str(roundn(Ylabels_new(Numofylabel),-1)); - % end - % - % end - % else%% Getting y ticks and legends for multiple-columns - % for Numofylabel = numel(Ylabels_new):-1:1 - % Ylabels_fin{Numofylabel} = num2str(roundn(Ylabels_new(Numofylabel),-1)); - % end - if numel(offset)>1 - count = 0; - for i = 0:numel(offset)-1 - leg_str = ''; - for Numofcolumn = 1: ColumnNum(S_ws_getbinchan.Select_index) - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',Elec_list{Elecs_shown(count)}); - else - leg_str = sprintf('%s',observe_ERPDAT.ERP.bindescr{Bins(count)}); - end - catch - leg_str = ''; - end - text(r_ax,X_zero_line(Numofcolumn),offset(i+1)+offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 18); - end - end - end - - - count = (numel(offset)-1)*ColumnNum(S_ws_getbinchan.Select_index); - leg_str = ''; - for Numofcolumn = 1: ColumnNum(S_ws_getbinchan.Select_index) - count = count+1; - try - if Bin_chans == 0 - leg_str = sprintf('%s',Elec_list{Elecs_shown(count)}); - else - leg_str = sprintf('%s',observe_ERPDAT.ERP.bindescr{Bins(count)}); - end - catch%% - leg_str = ''; - end - try - text(r_ax,X_zero_line(Numofcolumn),offset(end-1)/6,leg_str,'FontWeight','bold','FontSize', 18); - catch - text(r_ax,X_zero_line(Numofcolumn),Yscale/2,leg_str,'FontWeight','bold','FontSize', 18); - end - end - -end - - - - -% xticks = (Min_time:Timet_step:Max_time); -% some options currently only work post Matlab R2016a ,'XLim',[Min_time Max_time],'XLim',[Min_time Max_time] -if Matlab_ver >= 2016 - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','origin',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim,'XTick',[Min_time:Timet_step:Max_time], ... - 'box','off', 'Color','none','xticklabels',xticks_labels); -else - set(r_ax,'FontSize',tsize,'FontWeight','bold','XAxisLocation','bottom',... - 'XGrid','on','YGrid','on','YTick',yticks,'YTickLabel',Ylabels_new, ... - 'YLim',newlim, 'XTick',[Min_time:Timet_step:Max_time], ... - 'box','off', 'Color','none','xticklabels',xticks_labels); - hline(0,'k'); % backup xaxis -end -if numel(offset)>1 - set(r_ax, 'XTick', [], 'XTickLabel', []) -end - -%%%%%%%%%%%% -hold(r_ax,'off'); -% r_ax.Position(2) =r_ax.Position(2)-5; -line_colors_ldg = erpworkingmemory('PWColor'); -if isempty(line_colors_ldg) - line_colors_ldg = get_colors(numel(ndata)); -end - -if size(line_colors_ldg,1)~= numel(ndata) - if numel(ndata)> size(line_colors_ldg,1) - line_colors_ldg = get_colors(numel(ndata)); - else - line_colors_ldg = line_colors_ldg(1:numel(ndata),:,:); - end -end - -for Numofplot = 1:size(plot_erp_data,2) - plot(r_ax_legend,[0 0],'Color',line_colors_ldg(Numofplot,:,:),'LineWidth',3) -end - -if Bin_chans == 0 - - Leg_Name = {}; - - for Numofbin = 1:numel(Bins) - Leg_Name{Numofbin} = strcat('Bin',num2str(Bins(Numofbin))); - - end - -else - for Numofchan = 1:numel(Elecs_shown) - Leg_Name{Numofchan} = Elec_list{Numofchan}; - end -end -legend(r_ax_legend,Leg_Name,'FontSize',14,'TextColor','blue'); -legend(r_ax_legend,'boxoff'); -% title(here_lgd,'Legend'); - -% fix scaling shrinkage -pos_fix = r_ax.Position; -pos_fix(2) = 1; % Start at the bottom -pos_fix(4) = pb_height - 1; % fill the height; - -gui_erp.plotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high -gui_erp.plotgrid.Heights(3) = 30; % set the second element (x axis) to 30px high -gui_erp.plotgrid.Units = 'pixels'; -if splot_n*pb_height<(gui_erp.plotgrid.Position(4)-gui_erp.plotgrid.Heights(1))&&Fill - pb_height = (gui_erp.plotgrid.Position(4)-gui_erp.plotgrid.Heights(1)-gui_erp.plotgrid.Heights(2))/splot_n; -end - -gui_erp.ViewAxes.Heights = splot_n*pb_height; -gui_erp.plotgrid.Units = 'normalized'; - -end % redrawDemo - - -function colors = get_colors(ncolors) -% Each color gets 1 point divided into up to 2 of 3 groups (RGB). -degree_step = 6/ncolors; -angles = (0:ncolors-1)*degree_step; -colors = nan(numel(angles),3); -for i = 1:numel(angles) - if angles(i) < 1 - colors(i,:) = [1 (angles(i)-floor(angles(i))) 0]*0.75; - elseif angles(i) < 2 - colors(i,:) = [(1-(angles(i)-floor(angles(i)))) 1 0]*0.75; - elseif angles(i) < 3 - colors(i,:) = [0 1 (angles(i)-floor(angles(i)))]*0.75; - elseif angles(i) < 4 - colors(i,:) = [0 (1-(angles(i)-floor(angles(i)))) 1]*0.75; - elseif angles(i) < 5 - colors(i,:) = [(angles(i)-floor(angles(i))) 0 1]*0.75; - else - colors(i,:) = [1 0 (1-(angles(i)-floor(angles(i))))]*0.75; - end -end -end - - - -%------------------Display the waveform for proir ERPset-------------------- -function page_minus(~,~) -global observe_ERPDAT; -global gui_erp; - - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); - - -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index-1; -Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end - -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); - - -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); - - -observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 0 0]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -gui_erp.pageinfo_minus.Enable = Enable_minus; -gui_erp.pageinfo_plus.Enable = Enable_plus; -% f_redrawERP_mt_viewer(); -gui_erp.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -gui_erp.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -end - - - - - -%------------------Display the waveform for next ERPset-------------------- -function page_plus(~,~) -global observe_ERPDAT; -global gui_erp; - - -S_ws_geterpset= estudioworkingmemory('selectederpstudio'); -if isempty(S_ws_geterpset) - S_ws_geterpset = observe_ERPDAT.CURRENTERP; - - if isempty(S_ws_geterpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_ws_geterpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); -end - -S_ws_getbinchan = estudioworkingmemory('geterpbinchan'); - - - - -S_ws_getbinchan.Select_index = S_ws_getbinchan.Select_index+1; -Current_erp_Index = S_ws_geterpset(S_ws_getbinchan.Select_index); -if Current_erp_Index > length(observe_ERPDAT.ALLERP) - beep; - disp('Waiting for modifing'); - return; -end - -observe_ERPDAT.CURRENTERP = Current_erp_Index; -observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_erp_Index); - -estudioworkingmemory('geterpbinchan',S_ws_getbinchan); - -observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - - -if length(S_ws_geterpset) ==1 - Enable_minus = 'off'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 0 0]; -else - - if S_ws_getbinchan.Select_index ==1 - Enable_minus = 'off'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [1 1 1]; - elseif S_ws_getbinchan.Select_index == length(S_ws_geterpset) - Enable_minus = 'on'; - Enable_plus = 'off'; - Enable_plus_BackgroundColor = [0 0 0]; - Enable_minus_BackgroundColor = [0 1 0]; - - - else - Enable_minus = 'on'; - Enable_plus = 'on'; - Enable_plus_BackgroundColor = [0 1 0]; - Enable_minus_BackgroundColor = [0 1 0]; - end -end -gui_erp.pageinfo_minus.Enable = Enable_minus; -gui_erp.pageinfo_plus.Enable = Enable_plus; -gui_erp.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; -gui_erp.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; -end - - diff --git a/studio_functions/Functions/EStudio/ERP Tab/working_mem_save_load.m b/studio_functions/Functions/EStudio/ERP Tab/working_mem_save_load.m index f58a2338..e8cbec66 100755 --- a/studio_functions/Functions/EStudio/ERP Tab/working_mem_save_load.m +++ b/studio_functions/Functions/EStudio/ERP Tab/working_mem_save_load.m @@ -59,15 +59,11 @@ % save save(fullfile(wm_pathname, wm_fname), 'vmemoryerp'); - catch errordlg('Memory save problem. Perhaps memory was empty?'); end - - - elseif save_or_load == 2 diff --git a/studio_functions/Functions/estudioworking_mem_save_load.m b/studio_functions/Functions/estudioworking_mem_save_load.m new file mode 100644 index 00000000..33a50240 --- /dev/null +++ b/studio_functions/Functions/estudioworking_mem_save_load.m @@ -0,0 +1,68 @@ +% PURPOSE: saves or loads the ERPLAB Studio working memory to another location +% +% FORMAT +% +% estudioworking_mem_save_load(save_or_load) +% +% INPUT +% +% save_or_load - 1 for save; 2 for load +% +% OUTPUT +% +% Mat-file .erpm written to disk, or memory structure loaded. +% +% *** This function is part of ERPLAB StudioToolbox *** +% Author: Guanghui Zhang +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + + + + + +function [wm_loaded] = estudioworking_mem_save_load(save_or_load) + +if save_or_load == 1 + + wm_loaded = []; + + % prompt for path with file browser ui + [wm_fname, wm_pathname] = uiputfile({'*.erpm', 'ERP Studio working memory file (*.erpm)'; + '*.*' , 'All Files (*.*)'},'Save working memory file as',... + 'custom_memoryerp.erpm'); + + try + vmemoryestudio = evalin('base', 'vmemoryestudio'); + + % save + save(fullfile(wm_pathname, wm_fname), 'vmemoryestudio'); + + catch + errordlg('Memory save problem. Perhaps memory was empty?'); + end + + +elseif save_or_load == 2 + + + % prompt for path with file browser ui + [wm_load_fname, wm_load_pathname] = uigetfile({'*.erpm', 'ERP Studio working memory file (*.erpm)'; + '*.*' , 'All Files (*.*)'},'Pick an existing working memory file to load',... + 'custom_memoryerp.erpm'); + if isempty(wm_load_pathname) || length(wm_load_pathname)==1 + beep; + disp('User selected cancel'); + wm_loaded =[]; + return; + end + wm_loaded = load(fullfile(wm_load_pathname,wm_load_fname), '-mat'); + +else + errordlg('WM save function error?'); +end + +end + diff --git a/studio_functions/estudioworkingmemory.m b/studio_functions/Functions/estudioworkingmemory.m similarity index 86% rename from studio_functions/estudioworkingmemory.m rename to studio_functions/Functions/estudioworkingmemory.m index 85e8d42e..febe12f1 100755 --- a/studio_functions/estudioworkingmemory.m +++ b/studio_functions/Functions/estudioworkingmemory.m @@ -2,7 +2,7 @@ % % FORMAT : % -% output = erpworkingmemory(field, input2store) +% output = estudioworkingmemory(field, input2store) % % INPUTS : % @@ -17,12 +17,12 @@ % % EXAMPLE 1: encode pop_appenderp's memory (values currently being used) % -% erpworkingmemory('pop_appenderp', { optioni, erpset, prefixlist }); +% estudioworkingmemory('pop_appenderp', { optioni, erpset, prefixlist }); % % % EXAMPLE 2: retrieve pop_appenderp's memory (values last used) % -% def = erpworkingmemory('pop_appenderp'); +% def = estudioworkingmemory('pop_appenderp'); % % % *** This function is part of ERPLAB Toolbox *** @@ -30,7 +30,7 @@ % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2009 & 2022 +% 2009 & 2024 %b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b % @@ -66,7 +66,6 @@ end - if nargin==1 % read if ~isempty(vmemoryestudio) % variable at the workspace for storing/reading memory if isfield(vmemoryestudio, field) @@ -78,13 +77,10 @@ try p = which('o_ERPDAT'); p = p(1:findstr(p,'o_ERPDAT.m')-1); - v = load(fullfile(p,'memoryerpstudiopanels.erpm'), '-mat'); - + v = load(fullfile(p,'memoryerpstudio.erpm'), '-mat'); catch - - msgboxText = ['EStudio (memoryerpstudiopanels.m) could not find "memoryerpstudiopanels.erpm" or does not have permission for reading it.\n'... + msgboxText = ['EStudio (memoryerpstudio.m) could not find "memoryerpstudio.erpm" or does not have permission for reading it.\n'... 'Please, run EStudio again or go to EStudio''s Setting menu and specify/create a new memory file.\n']; - try cprintf([0.45 0.45 0.45], msgboxText'); catch @@ -102,7 +98,7 @@ return elseif nargin==2 % write if ~isempty(vmemoryestudio) % variable at the workspace for storing/reading memory - try + try vmemoryestudio.(field) = input2store; assignin('base','vmemoryestudio', vmemoryestudio); catch @@ -119,9 +115,9 @@ eval([field '=input2store;']) p = which('o_ERPDAT'); p = p(1:findstr(p,'o_ERPDAT.m')-1); - save(fullfile(p,'memoryerpstudiopanels.erpm'), field,'-append'); + save(fullfile(p,'memoryerpstudio.erpm'), field,'-append'); catch - msgboxText = ['EStudio could not find "memoryerpstudiopanels.erpm" or does not have permission for writting on it.\n'... + msgboxText = ['EStudio could not find "memoryerpstudio.erpm" or does not have permission for writting on it.\n'... 'Please, run EStudio again or go to EStudio''s Setting menu and specify/create a new memory file.\n']; try diff --git a/studio_functions/Functions/etudioamnesia.m b/studio_functions/Functions/etudioamnesia.m new file mode 100644 index 00000000..a0c99428 --- /dev/null +++ b/studio_functions/Functions/etudioamnesia.m @@ -0,0 +1,97 @@ +% PURPOSE: erases ERPLAB Studio's memory (values are those last used. Default ones are reloaded) +% +% FORMAT +% +% erplabamnesia(warningop) +% +% INPUT: +% +% warningop - display warning message. 1 yes; 0 no +% +% +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + + + +function runindex = etudioamnesia(warningop) +runindex =0; +if nargin<1 + warningop = 0; +end +if warningop>0 + %Warning Message + question = ['Resetting ERPLAB Studio''s working memory will\n'... + 'Clear all memory and cannot be recovered\n'... + 'Do you want to continue anyway?']; + title = 'ERPLAB Studio: Reset ERPLAB Studio''s working memory Confirmation'; + button = askquest(sprintf(question), title); + + if ~strcmpi(button,'yes') + return + end +end + +erplab_default_values % script +% check variable at workspace +try + vmemoryestudio = evalin('base', 'vmemoryestudio'); +catch + vmemoryestudio = []; +end +if isempty(vmemoryestudio) + fprintf('\n* FYI: ERPLAB Studio''s working memory variable does not exist at workspace.\n') +else + if isfield(vmemoryestudio, 'mshock') + mshock = vmemoryestudio.mshock; + else + mshock = 0; + end + clear vmemoryestudio + mshock = mshock + 1; + + % + % IMPORTANT: If this strucure (vmemoryestudio) is modified then also must be modified the same line at o_ERPDAT.m + % + vmemoryestudio = struct('erplabrel',erplabrel,'erplabver',erplabver,'ColorB',ColorB,'ColorF',ColorF,'fontsizeGUI',fontsizeGUI,... + 'fontunitsGUI',fontunitsGUI,'mshock',mshock, 'errorColorF', errorColorF, 'errorColorB', errorColorB); + assignin('base','vmemoryestudio',vmemoryestudio); + fprintf('\n* ERPLAB Studio''s working memory was reset (variable "vmemoryestudio", at workspace, was rebuild with default values).\n'); +end + +% check file for memory +p = which('o_ERPDAT'); +p = p(1:findstr(p,'o_ERPDAT.m')-1); +mfile = fullfile(p,'memoryerpstudio.erpm'); + +if exist(mfile, 'file')==2 + v = load(fullfile(p,'memoryerpstudio.erpm'), '-mat'); + if isfield(v, 'mshock') + mshock = v.mshock; + else + mshock = 0; + end + + recycle on; + delete(mfile) + pause(0.1) + recycle off + mshock = mshock + 1; + fprintf('\n*** ERPLAB Studio WARNING: ERPLAB Studio''s working memory was wiped out. Default values will be used.\n\n') + + % + % IMPORTANT: If this file (saved variables inside memoryerpstudio.erpm) is modified then also must be modified the same line at o_ERPDAT.m + % + save(fullfile(p,'memoryerpstudio.erpm'),'erplabrel','erplabver','ColorB','ColorF','errorColorB', 'errorColorF','fontsizeGUI','fontunitsGUI','mshock'); +else + fprintf('\n* FYI: ERPLAB Studio''s working memory file does not exist.\n') + return +end +if mshock>=30 && rand>0.8 + fprintf('\n\nIs it not enough???\n\n') +end +runindex=1; \ No newline at end of file diff --git a/studio_functions/Functions/get_studio_indexes.m b/studio_functions/Functions/get_studio_indexes.m new file mode 100644 index 00000000..6c3aba99 --- /dev/null +++ b/studio_functions/Functions/get_studio_indexes.m @@ -0,0 +1,28 @@ + + +%Author: Guanghui ZHANG +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +%Apr. 2024 + +% ERPLAB Studio + + + + + +function [EEGsetIndex,EEGchanindex, ERPsetindex, ERPchanindex, ERPbinindex,erpcom]= get_studio_indexes(); + +erpcom = ''; + +EEGsetIndex= estudioworkingmemory('EEGArray'); +EEGchanindex= estudioworkingmemory('EEG_ChanArray'); + +ERPsetindex = estudioworkingmemory('selectederpstudio'); +ERPchanindex = estudioworkingmemory('ERP_BinArray'); +ERPbinindex = estudioworkingmemory('ERP_ChanArray'); + +command = sprintf('[EEGsetIndex,EEGchanindex, ERPsetindex, ERPchanindex, ERPbinindex,erpcom]= get_studio_indexes();'); + +end \ No newline at end of file diff --git a/studio_functions/painterplabstudio.m b/studio_functions/Functions/painterplabstudio.m similarity index 97% rename from studio_functions/painterplabstudio.m rename to studio_functions/Functions/painterplabstudio.m index bdfbac85..63aa2e91 100755 --- a/studio_functions/painterplabstudio.m +++ b/studio_functions/Functions/painterplabstudio.m @@ -50,8 +50,8 @@ ColorF = [0 0 0]; end if isempty(ColorB) - ColorB = [0.95 0.95 0.95]; - %ColorB = [0.83 0.82 0.79]; +% ColorB = [0.7020 0.7647 0.8392]; + ColorB = [0.7020 0.7647 0.8392]; end if isempty(ColorF) ColorF = [0 0 0]; diff --git a/studio_functions/setfonterplabestudio.m b/studio_functions/Functions/setfonterplabestudio.m similarity index 100% rename from studio_functions/setfonterplabestudio.m rename to studio_functions/Functions/setfonterplabestudio.m diff --git a/studio_functions/GUI Layout Toolbox/layout/+uix/BoxPanel.m b/studio_functions/GUI Layout Toolbox/layout/+uix/BoxPanel.m index 322265a4..105bfbaf 100644 --- a/studio_functions/GUI Layout Toolbox/layout/+uix/BoxPanel.m +++ b/studio_functions/GUI Layout Toolbox/layout/+uix/BoxPanel.m @@ -9,9 +9,9 @@ % panel shows one of its contents and hides the others. % % See also: uix.Panel, uipanel, uix.CardPanel - - % Copyright 2009-2020 The MathWorks, Inc. - + + % Copyright 2009-2024 The MathWorks, Inc. + properties( Dependent ) TitleColor % title background color [RGB] Minimized % minimized [true|false] @@ -21,15 +21,15 @@ HelpFcn % help callback CloseRequestFcn % close request callback end - + properties( Dependent, SetAccess = private ) TitleHeight % title panel height [pixels] end - + properties( Access = private ) TitleBox % title bar box TitleText % title text label - EmptyTitle = '' % title when empty, [] otherwise + Title_ = '' % cache of title TitleAccess = 'public' % 'private' when getting or setting Title, 'public' otherwise TitleHeight_ = -1 % cache of title text height (-1 denotes stale cache) MinimizeButton % title button @@ -39,12 +39,12 @@ Docked_ = true % backing for Docked Minimized_ = false % backing for Minimized end - + properties( Constant, Access = private ) NullTitle = char.empty( [2 0] ) % an obscure empty string, the actual panel Title BlankTitle = ' ' % a non-empty blank string, the empty uicontrol String end - + properties MaximizeTooltipString = 'Expand this panel' % tooltip string MinimizeTooltipString = 'Collapse this panel' % tooltip string @@ -53,9 +53,9 @@ HelpTooltipString = 'Get help on this panel' % tooltip string CloseTooltipString = 'Close this panel' % tooltip string end - + methods - + function obj = BoxPanel( varargin ) %uix.BoxPanel Box panel constructor % @@ -63,14 +63,14 @@ % % p = uix.BoxPanel(p1,v1,p2,v2,...) sets parameter p1 to value % v1, etc. - + % Define default colors foregroundColor = [1 1 1]; backgroundColor = [0.05 0.25 0.5]; - + % Set default colors obj.ForegroundColor = foregroundColor; - + % Create panels and decorations titleBox = uix.HBox( 'Internal', true, 'Parent', obj, ... 'Units', 'pixels', 'BackgroundColor', backgroundColor ); @@ -78,7 +78,7 @@ 'ForegroundColor', foregroundColor, ... 'BackgroundColor', backgroundColor, ... 'String', obj.BlankTitle, 'HorizontalAlignment', 'left' ); - + % Create buttons minimizeButton = uix.Text( ... 'ForegroundColor', foregroundColor, ... @@ -98,7 +98,7 @@ 'BackgroundColor', backgroundColor, ... 'FontWeight', 'bold', 'String', char( 215 ), ... 'TooltipString', obj.CloseTooltipString, 'Enable', 'on' ); - + % Store properties obj.Title = obj.NullTitle; obj.TitleBox = titleBox; @@ -107,7 +107,7 @@ obj.DockButton = dockButton; obj.HelpButton = helpButton; obj.CloseButton = closeButton; - + % Create listeners addlistener( obj, 'BorderWidth', 'PostSet', ... @obj.onBorderWidthChanged ); @@ -131,10 +131,10 @@ @obj.onTitleReturned ); addlistener( obj, 'Title', 'PostSet', ... @obj.onTitleChanged ); - + % Draw buttons - obj.redrawButtons() - + obj.redrawButtons() + % Set properties try uix.set( obj, varargin{:} ) @@ -142,21 +142,21 @@ delete( obj ) e.throwAsCaller() end - + end % constructor - + end % structors - + methods - + function value = get.TitleColor( obj ) - + value = obj.TitleBox.BackgroundColor; - + end % get.TitleColor - + function set.TitleColor( obj, value ) - + % Set obj.TitleBox.BackgroundColor = value; obj.TitleText.BackgroundColor = value; @@ -164,65 +164,65 @@ obj.DockButton.BackgroundColor = value; obj.HelpButton.BackgroundColor = value; obj.CloseButton.BackgroundColor = value; - + end % set.TitleColor - + function value = get.CloseRequestFcn( obj ) - + value = obj.CloseButton.Callback; - + end % get.CloseRequestFcn - + function set.CloseRequestFcn( obj, value ) - + % Set obj.CloseButton.Callback = value; - + % Mark as dirty obj.redrawButtons() - + end % set.CloseRequestFcn - + function value = get.DockFcn( obj ) - + value = obj.DockButton.Callback; - + end % get.DockFcn - + function set.DockFcn( obj, value ) - + % Set obj.DockButton.Callback = value; - + % Mark as dirty obj.redrawButtons() - + end % set.DockFcn - + function value = get.HelpFcn( obj ) - + value = obj.HelpButton.Callback; - + end % get.HelpFcn - + function set.HelpFcn( obj, value ) - + % Set obj.HelpButton.Callback = value; - + % Mark as dirty obj.redrawButtons() - + end % set.HelpFcn - + function value = get.MinimizeFcn( obj ) - + value = obj.MinimizeButton.Callback; - + end % get.MinimizeFcn - + function set.MinimizeFcn( obj, value ) - + % Set obj.MinimizeButton.Callback = value; obj.TitleText.Callback = value; @@ -231,184 +231,184 @@ else obj.TitleText.Enable = 'on'; end - + % Mark as dirty obj.redrawButtons() - + end % set.MinimizeFcn - + function value = get.Docked( obj ) - + value = obj.Docked_; - + end % get.Docked - + function set.Docked( obj, value ) - + % Check assert( islogical( value ) && isequal( size( value ), [1 1] ), ... 'uix:InvalidPropertyValue', ... 'Property ''Docked'' must be true or false.' ) - + % Set obj.Docked_ = value; - + % Mark as dirty obj.redrawButtons() - + end % set.Docked - + function value = get.Minimized( obj ) - + value = obj.Minimized_; - + end % get.Minimized - + function set.Minimized( obj, value ) - + % Check assert( islogical( value ) && isequal( size( value ), [1 1] ), ... 'uix:InvalidPropertyValue', ... 'Property ''Minimized'' must be true or false.' ) - + % Set obj.Minimized_ = value; - + % Show selected child obj.showSelection() - + % Mark as dirty obj.Dirty = true; - + end % set.Minimized - + function value = get.TitleHeight( obj ) - + value = obj.TitleBox.Position(4); - + end % get.TitleHeight - + function set.MaximizeTooltipString( obj, value ) - + % Check value = uix.validateScalarStringOrCharacterArray( value, ... 'MaximizeTooltipString' ); - + % Set obj.MaximizeTooltipString = value; - + % Mark as dirty obj.redrawButtons() - + end % set.MaximizeTooltipString - + function set.MinimizeTooltipString( obj, value ) - + % Check value = uix.validateScalarStringOrCharacterArray( value, ... 'MinimizeTooltipString' ); - + % Set obj.MinimizeTooltipString = value; - + % Mark as dirty obj.redrawButtons() - + end % set.MinimizeTooltipString - + function set.UndockTooltipString( obj, value ) - + % Check value = uix.validateScalarStringOrCharacterArray( value, ... 'UndockTooltipString' ); - + % Set obj.UndockTooltipString = value; - + % Mark as dirty obj.redrawButtons() - + end % set.UndockTooltipString - + function set.DockTooltipString( obj, value ) - + % Check value = uix.validateScalarStringOrCharacterArray( value, ... 'DockTooltipString' ); - + % Set obj.DockTooltipString = value; - + % Mark as dirty obj.redrawButtons() - + end % set.DockTooltipString - + function set.HelpTooltipString( obj, value ) - + % Check value = uix.validateScalarStringOrCharacterArray( value, ... 'HelpTooltipString' ); - + % Set obj.HelpTooltipString = value; - + % Mark as dirty obj.redrawButtons() - + end % set.HelpTooltipString - + function set.CloseTooltipString( obj, value ) - + % Check value = uix.validateScalarStringOrCharacterArray( value, ... 'CloseTooltipString' ); - + % Set obj.CloseTooltipString = value; - + % Mark as dirty obj.redrawButtons() - + end % set.CloseTooltipString - + end % accessors - + methods( Access = private ) - + function onBorderWidthChanged( obj, ~, ~ ) - + % Mark as dirty obj.Dirty = true; - + end % onBorderWidthChanged - + function onBorderTypeChanged( obj, ~, ~ ) - + % Mark as dirty obj.Dirty = true; - + end % onBorderTypeChanged - + function onFontAngleChanged( obj, ~, ~ ) - + obj.TitleText.FontAngle = obj.FontAngle; - + end % onFontAngleChanged - + function onFontNameChanged( obj, ~, ~ ) - + % Set obj.TitleText.FontName = obj.FontName; - + % Mark as dirty obj.TitleHeight_ = -1; obj.Dirty = true; - + end % onFontNameChanged - + function onFontSizeChanged( obj, ~, ~ ) - + % Set fontSize = obj.FontSize; obj.TitleText.FontSize = fontSize; @@ -416,99 +416,94 @@ function onFontSizeChanged( obj, ~, ~ ) obj.CloseButton.FontSize = fontSize; obj.DockButton.FontSize = fontSize; obj.MinimizeButton.FontSize = fontSize; - + % Mark as dirty obj.TitleHeight_ = -1; obj.Dirty = true; - + end % onFontSizeChanged - + function onFontUnitsChanged( obj, ~, ~ ) - + fontUnits = obj.FontUnits; obj.TitleText.FontUnits = fontUnits; obj.HelpButton.FontUnits = fontUnits; obj.CloseButton.FontUnits = fontUnits; obj.DockButton.FontUnits = fontUnits; obj.MinimizeButton.FontUnits = fontUnits; - + end % onFontUnitsChanged - + function onFontWeightChanged( obj, ~, ~ ) - + obj.TitleText.FontWeight = obj.FontWeight; - + end % onFontWeightChanged - + function onForegroundColorChanged( obj, ~, ~ ) - + foregroundColor = obj.ForegroundColor; obj.TitleText.ForegroundColor = foregroundColor; obj.MinimizeButton.ForegroundColor = foregroundColor; obj.DockButton.ForegroundColor = foregroundColor; obj.HelpButton.ForegroundColor = foregroundColor; obj.CloseButton.ForegroundColor = foregroundColor; - + end % onForegroundColorChanged - + function onTitleReturning( obj, ~, ~ ) - - if strcmp( obj.TitleAccess, 'public' ) - + + if strcmp( obj.TitleAccess, 'public' ) && isjsdrawing() == false obj.TitleAccess = 'private'; % start - if ischar( obj.EmptyTitle ) - obj.Title = obj.EmptyTitle; - else - obj.Title = obj.TitleText.String; - end - + obj.Title = obj.Title_; end - + end % onTitleReturning - + function onTitleReturned( obj, ~, ~ ) - - obj.Title = obj.NullTitle; % unset Title + + if isjsdrawing() == false + obj.Title = obj.NullTitle; % unset Title + end obj.TitleAccess = 'public'; % finish - + end % onTitleReturned - + function onTitleChanged( obj, ~, ~ ) - - if strcmp( obj.TitleAccess, 'public' ) - + + if strcmp( obj.TitleAccess, 'public' ) && isjsdrawing() == false + % Set obj.TitleAccess = 'private'; % start title = obj.Title; + obj.Title_ = title; if isempty( title ) - obj.EmptyTitle = title; % store - obj.TitleText.String = obj.BlankTitle; % set String to blank + obj.TitleText.String = obj.BlankTitle; else - obj.EmptyTitle = []; % not empty obj.TitleText.String = title; % set String to title end obj.Title = obj.NullTitle; % unset Title obj.TitleAccess = 'public'; % finish - + % Mark as dirty obj.TitleHeight_ = -1; obj.Dirty = true; - + end - + end % onTitleChanged - + end % property event handlers - + methods( Access = protected ) - + function redraw( obj ) %redraw Redraw % % p.redraw() redraws the panel. % % See also: redrawButtons - + % Compute positions bounds = hgconvertunits( ancestor( obj, 'figure' ), ... [0 0 1 1], 'normalized', 'pixels', obj ); @@ -526,7 +521,7 @@ function redraw( obj ) cH = max( bounds(4) - tH - 2 * p, 1 ); cY = tY - p - cH; contentsPosition = [cX cY cW cH]; - + % Redraw contents selection = obj.Selection_; if selection ~= 0 @@ -534,18 +529,18 @@ function redraw( obj ) end obj.TitleBox.Position = [tX tY tW tH]; obj.redrawButtons() - + end % redraw - + function showSelection( obj ) %showSelection Show selected child, hide the others % % c.showSelection() shows the selected child of the container % c, and hides the others. - + % Call superclass method showSelection@uix.mixin.Panel( obj ) - + % If minimized, hide selected contents too selection = obj.Selection_; if selection ~= 0 && obj.Minimized_ @@ -563,13 +558,13 @@ function showSelection( obj ) child.Position(1) = -child.Position(3)-margin; end end - + end % showSelection - + end % template methods - + methods( Access = private ) - + function redrawButtons( obj ) %redrawButtons Redraw buttons % @@ -577,7 +572,7 @@ function redrawButtons( obj ) % % Buttons use unicode arrow symbols: % https://en.wikipedia.org/wiki/Arrow_%28symbol%29#Arrows_in_Unicode - + % Retrieve button box and buttons box = obj.TitleBox; titleText = obj.TitleText; @@ -585,14 +580,14 @@ function redrawButtons( obj ) dockButton = obj.DockButton; helpButton = obj.HelpButton; closeButton = obj.CloseButton; - + % Detach all buttons titleText.Parent = []; minimizeButton.Parent = []; dockButton.Parent = []; helpButton.Parent = []; closeButton.Parent = []; - + % Attach active buttons titleText.Parent = box; minimize = ~isempty( obj.MinimizeFcn ); @@ -617,7 +612,7 @@ function redrawButtons( obj ) closeButton.TooltipString = obj.CloseTooltipString; box.Widths(end) = closeButton.Extent(3); end - + % Update icons if obj.Minimized_ minimizeButton.String = char( 9662 ); @@ -633,9 +628,21 @@ function redrawButtons( obj ) dockButton.String = char( 8600 ); dockButton.TooltipString = obj.DockTooltipString; end - + end % redrawButtons - + end % helper methods - -end % classdef \ No newline at end of file + +end % classdef + +function tf = isjsdrawing() +%isjsdrawing Detect JavaScript drawing, which accesses properties + +s = dbstack(); +tf = false; +for ii = 1:numel( s ) + n = strsplit( s(ii).name, "." ); + if n(1) == "WebComponentController", tf = true; break; end +end + +end % isjsdrawing \ No newline at end of file diff --git a/studio_functions/GUI Layout Toolbox/layout/+uix/Panel.m b/studio_functions/GUI Layout Toolbox/layout/+uix/Panel.m index 9047da3c..82d8cecd 100644 --- a/studio_functions/GUI Layout Toolbox/layout/+uix/Panel.m +++ b/studio_functions/GUI Layout Toolbox/layout/+uix/Panel.m @@ -8,19 +8,19 @@ % contents and hides the others. % % See also: uix.CardPanel, uix.BoxPanel, uipanel - - % Copyright 2009-2020 The MathWorks, Inc. - + + % Copyright 2009-2024 The MathWorks, Inc. + methods - + function obj = Panel( varargin ) %uix.Panel Standard panel constructor % % p = uix.Panel() constructs a standard panel. % % p = uix.Panel(p1,v1,p2,v2,...) sets parameter p1 to value - % v1, etc. - + % v1, etc. + % Set properties try uix.set( obj, varargin{:} ) @@ -28,15 +28,20 @@ delete( obj ) e.throwAsCaller() end - + + % Disable auto resize + if isprop( obj, 'AutoResizeChildren' ) + obj.AutoResizeChildren = 'off'; + end + end % constructor - + end % structors - + methods( Access = protected ) - + function redraw( obj ) - + % Compute positions bounds = hgconvertunits( ancestor( obj, 'figure' ), ... [0 0 1 1], 'normalized', 'pixels', obj ); @@ -44,15 +49,15 @@ function redraw( obj ) xSizes = uix.calcPixelSizes( bounds(3), -1, 1, padding, 0 ); ySizes = uix.calcPixelSizes( bounds(4), -1, 1, padding, 0 ); position = [padding+1 padding+1 xSizes ySizes]; - + % Redraw contents selection = obj.Selection_; if selection ~= 0 uix.setPosition( obj.Contents_(selection), position, 'pixels' ) end - + end % redraw - + end % template methods - + end % classdef \ No newline at end of file diff --git a/studio_functions/GUI Layout Toolbox/layout/+uix/ScrollingPanel.m b/studio_functions/GUI Layout Toolbox/layout/+uix/ScrollingPanel.m index bf0fd5fd..84e5e5ef 100644 --- a/studio_functions/GUI Layout Toolbox/layout/+uix/ScrollingPanel.m +++ b/studio_functions/GUI Layout Toolbox/layout/+uix/ScrollingPanel.m @@ -484,15 +484,15 @@ function addChild( obj, child ) verticalSlider = matlab.ui.control.UIControl( ... 'Internal', true, 'Parent', obj, ... 'Units', 'pixels', 'Style', 'slider', ... - 'BackgroundColor', obj.BackgroundColor ); + 'BackgroundColor', [0.9 0.9 0.9] ); horizontalSlider = matlab.ui.control.UIControl( ... 'Internal', true, 'Parent', obj, ... 'Units', 'pixels', 'Style', 'slider', ... - 'BackgroundColor', obj.BackgroundColor ); + 'BackgroundColor', [0.9 0.9 0.9] ); blankingPlate = matlab.ui.control.UIControl( ... 'Internal', true, 'Parent', obj, ... 'Units', 'pixels', 'Style', 'text', 'Enable', 'inactive', ... - 'BackgroundColor', obj.BackgroundColor ); + 'BackgroundColor', [0.9 0.9 0.9] ); % Add to sizes obj.Widths_(end+1,:) = -1; @@ -668,8 +668,8 @@ function onMouseScrolled( obj, ~, eventData ) function onBackgroundColorChanged( obj, ~, ~ ) %onBackgroundColorChanged Handler for BackgroundColor changes - set( obj.HorizontalSliders, 'BackgroundColor', obj.BackgroundColor ) - set( obj.VerticalSliders, 'BackgroundColor', obj.BackgroundColor ) + set( obj.HorizontalSliders, 'BackgroundColor', [0.9 0.9 0.9] ) + set( obj.VerticalSliders, 'BackgroundColor', [0.9 0.9 0.9] ) set( obj.BlankingPlates, 'BackgroundColor', obj.BackgroundColor ) end % onBackgroundColorChanged diff --git a/studio_functions/GUI Layout Toolbox/layout/+uix/Text.m b/studio_functions/GUI Layout Toolbox/layout/+uix/Text.m index 30f7a23a..2957a686 100644 --- a/studio_functions/GUI Layout Toolbox/layout/+uix/Text.m +++ b/studio_functions/GUI Layout Toolbox/layout/+uix/Text.m @@ -9,27 +9,27 @@ % * Fire a Callback when the user clicks on the text % % See also: uicontrol - - % Copyright 2009-2020 The MathWorks, Inc. - + + % Copyright 2009-2024 The MathWorks, Inc. + properties( Dependent ) BackgroundColor end - + properties( Dependent, SetAccess = private ) BeingDeleted end - + properties( Dependent ) Callback DeleteFcn Enable end - + properties( Dependent, SetAccess = private ) Extent end - + properties( Dependent ) FontAngle FontName @@ -45,11 +45,11 @@ Tag TooltipString end - + properties( Dependent, SetAccess = private ) Type end - + properties( Dependent ) UIContextMenu Units @@ -57,7 +57,7 @@ VerticalAlignment Visible end - + properties( Access = private ) Container % container Checkbox % checkbox, used for label @@ -67,19 +67,19 @@ FigureObserver % observer FigureListener % listener end - + properties( Constant, Access = private ) Margin = checkBoxLabelOffset() % checkbox size end - + methods - + function obj = Text( varargin ) %uix.Text Text control % % t = uix.Text(p1,v1,p2,v2,...) constructs a text control and % sets parameter p1 to value v1, etc. - + % Create graphics container = uicontainer( 'Parent', [], ... 'Units', get( 0, 'DefaultUicontrolUnits' ), ... @@ -93,19 +93,19 @@ screen = uicontrol( 'Parent', container, ... 'HandleVisibility', 'off', ... 'Style', 'text', 'Units', 'pixels' ); - + % Create observers and listeners figureObserver = uix.FigureObserver( container ); figureListener = event.listener( figureObserver, ... 'FigureChanged', @obj.onFigureChanged ); - + % Store properties obj.Container = container; obj.Checkbox = checkbox; obj.Screen = screen; obj.FigureObserver = figureObserver; obj.FigureListener = figureListener; - + % Set properties try uix.set( obj, varargin{:} ) @@ -113,380 +113,385 @@ delete( obj ) e.throwAsCaller() end - + end % constructor - + function delete( obj ) %delete Destructor - + delete( obj.Container ) - + end % destructor - + end % structors - + methods - + function value = get.BackgroundColor( obj ) - + value = obj.Checkbox.BackgroundColor; - + end % get.BackgroundColor - + function set.BackgroundColor( obj, value ) - + obj.Container.BackgroundColor = value; obj.Checkbox.BackgroundColor = value; obj.Screen.BackgroundColor = value; - + end % set.BackgroundColor - + function value = get.BeingDeleted( obj ) - + value = obj.Checkbox.BeingDeleted; - + end % get.BeingDeleted - + function value = get.Callback( obj ) - + value = obj.Checkbox.Callback; - + end % get.Callback - + function set.Callback( obj, value ) - + obj.Checkbox.Callback = value; - + end % set.Callback - + function value = get.DeleteFcn( obj ) - + value = obj.Checkbox.DeleteFcn; - + end % get.DeleteFcn - + function set.DeleteFcn( obj, value ) - + obj.Checkbox.DeleteFcn = value; - + end % set.DeleteFcn - + function value = get.Enable( obj ) - + value = obj.Checkbox.Enable; - + end % get.Enable - + function set.Enable( obj, value ) - + obj.Checkbox.Enable = value; - + end % set.Enable - + function value = get.Extent( obj ) - + + % Get checkbox text extent value = obj.Checkbox.Extent; - + + % Correct for large fonts, g3328399 + if obj.FontSize > 28 && ~isempty( ancestor( obj.Container, 'figure' ) ) + value = extent( obj.FontSize, obj.Checkbox.String ); + end + end % get.Extent - + function value = get.FontAngle( obj ) - + value = obj.Checkbox.FontAngle; - + end % get.FontAngle - + function set.FontAngle( obj, value ) - + % Set obj.Checkbox.FontAngle = value; - + % Mark as dirty obj.setDirty() - + end % set.FontAngle - + function value = get.FontName( obj ) - + value = obj.Checkbox.FontName; - + end % get.FontName - + function set.FontName( obj, value ) - + % Set obj.Checkbox.FontName = value; - + % Mark as dirty obj.setDirty() - + end % set.FontName - + function value = get.FontSize( obj ) - + value = obj.Checkbox.FontSize; - + end % get.FontSize - + function set.FontSize( obj, value ) - + % Set obj.Checkbox.FontSize = value; - + % Mark as dirty obj.setDirty() - + end % set.FontSize - + function value = get.FontUnits( obj ) - + value = obj.Checkbox.FontUnits; - + end % get.FontUnits - + function set.FontUnits( obj, value ) - + obj.Checkbox.FontUnits = value; - + end % set.FontUnits - + function value = get.FontWeight( obj ) - + value = obj.Checkbox.FontWeight; - + end % get.FontWeight - + function set.FontWeight( obj, value ) - + % Set obj.Checkbox.FontWeight = value; - + % Mark as dirty obj.setDirty() - + end % set.FontWeight - + function value = get.ForegroundColor( obj ) - + value = obj.Checkbox.ForegroundColor; - + end % get.ForegroundColor - + function set.ForegroundColor( obj, value ) - + obj.Checkbox.ForegroundColor = value; - + end % set.ForegroundColor - + function value = get.HandleVisibility( obj ) - + value = obj.Container.HandleVisibility; - + end % get.HandleVisibility - + function set.HandleVisibility( obj, value ) - + obj.Container.HandleVisibility = value; - + end % set.HandleVisibility - + function value = get.HorizontalAlignment( obj ) - + value = obj.Checkbox.HorizontalAlignment; - + end % get.HorizontalAlignment - + function set.HorizontalAlignment( obj, value ) - + % Set obj.Checkbox.HorizontalAlignment = value; - + % Mark as dirty obj.setDirty() - + end % set.HorizontalAlignment - + function value = get.Parent( obj ) - + value = obj.Container.Parent; - + end % get.Parent - + function set.Parent( obj, value ) - + obj.Container.Parent = value; - + end % set.Parent - + function value = get.Position( obj ) - + value = obj.Container.Position; - + end % get.Position - + function set.Position( obj, value ) - + obj.Container.Position = value; - + end % set.Position - + function value = get.String( obj ) - + value = obj.Checkbox.String; - + end % get.String - + function set.String( obj, value ) - + % Set obj.Checkbox.String = value; - + % Mark as dirty obj.setDirty() - + end % set.String - + function value = get.Tag( obj ) - + value = obj.Checkbox.Tag; - + end % get.Tag - + function set.Tag( obj, value ) - + obj.Checkbox.Tag = value; - + end % set.Tag - + function value = get.TooltipString( obj ) - + value = obj.Checkbox.TooltipString; - + end % get.TooltipString - + function set.TooltipString( obj, value ) - + obj.Checkbox.TooltipString = value; - + end % set.TooltipString - + function value = get.Type( obj ) - + value = obj.Checkbox.Type; - + end % get.Type - + function value = get.UIContextMenu( obj ) - + value = obj.Checkbox.UIContextMenu; - + end % get.UIContextMenu - + function set.UIContextMenu( obj, value ) - + obj.Checkbox.UIContextMenu = value; - + end % set.UIContextMenu - + function value = get.Units( obj ) - + value = obj.Container.Units; - + end % get.Units - + function set.Units( obj, value ) - + obj.Container.Units = value; - + end % set.Units - + function value = get.UserData( obj ) - + value = obj.Checkbox.UserData; - + end % get.UserData - + function set.UserData( obj, value ) - + obj.Checkbox.UserData = value; - + end % set.UserData - + function value = get.VerticalAlignment( obj ) - + value = obj.VerticalAlignment_; - + end % get.VerticalAlignment - + function set.VerticalAlignment( obj, value ) - + % Check - assert( ischar( value ) && ... - any( strcmp( value, {'top','middle','bottom'} ) ), ... + assert( any( strcmp( value, {'top','middle','bottom'} ) ), ... 'uix:InvalidPropertyValue', ... 'Property ''VerticalAlignment'' must be ''top'', ''middle'' or ''bottom''.' ) - + % Set - obj.VerticalAlignment_ = value; - + obj.VerticalAlignment_ = char( value ); + % Mark as dirty obj.setDirty() - + end % set.VerticalAlignment - + function value = get.Visible( obj ) - + value = obj.Container.Visible; - + end % get.Visible - + function set.Visible( obj, value ) - + obj.Container.Visible = value; - + end % set.Visible - + end % accessors - + methods( Access = private ) - + function onResized( obj, ~, ~ ) %onResized Event handler - + % Rooted, so redraw obj.redraw() - + end % onResized - + function onFigureChanged( obj, ~, eventData ) - + % If rooted, redraw if isempty( eventData.OldFigure ) && ... ~isempty( eventData.NewFigure ) && obj.Dirty obj.redraw() end - + end % onFigureChanged - + end % event handlers - + methods( Access = private ) - + function setDirty( obj ) %setDirty Mark as dirty % % t.setDirty() marks the text control t as dirty. If the text % control is rooted then it is redrawn immediately. If not % then the redraw is queued for when it is next rooted. - + if isempty( obj.FigureObserver.Figure ) obj.Dirty = true; % set flag else obj.Dirty = false; % unset flag obj.redraw() % redraw end - + end % setDirty - + function redraw( obj ) %redraw Redraw % @@ -494,14 +499,14 @@ function redraw( obj ) % requires the text control to be rooted. Methods should % request redraws using setDirty, rather than calling redraw % directly. - + c = obj.Container; b = obj.Checkbox; s = obj.Screen; bo = hgconvertunits( ancestor( obj, 'figure' ), ... [0 0 1 1], 'normalized', 'pixels', c ); % bounds m = obj.Margin; - e = b.Extent; + e = obj.Extent; switch b.HorizontalAlignment case 'left' x = 1 - m; @@ -522,11 +527,11 @@ function redraw( obj ) h = e(4); b.Position = [x y w h]; s.Position = [x y m h]; - + end % redraw - + end % helpers - + end % classdef function o = checkBoxLabelOffset() @@ -542,4 +547,15 @@ function redraw( obj ) end end -end % margin \ No newline at end of file +end % checkBoxLabelOffset + +function e = extent( fs, s ) +%extent Extent fallback for web graphics with large fonts + +f = figure( 'Visible', 'off' ); % create invisible *Java* figure +c = uicontrol( 'Parent', f, 'Style', 'checkbox', 'Units', 'pixels', ... + 'Position', [20 20 1000 200], 'FontSize', fs, 'String', s ); % text +e = c.Extent; % Java extents are correct and similar to JavaScript +delete( f ) % clean up + +end % extent \ No newline at end of file diff --git a/studio_functions/GUI Layout Toolbox/layout/Contents.m b/studio_functions/GUI Layout Toolbox/layout/Contents.m index caf540c3..742eb4bf 100644 --- a/studio_functions/GUI Layout Toolbox/layout/Contents.m +++ b/studio_functions/GUI Layout Toolbox/layout/Contents.m @@ -1,5 +1,5 @@ % GUI Layout Toolbox -% Version 2.3.6 (R2023a) 21-May-2023 +% Version 2.3.7 (R2023a) 31-May-2024 % % Panels % uix.Panel - arrange a single element inside a standard panel @@ -24,4 +24,4 @@ % uix.Empty - create an empty space % uix.tracking - track anonymized usage data -% Copyright 2009-2023 The MathWorks, Inc. +% Copyright 2009-2024 The MathWorks, Inc. diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/AxesExample.html b/studio_functions/GUI Layout Toolbox/layoutdoc/AxesExample.html index 19f38b92..7d607fa7 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/AxesExample.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/AxesExample.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/AxesLegendsColorbars.html b/studio_functions/GUI Layout Toolbox/layoutdoc/AxesLegendsColorbars.html index 6d14634d..38ac215a 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/AxesLegendsColorbars.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/AxesLegendsColorbars.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/BoxPanelFancyStuff.html b/studio_functions/GUI Layout Toolbox/layoutdoc/BoxPanelFancyStuff.html index 88371c09..2a34dee9 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/BoxPanelFancyStuff.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/BoxPanelFancyStuff.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Compiling.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Compiling.html index ea0a2024..5640e631 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Compiling.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Compiling.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/ExampleApp.html b/studio_functions/GUI Layout Toolbox/layoutdoc/ExampleApp.html index 3818e426..b71e6715 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/ExampleApp.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/ExampleApp.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Examples.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Examples.html index e10b8df4..11de3380 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Examples.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Examples.html @@ -4,7 +4,7 @@ - + Examples @@ -14,7 +14,7 @@ - +
GUI Layout Toolbox 2.3.6GUI Layout Toolbox 2.3.7 previous pagenext page
@@ -79,7 +79,7 @@

Applications

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference.html index 98d6397a..b25fb093 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference.html @@ -4,7 +4,7 @@ - + Function reference @@ -14,7 +14,7 @@ - +
GUI Layout Toolbox 2.3.6GUI Layout Toolbox 2.3.7 previous pagenext page
@@ -180,7 +180,7 @@

Function reference next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_1.html index 66f8c11c..1733ff9a 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_1.html @@ -3,7 +3,7 @@ - + uix.Panel @@ -73,7 +73,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_2.html index ec6c9a1a..0014ae83 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_2.html @@ -3,7 +3,7 @@ - + uix.CardPanel @@ -67,7 +67,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_3.html index 96f863d3..78be95a0 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_3.html @@ -3,7 +3,7 @@ - + uix.BoxPanel @@ -77,7 +77,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_4.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_4.html index 181bb502..7f22bae8 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_4.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_4.html @@ -3,7 +3,7 @@ - + uix.TabPanel @@ -65,7 +65,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_5.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_5.html index 347404f5..f7f6c2f1 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_5.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference1_5.html @@ -3,7 +3,7 @@ - + uix.ScrollingPanel @@ -65,7 +65,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_1.html index 4d6f3f65..842ad9b3 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_1.html @@ -3,7 +3,7 @@ - + uix.HBox @@ -78,7 +78,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_2.html index 84d36736..78f52dc7 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_2.html @@ -3,7 +3,7 @@ - + uix.VBox @@ -77,7 +77,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_3.html index 391fb83c..29a7204c 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_3.html @@ -3,7 +3,7 @@ - + uix.HBoxFlex @@ -69,7 +69,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_4.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_4.html index 1bf7a727..be37c209 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_4.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_4.html @@ -3,7 +3,7 @@ - + uix.VBoxFlex @@ -68,7 +68,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_5.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_5.html index 122a230d..e3ba9086 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_5.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_5.html @@ -3,7 +3,7 @@ - + uix.HButtonBox @@ -70,7 +70,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_6.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_6.html index bf38e9b4..8e795958 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_6.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference2_6.html @@ -3,7 +3,7 @@ - + uix.VButtonBox @@ -70,7 +70,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_1.html index 6f72ca96..4561e885 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_1.html @@ -3,7 +3,7 @@ - + uix.Grid @@ -72,7 +72,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_2.html index 02e07d5f..2c945012 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference3_2.html @@ -3,7 +3,7 @@ - + uix.GridFlex @@ -73,7 +73,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_1.html index 5610a177..a2cc6396 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_1.html @@ -3,7 +3,7 @@ - + uix.Empty @@ -59,7 +59,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_2.html index efe3537e..31b6005b 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_2.html @@ -3,7 +3,7 @@ - + uix.tracking @@ -53,7 +53,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_3.html index 441d71f5..f06f73e3 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Function_reference4_3.html @@ -3,7 +3,7 @@ - + layoutRoot @@ -47,7 +47,7 @@

For example:

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/GUI Layout.html b/studio_functions/GUI Layout Toolbox/layoutdoc/GUI Layout.html index 3b0037a0..dce60941 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/GUI Layout.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/GUI Layout.html @@ -1,5 +1,5 @@ - + diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started.html index fbd55ee3..2dd4a5f9 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started.html @@ -4,7 +4,7 @@ - + Getting Started @@ -14,7 +14,7 @@ - +
GUI Layout Toolbox 2.3.6GUI Layout Toolbox 2.3.7 previous pagenext page
@@ -75,7 +75,7 @@

Getting Started next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started1.html index 199607c9..4e6e383b 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started1.html @@ -3,7 +3,7 @@ - + What is GUI Layout Toolbox? @@ -43,7 +43,7 @@

1: What is GUI Layout Toolbox? next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started2.html index b348a41f..6908d0a6 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started2.html @@ -3,7 +3,7 @@ - + Compatibility considerations @@ -144,14 +144,14 @@

 2.3: Web graphics support uix.Panel + uix.Panel
uix.BoxPanel R2022b In R2022b, due to a bug, Units and Position specified during construction are ignored, and the @@ -193,12 +193,6 @@

Support

Units and Position after construction. This bug is fixed in R2023a. - - uix.BoxPanel - Unsupported - The implementation has not yet been updated to support - web graphics. -

Usage

@@ -235,7 +229,7 @@

Usage

next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started3.html index 8a85cff4..644f3a8e 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started3.html @@ -3,7 +3,7 @@ - + Release notes @@ -48,25 +48,28 @@

3: Release notes  -
  • 3.1. Version 2.3.6
  • -
  • 3.2. Version 2.3.5
  • -
  • 3.3. Version 2.3.4
  • -
  • 3.4. Version 2.3.3
  • -
  • 3.5. Version 2.3.2
  • -
  • 3.6. Version 2.3.1
  • -
  • 3.7. Version 2.3
  • -
  • 3.8. Version 2.2.2
  • -
  • 3.9. Version 2.2.1
  • -
  • 3.10. Version 2.2
  • -
  • 3.11. Version 2.1.2
  • -
  • 3.12. Version 2.1.1
  • -
  • 3.13. Version 2.1
  • +
  • 3.1. Version 2.3.7
  • +
  • 3.2. Version 2.3.6
  • +
  • 3.3. Version 2.3.5
  • +
  • 3.4. Version 2.3.4
  • +
  • 3.5. Version 2.3.3
  • +
  • 3.6. Version 2.3.2
  • +
  • 3.7. Version 2.3.1
  • +
  • 3.8. Version 2.3
  • +
  • 3.9. Version 2.2.2
  • +
  • 3.10. Version 2.2.1
  • +
  • 3.11. Version 2.2
  • +
  • 3.12. Version 2.1.2
  • +
  • 3.13. Version 2.1.1
  • +
  • 3.14. Version 2.1
    • @@ -77,7 +80,15 @@

      Section contents:



    -

     3.1: Version 2.3.6 Go back up one level

    +

     3.1: Version 2.3.7 Go back up one level

    + +
      +
    • Released 31 May 2024
    • +
    • Added web graphics support for uix.BoxPanel
    • +
    +

    + +

     3.2: Version 2.3.6 Go back up one level

    • Released 21 May 2023
    • @@ -86,7 +97,7 @@

       3.1: Version 2.3.6 
      -

       3.2: Version 2.3.5 Go back up one level

      +

       3.3: Version 2.3.5 Go back up one level

      • Released 29 October 2020
      • @@ -97,7 +108,7 @@

         3.2: Version 2.3.5 
        -

         3.3: Version 2.3.4 Go back up one level

        +

         3.4: Version 2.3.4 Go back up one level

        • Released 31 January 2019
        • @@ -106,7 +117,7 @@

           3.3: Version 2.3.4 
          -

           3.4: Version 2.3.3 Go back up one level

          +

           3.5: Version 2.3.3 Go back up one level

          • Released 25 October 2018
          • @@ -115,7 +126,7 @@

             3.4: Version 2.3.3 
            -

             3.5: Version 2.3.2 Go back up one level

            +

             3.6: Version 2.3.2 Go back up one level

            • Released 1 May 2018
            • @@ -127,7 +138,7 @@

               3.5: Version 2.3.2 
              -

               3.6: Version 2.3.1 Go back up one level

              +

               3.7: Version 2.3.1 Go back up one level

              • Released 31 January 2017
              • @@ -138,7 +149,7 @@

                 3.6: Version 2.3.1 
                -

                 3.7: Version 2.3 Go back up one level

                +

                 3.8: Version 2.3 Go back up one level

                • Released 24 November 2016
                • @@ -148,7 +159,7 @@

                   3.7: Version 2.3 



                -

                 3.8: Version 2.2.2 Go back up one level

                +

                 3.9: Version 2.2.2 Go back up one level

                • Released 22 August 2016
                • @@ -160,7 +171,7 @@

                   3.8: Version 2.2.2 
                  -

                   3.9: Version 2.2.1 Go back up one level

                  +

                   3.10: Version 2.2.1 Go back up one level

                  • Released 26 February 2016
                  • @@ -169,7 +180,7 @@

                     3.9: Version 2.2.1 
                    -

                     3.10: Version 2.2 Go back up one level

                    +

                     3.11: Version 2.2 Go back up one level

                    • Released 18 December 2015
                    • @@ -184,7 +195,7 @@

                       3.10: Version 2.2 
                      -

                       3.11: Version 2.1.2 Go back up one level

                      +

                       3.12: Version 2.1.2 Go back up one level

                      • Released 29 May 2015
                      • @@ -194,7 +205,7 @@

                         3.11: Version 2.1.2 
                        -

                         3.12: Version 2.1.1 Go back up one level

                        +

                         3.13: Version 2.1.1 Go back up one level

                        • Released 15 May 2015
                        • @@ -208,7 +219,7 @@

                           3.12: Version 2.1.1 
                          -

                           3.13: Version 2.1 Go back up one level

                          +

                           3.14: Version 2.1 Go back up one level

                          • Released 2 October 2014
                          • @@ -227,7 +238,7 @@

                             3.13: Version 2.1 next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started4.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started4.html index 893ad28a..feb905e0 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started4.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started4.html @@ -3,7 +3,7 @@ - + Installation @@ -40,7 +40,7 @@

                            4: Installation next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started5.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started5.html index 984977e4..30339a6f 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started5.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started5.html @@ -3,7 +3,7 @@ - + Support @@ -44,7 +44,7 @@

                            5: Support next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started6.html b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started6.html index 48f0cab6..5228e202 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started6.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/Getting_Started6.html @@ -3,7 +3,7 @@ - + Acknowledgements @@ -39,7 +39,7 @@

                            6: Acknowledgements next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/HierarchyExample.html b/studio_functions/GUI Layout Toolbox/layoutdoc/HierarchyExample.html index 9cf3f9bd..e2b3cb02 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/HierarchyExample.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/HierarchyExample.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/BoxPanel2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/BoxPanel2.png index af9ca016..da5eadae 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/BoxPanel2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/BoxPanel2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/Panel2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/Panel2.png index 863de735..a55d65ed 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/Panel2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/Panel2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/ScrollingPanel.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/ScrollingPanel.png index 9d806848..75a7867a 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/ScrollingPanel.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/ScrollingPanel.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_inner.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_inner.png index 5a9fad17..c4e60e7c 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_inner.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_inner.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_2.png index 3f9f29f1..5975046b 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_3.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_3.png index a89912e9..21388f71 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_3.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_layout_example_3.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_outer.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_outer.png index 39858c43..3256d175 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_outer.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/axes_outer.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_2.png index 928c5a8f..c69b186a 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_3.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_3.png index cd48e213..a4c2d007 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_3.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/colorbar_example_3.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed1.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed1.png index 003f4428..ca480f13 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed1.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed1.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed2.png index 2d83f5ca..12037394 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_fixed2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_1.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_1.png index 7ba448a8..c215cf14 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_1.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_1.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_2.png index 185fad3a..e76cb36c 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout0_2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout1.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout1.png index 185fad3a..e76cb36c 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout1.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout1.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout2.png index c8780a82..bca3e679 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_layout2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized1.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized1.png index 94ce5e42..48864b4f 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized1.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized1.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized2.png b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized2.png index fa4e8c59..2e213f3d 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized2.png and b/studio_functions/GUI Layout Toolbox/layoutdoc/Images/why_normalized2.png differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/LayoutsGUIDE.html b/studio_functions/GUI Layout Toolbox/layoutdoc/LayoutsGUIDE.html index e778d7a2..e068c770 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/LayoutsGUIDE.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/LayoutsGUIDE.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/PanelDock.html b/studio_functions/GUI Layout Toolbox/layoutdoc/PanelDock.html index a5a88150..b83c222b 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/PanelDock.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/PanelDock.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/PanelHelp.html b/studio_functions/GUI Layout Toolbox/layoutdoc/PanelHelp.html index 36a936fe..bc211ae9 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/PanelHelp.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/PanelHelp.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/PanelMinimize.html b/studio_functions/GUI Layout Toolbox/layoutdoc/PanelMinimize.html index aa07a9b3..996f3281 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/PanelMinimize.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/PanelMinimize.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide.html index f3e399e6..a62eff51 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide.html @@ -4,7 +4,7 @@ - + User guide @@ -14,7 +14,7 @@ - +
                            GUI Layout Toolbox 2.3.6GUI Layout Toolbox 2.3.7 previous pagenext page
                            @@ -75,7 +75,7 @@

                            User guide next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1.html index 1cc89459..35e38067 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1.html @@ -3,7 +3,7 @@ - + Understanding layouts @@ -66,7 +66,7 @@

                            Section contents:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_1.html index b9c89bb4..a685d601 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_1.html @@ -3,7 +3,7 @@ - + Layout basics @@ -78,7 +78,7 @@

                            1.1: Layout basics next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_2.html index 38472817..13d7815c 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_2.html @@ -3,7 +3,7 @@ - + Types of layout @@ -55,7 +55,7 @@

                            1.2: Types of layout next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_3.html index eeddccf4..40bade70 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_3.html @@ -3,7 +3,7 @@ - + Sizes and units @@ -84,7 +84,7 @@

                            1.3: Sizes and units next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_4.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_4.html index f62d2ac1..c64c8651 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_4.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_4.html @@ -3,7 +3,7 @@ - + Layout hierarchies @@ -82,7 +82,7 @@

                            1.4: Layout hierarchies next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_5.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_5.html index c70eb41b..280c7df7 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_5.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide1_5.html @@ -3,7 +3,7 @@ - + Why use layouts? @@ -94,7 +94,7 @@

                            For example:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2.html index 19627a59..64159d05 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2.html @@ -3,7 +3,7 @@ - + Positioning axes @@ -58,7 +58,7 @@

                            Section contents:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_1.html index 358188ca..abfc1050 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_1.html @@ -3,7 +3,7 @@ - + Position vs OuterPosition @@ -52,7 +52,7 @@

                            For example:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_2.html index 20e442c6..c7668696 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_2.html @@ -3,7 +3,7 @@ - + Axes inside layouts @@ -82,7 +82,7 @@

                            Fill the axes

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_3.html index d260749a..c851d399 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide2_3.html @@ -3,7 +3,7 @@ - + Colorbars and legends @@ -74,7 +74,7 @@

                            Add decorations

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3.html index 6e317635..5856e9a0 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3.html @@ -3,7 +3,7 @@ - + Controlling visibility @@ -47,7 +47,7 @@

                            Section contents:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3_1.html index e9c1da6e..7e686605 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide3_1.html @@ -3,7 +3,7 @@ - + Visible example @@ -73,7 +73,7 @@

                            3.1: Visible example next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4.html index 5a9063b8..cde16471 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4.html @@ -3,7 +3,7 @@ - + Advanced maneuvers with panels @@ -58,7 +58,7 @@

                            Section contents:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_1.html index a2abb01e..e2969dbe 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_1.html @@ -3,7 +3,7 @@ - + Context help @@ -52,7 +52,7 @@

                            For example:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_2.html index 1a45599b..33834e6a 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_2.html @@ -3,7 +3,7 @@ - + Minimize and maximize @@ -130,7 +130,7 @@

                            Click the minimize buttons

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_3.html index e2114588..e59c8f44 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide4_3.html @@ -3,7 +3,7 @@ - + Dock and undock @@ -143,7 +143,7 @@

                            Click the dock buttons

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide5.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide5.html index 006bc190..77cb2b8c 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide5.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide5.html @@ -3,7 +3,7 @@ - + Using layouts inside GUIDE GUIs @@ -73,7 +73,7 @@

                            Insert the layout

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide6.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide6.html index af406381..a64d556d 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide6.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide6.html @@ -3,7 +3,7 @@ - + Deploying GUIs using the MATLAB Compiler @@ -45,7 +45,7 @@

                            Example

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7.html index 03b50f14..fc8d8a0b 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7.html @@ -3,7 +3,7 @@ - + A complete example @@ -77,7 +77,7 @@

                            Section contents:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_1.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_1.html index 33ff818c..36fbd660 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_1.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_1.html @@ -3,7 +3,7 @@ - + Application structure @@ -95,7 +95,7 @@

                            7.1: Application structure next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_2.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_2.html index 25c382a1..a311c4d1 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_2.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_2.html @@ -3,7 +3,7 @@ - + createInterface @@ -95,7 +95,7 @@

                            7.2: createInterface next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_3.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_3.html index 5f4c1b5a..4eb3888d 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_3.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_3.html @@ -3,7 +3,7 @@ - + updateInterface @@ -60,7 +60,7 @@

                            7.3: updateInterface next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_4.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_4.html index 4d075935..55dd2b37 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_4.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_4.html @@ -3,7 +3,7 @@ - + onListSelection @@ -60,7 +60,7 @@

                            7.4: onListSelection next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_5.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_5.html index 27f863a3..eefb2b93 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_5.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_5.html @@ -3,7 +3,7 @@ - + Running it @@ -51,7 +51,7 @@

                            For example:

                            next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_6.html b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_6.html index 02c2f55e..1ef461be 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_6.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/User_guide7_6.html @@ -3,7 +3,7 @@ - + Scalability @@ -50,7 +50,7 @@

                            7.6: Scalability next page - © 2023 The MathWorks Ltd + © 2024 The MathWorks Ltd Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/VisibleExample.html b/studio_functions/GUI Layout Toolbox/layoutdoc/VisibleExample.html index ee6994f4..683e6dd4 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/VisibleExample.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/VisibleExample.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/about.html b/studio_functions/GUI Layout Toolbox/layoutdoc/about.html index a6d086d4..460a883c 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/about.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/about.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/atoz.html b/studio_functions/GUI Layout Toolbox/layoutdoc/atoz.html index a3eef9f7..e54678ec 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/atoz.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/atoz.html @@ -3,10 +3,10 @@ GUI Layout Toolbox documentation: Index - +
                            - GUI Layout Toolbox 2.3.6 + GUI Layout Toolbox 2.3.7

                            Alphabetical index

                            @@ -173,7 +173,7 @@

                            Alphabetical index

                            Back to Top - © 2023 The MathWorks Inc + © 2024 The MathWorks Inc Terms of Use Patents Trademarks diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/compatibility.html b/studio_functions/GUI Layout Toolbox/layoutdoc/compatibility.html index 3447fbb6..b91f1cc8 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/compatibility.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/compatibility.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserCreateInterface.html b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserCreateInterface.html index 59d55c3b..648fb692 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserCreateInterface.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserCreateInterface.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserOnListSelection.html b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserOnListSelection.html index bc6e447d..771aaefc 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserOnListSelection.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserOnListSelection.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserRun.html b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserRun.html index bc89fde0..b2006513 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserRun.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserRun.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserScalability.html b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserScalability.html index bdda7d8c..590a216f 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserScalability.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserScalability.html @@ -1 +1 @@ - + diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserStructure.html b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserStructure.html index d187f644..d16a5444 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserStructure.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserStructure.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserUpdateInterface.html b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserUpdateInterface.html index 5f8adb8b..67972b54 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserUpdateInterface.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/demoBrowserUpdateInterface.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/000000000002.zap b/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/000000000002.zap index cd772d67..6ae97a2b 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/000000000002.zap and b/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/000000000002.zap differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/root.bolt b/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/root.bolt index c26b9312..5421a24f 100644 Binary files a/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/root.bolt and b/studio_functions/GUI Layout Toolbox/layoutdoc/helpsearch-v4_en/store/root.bolt differ diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/helptoc.xml b/studio_functions/GUI Layout Toolbox/layoutdoc/helptoc.xml index c589f4da..55e81a96 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/helptoc.xml +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/helptoc.xml @@ -1,6 +1,6 @@ - + GUI Layout Getting Started1. What is GUI Layout Toolbox?2. Compatibility considerations3. Release notes4. Installation5. Support6. Acknowledgements diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/index.html b/studio_functions/GUI Layout Toolbox/layoutdoc/index.html index ef689060..d105d02b 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/index.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/index.html @@ -11,7 +11,7 @@

                            GUI Layout Toolbox

                            - Version: 2.3.6 + Version: 2.3.7

                            GUI Layout Toolbox is a layout manager for creating MATLAB graphical user interfaces that resize gracefully. The classes supplied can be used in @@ -46,7 +46,7 @@

                            Contents:


                            -

                            © 2023 The MathWorks Ltd +

                            © 2024 The MathWorks Ltd Terms of Use Patents Trademarks

                            diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/layoutRoot.html b/studio_functions/GUI Layout Toolbox/layoutdoc/layoutRoot.html index edac4b7c..8c085e3c 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/layoutRoot.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/layoutRoot.html @@ -1 +1 @@ - + diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/releasenotes.html b/studio_functions/GUI Layout Toolbox/layoutdoc/releasenotes.html index 4cdca716..9245718e 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/releasenotes.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/releasenotes.html @@ -1 +1 @@ - + diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.BoxPanel.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.BoxPanel.html index 66df8d4b..3048c217 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.BoxPanel.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.BoxPanel.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.CardPanel.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.CardPanel.html index 7a5b3acb..67b3834d 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.CardPanel.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.CardPanel.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Empty.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Empty.html index 60a2a58a..98c7cce7 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Empty.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Empty.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Grid.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Grid.html index 6dcd3441..0fe0cc99 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Grid.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Grid.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.GridFlex.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.GridFlex.html index 3cfbe24e..a821c356 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.GridFlex.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.GridFlex.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBox.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBox.html index 7cb32cb4..66bfcf14 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBox.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBox.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBoxFlex.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBoxFlex.html index 009944e6..e1ca9260 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBoxFlex.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HBoxFlex.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HButtonBox.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HButtonBox.html index 64b8e288..77d66255 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HButtonBox.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.HButtonBox.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Panel.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Panel.html index a7f20fb4..6980aa09 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Panel.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.Panel.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.ScrollingPanel.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.ScrollingPanel.html index fce20ab2..233f1aa5 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.ScrollingPanel.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.ScrollingPanel.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.TabPanel.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.TabPanel.html index ebdf2592..d4e37057 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.TabPanel.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.TabPanel.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBox.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBox.html index b050cf96..60c95dc5 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBox.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBox.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBoxFlex.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBoxFlex.html index 2dbfca85..461d23fd 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBoxFlex.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VBoxFlex.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VButtonBox.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VButtonBox.html index 31a2b212..51aaddb2 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VButtonBox.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.VButtonBox.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.tracking.html b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.tracking.html index 82654090..3f962ffe 100644 --- a/studio_functions/GUI Layout Toolbox/layoutdoc/uix.tracking.html +++ b/studio_functions/GUI Layout Toolbox/layoutdoc/uix.tracking.html @@ -1 +1 @@ - > + > diff --git a/studio_functions/GUI Layout Toolbox/license.txt b/studio_functions/GUI Layout Toolbox/license.txt index 3f8cfed7..06a9d18d 100644 --- a/studio_functions/GUI Layout Toolbox/license.txt +++ b/studio_functions/GUI Layout Toolbox/license.txt @@ -1,4 +1,4 @@ -Copyright (c) 2023, The MathWorks, Inc. +Copyright (c) 2024, The MathWorks, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/studio_functions/GUIs/.txt b/studio_functions/GUIs/.txt new file mode 100644 index 00000000..594a785a --- /dev/null +++ b/studio_functions/GUIs/.txt @@ -0,0 +1,1028 @@ +# Non-editable header begin -------------------------------------------------------------------------------- +# +# data format...............: continuous +# setname...................: 1_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new +# filename..................: 1_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new.set +# filepath..................: /Users/gzhang/Documents/Demo data/EEGsets/EEG set/ +# nchan.....................: 30 +# pnts......................: 155648 +# srate.....................: 256 +# nevents...................: 1002 +# generated by (bdf)........: +# generated by (set)........: 1_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new +# reported in ..............: +# prog Version..............: 10.0 +# creation date.............: 12-Mar-2024 17:49:52 +# user Account..............: +# +# Non-editable header end -------------------------------------------------------------------------------- + + + + +# item bepoch ecode label onset diff dura b_flags a_flags enable bin +# (sec) (msec) (msec) (binary) (binary) + + +1 0 1 "" 12.0752 0.00 0.0 00000000 00000000 1 [ ] +2 0 180 "" 15.1162 3041.02 0.0 00000000 00000000 1 [ ] +3 0 180 "" 15.7129 596.68 0.0 00000000 00000000 1 [ ] +4 0 180 "" 16.3330 620.12 0.0 00000000 00000000 1 [ ] +5 0 180 "" 16.9170 583.98 0.0 00000000 00000000 1 [ ] +6 0 180 "" 17.4834 566.41 0.0 00000000 00000000 1 [ ] +7 0 180 "" 18.1064 623.05 0.0 00000000 00000000 1 [ ] +8 0 180 "" 18.6465 540.04 0.0 00000000 00000000 1 [ ] +9 0 180 "" 19.2734 626.95 0.0 00000000 00000000 1 [ ] +10 0 180 "" 19.9033 629.88 0.0 00000000 00000000 1 [ ] +11 0 180 "" 20.4336 530.27 0.0 00000000 00000000 1 [ ] +12 0 180 "" 20.9932 559.57 0.0 00000000 00000000 1 [ ] +13 0 180 "" 21.5801 586.91 0.0 00000000 00000000 1 [ ] +14 0 180 "" 22.1895 609.38 0.0 00000000 00000000 1 [ ] +15 0 180 "" 22.7793 589.84 0.0 00000000 00000000 1 [ ] +16 0 180 "" 23.3398 560.55 0.0 00000000 00000000 1 [ ] +17 0 80 "" 23.8965 556.64 0.0 00000000 00000000 1 [ ] +18 0 80 "" 24.5264 629.88 0.0 00000000 00000000 1 [ ] +19 0 80 "" 25.1465 620.12 0.0 00000000 00000000 1 [ ] +20 0 80 "" 25.7568 610.35 0.0 00000000 00000000 1 [ ] +21 0 80 "" 26.3701 613.28 0.0 00000000 00000000 1 [ ] +22 0 80 "" 26.9160 545.90 0.0 00000000 00000000 1 [ ] +23 0 70 "" 27.5361 620.12 0.0 00000000 00000000 1 [ ] +24 0 80 "" 28.1533 617.19 0.0 00000000 00000000 1 [ ] +25 0 80 "" 28.7500 596.68 0.0 00000000 00000000 1 [ ] +26 0 80 "" 29.3799 629.88 0.0 00000000 00000000 1 [ ] +27 0 80 "" 29.9629 583.01 0.0 00000000 00000000 1 [ ] +28 0 80 "" 30.5830 620.12 0.0 00000000 00000000 1 [ ] +29 0 80 "" 31.1494 566.41 0.0 00000000 00000000 1 [ ] +30 0 80 "" 31.6934 543.95 0.0 00000000 00000000 1 [ ] +31 0 80 "" 32.3232 629.88 0.0 00000000 00000000 1 [ ] +32 0 80 "" 32.9365 613.28 0.0 00000000 00000000 1 [ ] +33 0 80 "" 33.4893 552.73 0.0 00000000 00000000 1 [ ] +34 0 70 "" 34.0527 563.48 0.0 00000000 00000000 1 [ ] +35 0 80 "" 34.6260 573.24 0.0 00000000 00000000 1 [ ] +36 0 70 "" 35.1797 553.71 0.0 00000000 00000000 1 [ ] +37 0 80 "" 35.7998 620.12 0.0 00000000 00000000 1 [ ] +38 0 80 "" 36.3691 569.34 0.0 00000000 00000000 1 [ ] +39 0 70 "" 36.9863 617.19 0.0 00000000 00000000 1 [ ] +40 0 80 "" 37.5664 580.08 0.0 00000000 00000000 1 [ ] +41 0 80 "" 38.1357 569.34 0.0 00000000 00000000 1 [ ] +42 0 80 "" 38.7725 636.72 0.0 00000000 00000000 1 [ ] +43 0 80 "" 39.4023 629.88 0.0 00000000 00000000 1 [ ] +44 0 80 "" 39.9658 563.48 0.0 00000000 00000000 1 [ ] +45 0 80 "" 40.5361 570.31 0.0 00000000 00000000 1 [ ] +46 0 80 "" 41.0996 563.48 0.0 00000000 00000000 1 [ ] +47 0 80 "" 41.6426 542.97 0.0 00000000 00000000 1 [ ] +48 0 80 "" 42.2197 577.15 0.0 00000000 00000000 1 [ ] +49 0 70 "" 42.8262 606.45 0.0 00000000 00000000 1 [ ] +50 0 80 "" 43.4023 576.17 0.0 00000000 00000000 1 [ ] +51 0 70 "" 43.9727 570.31 0.0 00000000 00000000 1 [ ] +52 0 80 "" 44.5391 566.41 0.0 00000000 00000000 1 [ ] +53 0 80 "" 45.0762 537.11 0.0 00000000 00000000 1 [ ] +54 0 80 "" 45.6826 606.45 0.0 00000000 00000000 1 [ ] +55 0 80 "" 46.2227 540.04 0.0 00000000 00000000 1 [ ] +56 0 80 "" 46.8330 610.35 0.0 00000000 00000000 1 [ ] +57 0 70 "" 47.4863 653.32 0.0 00000000 00000000 1 [ ] +58 0 80 "" 48.0791 592.77 0.0 00000000 00000000 1 [ ] +59 0 80 "" 48.6689 589.84 0.0 00000000 00000000 1 [ ] +60 0 80 "" 49.2793 610.35 0.0 00000000 00000000 1 [ ] +61 0 80 "" 49.8193 540.04 0.0 00000000 00000000 1 [ ] +62 0 80 "" 50.3691 549.80 0.0 00000000 00000000 1 [ ] +63 0 80 "" 50.9092 540.04 0.0 00000000 00000000 1 [ ] +64 0 80 "" 51.4922 583.01 0.0 00000000 00000000 1 [ ] +65 0 80 "" 52.0859 593.75 0.0 00000000 00000000 1 [ ] +66 0 80 "" 52.6689 583.01 0.0 00000000 00000000 1 [ ] +67 0 70 "" 53.2422 573.24 0.0 00000000 00000000 1 [ ] +68 0 80 "" 53.8721 629.88 0.0 00000000 00000000 1 [ ] +69 0 80 "" 54.4795 607.42 0.0 00000000 00000000 1 [ ] +70 0 70 "" 55.0557 576.17 0.0 00000000 00000000 1 [ ] +71 0 80 "" 55.6025 546.88 0.0 00000000 00000000 1 [ ] +72 0 80 "" 56.1455 542.97 0.0 00000000 00000000 1 [ ] +73 0 80 "" 56.6924 546.88 0.0 00000000 00000000 1 [ ] +74 0 80 "" 57.2422 549.80 0.0 00000000 00000000 1 [ ] +75 0 80 "" 57.7920 549.80 0.0 00000000 00000000 1 [ ] +76 0 80 "" 58.3359 543.95 0.0 00000000 00000000 1 [ ] +77 0 80 "" 58.8955 559.57 0.0 00000000 00000000 1 [ ] +78 0 80 "" 59.5186 623.05 0.0 00000000 00000000 1 [ ] +79 0 80 "" 60.1191 600.59 0.0 00000000 00000000 1 [ ] +80 0 80 "" 60.6758 556.64 0.0 00000000 00000000 1 [ ] +81 0 70 "" 61.2256 549.80 0.0 00000000 00000000 1 [ ] +82 0 80 "" 61.8320 606.45 0.0 00000000 00000000 1 [ ] +83 0 80 "" 62.4326 600.59 0.0 00000000 00000000 1 [ ] +84 0 80 "" 63.0557 623.05 0.0 00000000 00000000 1 [ ] +85 0 80 "" 63.6357 580.08 0.0 00000000 00000000 1 [ ] +86 0 70 "" 64.2588 623.05 0.0 00000000 00000000 1 [ ] +87 0 80 "" 64.8359 577.15 0.0 00000000 00000000 1 [ ] +88 0 70 "" 65.3818 545.90 0.0 00000000 00000000 1 [ ] +89 0 80 "" 65.9219 540.04 0.0 00000000 00000000 1 [ ] +90 0 80 "" 66.4893 567.38 0.0 00000000 00000000 1 [ ] +91 0 80 "" 67.1152 625.98 0.0 00000000 00000000 1 [ ] +92 0 80 "" 67.7393 624.02 0.0 00000000 00000000 1 [ ] +93 0 70 "" 68.3789 639.65 0.0 00000000 00000000 1 [ ] +94 0 80 "" 68.9756 596.68 0.0 00000000 00000000 1 [ ] +95 0 70 "" 69.5557 580.08 0.0 00000000 00000000 1 [ ] +96 0 80 "" 70.1221 566.41 0.0 00000000 00000000 1 [ ] +97 0 80 "" 70.7451 623.05 0.0 00000000 00000000 1 [ ] +98 0 70 "" 71.3350 589.84 0.0 00000000 00000000 1 [ ] +99 0 80 "" 71.8955 560.55 0.0 00000000 00000000 1 [ ] +100 0 70 "" 72.4883 592.77 0.0 00000000 00000000 1 [ ] +101 0 80 "" 73.0957 607.42 0.0 00000000 00000000 1 [ ] +102 0 70 "" 73.6621 566.41 0.0 00000000 00000000 1 [ ] +103 0 80 "" 74.2490 586.91 0.0 00000000 00000000 1 [ ] +104 0 80 "" 74.8457 596.68 0.0 00000000 00000000 1 [ ] +105 0 80 "" 75.3887 542.97 0.0 00000000 00000000 1 [ ] +106 0 80 "" 75.9355 546.88 0.0 00000000 00000000 1 [ ] +107 0 80 "" 76.5557 620.12 0.0 00000000 00000000 1 [ ] +108 0 80 "" 77.1816 625.98 0.0 00000000 00000000 1 [ ] +109 0 80 "" 77.7256 543.95 0.0 00000000 00000000 1 [ ] +110 0 80 "" 78.2715 545.90 0.0 00000000 00000000 1 [ ] +111 0 80 "" 78.8486 577.15 0.0 00000000 00000000 1 [ ] +112 0 80 "" 79.4648 616.21 0.0 00000000 00000000 1 [ ] +113 0 80 "" 80.0684 603.52 0.0 00000000 00000000 1 [ ] +114 0 80 "" 80.6123 543.95 0.0 00000000 00000000 1 [ ] +115 0 80 "" 81.2354 623.05 0.0 00000000 00000000 1 [ ] +116 0 80 "" 81.8623 626.95 0.0 00000000 00000000 1 [ ] +117 0 80 "" 82.4453 583.01 0.0 00000000 00000000 1 [ ] +118 0 80 "" 83.0723 626.95 0.0 00000000 00000000 1 [ ] +119 0 70 "" 83.6289 556.64 0.0 00000000 00000000 1 [ ] +120 0 80 "" 84.1787 549.80 0.0 00000000 00000000 1 [ ] +121 0 80 "" 84.8047 625.98 0.0 00000000 00000000 1 [ ] +122 0 80 "" 85.3721 567.38 0.0 00000000 00000000 1 [ ] +123 0 80 "" 85.9785 606.45 0.0 00000000 00000000 1 [ ] +124 0 80 "" 86.6084 629.88 0.0 00000000 00000000 1 [ ] +125 0 70 "" 87.2119 603.52 0.0 00000000 00000000 1 [ ] +126 0 80 "" 87.7783 566.41 0.0 00000000 00000000 1 [ ] +127 0 70 "" 88.3818 603.52 0.0 00000000 00000000 1 [ ] +128 0 80 "" 88.9688 586.91 0.0 00000000 00000000 1 [ ] +129 0 70 "" 89.5420 573.24 0.0 00000000 00000000 1 [ ] +130 0 80 "" 90.1016 559.57 0.0 00000000 00000000 1 [ ] +131 0 80 "" 90.7383 636.72 0.0 00000000 00000000 1 [ ] +132 0 80 "" 91.3682 629.88 0.0 00000000 00000000 1 [ ] +133 0 80 "" 91.9785 610.35 0.0 00000000 00000000 1 [ ] +134 0 80 "" 92.5879 609.38 0.0 00000000 00000000 1 [ ] +135 0 80 "" 93.1514 563.48 0.0 00000000 00000000 1 [ ] +136 0 80 "" 93.7520 600.59 0.0 00000000 00000000 1 [ ] +137 0 70 "" 94.3418 589.84 0.0 00000000 00000000 1 [ ] +138 0 80 "" 94.9053 563.48 0.0 00000000 00000000 1 [ ] +139 0 80 "" 95.5215 616.21 0.0 00000000 00000000 1 [ ] +140 0 80 "" 96.0752 553.71 0.0 00000000 00000000 1 [ ] +141 0 80 "" 96.6914 616.21 0.0 00000000 00000000 1 [ ] +142 0 80 "" 97.2480 556.64 0.0 00000000 00000000 1 [ ] +143 0 80 "" 97.7910 542.97 0.0 00000000 00000000 1 [ ] +144 0 80 "" 98.3779 586.91 0.0 00000000 00000000 1 [ ] +145 0 80 "" 98.9180 540.04 0.0 00000000 00000000 1 [ ] +146 0 80 "" 99.4648 546.88 0.0 00000000 00000000 1 [ ] +147 0 80 "" 100.0645 599.61 0.0 00000000 00000000 1 [ ] +148 0 70 "" 100.6582 593.75 0.0 00000000 00000000 1 [ ] +149 0 80 "" 101.2510 592.77 0.0 00000000 00000000 1 [ ] +150 0 80 "" 101.8652 614.26 0.0 00000000 00000000 1 [ ] +151 0 80 "" 102.4014 536.13 0.0 00000000 00000000 1 [ ] +152 0 70 "" 102.9883 586.91 0.0 00000000 00000000 1 [ ] +153 0 80 "" 103.5576 569.34 0.0 00000000 00000000 1 [ ] +154 0 80 "" 104.1084 550.78 0.0 00000000 00000000 1 [ ] +155 0 80 "" 104.6611 552.73 0.0 00000000 00000000 1 [ ] +156 0 80 "" 105.2783 617.19 0.0 00000000 00000000 1 [ ] +157 0 70 "" 105.8711 592.77 0.0 00000000 00000000 1 [ ] +158 0 80 "" 106.4248 553.71 0.0 00000000 00000000 1 [ ] +159 0 70 "" 106.9580 533.20 0.0 00000000 00000000 1 [ ] +160 0 80 "" 107.5576 599.61 0.0 00000000 00000000 1 [ ] +161 0 80 "" 108.1016 543.95 0.0 00000000 00000000 1 [ ] +162 0 80 "" 108.6816 580.08 0.0 00000000 00000000 1 [ ] +163 0 80 "" 109.2812 599.61 0.0 00000000 00000000 1 [ ] +164 0 80 "" 109.8408 559.57 0.0 00000000 00000000 1 [ ] +165 0 80 "" 110.4043 563.48 0.0 00000000 00000000 1 [ ] +166 0 70 "" 111.0010 596.68 0.0 00000000 00000000 1 [ ] +167 0 80 "" 111.5742 573.24 0.0 00000000 00000000 1 [ ] +168 0 70 "" 112.1680 593.75 0.0 00000000 00000000 1 [ ] +169 0 80 "" 112.7275 559.57 0.0 00000000 00000000 1 [ ] +170 0 70 "" 113.2676 540.04 0.0 00000000 00000000 1 [ ] +171 0 80 "" 113.8545 586.91 0.0 00000000 00000000 1 [ ] +172 0 70 "" 114.4346 580.08 0.0 00000000 00000000 1 [ ] +173 0 80 "" 115.0781 643.55 0.0 00000000 00000000 1 [ ] +174 0 80 "" 115.6445 566.41 0.0 00000000 00000000 1 [ ] +175 0 80 "" 116.2344 589.84 0.0 00000000 00000000 1 [ ] +176 0 70 "" 116.7744 540.04 0.0 00000000 00000000 1 [ ] +177 0 80 "" 117.3740 599.61 0.0 00000000 00000000 1 [ ] +178 0 80 "" 117.9277 553.71 0.0 00000000 00000000 1 [ ] +179 0 80 "" 118.4873 559.57 0.0 00000000 00000000 1 [ ] +180 0 80 "" 119.0713 583.98 0.0 00000000 00000000 1 [ ] +181 0 70 "" 119.6182 546.88 0.0 00000000 00000000 1 [ ] +182 0 80 "" 120.2080 589.84 0.0 00000000 00000000 1 [ ] +183 0 80 "" 120.8477 639.65 0.0 00000000 00000000 1 [ ] +184 0 70 "" 121.4814 633.79 0.0 00000000 00000000 1 [ ] +185 0 80 "" 122.0439 562.50 0.0 00000000 00000000 1 [ ] +186 0 80 "" 122.6875 643.55 0.0 00000000 00000000 1 [ ] +187 0 70 "" 123.2842 596.68 0.0 00000000 00000000 1 [ ] +188 0 80 "" 123.9238 639.65 0.0 00000000 00000000 1 [ ] +189 0 80 "" 124.4678 543.95 0.0 00000000 00000000 1 [ ] +190 0 80 "" 125.0811 613.28 0.0 00000000 00000000 1 [ ] +191 0 80 "" 125.7109 629.88 0.0 00000000 00000000 1 [ ] +192 0 80 "" 126.3340 623.05 0.0 00000000 00000000 1 [ ] +193 0 80 "" 126.8838 549.80 0.0 00000000 00000000 1 [ ] +194 0 80 "" 127.4307 546.88 0.0 00000000 00000000 1 [ ] +195 0 80 "" 128.0537 623.05 0.0 00000000 00000000 1 [ ] +196 0 70 "" 128.6543 600.59 0.0 00000000 00000000 1 [ ] +197 0 80 "" 129.1904 536.13 0.0 00000000 00000000 1 [ ] +198 0 70 "" 129.8145 624.02 0.0 00000000 00000000 1 [ ] +199 0 80 "" 130.3809 566.41 0.0 00000000 00000000 1 [ ] +200 0 70 "" 130.9609 580.08 0.0 00000000 00000000 1 [ ] +201 0 80 "" 131.5342 573.24 0.0 00000000 00000000 1 [ ] +202 0 80 "" 132.0811 546.88 0.0 00000000 00000000 1 [ ] +203 0 80 "" 132.6406 559.57 0.0 00000000 00000000 1 [ ] +204 0 70 "" 133.2637 623.05 0.0 00000000 00000000 1 [ ] +205 0 80 "" 133.8770 613.28 0.0 00000000 00000000 1 [ ] +206 0 80 "" 134.4609 583.98 0.0 00000000 00000000 1 [ ] +207 0 70 "" 135.0508 589.84 0.0 00000000 00000000 1 [ ] +208 0 80 "" 135.6270 576.17 0.0 00000000 00000000 1 [ ] +209 0 80 "" 136.2676 640.62 0.0 00000000 00000000 1 [ ] +210 0 80 "" 136.8838 616.21 0.0 00000000 00000000 1 [ ] +211 0 80 "" 137.4941 610.35 0.0 00000000 00000000 1 [ ] +212 0 80 "" 138.0840 589.84 0.0 00000000 00000000 1 [ ] +213 0 80 "" 138.6709 586.91 0.0 00000000 00000000 1 [ ] +214 0 80 "" 139.2070 536.13 0.0 00000000 00000000 1 [ ] +215 0 80 "" 139.8203 613.28 0.0 00000000 00000000 1 [ ] +216 0 80 "" 140.4502 629.88 0.0 00000000 00000000 1 [ ] +217 0 80 "" 141.0605 610.35 0.0 00000000 00000000 1 [ ] +218 0 80 "" 141.6377 577.15 0.0 00000000 00000000 1 [ ] +219 0 70 "" 142.2168 579.10 0.0 00000000 00000000 1 [ ] +220 0 80 "" 142.7637 546.88 0.0 00000000 00000000 1 [ ] +221 0 70 "" 143.3574 593.75 0.0 00000000 00000000 1 [ ] +222 0 80 "" 143.9434 585.94 0.0 00000000 00000000 1 [ ] +223 0 80 "" 144.4971 553.71 0.0 00000000 00000000 1 [ ] +224 0 80 "" 145.0840 586.91 0.0 00000000 00000000 1 [ ] +225 0 70 "" 145.7002 616.21 0.0 00000000 00000000 1 [ ] +226 0 80 "" 146.2734 573.24 0.0 00000000 00000000 1 [ ] +227 0 70 "" 146.8643 590.82 0.0 00000000 00000000 1 [ ] +228 0 80 "" 147.4307 566.41 0.0 00000000 00000000 1 [ ] +229 0 80 "" 148.0137 583.01 0.0 00000000 00000000 1 [ ] +230 0 70 "" 148.6201 606.45 0.0 00000000 00000000 1 [ ] +231 0 80 "" 149.1738 553.71 0.0 00000000 00000000 1 [ ] +232 0 80 "" 149.7266 552.73 0.0 00000000 00000000 1 [ ] +233 0 70 "" 150.3135 586.91 0.0 00000000 00000000 1 [ ] +234 0 80 "" 150.8506 537.11 0.0 00000000 00000000 1 [ ] +235 0 80 "" 151.4238 573.24 0.0 00000000 00000000 1 [ ] +236 0 80 "" 151.9766 552.73 0.0 00000000 00000000 1 [ ] +237 0 80 "" 152.6074 630.86 0.0 00000000 00000000 1 [ ] +238 0 80 "" 153.2207 613.28 0.0 00000000 00000000 1 [ ] +239 0 70 "" 153.8438 623.05 0.0 00000000 00000000 1 [ ] +240 0 80 "" 154.4766 632.81 0.0 00000000 00000000 1 [ ] +241 0 80 "" 155.0498 573.24 0.0 00000000 00000000 1 [ ] +242 0 80 "" 155.6865 636.72 0.0 00000000 00000000 1 [ ] +243 0 70 "" 156.3066 620.12 0.0 00000000 00000000 1 [ ] +244 0 80 "" 156.8740 567.38 0.0 00000000 00000000 1 [ ] +245 0 70 "" 157.5068 632.81 0.0 00000000 00000000 1 [ ] +246 0 80 "" 158.0771 570.31 0.0 00000000 00000000 1 [ ] +247 0 80 "" 158.6299 552.73 0.0 00000000 00000000 1 [ ] +248 0 80 "" 159.2168 586.91 0.0 00000000 00000000 1 [ ] +249 0 80 "" 159.8604 643.55 0.0 00000000 00000000 1 [ ] +250 0 80 "" 160.4600 599.61 0.0 00000000 00000000 1 [ ] +251 0 70 "" 161.0664 606.45 0.0 00000000 00000000 1 [ ] +252 0 80 "" 161.6299 563.48 0.0 00000000 00000000 1 [ ] +253 0 70 "" 162.2568 626.95 0.0 00000000 00000000 1 [ ] +254 0 80 "" 162.8896 632.81 0.0 00000000 00000000 1 [ ] +255 0 70 "" 163.4570 567.38 0.0 00000000 00000000 1 [ ] +256 0 80 "" 164.0566 599.61 0.0 00000000 00000000 1 [ ] +257 0 80 "" 164.6367 580.08 0.0 00000000 00000000 1 [ ] +258 0 80 "" 165.2100 573.24 0.0 00000000 00000000 1 [ ] +259 0 80 "" 165.7930 583.01 0.0 00000000 00000000 1 [ ] +260 0 80 "" 166.3730 580.08 0.0 00000000 00000000 1 [ ] +261 0 80 "" 166.9268 553.71 0.0 00000000 00000000 1 [ ] +262 0 80 "" 167.5068 580.08 0.0 00000000 00000000 1 [ ] +263 0 70 "" 168.1201 613.28 0.0 00000000 00000000 1 [ ] +264 0 80 "" 168.6865 566.41 0.0 00000000 00000000 1 [ ] +265 0 80 "" 169.2363 549.80 0.0 00000000 00000000 1 [ ] +266 0 80 "" 169.8535 617.19 0.0 00000000 00000000 1 [ ] +267 0 70 "" 170.4902 636.72 0.0 00000000 00000000 1 [ ] +268 0 80 "" 171.0596 569.34 0.0 00000000 00000000 1 [ ] +269 0 80 "" 171.6768 617.19 0.0 00000000 00000000 1 [ ] +270 0 80 "" 172.3037 626.95 0.0 00000000 00000000 1 [ ] +271 0 80 "" 172.8633 559.57 0.0 00000000 00000000 1 [ ] +272 0 80 "" 173.4531 589.84 0.0 00000000 00000000 1 [ ] +273 0 70 "" 174.0166 563.48 0.0 00000000 00000000 1 [ ] +274 0 80 "" 174.5830 566.41 0.0 00000000 00000000 1 [ ] +275 0 80 "" 175.1699 586.91 0.0 00000000 00000000 1 [ ] +276 0 80 "" 175.7266 556.64 0.0 00000000 00000000 1 [ ] +277 0 80 "" 176.2695 542.97 0.0 00000000 00000000 1 [ ] +278 0 80 "" 176.8936 624.02 0.0 00000000 00000000 1 [ ] +279 0 70 "" 177.5000 606.45 0.0 00000000 00000000 1 [ ] +280 0 80 "" 178.0898 589.84 0.0 00000000 00000000 1 [ ] +281 0 80 "" 178.7197 629.88 0.0 00000000 00000000 1 [ ] +282 0 70 "" 179.2930 573.24 0.0 00000000 00000000 1 [ ] +283 0 80 "" 179.8867 593.75 0.0 00000000 00000000 1 [ ] +284 0 70 "" 180.4434 556.64 0.0 00000000 00000000 1 [ ] +285 0 80 "" 181.0029 559.57 0.0 00000000 00000000 1 [ ] +286 0 80 "" 181.5664 563.48 0.0 00000000 00000000 1 [ ] +287 0 80 "" 182.1826 616.21 0.0 00000000 00000000 1 [ ] +288 0 70 "" 182.7959 613.28 0.0 00000000 00000000 1 [ ] +289 0 80 "" 183.3760 580.08 0.0 00000000 00000000 1 [ ] +290 0 80 "" 183.9893 613.28 0.0 00000000 00000000 1 [ ] +291 0 80 "" 184.6133 624.02 0.0 00000000 00000000 1 [ ] +292 0 70 "" 185.1895 576.17 0.0 00000000 00000000 1 [ ] +293 0 80 "" 185.7900 600.59 0.0 00000000 00000000 1 [ ] +294 0 80 "" 186.3564 566.41 0.0 00000000 00000000 1 [ ] +295 0 80 "" 186.9795 623.05 0.0 00000000 00000000 1 [ ] +296 0 70 "" 187.5859 606.45 0.0 00000000 00000000 1 [ ] +297 0 80 "" 188.2129 626.95 0.0 00000000 00000000 1 [ ] +298 0 70 "" 188.8359 623.05 0.0 00000000 00000000 1 [ ] +299 0 80 "" 189.3828 546.88 0.0 00000000 00000000 1 [ ] +300 0 80 "" 189.9463 563.48 0.0 00000000 00000000 1 [ ] +301 0 70 "" 190.5430 596.68 0.0 00000000 00000000 1 [ ] +302 0 80 "" 191.1631 620.12 0.0 00000000 00000000 1 [ ] +303 0 80 "" 191.8027 639.65 0.0 00000000 00000000 1 [ ] +304 0 70 "" 192.3965 593.75 0.0 00000000 00000000 1 [ ] +305 0 80 "" 192.9766 580.08 0.0 00000000 00000000 1 [ ] +306 0 80 "" 193.5996 623.05 0.0 00000000 00000000 1 [ ] +307 0 80 "" 194.1758 576.17 0.0 00000000 00000000 1 [ ] +308 0 80 "" 194.7490 573.24 0.0 00000000 00000000 1 [ ] +309 0 80 "" 195.3057 556.64 0.0 00000000 00000000 1 [ ] +310 0 80 "" 195.9160 610.35 0.0 00000000 00000000 1 [ ] +311 0 80 "" 196.5430 626.95 0.0 00000000 00000000 1 [ ] +312 0 80 "" 197.1289 585.94 0.0 00000000 00000000 1 [ ] +313 0 80 "" 197.7227 593.75 0.0 00000000 00000000 1 [ ] +314 0 70 "" 198.3262 603.52 0.0 00000000 00000000 1 [ ] +315 0 80 "" 198.9355 609.38 0.0 00000000 00000000 1 [ ] +316 0 80 "" 199.5527 617.19 0.0 00000000 00000000 1 [ ] +317 0 70 "" 200.1289 576.17 0.0 00000000 00000000 1 [ ] +318 0 80 "" 200.7627 633.79 0.0 00000000 00000000 1 [ ] +319 0 70 "" 201.3027 540.04 0.0 00000000 00000000 1 [ ] +320 0 80 "" 201.9092 606.45 0.0 00000000 00000000 1 [ ] +321 0 70 "" 202.4756 566.41 0.0 00000000 00000000 1 [ ] +322 0 80 "" 203.0762 600.59 0.0 00000000 00000000 1 [ ] +323 0 80 "" 203.6924 616.21 0.0 00000000 00000000 1 [ ] +324 0 80 "" 204.3457 653.32 0.0 00000000 00000000 1 [ ] +325 0 80 "" 204.9658 620.12 0.0 00000000 00000000 1 [ ] +326 0 80 "" 205.6025 636.72 0.0 00000000 00000000 1 [ ] +327 0 70 "" 206.2061 603.52 0.0 00000000 00000000 1 [ ] +328 0 80 "" 206.8057 599.61 0.0 00000000 00000000 1 [ ] +329 0 70 "" 207.3623 556.64 0.0 00000000 00000000 1 [ ] +330 0 80 "" 207.9922 629.88 0.0 00000000 00000000 1 [ ] +331 0 70 "" 208.5625 570.31 0.0 00000000 00000000 1 [ ] +332 0 80 "" 209.1162 553.71 0.0 00000000 00000000 1 [ ] +333 0 70 "" 209.6787 562.50 0.0 00000000 00000000 1 [ ] +334 0 80 "" 210.3096 630.86 0.0 00000000 00000000 1 [ ] +335 0 80 "" 210.9355 625.98 0.0 00000000 00000000 1 [ ] +336 0 80 "" 211.4922 556.64 0.0 00000000 00000000 1 [ ] +337 0 80 "" 212.1162 624.02 0.0 00000000 00000000 1 [ ] +338 0 80 "" 212.6729 556.64 0.0 00000000 00000000 1 [ ] +339 0 80 "" 213.2588 585.94 0.0 00000000 00000000 1 [ ] +340 0 80 "" 213.8828 624.02 0.0 00000000 00000000 1 [ ] +341 0 80 "" 214.4453 562.50 0.0 00000000 00000000 1 [ ] +342 0 80 "" 215.0723 626.95 0.0 00000000 00000000 1 [ ] +343 0 80 "" 215.6494 577.15 0.0 00000000 00000000 1 [ ] +344 0 80 "" 216.2061 556.64 0.0 00000000 00000000 1 [ ] +345 0 80 "" 216.7627 556.64 0.0 00000000 00000000 1 [ ] +346 0 80 "" 217.3057 542.97 0.0 00000000 00000000 1 [ ] +347 0 70 "" 217.9521 646.48 0.0 00000000 00000000 1 [ ] +348 0 80 "" 218.5322 580.08 0.0 00000000 00000000 1 [ ] +349 0 80 "" 219.0791 546.88 0.0 00000000 00000000 1 [ ] +350 0 80 "" 219.6660 586.91 0.0 00000000 00000000 1 [ ] +351 0 70 "" 220.2090 542.97 0.0 00000000 00000000 1 [ ] +352 0 80 "" 220.8223 613.28 0.0 00000000 00000000 1 [ ] +353 0 80 "" 221.4121 589.84 0.0 00000000 00000000 1 [ ] +354 0 80 "" 222.0322 620.12 0.0 00000000 00000000 1 [ ] +355 0 80 "" 222.6084 576.17 0.0 00000000 00000000 1 [ ] +356 0 80 "" 223.1758 567.38 0.0 00000000 00000000 1 [ ] +357 0 80 "" 223.7959 620.12 0.0 00000000 00000000 1 [ ] +358 0 80 "" 224.4053 609.38 0.0 00000000 00000000 1 [ ] +359 0 80 "" 224.9424 537.11 0.0 00000000 00000000 1 [ ] +360 0 80 "" 225.5283 585.94 0.0 00000000 00000000 1 [ ] +361 0 80 "" 226.0820 553.71 0.0 00000000 00000000 1 [ ] +362 0 80 "" 226.7090 626.95 0.0 00000000 00000000 1 [ ] +363 0 80 "" 227.2988 589.84 0.0 00000000 00000000 1 [ ] +364 0 80 "" 227.9258 626.95 0.0 00000000 00000000 1 [ ] +365 0 80 "" 228.5352 609.38 0.0 00000000 00000000 1 [ ] +366 0 80 "" 229.1016 566.41 0.0 00000000 00000000 1 [ ] +367 0 80 "" 229.6885 586.91 0.0 00000000 00000000 1 [ ] +368 0 80 "" 230.2617 573.24 0.0 00000000 00000000 1 [ ] +369 0 80 "" 230.8320 570.31 0.0 00000000 00000000 1 [ ] +370 0 80 "" 231.4082 576.17 0.0 00000000 00000000 1 [ ] +371 0 70 "" 232.0186 610.35 0.0 00000000 00000000 1 [ ] +372 0 80 "" 232.5850 566.41 0.0 00000000 00000000 1 [ ] +373 0 80 "" 233.2021 617.19 0.0 00000000 00000000 1 [ ] +374 0 80 "" 233.7549 552.73 0.0 00000000 00000000 1 [ ] +375 0 80 "" 234.3320 577.15 0.0 00000000 00000000 1 [ ] +376 0 70 "" 234.9424 610.35 0.0 00000000 00000000 1 [ ] +377 0 80 "" 235.5352 592.77 0.0 00000000 00000000 1 [ ] +378 0 80 "" 236.1123 577.15 0.0 00000000 00000000 1 [ ] +379 0 80 "" 236.6953 583.01 0.0 00000000 00000000 1 [ ] +380 0 70 "" 237.2822 586.91 0.0 00000000 00000000 1 [ ] +381 0 80 "" 237.8418 559.57 0.0 00000000 00000000 1 [ ] +382 0 80 "" 238.3848 542.97 0.0 00000000 00000000 1 [ ] +383 0 80 "" 239.0020 617.19 0.0 00000000 00000000 1 [ ] +384 0 80 "" 239.5547 552.73 0.0 00000000 00000000 1 [ ] +385 0 80 "" 240.1582 603.52 0.0 00000000 00000000 1 [ ] +386 0 70 "" 240.7188 560.55 0.0 00000000 00000000 1 [ ] +387 0 80 "" 241.2783 559.57 0.0 00000000 00000000 1 [ ] +388 0 80 "" 241.8682 589.84 0.0 00000000 00000000 1 [ ] +389 0 80 "" 242.4980 629.88 0.0 00000000 00000000 1 [ ] +390 0 80 "" 243.0684 570.31 0.0 00000000 00000000 1 [ ] +391 0 80 "" 243.6748 606.45 0.0 00000000 00000000 1 [ ] +392 0 70 "" 244.2188 543.95 0.0 00000000 00000000 1 [ ] +393 0 80 "" 244.8350 616.21 0.0 00000000 00000000 1 [ ] +394 0 70 "" 245.4150 580.08 0.0 00000000 00000000 1 [ ] +395 0 80 "" 246.0088 593.75 0.0 00000000 00000000 1 [ ] +396 0 80 "" 246.6445 635.74 0.0 00000000 00000000 1 [ ] +397 0 80 "" 247.1885 543.95 0.0 00000000 00000000 1 [ ] +398 0 80 "" 247.7852 596.68 0.0 00000000 00000000 1 [ ] +399 0 80 "" 248.3779 592.77 0.0 00000000 00000000 1 [ ] +400 0 80 "" 249.0146 636.72 0.0 00000000 00000000 1 [ ] +401 0 80 "" 249.5645 549.80 0.0 00000000 00000000 1 [ ] +402 0 80 "" 250.1250 560.55 0.0 00000000 00000000 1 [ ] +403 0 80 "" 250.7148 589.84 0.0 00000000 00000000 1 [ ] +404 0 80 "" 251.2920 577.15 0.0 00000000 00000000 1 [ ] +405 0 80 "" 251.8379 545.90 0.0 00000000 00000000 1 [ ] +406 0 80 "" 252.4150 577.15 0.0 00000000 00000000 1 [ ] +407 0 80 "" 253.0381 623.05 0.0 00000000 00000000 1 [ ] +408 0 80 "" 253.5645 526.37 0.0 00000000 00000000 1 [ ] +409 0 80 "" 254.1582 593.75 0.0 00000000 00000000 1 [ ] +410 0 80 "" 254.7383 580.08 0.0 00000000 00000000 1 [ ] +411 0 80 "" 255.3418 603.52 0.0 00000000 00000000 1 [ ] +412 0 80 "" 255.9180 576.17 0.0 00000000 00000000 1 [ ] +413 0 80 "" 256.4746 556.64 0.0 00000000 00000000 1 [ ] +414 0 70 "" 257.0449 570.31 0.0 00000000 00000000 1 [ ] +415 0 80 "" 257.6113 566.41 0.0 00000000 00000000 1 [ ] +416 0 80 "" 258.2080 596.68 0.0 00000000 00000000 1 [ ] +417 0 70 "" 258.7578 549.80 0.0 00000000 00000000 1 [ ] +418 0 80 "" 259.3545 596.68 0.0 00000000 00000000 1 [ ] +419 0 80 "" 259.9814 626.95 0.0 00000000 00000000 1 [ ] +420 0 80 "" 260.5713 589.84 0.0 00000000 00000000 1 [ ] +421 0 80 "" 261.1543 583.01 0.0 00000000 00000000 1 [ ] +422 0 70 "" 261.7744 620.12 0.0 00000000 00000000 1 [ ] +423 0 80 "" 262.3984 624.02 0.0 00000000 00000000 1 [ ] +424 0 80 "" 263.0244 625.98 0.0 00000000 00000000 1 [ ] +425 0 70 "" 263.6611 636.72 0.0 00000000 00000000 1 [ ] +426 0 80 "" 264.1943 533.20 0.0 00000000 00000000 1 [ ] +427 0 70 "" 264.7314 537.11 0.0 00000000 00000000 1 [ ] +428 0 80 "" 265.2783 546.88 0.0 00000000 00000000 1 [ ] +429 0 80 "" 265.8516 573.24 0.0 00000000 00000000 1 [ ] +430 0 80 "" 266.4443 592.77 0.0 00000000 00000000 1 [ ] +431 0 80 "" 266.9941 549.80 0.0 00000000 00000000 1 [ ] +432 0 80 "" 267.6377 643.55 0.0 00000000 00000000 1 [ ] +433 0 70 "" 268.2549 617.19 0.0 00000000 00000000 1 [ ] +434 0 80 "" 268.8613 606.45 0.0 00000000 00000000 1 [ ] +435 0 70 "" 269.4443 583.01 0.0 00000000 00000000 1 [ ] +436 0 80 "" 269.9941 549.80 0.0 00000000 00000000 1 [ ] +437 0 80 "" 270.5908 596.68 0.0 00000000 00000000 1 [ ] +438 0 80 "" 271.2109 620.12 0.0 00000000 00000000 1 [ ] +439 0 80 "" 271.7510 540.04 0.0 00000000 00000000 1 [ ] +440 0 80 "" 272.2949 543.95 0.0 00000000 00000000 1 [ ] +441 0 80 "" 272.9414 646.48 0.0 00000000 00000000 1 [ ] +442 0 80 "" 273.5312 589.84 0.0 00000000 00000000 1 [ ] +443 0 80 "" 274.0840 552.73 0.0 00000000 00000000 1 [ ] +444 0 80 "" 274.6514 567.38 0.0 00000000 00000000 1 [ ] +445 0 80 "" 275.2373 585.94 0.0 00000000 00000000 1 [ ] +446 0 70 "" 275.8145 577.15 0.0 00000000 00000000 1 [ ] +447 0 80 "" 276.4209 606.45 0.0 00000000 00000000 1 [ ] +448 0 80 "" 277.0479 626.95 0.0 00000000 00000000 1 [ ] +449 0 80 "" 277.6572 609.38 0.0 00000000 00000000 1 [ ] +450 0 80 "" 278.2578 600.59 0.0 00000000 00000000 1 [ ] +451 0 70 "" 278.8672 609.38 0.0 00000000 00000000 1 [ ] +452 0 80 "" 279.4512 583.98 0.0 00000000 00000000 1 [ ] +453 0 70 "" 280.0244 573.24 0.0 00000000 00000000 1 [ ] +454 0 80 "" 280.6514 626.95 0.0 00000000 00000000 1 [ ] +455 0 70 "" 281.2744 623.05 0.0 00000000 00000000 1 [ ] +456 0 80 "" 281.9180 643.55 0.0 00000000 00000000 1 [ ] +457 0 70 "" 282.4805 562.50 0.0 00000000 00000000 1 [ ] +458 0 80 "" 283.0674 586.91 0.0 00000000 00000000 1 [ ] +459 0 80 "" 283.6973 629.88 0.0 00000000 00000000 1 [ ] +460 0 80 "" 284.3037 606.45 0.0 00000000 00000000 1 [ ] +461 0 80 "" 284.9238 620.12 0.0 00000000 00000000 1 [ ] +462 0 80 "" 285.5273 603.52 0.0 00000000 00000000 1 [ ] +463 0 80 "" 286.1172 589.84 0.0 00000000 00000000 1 [ ] +464 0 80 "" 286.7246 607.42 0.0 00000000 00000000 1 [ ] +465 0 80 "" 287.3477 623.05 0.0 00000000 00000000 1 [ ] +466 0 80 "" 287.8877 540.04 0.0 00000000 00000000 1 [ ] +467 0 80 "" 288.4346 546.88 0.0 00000000 00000000 1 [ ] +468 0 80 "" 288.9941 559.57 0.0 00000000 00000000 1 [ ] +469 0 70 "" 289.5938 599.61 0.0 00000000 00000000 1 [ ] +470 0 80 "" 290.2275 633.79 0.0 00000000 00000000 1 [ ] +471 0 80 "" 290.8174 589.84 0.0 00000000 00000000 1 [ ] +472 0 80 "" 291.3945 577.15 0.0 00000000 00000000 1 [ ] +473 0 80 "" 291.9902 595.70 0.0 00000000 00000000 1 [ ] +474 0 80 "" 292.5742 583.98 0.0 00000000 00000000 1 [ ] +475 0 80 "" 293.1904 616.21 0.0 00000000 00000000 1 [ ] +476 0 80 "" 293.8008 610.35 0.0 00000000 00000000 1 [ ] +477 0 80 "" 294.4209 620.12 0.0 00000000 00000000 1 [ ] +478 0 70 "" 295.0469 625.98 0.0 00000000 00000000 1 [ ] +479 0 80 "" 295.6143 567.38 0.0 00000000 00000000 1 [ ] +480 0 70 "" 296.1709 556.64 0.0 00000000 00000000 1 [ ] +481 0 80 "" 296.7939 623.05 0.0 00000000 00000000 1 [ ] +482 0 80 "" 297.4238 629.88 0.0 00000000 00000000 1 [ ] +483 0 80 "" 297.9873 563.48 0.0 00000000 00000000 1 [ ] +484 0 70 "" 298.5977 610.35 0.0 00000000 00000000 1 [ ] +485 0 80 "" 299.2305 632.81 0.0 00000000 00000000 1 [ ] +486 0 70 "" 299.7705 540.04 0.0 00000000 00000000 1 [ ] +487 0 80 "" 300.3672 596.68 0.0 00000000 00000000 1 [ ] +488 0 80 "" 300.9434 576.17 0.0 00000000 00000000 1 [ ] +489 0 80 "" 301.5010 557.62 0.0 00000000 00000000 1 [ ] +490 0 70 "" 302.0508 549.80 0.0 00000000 00000000 1 [ ] +491 0 80 "" 302.5908 540.04 0.0 00000000 00000000 1 [ ] +492 0 70 "" 303.1973 606.45 0.0 00000000 00000000 1 [ ] +493 0 80 "" 303.8271 629.88 0.0 00000000 00000000 1 [ ] +494 0 80 "" 304.4434 616.21 0.0 00000000 00000000 1 [ ] +495 0 70 "" 304.9902 546.88 0.0 00000000 00000000 1 [ ] +496 0 80 "" 305.5605 570.31 0.0 00000000 00000000 1 [ ] +497 0 80 "" 306.1436 583.01 0.0 00000000 00000000 1 [ ] +498 0 80 "" 306.6807 537.11 0.0 00000000 00000000 1 [ ] +499 0 80 "" 307.2539 573.24 0.0 00000000 00000000 1 [ ] +500 0 80 "" 307.8467 592.77 0.0 00000000 00000000 1 [ ] +501 0 80 "" 308.4102 563.48 0.0 00000000 00000000 1 [ ] +502 0 80 "" 309.0137 603.52 0.0 00000000 00000000 1 [ ] +503 0 80 "" 309.5938 580.08 0.0 00000000 00000000 1 [ ] +504 0 80 "" 310.1465 552.73 0.0 00000000 00000000 1 [ ] +505 0 80 "" 310.6768 530.27 0.0 00000000 00000000 1 [ ] +506 0 70 "" 311.2471 570.31 0.0 00000000 00000000 1 [ ] +507 0 80 "" 311.8672 620.12 0.0 00000000 00000000 1 [ ] +508 0 80 "" 312.4199 552.73 0.0 00000000 00000000 1 [ ] +509 0 70 "" 312.9873 567.38 0.0 00000000 00000000 1 [ ] +510 0 80 "" 313.6006 613.28 0.0 00000000 00000000 1 [ ] +511 0 80 "" 314.2100 609.38 0.0 00000000 00000000 1 [ ] +512 0 80 "" 314.7773 567.38 0.0 00000000 00000000 1 [ ] +513 0 70 "" 315.3340 556.64 0.0 00000000 00000000 1 [ ] +514 0 80 "" 315.9199 585.94 0.0 00000000 00000000 1 [ ] +515 0 80 "" 316.4600 540.04 0.0 00000000 00000000 1 [ ] +516 0 80 "" 317.0166 556.64 0.0 00000000 00000000 1 [ ] +517 0 80 "" 317.6465 629.88 0.0 00000000 00000000 1 [ ] +518 0 80 "" 318.2471 600.59 0.0 00000000 00000000 1 [ ] +519 0 80 "" 318.8203 573.24 0.0 00000000 00000000 1 [ ] +520 0 80 "" 319.4131 592.77 0.0 00000000 00000000 1 [ ] +521 0 80 "" 320.0098 596.68 0.0 00000000 00000000 1 [ ] +522 0 80 "" 320.6035 593.75 0.0 00000000 00000000 1 [ ] +523 0 80 "" 321.1738 570.31 0.0 00000000 00000000 1 [ ] +524 0 70 "" 321.8037 629.88 0.0 00000000 00000000 1 [ ] +525 0 80 "" 322.3633 559.57 0.0 00000000 00000000 1 [ ] +526 0 80 "" 322.9834 620.12 0.0 00000000 00000000 1 [ ] +527 0 80 "" 323.5898 606.45 0.0 00000000 00000000 1 [ ] +528 0 80 "" 324.1934 603.52 0.0 00000000 00000000 1 [ ] +529 0 80 "" 324.7598 566.41 0.0 00000000 00000000 1 [ ] +530 0 80 "" 325.3867 626.95 0.0 00000000 00000000 1 [ ] +531 0 80 "" 325.9697 583.01 0.0 00000000 00000000 1 [ ] +532 0 80 "" 326.5635 593.75 0.0 00000000 00000000 1 [ ] +533 0 80 "" 327.1270 563.48 0.0 00000000 00000000 1 [ ] +534 0 80 "" 327.7002 573.24 0.0 00000000 00000000 1 [ ] +535 0 80 "" 328.2568 556.64 0.0 00000000 00000000 1 [ ] +536 0 70 "" 328.8301 573.24 0.0 00000000 00000000 1 [ ] +537 0 80 "" 329.3799 549.80 0.0 00000000 00000000 1 [ ] +538 0 80 "" 329.9531 573.24 0.0 00000000 00000000 1 [ ] +539 0 70 "" 330.5996 646.48 0.0 00000000 00000000 1 [ ] +540 0 80 "" 331.1836 583.98 0.0 00000000 00000000 1 [ ] +541 0 70 "" 331.7598 576.17 0.0 00000000 00000000 1 [ ] +542 0 80 "" 332.3428 583.01 0.0 00000000 00000000 1 [ ] +543 0 80 "" 332.9365 593.75 0.0 00000000 00000000 1 [ ] +544 0 80 "" 333.5303 593.75 0.0 00000000 00000000 1 [ ] +545 0 80 "" 334.1436 613.28 0.0 00000000 00000000 1 [ ] +546 0 70 "" 334.7363 592.77 0.0 00000000 00000000 1 [ ] +547 0 80 "" 335.3496 613.28 0.0 00000000 00000000 1 [ ] +548 0 80 "" 335.9268 577.15 0.0 00000000 00000000 1 [ ] +549 0 80 "" 336.5068 580.08 0.0 00000000 00000000 1 [ ] +550 0 80 "" 337.1094 602.54 0.0 00000000 00000000 1 [ ] +551 0 80 "" 337.6797 570.31 0.0 00000000 00000000 1 [ ] +552 0 80 "" 338.2832 603.52 0.0 00000000 00000000 1 [ ] +553 0 80 "" 338.9062 623.05 0.0 00000000 00000000 1 [ ] +554 0 80 "" 339.5361 629.88 0.0 00000000 00000000 1 [ ] +555 0 80 "" 340.1465 610.35 0.0 00000000 00000000 1 [ ] +556 0 80 "" 340.7363 589.84 0.0 00000000 00000000 1 [ ] +557 0 80 "" 341.2930 556.64 0.0 00000000 00000000 1 [ ] +558 0 80 "" 341.8730 580.08 0.0 00000000 00000000 1 [ ] +559 0 80 "" 342.4531 580.08 0.0 00000000 00000000 1 [ ] +560 0 80 "" 343.0000 546.88 0.0 00000000 00000000 1 [ ] +561 0 80 "" 343.6367 636.72 0.0 00000000 00000000 1 [ ] +562 0 80 "" 344.2334 596.68 0.0 00000000 00000000 1 [ ] +563 0 70 "" 344.8594 625.98 0.0 00000000 00000000 1 [ ] +564 0 80 "" 345.4697 610.35 0.0 00000000 00000000 1 [ ] +565 0 80 "" 346.0928 623.05 0.0 00000000 00000000 1 [ ] +566 0 70 "" 346.7031 610.35 0.0 00000000 00000000 1 [ ] +567 0 80 "" 347.3066 603.52 0.0 00000000 00000000 1 [ ] +568 0 80 "" 347.8594 552.73 0.0 00000000 00000000 1 [ ] +569 0 70 "" 348.4727 613.28 0.0 00000000 00000000 1 [ ] +570 0 80 "" 349.0830 610.35 0.0 00000000 00000000 1 [ ] +571 0 80 "" 349.6924 609.38 0.0 00000000 00000000 1 [ ] +572 0 80 "" 350.2725 580.08 0.0 00000000 00000000 1 [ ] +573 0 80 "" 350.8965 624.02 0.0 00000000 00000000 1 [ ] +574 0 80 "" 351.5225 625.98 0.0 00000000 00000000 1 [ ] +575 0 80 "" 352.1260 603.52 0.0 00000000 00000000 1 [ ] +576 0 80 "" 352.7393 613.28 0.0 00000000 00000000 1 [ ] +577 0 80 "" 353.3564 617.19 0.0 00000000 00000000 1 [ ] +578 0 80 "" 353.9932 636.72 0.0 00000000 00000000 1 [ ] +579 0 80 "" 354.6025 609.38 0.0 00000000 00000000 1 [ ] +580 0 80 "" 355.1963 593.75 0.0 00000000 00000000 1 [ ] +581 0 80 "" 355.7529 556.64 0.0 00000000 00000000 1 [ ] +582 0 80 "" 356.3125 559.57 0.0 00000000 00000000 1 [ ] +583 0 80 "" 356.9355 623.05 0.0 00000000 00000000 1 [ ] +584 0 80 "" 357.4795 543.95 0.0 00000000 00000000 1 [ ] +585 0 80 "" 358.0293 549.80 0.0 00000000 00000000 1 [ ] +586 0 80 "" 358.5693 540.04 0.0 00000000 00000000 1 [ ] +587 0 70 "" 359.1592 589.84 0.0 00000000 00000000 1 [ ] +588 0 80 "" 359.7021 542.97 0.0 00000000 00000000 1 [ ] +589 0 70 "" 360.2959 593.75 0.0 00000000 00000000 1 [ ] +590 0 80 "" 360.8496 553.71 0.0 00000000 00000000 1 [ ] +591 0 80 "" 361.4395 589.84 0.0 00000000 00000000 1 [ ] +592 0 70 "" 362.0029 563.48 0.0 00000000 00000000 1 [ ] +593 0 80 "" 362.6357 632.81 0.0 00000000 00000000 1 [ ] +594 0 80 "" 363.1855 549.80 0.0 00000000 00000000 1 [ ] +595 0 80 "" 363.7988 613.28 0.0 00000000 00000000 1 [ ] +596 0 70 "" 364.3457 546.88 0.0 00000000 00000000 1 [ ] +597 0 80 "" 364.9395 593.75 0.0 00000000 00000000 1 [ ] +598 0 80 "" 365.5156 576.17 0.0 00000000 00000000 1 [ ] +599 0 80 "" 366.1426 626.95 0.0 00000000 00000000 1 [ ] +600 0 70 "" 366.7129 570.31 0.0 00000000 00000000 1 [ ] +601 0 80 "" 367.3154 602.54 0.0 00000000 00000000 1 [ ] +602 0 80 "" 367.9492 633.79 0.0 00000000 00000000 1 [ ] +603 0 80 "" 368.5762 626.95 0.0 00000000 00000000 1 [ ] +604 0 80 "" 369.1729 596.68 0.0 00000000 00000000 1 [ ] +605 0 80 "" 369.7061 533.20 0.0 00000000 00000000 1 [ ] +606 0 80 "" 370.2490 542.97 0.0 00000000 00000000 1 [ ] +607 0 80 "" 370.7959 546.88 0.0 00000000 00000000 1 [ ] +608 0 70 "" 371.4326 636.72 0.0 00000000 00000000 1 [ ] +609 0 80 "" 372.0557 623.05 0.0 00000000 00000000 1 [ ] +610 0 70 "" 372.6455 589.84 0.0 00000000 00000000 1 [ ] +611 0 80 "" 373.1787 533.20 0.0 00000000 00000000 1 [ ] +612 0 80 "" 373.7793 600.59 0.0 00000000 00000000 1 [ ] +613 0 80 "" 374.3555 576.17 0.0 00000000 00000000 1 [ ] +614 0 80 "" 374.9756 620.12 0.0 00000000 00000000 1 [ ] +615 0 80 "" 375.5654 589.84 0.0 00000000 00000000 1 [ ] +616 0 80 "" 376.1455 580.08 0.0 00000000 00000000 1 [ ] +617 0 80 "" 376.7520 606.45 0.0 00000000 00000000 1 [ ] +618 0 80 "" 377.2959 543.95 0.0 00000000 00000000 1 [ ] +619 0 80 "" 377.8389 542.97 0.0 00000000 00000000 1 [ ] +620 0 80 "" 378.4756 636.72 0.0 00000000 00000000 1 [ ] +621 0 80 "" 379.1191 643.55 0.0 00000000 00000000 1 [ ] +622 0 70 "" 379.7188 599.61 0.0 00000000 00000000 1 [ ] +623 0 80 "" 380.3389 620.12 0.0 00000000 00000000 1 [ ] +624 0 80 "" 380.9355 596.68 0.0 00000000 00000000 1 [ ] +625 0 80 "" 381.5283 592.77 0.0 00000000 00000000 1 [ ] +626 0 80 "" 382.1221 593.75 0.0 00000000 00000000 1 [ ] +627 0 80 "" 382.7285 606.45 0.0 00000000 00000000 1 [ ] +628 0 80 "" 383.3389 610.35 0.0 00000000 00000000 1 [ ] +629 0 70 "" 383.9287 589.84 0.0 00000000 00000000 1 [ ] +630 0 80 "" 384.4951 566.41 0.0 00000000 00000000 1 [ ] +631 0 80 "" 385.0918 596.68 0.0 00000000 00000000 1 [ ] +632 0 80 "" 385.7256 633.79 0.0 00000000 00000000 1 [ ] +633 0 80 "" 386.3516 625.98 0.0 00000000 00000000 1 [ ] +634 0 80 "" 386.9385 586.91 0.0 00000000 00000000 1 [ ] +635 0 70 "" 387.5586 620.12 0.0 00000000 00000000 1 [ ] +636 0 80 "" 388.1953 636.72 0.0 00000000 00000000 1 [ ] +637 0 80 "" 388.7822 586.91 0.0 00000000 00000000 1 [ ] +638 0 80 "" 389.4189 636.72 0.0 00000000 00000000 1 [ ] +639 0 70 "" 389.9648 545.90 0.0 00000000 00000000 1 [ ] +640 0 80 "" 390.5850 620.12 0.0 00000000 00000000 1 [ ] +641 0 80 "" 391.1621 577.15 0.0 00000000 00000000 1 [ ] +642 0 70 "" 391.7891 626.95 0.0 00000000 00000000 1 [ ] +643 0 80 "" 392.4053 616.21 0.0 00000000 00000000 1 [ ] +644 0 70 "" 392.9717 566.41 0.0 00000000 00000000 1 [ ] +645 0 80 "" 393.5254 553.71 0.0 00000000 00000000 1 [ ] +646 0 70 "" 394.1387 613.28 0.0 00000000 00000000 1 [ ] +647 0 80 "" 394.7217 583.01 0.0 00000000 00000000 1 [ ] +648 0 80 "" 395.2783 556.64 0.0 00000000 00000000 1 [ ] +649 0 80 "" 395.8281 549.80 0.0 00000000 00000000 1 [ ] +650 0 70 "" 396.4082 580.08 0.0 00000000 00000000 1 [ ] +651 0 80 "" 396.9854 577.15 0.0 00000000 00000000 1 [ ] +652 0 80 "" 397.6221 636.72 0.0 00000000 00000000 1 [ ] +653 0 80 "" 398.1680 545.90 0.0 00000000 00000000 1 [ ] +654 0 80 "" 398.7285 560.55 0.0 00000000 00000000 1 [ ] +655 0 80 "" 399.2920 563.48 0.0 00000000 00000000 1 [ ] +656 0 80 "" 399.9082 616.21 0.0 00000000 00000000 1 [ ] +657 0 80 "" 400.5381 629.88 0.0 00000000 00000000 1 [ ] +658 0 80 "" 401.1582 620.12 0.0 00000000 00000000 1 [ ] +659 0 80 "" 401.7314 573.24 0.0 00000000 00000000 1 [ ] +660 0 80 "" 402.3516 620.12 0.0 00000000 00000000 1 [ ] +661 0 80 "" 402.9648 613.28 0.0 00000000 00000000 1 [ ] +662 0 80 "" 403.5820 617.19 0.0 00000000 00000000 1 [ ] +663 0 80 "" 404.1816 599.61 0.0 00000000 00000000 1 [ ] +664 0 80 "" 404.7783 596.68 0.0 00000000 00000000 1 [ ] +665 0 70 "" 405.3418 563.48 0.0 00000000 00000000 1 [ ] +666 0 80 "" 405.9414 599.61 0.0 00000000 00000000 1 [ ] +667 0 80 "" 406.5020 560.55 0.0 00000000 00000000 1 [ ] +668 0 80 "" 407.1182 616.21 0.0 00000000 00000000 1 [ ] +669 0 70 "" 407.7178 599.61 0.0 00000000 00000000 1 [ ] +670 0 80 "" 408.2744 556.64 0.0 00000000 00000000 1 [ ] +671 0 80 "" 408.8750 600.59 0.0 00000000 00000000 1 [ ] +672 0 80 "" 409.4678 592.77 0.0 00000000 00000000 1 [ ] +673 0 80 "" 410.0283 560.55 0.0 00000000 00000000 1 [ ] +674 0 80 "" 410.6211 592.77 0.0 00000000 00000000 1 [ ] +675 0 80 "" 411.1816 560.55 0.0 00000000 00000000 1 [ ] +676 0 80 "" 411.7520 570.31 0.0 00000000 00000000 1 [ ] +677 0 80 "" 412.2910 539.06 0.0 00000000 00000000 1 [ ] +678 0 70 "" 412.8516 560.55 0.0 00000000 00000000 1 [ ] +679 0 80 "" 413.4248 573.24 0.0 00000000 00000000 1 [ ] +680 0 80 "" 413.9746 549.80 0.0 00000000 00000000 1 [ ] +681 0 80 "" 414.5811 606.45 0.0 00000000 00000000 1 [ ] +682 0 80 "" 415.2178 636.72 0.0 00000000 00000000 1 [ ] +683 0 80 "" 415.7881 570.31 0.0 00000000 00000000 1 [ ] +684 0 80 "" 416.4111 623.05 0.0 00000000 00000000 1 [ ] +685 0 80 "" 416.9785 567.38 0.0 00000000 00000000 1 [ ] +686 0 80 "" 417.5684 589.84 0.0 00000000 00000000 1 [ ] +687 0 80 "" 418.1113 542.97 0.0 00000000 00000000 1 [ ] +688 0 70 "" 418.7217 610.35 0.0 00000000 00000000 1 [ ] +689 0 80 "" 419.3047 583.01 0.0 00000000 00000000 1 [ ] +690 0 80 "" 419.8984 593.75 0.0 00000000 00000000 1 [ ] +691 0 70 "" 420.5117 613.28 0.0 00000000 00000000 1 [ ] +692 0 80 "" 421.0615 549.80 0.0 00000000 00000000 1 [ ] +693 0 70 "" 421.6846 623.05 0.0 00000000 00000000 1 [ ] +694 0 80 "" 422.2480 563.48 0.0 00000000 00000000 1 [ ] +695 0 70 "" 422.8115 563.48 0.0 00000000 00000000 1 [ ] +696 0 80 "" 423.3975 585.94 0.0 00000000 00000000 1 [ ] +697 0 70 "" 423.9580 560.55 0.0 00000000 00000000 1 [ ] +698 0 80 "" 424.5713 613.28 0.0 00000000 00000000 1 [ ] +699 0 80 "" 425.1982 626.95 0.0 00000000 00000000 1 [ ] +700 0 70 "" 425.7676 569.34 0.0 00000000 00000000 1 [ ] +701 0 80 "" 426.3877 620.12 0.0 00000000 00000000 1 [ ] +702 0 80 "" 426.9980 610.35 0.0 00000000 00000000 1 [ ] +703 0 80 "" 427.5576 559.57 0.0 00000000 00000000 1 [ ] +704 0 80 "" 428.1377 580.08 0.0 00000000 00000000 1 [ ] +705 0 80 "" 428.7480 610.35 0.0 00000000 00000000 1 [ ] +706 0 80 "" 429.3242 576.17 0.0 00000000 00000000 1 [ ] +707 0 80 "" 429.9414 617.19 0.0 00000000 00000000 1 [ ] +708 0 80 "" 430.5674 625.98 0.0 00000000 00000000 1 [ ] +709 0 80 "" 431.1377 570.31 0.0 00000000 00000000 1 [ ] +710 0 80 "" 431.7646 626.95 0.0 00000000 00000000 1 [ ] +711 0 80 "" 432.3877 623.05 0.0 00000000 00000000 1 [ ] +712 0 80 "" 432.9443 556.64 0.0 00000000 00000000 1 [ ] +713 0 70 "" 433.5312 586.91 0.0 00000000 00000000 1 [ ] +714 0 80 "" 434.1113 580.08 0.0 00000000 00000000 1 [ ] +715 0 80 "" 434.7373 625.98 0.0 00000000 00000000 1 [ ] +716 0 70 "" 435.3076 570.31 0.0 00000000 00000000 1 [ ] +717 0 80 "" 435.8848 577.15 0.0 00000000 00000000 1 [ ] +718 0 70 "" 436.4512 566.41 0.0 00000000 00000000 1 [ ] +719 0 80 "" 437.0146 563.48 0.0 00000000 00000000 1 [ ] +720 0 80 "" 437.6113 596.68 0.0 00000000 00000000 1 [ ] +721 0 80 "" 438.1572 545.90 0.0 00000000 00000000 1 [ ] +722 0 70 "" 438.7979 640.62 0.0 00000000 00000000 1 [ ] +723 0 80 "" 439.3477 549.80 0.0 00000000 00000000 1 [ ] +724 0 80 "" 439.8975 549.80 0.0 00000000 00000000 1 [ ] +725 0 70 "" 440.5381 640.62 0.0 00000000 00000000 1 [ ] +726 0 80 "" 441.1475 609.38 0.0 00000000 00000000 1 [ ] +727 0 80 "" 441.7812 633.79 0.0 00000000 00000000 1 [ ] +728 0 80 "" 442.3711 589.84 0.0 00000000 00000000 1 [ ] +729 0 70 "" 442.9277 556.64 0.0 00000000 00000000 1 [ ] +730 0 80 "" 443.4873 559.57 0.0 00000000 00000000 1 [ ] +731 0 80 "" 444.0771 589.84 0.0 00000000 00000000 1 [ ] +732 0 80 "" 444.6504 573.24 0.0 00000000 00000000 1 [ ] +733 0 70 "" 445.2578 607.42 0.0 00000000 00000000 1 [ ] +734 0 80 "" 445.8574 599.61 0.0 00000000 00000000 1 [ ] +735 0 70 "" 446.4678 610.35 0.0 00000000 00000000 1 [ ] +736 0 80 "" 447.0205 552.73 0.0 00000000 00000000 1 [ ] +737 0 80 "" 447.5605 540.04 0.0 00000000 00000000 1 [ ] +738 0 80 "" 448.1172 556.64 0.0 00000000 00000000 1 [ ] +739 0 80 "" 448.6777 560.55 0.0 00000000 00000000 1 [ ] +740 0 70 "" 449.3242 646.48 0.0 00000000 00000000 1 [ ] +741 0 80 "" 449.9404 616.21 0.0 00000000 00000000 1 [ ] +742 0 80 "" 450.5537 613.28 0.0 00000000 00000000 1 [ ] +743 0 80 "" 451.1436 589.84 0.0 00000000 00000000 1 [ ] +744 0 80 "" 451.6973 553.71 0.0 00000000 00000000 1 [ ] +745 0 70 "" 452.2910 593.75 0.0 00000000 00000000 1 [ ] +746 0 80 "" 452.8271 536.13 0.0 00000000 00000000 1 [ ] +747 0 80 "" 453.4307 603.52 0.0 00000000 00000000 1 [ ] +748 0 80 "" 453.9736 542.97 0.0 00000000 00000000 1 [ ] +749 0 80 "" 454.5508 577.15 0.0 00000000 00000000 1 [ ] +750 0 80 "" 455.1738 623.05 0.0 00000000 00000000 1 [ ] +751 0 80 "" 455.7910 617.19 0.0 00000000 00000000 1 [ ] +752 0 80 "" 456.3242 533.20 0.0 00000000 00000000 1 [ ] +753 0 80 "" 456.8975 573.24 0.0 00000000 00000000 1 [ ] +754 0 80 "" 457.5039 606.45 0.0 00000000 00000000 1 [ ] +755 0 80 "" 458.1270 623.05 0.0 00000000 00000000 1 [ ] +756 0 70 "" 458.6934 566.41 0.0 00000000 00000000 1 [ ] +757 0 80 "" 459.2969 603.52 0.0 00000000 00000000 1 [ ] +758 0 80 "" 459.8740 577.15 0.0 00000000 00000000 1 [ ] +759 0 80 "" 460.4072 533.20 0.0 00000000 00000000 1 [ ] +760 0 70 "" 460.9570 549.80 0.0 00000000 00000000 1 [ ] +761 0 80 "" 461.5605 603.52 0.0 00000000 00000000 1 [ ] +762 0 70 "" 462.1572 596.68 0.0 00000000 00000000 1 [ ] +763 0 80 "" 462.7969 639.65 0.0 00000000 00000000 1 [ ] +764 0 80 "" 463.3633 566.41 0.0 00000000 00000000 1 [ ] +765 0 80 "" 463.9404 577.15 0.0 00000000 00000000 1 [ ] +766 0 80 "" 464.4873 546.88 0.0 00000000 00000000 1 [ ] +767 0 80 "" 465.0469 559.57 0.0 00000000 00000000 1 [ ] +768 0 80 "" 465.6533 606.45 0.0 00000000 00000000 1 [ ] +769 0 80 "" 466.2568 603.52 0.0 00000000 00000000 1 [ ] +770 0 70 "" 466.8672 610.35 0.0 00000000 00000000 1 [ ] +771 0 80 "" 467.5039 636.72 0.0 00000000 00000000 1 [ ] +772 0 70 "" 468.0605 556.64 0.0 00000000 00000000 1 [ ] +773 0 80 "" 468.6807 620.12 0.0 00000000 00000000 1 [ ] +774 0 80 "" 469.2705 589.84 0.0 00000000 00000000 1 [ ] +775 0 80 "" 469.8369 566.41 0.0 00000000 00000000 1 [ ] +776 0 70 "" 470.4404 603.52 0.0 00000000 00000000 1 [ ] +777 0 80 "" 471.0000 559.57 0.0 00000000 00000000 1 [ ] +778 0 70 "" 471.6104 610.35 0.0 00000000 00000000 1 [ ] +779 0 80 "" 472.1533 542.97 0.0 00000000 00000000 1 [ ] +780 0 70 "" 472.6865 533.20 0.0 00000000 00000000 1 [ ] +781 0 80 "" 473.2334 546.88 0.0 00000000 00000000 1 [ ] +782 0 70 "" 473.7969 563.48 0.0 00000000 00000000 1 [ ] +783 0 80 "" 474.4033 606.45 0.0 00000000 00000000 1 [ ] +784 0 80 "" 475.0039 600.59 0.0 00000000 00000000 1 [ ] +785 0 70 "" 475.6133 609.38 0.0 00000000 00000000 1 [ ] +786 0 80 "" 476.2305 617.19 0.0 00000000 00000000 1 [ ] +787 0 80 "" 476.8633 632.81 0.0 00000000 00000000 1 [ ] +788 0 80 "" 477.5000 636.72 0.0 00000000 00000000 1 [ ] +789 0 80 "" 478.0771 577.15 0.0 00000000 00000000 1 [ ] +790 0 80 "" 478.6934 616.21 0.0 00000000 00000000 1 [ ] +791 0 80 "" 479.2969 603.52 0.0 00000000 00000000 1 [ ] +792 0 80 "" 479.8867 589.84 0.0 00000000 00000000 1 [ ] +793 0 80 "" 480.5166 629.88 0.0 00000000 00000000 1 [ ] +794 0 80 "" 481.1035 586.91 0.0 00000000 00000000 1 [ ] +795 0 80 "" 481.6904 586.91 0.0 00000000 00000000 1 [ ] +796 0 80 "" 482.2236 533.20 0.0 00000000 00000000 1 [ ] +797 0 80 "" 482.7803 556.64 0.0 00000000 00000000 1 [ ] +798 0 80 "" 483.3369 556.64 0.0 00000000 00000000 1 [ ] +799 0 80 "" 483.9336 596.68 0.0 00000000 00000000 1 [ ] +800 0 80 "" 484.5264 592.77 0.0 00000000 00000000 1 [ ] +801 0 80 "" 485.0664 540.04 0.0 00000000 00000000 1 [ ] +802 0 80 "" 485.6768 610.35 0.0 00000000 00000000 1 [ ] +803 0 80 "" 486.3262 649.41 0.0 00000000 00000000 1 [ ] +804 0 70 "" 486.8701 543.95 0.0 00000000 00000000 1 [ ] +805 0 80 "" 487.4795 609.38 0.0 00000000 00000000 1 [ ] +806 0 80 "" 488.0400 560.55 0.0 00000000 00000000 1 [ ] +807 0 80 "" 488.6729 632.81 0.0 00000000 00000000 1 [ ] +808 0 70 "" 489.2402 567.38 0.0 00000000 00000000 1 [ ] +809 0 80 "" 489.7861 545.90 0.0 00000000 00000000 1 [ ] +810 0 70 "" 490.3633 577.15 0.0 00000000 00000000 1 [ ] +811 0 80 "" 490.9961 632.81 0.0 00000000 00000000 1 [ ] +812 0 70 "" 491.5693 573.24 0.0 00000000 00000000 1 [ ] +813 0 80 "" 492.1396 570.31 0.0 00000000 00000000 1 [ ] +814 0 80 "" 492.7529 613.28 0.0 00000000 00000000 1 [ ] +815 0 70 "" 493.3135 560.55 0.0 00000000 00000000 1 [ ] +816 0 80 "" 493.8936 580.08 0.0 00000000 00000000 1 [ ] +817 0 80 "" 494.4600 566.41 0.0 00000000 00000000 1 [ ] +818 0 70 "" 495.0830 623.05 0.0 00000000 00000000 1 [ ] +819 0 80 "" 495.6826 599.61 0.0 00000000 00000000 1 [ ] +820 0 80 "" 496.2900 607.42 0.0 00000000 00000000 1 [ ] +821 0 70 "" 496.8594 569.34 0.0 00000000 00000000 1 [ ] +822 0 80 "" 497.5059 646.48 0.0 00000000 00000000 1 [ ] +823 0 80 "" 498.0566 550.78 0.0 00000000 00000000 1 [ ] +824 0 80 "" 498.6631 606.45 0.0 00000000 00000000 1 [ ] +825 0 80 "" 499.2998 636.72 0.0 00000000 00000000 1 [ ] +826 0 70 "" 499.8564 556.64 0.0 00000000 00000000 1 [ ] +827 0 80 "" 500.4893 632.81 0.0 00000000 00000000 1 [ ] +828 0 80 "" 501.0566 567.38 0.0 00000000 00000000 1 [ ] +829 0 70 "" 501.5967 540.04 0.0 00000000 00000000 1 [ ] +830 0 80 "" 502.1826 585.94 0.0 00000000 00000000 1 [ ] +831 0 80 "" 502.7861 603.52 0.0 00000000 00000000 1 [ ] +832 0 70 "" 503.3857 599.61 0.0 00000000 00000000 1 [ ] +833 0 80 "" 504.0098 624.02 0.0 00000000 00000000 1 [ ] +834 0 80 "" 504.5732 563.48 0.0 00000000 00000000 1 [ ] +835 0 80 "" 505.1328 559.57 0.0 00000000 00000000 1 [ ] +836 0 70 "" 505.6924 559.57 0.0 00000000 00000000 1 [ ] +837 0 80 "" 506.2861 593.75 0.0 00000000 00000000 1 [ ] +838 0 80 "" 506.9092 623.05 0.0 00000000 00000000 1 [ ] +839 0 80 "" 507.4561 546.88 0.0 00000000 00000000 1 [ ] +840 0 80 "" 508.0557 599.61 0.0 00000000 00000000 1 [ ] +841 0 80 "" 508.5957 540.04 0.0 00000000 00000000 1 [ ] +842 0 70 "" 509.1865 590.82 0.0 00000000 00000000 1 [ ] +843 0 80 "" 509.8125 625.98 0.0 00000000 00000000 1 [ ] +844 0 70 "" 510.4160 603.52 0.0 00000000 00000000 1 [ ] +845 0 80 "" 510.9961 580.08 0.0 00000000 00000000 1 [ ] +846 0 80 "" 511.5498 553.71 0.0 00000000 00000000 1 [ ] +847 0 70 "" 512.1631 613.28 0.0 00000000 00000000 1 [ ] +848 0 80 "" 512.7764 613.28 0.0 00000000 00000000 1 [ ] +849 0 70 "" 513.3662 589.84 0.0 00000000 00000000 1 [ ] +850 0 80 "" 513.9824 616.21 0.0 00000000 00000000 1 [ ] +851 0 80 "" 514.5488 566.41 0.0 00000000 00000000 1 [ ] +852 0 70 "" 515.1162 567.38 0.0 00000000 00000000 1 [ ] +853 0 80 "" 515.7295 613.28 0.0 00000000 00000000 1 [ ] +854 0 70 "" 516.3330 603.52 0.0 00000000 00000000 1 [ ] +855 0 80 "" 516.9092 576.17 0.0 00000000 00000000 1 [ ] +856 0 80 "" 517.5195 610.35 0.0 00000000 00000000 1 [ ] +857 0 80 "" 518.1328 613.28 0.0 00000000 00000000 1 [ ] +858 0 80 "" 518.7588 625.98 0.0 00000000 00000000 1 [ ] +859 0 80 "" 519.3691 610.35 0.0 00000000 00000000 1 [ ] +860 0 70 "" 519.9062 537.11 0.0 00000000 00000000 1 [ ] +861 0 80 "" 520.4395 533.20 0.0 00000000 00000000 1 [ ] +862 0 80 "" 521.0654 625.98 0.0 00000000 00000000 1 [ ] +863 0 70 "" 521.6025 537.11 0.0 00000000 00000000 1 [ ] +864 0 80 "" 522.1855 583.01 0.0 00000000 00000000 1 [ ] +865 0 80 "" 522.7920 606.45 0.0 00000000 00000000 1 [ ] +866 0 70 "" 523.3691 577.15 0.0 00000000 00000000 1 [ ] +867 0 80 "" 523.9688 599.61 0.0 00000000 00000000 1 [ ] +868 0 70 "" 524.5625 593.75 0.0 00000000 00000000 1 [ ] +869 0 80 "" 525.1729 610.35 0.0 00000000 00000000 1 [ ] +870 0 70 "" 525.7461 573.24 0.0 00000000 00000000 1 [ ] +871 0 80 "" 526.2920 545.90 0.0 00000000 00000000 1 [ ] +872 0 80 "" 526.9229 630.86 0.0 00000000 00000000 1 [ ] +873 0 80 "" 527.5293 606.45 0.0 00000000 00000000 1 [ ] +874 0 80 "" 528.1328 603.52 0.0 00000000 00000000 1 [ ] +875 0 80 "" 528.7119 579.10 0.0 00000000 00000000 1 [ ] +876 0 80 "" 529.3428 630.86 0.0 00000000 00000000 1 [ ] +877 0 80 "" 529.9053 562.50 0.0 00000000 00000000 1 [ ] +878 0 80 "" 530.5059 600.59 0.0 00000000 00000000 1 [ ] +879 0 80 "" 531.0586 552.73 0.0 00000000 00000000 1 [ ] +880 0 70 "" 531.6758 617.19 0.0 00000000 00000000 1 [ ] +881 0 80 "" 532.2188 542.97 0.0 00000000 00000000 1 [ ] +882 0 80 "" 532.8193 600.59 0.0 00000000 00000000 1 [ ] +883 0 80 "" 533.3555 536.13 0.0 00000000 00000000 1 [ ] +884 0 80 "" 533.8818 526.37 0.0 00000000 00000000 1 [ ] +885 0 80 "" 534.4658 583.98 0.0 00000000 00000000 1 [ ] +886 0 80 "" 535.0322 566.41 0.0 00000000 00000000 1 [ ] +887 0 80 "" 535.6055 573.24 0.0 00000000 00000000 1 [ ] +888 0 80 "" 536.2393 633.79 0.0 00000000 00000000 1 [ ] +889 0 80 "" 536.8252 585.94 0.0 00000000 00000000 1 [ ] +890 0 70 "" 537.4092 583.98 0.0 00000000 00000000 1 [ ] +891 0 80 "" 538.0459 636.72 0.0 00000000 00000000 1 [ ] +892 0 80 "" 538.5918 545.90 0.0 00000000 00000000 1 [ ] +893 0 80 "" 539.1426 550.78 0.0 00000000 00000000 1 [ ] +894 0 80 "" 539.7324 589.84 0.0 00000000 00000000 1 [ ] +895 0 80 "" 540.3584 625.98 0.0 00000000 00000000 1 [ ] +896 0 70 "" 540.9756 617.19 0.0 00000000 00000000 1 [ ] +897 0 80 "" 541.5518 576.17 0.0 00000000 00000000 1 [ ] +898 0 80 "" 542.0791 527.34 0.0 00000000 00000000 1 [ ] +899 0 80 "" 542.6152 536.13 0.0 00000000 00000000 1 [ ] +900 0 80 "" 543.2021 586.91 0.0 00000000 00000000 1 [ ] +901 0 70 "" 543.7852 583.01 0.0 00000000 00000000 1 [ ] +902 0 80 "" 544.3555 570.31 0.0 00000000 00000000 1 [ ] +903 0 80 "" 544.9053 549.80 0.0 00000000 00000000 1 [ ] +904 0 70 "" 545.5254 620.12 0.0 00000000 00000000 1 [ ] +905 0 80 "" 546.1484 623.05 0.0 00000000 00000000 1 [ ] +906 0 80 "" 546.7490 600.59 0.0 00000000 00000000 1 [ ] +907 0 80 "" 547.3818 632.81 0.0 00000000 00000000 1 [ ] +908 0 80 "" 547.9756 593.75 0.0 00000000 00000000 1 [ ] +909 0 80 "" 548.5586 583.01 0.0 00000000 00000000 1 [ ] +910 0 80 "" 549.1123 553.71 0.0 00000000 00000000 1 [ ] +911 0 70 "" 549.6689 556.64 0.0 00000000 00000000 1 [ ] +912 0 80 "" 550.2920 623.05 0.0 00000000 00000000 1 [ ] +913 0 80 "" 550.8584 566.41 0.0 00000000 00000000 1 [ ] +914 0 80 "" 551.4287 570.31 0.0 00000000 00000000 1 [ ] +915 0 70 "" 552.0088 580.08 0.0 00000000 00000000 1 [ ] +916 0 80 "" 552.6484 639.65 0.0 00000000 00000000 1 [ ] +917 0 80 "" 553.2451 596.68 0.0 00000000 00000000 1 [ ] +918 0 80 "" 553.8682 623.05 0.0 00000000 00000000 1 [ ] +919 0 80 "" 554.4453 577.15 0.0 00000000 00000000 1 [ ] +920 0 80 "" 555.0420 596.68 0.0 00000000 00000000 1 [ ] +921 0 80 "" 555.5752 533.20 0.0 00000000 00000000 1 [ ] +922 0 80 "" 556.1748 599.61 0.0 00000000 00000000 1 [ ] +923 0 70 "" 556.7881 613.28 0.0 00000000 00000000 1 [ ] +924 0 80 "" 557.3848 596.68 0.0 00000000 00000000 1 [ ] +925 0 80 "" 557.9648 580.08 0.0 00000000 00000000 1 [ ] +926 0 70 "" 558.5420 577.15 0.0 00000000 00000000 1 [ ] +927 0 80 "" 559.1387 596.68 0.0 00000000 00000000 1 [ ] +928 0 70 "" 559.6914 552.73 0.0 00000000 00000000 1 [ ] +929 0 80 "" 560.2451 553.71 0.0 00000000 00000000 1 [ ] +930 0 70 "" 560.8086 563.48 0.0 00000000 00000000 1 [ ] +931 0 80 "" 561.3516 542.97 0.0 00000000 00000000 1 [ ] +932 0 80 "" 562.0049 653.32 0.0 00000000 00000000 1 [ ] +933 0 80 "" 562.5820 577.15 0.0 00000000 00000000 1 [ ] +934 0 80 "" 563.1650 583.01 0.0 00000000 00000000 1 [ ] +935 0 80 "" 563.7783 613.28 0.0 00000000 00000000 1 [ ] +936 0 80 "" 564.4150 636.72 0.0 00000000 00000000 1 [ ] +937 0 70 "" 565.0283 613.28 0.0 00000000 00000000 1 [ ] +938 0 80 "" 565.6514 623.05 0.0 00000000 00000000 1 [ ] +939 0 80 "" 566.1953 543.95 0.0 00000000 00000000 1 [ ] +940 0 70 "" 566.7852 589.84 0.0 00000000 00000000 1 [ ] +941 0 80 "" 567.3320 546.88 0.0 00000000 00000000 1 [ ] +942 0 80 "" 567.8750 542.97 0.0 00000000 00000000 1 [ ] +943 0 80 "" 568.4150 540.04 0.0 00000000 00000000 1 [ ] +944 0 70 "" 568.9580 542.97 0.0 00000000 00000000 1 [ ] +945 0 80 "" 569.5146 556.64 0.0 00000000 00000000 1 [ ] +946 0 80 "" 570.1445 629.88 0.0 00000000 00000000 1 [ ] +947 0 80 "" 570.7412 596.68 0.0 00000000 00000000 1 [ ] +948 0 80 "" 571.3379 596.68 0.0 00000000 00000000 1 [ ] +949 0 80 "" 571.9551 617.19 0.0 00000000 00000000 1 [ ] +950 0 80 "" 572.5576 602.54 0.0 00000000 00000000 1 [ ] +951 0 80 "" 573.1514 593.75 0.0 00000000 00000000 1 [ ] +952 0 80 "" 573.7451 593.75 0.0 00000000 00000000 1 [ ] +953 0 70 "" 574.2881 542.97 0.0 00000000 00000000 1 [ ] +954 0 80 "" 574.8682 580.08 0.0 00000000 00000000 1 [ ] +955 0 70 "" 575.4883 620.12 0.0 00000000 00000000 1 [ ] +956 0 80 "" 576.0811 592.77 0.0 00000000 00000000 1 [ ] +957 0 80 "" 576.6211 540.04 0.0 00000000 00000000 1 [ ] +958 0 70 "" 577.1680 546.88 0.0 00000000 00000000 1 [ ] +959 0 80 "" 577.7148 546.88 0.0 00000000 00000000 1 [ ] +960 0 80 "" 578.3145 599.61 0.0 00000000 00000000 1 [ ] +961 0 80 "" 578.8613 546.88 0.0 00000000 00000000 1 [ ] +962 0 80 "" 579.4912 629.88 0.0 00000000 00000000 1 [ ] +963 0 80 "" 580.0547 563.48 0.0 00000000 00000000 1 [ ] +964 0 70 "" 580.6777 623.05 0.0 00000000 00000000 1 [ ] +965 0 80 "" 581.2842 606.45 0.0 00000000 00000000 1 [ ] +966 0 80 "" 581.8779 593.75 0.0 00000000 00000000 1 [ ] +967 0 80 "" 582.4277 549.80 0.0 00000000 00000000 1 [ ] +968 0 80 "" 583.0078 580.08 0.0 00000000 00000000 1 [ ] +969 0 70 "" 583.5713 563.48 0.0 00000000 00000000 1 [ ] +970 0 80 "" 584.1143 542.97 0.0 00000000 00000000 1 [ ] +971 0 80 "" 584.7109 596.68 0.0 00000000 00000000 1 [ ] +972 0 70 "" 585.3311 620.12 0.0 00000000 00000000 1 [ ] +973 0 80 "" 585.9414 610.35 0.0 00000000 00000000 1 [ ] +974 0 80 "" 586.5146 573.24 0.0 00000000 00000000 1 [ ] +975 0 70 "" 587.1074 592.77 0.0 00000000 00000000 1 [ ] +976 0 80 "" 587.6875 580.08 0.0 00000000 00000000 1 [ ] +977 0 80 "" 588.2715 583.98 0.0 00000000 00000000 1 [ ] +978 0 80 "" 588.8379 566.41 0.0 00000000 00000000 1 [ ] +979 0 80 "" 589.3848 546.88 0.0 00000000 00000000 1 [ ] +980 0 80 "" 589.9814 596.68 0.0 00000000 00000000 1 [ ] +981 0 80 "" 590.5742 592.77 0.0 00000000 00000000 1 [ ] +982 0 80 "" 591.1914 617.19 0.0 00000000 00000000 1 [ ] +983 0 80 "" 591.8008 609.38 0.0 00000000 00000000 1 [ ] +984 0 80 "" 592.3877 586.91 0.0 00000000 00000000 1 [ ] +985 0 80 "" 593.0205 632.81 0.0 00000000 00000000 1 [ ] +986 0 80 "" 593.6309 610.35 0.0 00000000 00000000 1 [ ] +987 0 80 "" 594.2539 623.05 0.0 00000000 00000000 1 [ ] +988 0 80 "" 594.8174 563.48 0.0 00000000 00000000 1 [ ] +989 0 70 "" 595.4346 617.19 0.0 00000000 00000000 1 [ ] +990 0 80 "" 596.0439 609.38 0.0 00000000 00000000 1 [ ] +991 0 80 "" 596.6074 563.48 0.0 00000000 00000000 1 [ ] +992 0 80 "" 597.1777 570.31 0.0 00000000 00000000 1 [ ] +993 0 80 "" 597.7441 566.41 0.0 00000000 00000000 1 [ ] +994 0 80 "" 598.3047 560.55 0.0 00000000 00000000 1 [ ] +995 0 70 "" 598.9072 602.54 0.0 00000000 00000000 1 [ ] +996 0 80 "" 599.5371 629.88 0.0 00000000 00000000 1 [ ] +997 0 80 "" 600.1104 573.24 0.0 00000000 00000000 1 [ ] +998 0 80 "" 600.6943 583.98 0.0 00000000 00000000 1 [ ] +999 0 80 "" 601.3145 620.12 0.0 00000000 00000000 1 [ ] +1000 0 80 "" 601.9375 623.05 0.0 00000000 00000000 1 [ ] +1001 0 70 "" 602.5039 566.41 0.0 00000000 00000000 1 [ ] +1002 0 1 "" 605.8389 3334.96 0.0 00000000 00000000 1 [ ] diff --git a/studio_functions/GUIs/EEG Tab/.erp b/studio_functions/GUIs/EEG Tab/.erp new file mode 100644 index 00000000..d453e678 Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/.erp differ diff --git a/studio_functions/GUIs/EEG Tab/.txt b/studio_functions/GUIs/EEG Tab/.txt new file mode 100644 index 00000000..c59dc82f --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/.txt @@ -0,0 +1,388 @@ +# Non-editable header begin -------------------------------------------------------------------------------- +# +# data format...............: continuous +# setname...................: 6_N400_filt +# filename..................: 6_N400_filt.set +# filepath..................: /Users/gzhang/Downloads/ +# nchan.....................: 30 +# pnts......................: 79400 +# srate.....................: 200 +# nevents...................: 362 +# generated by (bdf)........: +# generated by (set)........: 6_N400_filt +# reported in ..............: +# prog Version..............: 10.11 +# creation date.............: 07-Jun-2024 09:59:14 +# user Account..............: +# +# Non-editable header end -------------------------------------------------------------------------------- + + + + +# item bepoch ecode label onset diff dura b_flags a_flags enable bin +# (sec) (msec) (msec) (binary) (binary) + + +1 0 202 "" 1.6426 0.00 0.0 00000000 00000000 1 [ ] +2 0 202 "" 2.6504 1007.81 0.0 00000000 00000000 1 [ ] +3 0 121 "" 6.6348 3984.38 0.0 00000000 00000000 1 [ ] +4 0 221 "" 7.7510 1116.21 0.0 00000000 00000000 1 [ ] +5 0 201 "" 8.3145 563.48 0.0 00000000 00000000 1 [ ] +6 0 121 "" 9.5010 1186.52 0.0 00000000 00000000 1 [ ] +7 0 221 "" 10.7998 1298.83 0.0 00000000 00000000 1 [ ] +8 0 201 "" 11.2988 499.02 0.0 00000000 00000000 1 [ ] +9 0 111 "" 12.5332 1234.38 0.0 00000000 00000000 1 [ ] +10 0 211 "" 13.6494 1116.21 0.0 00000000 00000000 1 [ ] +11 0 201 "" 14.2500 600.59 0.0 00000000 00000000 1 [ ] +12 0 111 "" 15.3652 1115.23 0.0 00000000 00000000 1 [ ] +13 0 211 "" 16.5811 1215.82 0.0 00000000 00000000 1 [ ] +14 0 201 "" 17.4102 829.10 0.0 00000000 00000000 1 [ ] +15 0 121 "" 18.2979 887.70 0.0 00000000 00000000 1 [ ] +16 0 221 "" 19.4805 1182.62 0.0 00000000 00000000 1 [ ] +17 0 201 "" 20.2266 746.09 0.0 00000000 00000000 1 [ ] +18 0 111 "" 21.2129 986.33 0.0 00000000 00000000 1 [ ] +19 0 211 "" 22.3789 1166.02 0.0 00000000 00000000 1 [ ] +20 0 201 "" 23.0664 687.50 0.0 00000000 00000000 1 [ ] +21 0 111 "" 24.1455 1079.10 0.0 00000000 00000000 1 [ ] +22 0 211 "" 25.2783 1132.81 0.0 00000000 00000000 1 [ ] +23 0 201 "" 25.7617 483.40 0.0 00000000 00000000 1 [ ] +24 0 121 "" 26.9775 1215.82 0.0 00000000 00000000 1 [ ] +25 0 221 "" 28.1943 1216.80 0.0 00000000 00000000 1 [ ] +26 0 201 "" 28.6982 503.91 0.0 00000000 00000000 1 [ ] +27 0 121 "" 29.8936 1195.31 0.0 00000000 00000000 1 [ ] +28 0 221 "" 31.0762 1182.62 0.0 00000000 00000000 1 [ ] +29 0 201 "" 31.6182 541.99 0.0 00000000 00000000 1 [ ] +30 0 111 "" 32.7422 1124.02 0.0 00000000 00000000 1 [ ] +31 0 211 "" 33.9590 1216.80 0.0 00000000 00000000 1 [ ] +32 0 201 "" 34.4102 451.17 0.0 00000000 00000000 1 [ ] +33 0 111 "" 35.6416 1231.45 0.0 00000000 00000000 1 [ ] +34 0 211 "" 36.7578 1116.21 0.0 00000000 00000000 1 [ ] +35 0 201 "" 37.3379 580.08 0.0 00000000 00000000 1 [ ] +36 0 121 "" 38.5068 1168.95 0.0 00000000 00000000 1 [ ] +37 0 221 "" 39.7900 1283.20 0.0 00000000 00000000 1 [ ] +38 0 201 "" 40.2334 443.36 0.0 00000000 00000000 1 [ ] +39 0 111 "" 41.4395 1206.05 0.0 00000000 00000000 1 [ ] +40 0 211 "" 42.6553 1215.82 0.0 00000000 00000000 1 [ ] +41 0 201 "" 43.1221 466.80 0.0 00000000 00000000 1 [ ] +42 0 121 "" 44.3545 1232.42 0.0 00000000 00000000 1 [ ] +43 0 221 "" 45.4707 1116.21 0.0 00000000 00000000 1 [ ] +44 0 201 "" 45.9541 483.40 0.0 00000000 00000000 1 [ ] +45 0 111 "" 47.2373 1283.20 0.0 00000000 00000000 1 [ ] +46 0 211 "" 48.3867 1149.41 0.0 00000000 00000000 1 [ ] +47 0 201 "" 48.8652 478.52 0.0 00000000 00000000 1 [ ] +48 0 111 "" 50.0361 1170.90 0.0 00000000 00000000 1 [ ] +49 0 211 "" 51.3193 1283.20 0.0 00000000 00000000 1 [ ] +50 0 201 "" 51.6416 322.27 0.0 00000000 00000000 1 [ ] +51 0 111 "" 53.1182 1476.56 0.0 00000000 00000000 1 [ ] +52 0 211 "" 54.2676 1149.41 0.0 00000000 00000000 1 [ ] +53 0 202 "" 54.7295 461.91 0.0 00000000 00000000 1 [ ] +54 0 111 "" 55.9336 1204.10 0.0 00000000 00000000 1 [ ] +55 0 211 "" 57.0840 1150.39 0.0 00000000 00000000 1 [ ] +56 0 201 "" 57.4814 397.46 0.0 00000000 00000000 1 [ ] +57 0 121 "" 58.8164 1334.96 0.0 00000000 00000000 1 [ ] +58 0 221 "" 60.0996 1283.20 0.0 00000000 00000000 1 [ ] +59 0 201 "" 60.5537 454.10 0.0 00000000 00000000 1 [ ] +60 0 111 "" 61.7822 1228.52 0.0 00000000 00000000 1 [ ] +61 0 211 "" 63.0811 1298.83 0.0 00000000 00000000 1 [ ] +62 0 201 "" 63.4258 344.73 0.0 00000000 00000000 1 [ ] +63 0 121 "" 70.5791 7153.32 0.0 00000000 00000000 1 [ ] +64 0 221 "" 71.7285 1149.41 0.0 00000000 00000000 1 [ ] +65 0 201 "" 72.2734 544.92 0.0 00000000 00000000 1 [ ] +66 0 121 "" 73.3613 1087.89 0.0 00000000 00000000 1 [ ] +67 0 221 "" 74.4941 1132.81 0.0 00000000 00000000 1 [ ] +68 0 201 "" 75.1768 682.62 0.0 00000000 00000000 1 [ ] +69 0 121 "" 76.1768 1000.00 0.0 00000000 00000000 1 [ ] +70 0 221 "" 77.4434 1266.60 0.0 00000000 00000000 1 [ ] +71 0 201 "" 77.9131 469.73 0.0 00000000 00000000 1 [ ] +72 0 121 "" 79.1094 1196.29 0.0 00000000 00000000 1 [ ] +73 0 221 "" 80.2256 1116.21 0.0 00000000 00000000 1 [ ] +74 0 201 "" 80.7607 535.16 0.0 00000000 00000000 1 [ ] +75 0 121 "" 81.9746 1213.87 0.0 00000000 00000000 1 [ ] +76 0 221 "" 83.2080 1233.40 0.0 00000000 00000000 1 [ ] +77 0 201 "" 83.6973 489.26 0.0 00000000 00000000 1 [ ] +78 0 121 "" 84.8232 1125.98 0.0 00000000 00000000 1 [ ] +79 0 221 "" 86.0400 1216.80 0.0 00000000 00000000 1 [ ] +80 0 201 "" 86.5605 520.51 0.0 00000000 00000000 1 [ ] +81 0 111 "" 87.7725 1211.91 0.0 00000000 00000000 1 [ ] +82 0 211 "" 88.9893 1216.80 0.0 00000000 00000000 1 [ ] +83 0 201 "" 89.3447 355.47 0.0 00000000 00000000 1 [ ] +84 0 121 "" 90.7383 1393.55 0.0 00000000 00000000 1 [ ] +85 0 221 "" 92.0215 1283.20 0.0 00000000 00000000 1 [ ] +86 0 201 "" 92.4326 411.13 0.0 00000000 00000000 1 [ ] +87 0 111 "" 93.7207 1288.09 0.0 00000000 00000000 1 [ ] +88 0 211 "" 94.9033 1182.62 0.0 00000000 00000000 1 [ ] +89 0 201 "" 95.4805 577.15 0.0 00000000 00000000 1 [ ] +90 0 121 "" 96.6865 1206.05 0.0 00000000 00000000 1 [ ] +91 0 221 "" 97.7861 1099.61 0.0 00000000 00000000 1 [ ] +92 0 201 "" 98.1602 374.02 0.0 00000000 00000000 1 [ ] +93 0 111 "" 99.5850 1424.80 0.0 00000000 00000000 1 [ ] +94 0 211 "" 100.7012 1116.21 0.0 00000000 00000000 1 [ ] +95 0 201 "" 100.9922 291.02 0.0 00000000 00000000 1 [ ] +96 0 111 "" 102.3838 1391.60 0.0 00000000 00000000 1 [ ] +97 0 211 "" 103.6338 1250.00 0.0 00000000 00000000 1 [ ] +98 0 202 "" 104.1602 526.37 0.0 00000000 00000000 1 [ ] +99 0 121 "" 105.3164 1156.25 0.0 00000000 00000000 1 [ ] +100 0 221 "" 106.5996 1283.20 0.0 00000000 00000000 1 [ ] +101 0 201 "" 107.1602 560.55 0.0 00000000 00000000 1 [ ] +102 0 121 "" 108.3320 1171.88 0.0 00000000 00000000 1 [ ] +103 0 221 "" 109.4482 1116.21 0.0 00000000 00000000 1 [ ] +104 0 201 "" 110.1768 728.52 0.0 00000000 00000000 1 [ ] +105 0 111 "" 111.0811 904.30 0.0 00000000 00000000 1 [ ] +106 0 211 "" 112.1973 1116.21 0.0 00000000 00000000 1 [ ] +107 0 201 "" 112.5527 355.47 0.0 00000000 00000000 1 [ ] +108 0 111 "" 113.9629 1410.16 0.0 00000000 00000000 1 [ ] +109 0 211 "" 115.1299 1166.99 0.0 00000000 00000000 1 [ ] +110 0 201 "" 115.4961 366.21 0.0 00000000 00000000 1 [ ] +111 0 111 "" 116.8623 1366.21 0.0 00000000 00000000 1 [ ] +112 0 211 "" 118.0781 1215.82 0.0 00000000 00000000 1 [ ] +113 0 201 "" 118.3926 314.45 0.0 00000000 00000000 1 [ ] +114 0 111 "" 119.7275 1334.96 0.0 00000000 00000000 1 [ ] +115 0 211 "" 121.0273 1299.80 0.0 00000000 00000000 1 [ ] +116 0 201 "" 121.4482 420.90 0.0 00000000 00000000 1 [ ] +117 0 111 "" 122.7598 1311.52 0.0 00000000 00000000 1 [ ] +118 0 211 "" 123.9766 1216.80 0.0 00000000 00000000 1 [ ] +119 0 201 "" 124.5195 542.97 0.0 00000000 00000000 1 [ ] +120 0 111 "" 125.6094 1089.84 0.0 00000000 00000000 1 [ ] +121 0 211 "" 126.7920 1182.62 0.0 00000000 00000000 1 [ ] +122 0 201 "" 127.1924 400.39 0.0 00000000 00000000 1 [ ] +123 0 111 "" 133.9229 6730.47 0.0 00000000 00000000 1 [ ] +124 0 211 "" 135.1221 1199.22 0.0 00000000 00000000 1 [ ] +125 0 201 "" 135.5674 445.31 0.0 00000000 00000000 1 [ ] +126 0 121 "" 136.8389 1271.48 0.0 00000000 00000000 1 [ ] +127 0 221 "" 137.9883 1149.41 0.0 00000000 00000000 1 [ ] +128 0 201 "" 138.4961 507.81 0.0 00000000 00000000 1 [ ] +129 0 111 "" 139.6377 1141.60 0.0 00000000 00000000 1 [ ] +130 0 211 "" 140.9199 1282.23 0.0 00000000 00000000 1 [ ] +131 0 201 "" 141.3760 456.05 0.0 00000000 00000000 1 [ ] +132 0 111 "" 142.6699 1293.95 0.0 00000000 00000000 1 [ ] +133 0 211 "" 143.8193 1149.41 0.0 00000000 00000000 1 [ ] +134 0 201 "" 144.3037 484.38 0.0 00000000 00000000 1 [ ] +135 0 121 "" 145.5850 1281.25 0.0 00000000 00000000 1 [ ] +136 0 221 "" 146.8350 1250.00 0.0 00000000 00000000 1 [ ] +137 0 201 "" 147.2471 412.11 0.0 00000000 00000000 1 [ ] +138 0 121 "" 148.4678 1220.70 0.0 00000000 00000000 1 [ ] +139 0 221 "" 149.6836 1215.82 0.0 00000000 00000000 1 [ ] +140 0 201 "" 150.0635 379.88 0.0 00000000 00000000 1 [ ] +141 0 121 "" 151.3662 1302.73 0.0 00000000 00000000 1 [ ] +142 0 221 "" 152.6494 1283.20 0.0 00000000 00000000 1 [ ] +143 0 201 "" 153.3994 750.00 0.0 00000000 00000000 1 [ ] +144 0 121 "" 154.2656 866.21 0.0 00000000 00000000 1 [ ] +145 0 221 "" 155.4150 1149.41 0.0 00000000 00000000 1 [ ] +146 0 201 "" 155.8555 440.43 0.0 00000000 00000000 1 [ ] +147 0 121 "" 157.1309 1275.39 0.0 00000000 00000000 1 [ ] +148 0 221 "" 158.3477 1216.80 0.0 00000000 00000000 1 [ ] +149 0 201 "" 158.7988 451.17 0.0 00000000 00000000 1 [ ] +150 0 111 "" 160.0967 1297.85 0.0 00000000 00000000 1 [ ] +151 0 211 "" 161.3633 1266.60 0.0 00000000 00000000 1 [ ] +152 0 201 "" 161.7275 364.26 0.0 00000000 00000000 1 [ ] +153 0 111 "" 163.0127 1285.16 0.0 00000000 00000000 1 [ ] +154 0 211 "" 164.1289 1116.21 0.0 00000000 00000000 1 [ ] +155 0 201 "" 164.4229 293.95 0.0 00000000 00000000 1 [ ] +156 0 121 "" 165.8281 1405.27 0.0 00000000 00000000 1 [ ] +157 0 221 "" 167.0107 1182.62 0.0 00000000 00000000 1 [ ] +158 0 201 "" 167.3828 372.07 0.0 00000000 00000000 1 [ ] +159 0 121 "" 168.7607 1377.93 0.0 00000000 00000000 1 [ ] +160 0 221 "" 169.8770 1116.21 0.0 00000000 00000000 1 [ ] +161 0 201 "" 170.3193 442.38 0.0 00000000 00000000 1 [ ] +162 0 111 "" 171.5264 1207.03 0.0 00000000 00000000 1 [ ] +163 0 211 "" 172.6758 1149.41 0.0 00000000 00000000 1 [ ] +164 0 201 "" 173.1426 466.80 0.0 00000000 00000000 1 [ ] +165 0 121 "" 174.3750 1232.42 0.0 00000000 00000000 1 [ ] +166 0 221 "" 175.5742 1199.22 0.0 00000000 00000000 1 [ ] +167 0 201 "" 175.8711 296.88 0.0 00000000 00000000 1 [ ] +168 0 121 "" 177.3076 1436.52 0.0 00000000 00000000 1 [ ] +169 0 221 "" 178.5400 1232.42 0.0 00000000 00000000 1 [ ] +170 0 201 "" 178.9424 402.34 0.0 00000000 00000000 1 [ ] +171 0 111 "" 180.2061 1263.67 0.0 00000000 00000000 1 [ ] +172 0 211 "" 181.3389 1132.81 0.0 00000000 00000000 1 [ ] +173 0 201 "" 181.5908 251.95 0.0 00000000 00000000 1 [ ] +174 0 121 "" 182.9883 1397.46 0.0 00000000 00000000 1 [ ] +175 0 221 "" 184.2383 1250.00 0.0 00000000 00000000 1 [ ] +176 0 201 "" 184.6631 424.80 0.0 00000000 00000000 1 [ ] +177 0 121 "" 185.8711 1208.01 0.0 00000000 00000000 1 [ ] +178 0 221 "" 187.1543 1283.20 0.0 00000000 00000000 1 [ ] +179 0 201 "" 187.5430 388.67 0.0 00000000 00000000 1 [ ] +180 0 111 "" 188.8867 1343.75 0.0 00000000 00000000 1 [ ] +181 0 211 "" 190.0361 1149.41 0.0 00000000 00000000 1 [ ] +182 0 201 "" 190.3428 306.64 0.0 00000000 00000000 1 [ ] +183 0 122 "" 196.7666 6423.83 0.0 00000000 00000000 1 [ ] +184 0 222 "" 198.0332 1266.60 0.0 00000000 00000000 1 [ ] +185 0 202 "" 198.2705 237.30 0.0 00000000 00000000 1 [ ] +186 0 122 "" 199.6826 1412.11 0.0 00000000 00000000 1 [ ] +187 0 222 "" 200.8652 1182.62 0.0 00000000 00000000 1 [ ] +188 0 202 "" 201.2139 348.63 0.0 00000000 00000000 1 [ ] +189 0 122 "" 202.5986 1384.77 0.0 00000000 00000000 1 [ ] +190 0 222 "" 203.7979 1199.22 0.0 00000000 00000000 1 [ ] +191 0 201 "" 204.2139 416.02 0.0 00000000 00000000 1 [ ] +192 0 112 "" 205.5635 1349.61 0.0 00000000 00000000 1 [ ] +193 0 212 "" 206.8301 1266.60 0.0 00000000 00000000 1 [ ] +194 0 201 "" 207.0859 255.86 0.0 00000000 00000000 1 [ ] +195 0 122 "" 208.6133 1527.34 0.0 00000000 00000000 1 [ ] +196 0 222 "" 209.8125 1199.22 0.0 00000000 00000000 1 [ ] +197 0 201 "" 210.1982 385.74 0.0 00000000 00000000 1 [ ] +198 0 122 "" 211.5117 1313.48 0.0 00000000 00000000 1 [ ] +199 0 222 "" 212.7285 1216.80 0.0 00000000 00000000 1 [ ] +200 0 201 "" 213.3818 653.32 0.0 00000000 00000000 1 [ ] +201 0 122 "" 214.4941 1112.30 0.0 00000000 00000000 1 [ ] +202 0 222 "" 215.7432 1249.02 0.0 00000000 00000000 1 [ ] +203 0 201 "" 216.1416 398.44 0.0 00000000 00000000 1 [ ] +204 0 122 "" 217.5264 1384.77 0.0 00000000 00000000 1 [ ] +205 0 222 "" 218.7256 1199.22 0.0 00000000 00000000 1 [ ] +206 0 201 "" 219.1660 440.43 0.0 00000000 00000000 1 [ ] +207 0 122 "" 220.3916 1225.59 0.0 00000000 00000000 1 [ ] +208 0 222 "" 221.5586 1166.99 0.0 00000000 00000000 1 [ ] +209 0 201 "" 222.0381 479.49 0.0 00000000 00000000 1 [ ] +210 0 112 "" 223.2744 1236.33 0.0 00000000 00000000 1 [ ] +211 0 212 "" 224.5400 1265.62 0.0 00000000 00000000 1 [ ] +212 0 201 "" 224.8936 353.52 0.0 00000000 00000000 1 [ ] +213 0 122 "" 226.2900 1396.48 0.0 00000000 00000000 1 [ ] +214 0 222 "" 227.5225 1232.42 0.0 00000000 00000000 1 [ ] +215 0 201 "" 227.8613 338.87 0.0 00000000 00000000 1 [ ] +216 0 112 "" 229.3057 1444.34 0.0 00000000 00000000 1 [ ] +217 0 212 "" 230.4551 1149.41 0.0 00000000 00000000 1 [ ] +218 0 201 "" 230.8936 438.48 0.0 00000000 00000000 1 [ ] +219 0 112 "" 232.0879 1194.34 0.0 00000000 00000000 1 [ ] +220 0 212 "" 233.2539 1166.02 0.0 00000000 00000000 1 [ ] +221 0 201 "" 233.6621 408.20 0.0 00000000 00000000 1 [ ] +222 0 122 "" 234.9365 1274.41 0.0 00000000 00000000 1 [ ] +223 0 222 "" 236.0693 1132.81 0.0 00000000 00000000 1 [ ] +224 0 201 "" 236.4697 400.39 0.0 00000000 00000000 1 [ ] +225 0 112 "" 237.8193 1349.61 0.0 00000000 00000000 1 [ ] +226 0 212 "" 239.0684 1249.02 0.0 00000000 00000000 1 [ ] +227 0 201 "" 239.4053 336.91 0.0 00000000 00000000 1 [ ] +228 0 112 "" 240.6846 1279.30 0.0 00000000 00000000 1 [ ] +229 0 212 "" 241.9512 1266.60 0.0 00000000 00000000 1 [ ] +230 0 201 "" 242.4375 486.33 0.0 00000000 00000000 1 [ ] +231 0 112 "" 243.6504 1212.89 0.0 00000000 00000000 1 [ ] +232 0 212 "" 244.9336 1283.20 0.0 00000000 00000000 1 [ ] +233 0 201 "" 245.3252 391.60 0.0 00000000 00000000 1 [ ] +234 0 122 "" 246.7158 1390.62 0.0 00000000 00000000 1 [ ] +235 0 222 "" 247.8320 1116.21 0.0 00000000 00000000 1 [ ] +236 0 201 "" 248.3252 493.16 0.0 00000000 00000000 1 [ ] +237 0 122 "" 249.4648 1139.65 0.0 00000000 00000000 1 [ ] +238 0 222 "" 250.5811 1116.21 0.0 00000000 00000000 1 [ ] +239 0 201 "" 251.0293 448.24 0.0 00000000 00000000 1 [ ] +240 0 122 "" 252.2139 1184.57 0.0 00000000 00000000 1 [ ] +241 0 222 "" 253.3965 1182.62 0.0 00000000 00000000 1 [ ] +242 0 201 "" 253.8213 424.80 0.0 00000000 00000000 1 [ ] +243 0 112 "" 260.2607 6439.45 0.0 00000000 00000000 1 [ ] +244 0 212 "" 261.4111 1150.39 0.0 00000000 00000000 1 [ ] +245 0 201 "" 261.7246 313.48 0.0 00000000 00000000 1 [ ] +246 0 112 "" 263.1270 1402.34 0.0 00000000 00000000 1 [ ] +247 0 212 "" 264.4258 1298.83 0.0 00000000 00000000 1 [ ] +248 0 201 "" 264.8213 395.51 0.0 00000000 00000000 1 [ ] +249 0 122 "" 266.0928 1271.48 0.0 00000000 00000000 1 [ ] +250 0 222 "" 267.3418 1249.02 0.0 00000000 00000000 1 [ ] +251 0 201 "" 267.8213 479.49 0.0 00000000 00000000 1 [ ] +252 0 122 "" 269.0908 1269.53 0.0 00000000 00000000 1 [ ] +253 0 222 "" 270.3574 1266.60 0.0 00000000 00000000 1 [ ] +254 0 201 "" 270.7090 351.56 0.0 00000000 00000000 1 [ ] +255 0 122 "" 272.1572 1448.24 0.0 00000000 00000000 1 [ ] +256 0 222 "" 273.4561 1298.83 0.0 00000000 00000000 1 [ ] +257 0 201 "" 273.7969 340.82 0.0 00000000 00000000 1 [ ] +258 0 112 "" 275.1055 1308.59 0.0 00000000 00000000 1 [ ] +259 0 212 "" 276.2549 1149.41 0.0 00000000 00000000 1 [ ] +260 0 201 "" 276.4932 238.28 0.0 00000000 00000000 1 [ ] +261 0 112 "" 277.8711 1377.93 0.0 00000000 00000000 1 [ ] +262 0 212 "" 279.1709 1299.80 0.0 00000000 00000000 1 [ ] +263 0 201 "" 279.4287 257.81 0.0 00000000 00000000 1 [ ] +264 0 112 "" 280.8037 1375.00 0.0 00000000 00000000 1 [ ] +265 0 212 "" 282.0195 1215.82 0.0 00000000 00000000 1 [ ] +266 0 201 "" 282.3643 344.73 0.0 00000000 00000000 1 [ ] +267 0 112 "" 283.6865 1322.27 0.0 00000000 00000000 1 [ ] +268 0 212 "" 284.8691 1182.62 0.0 00000000 00000000 1 [ ] +269 0 201 "" 285.1641 294.92 0.0 00000000 00000000 1 [ ] +270 0 112 "" 286.5352 1371.09 0.0 00000000 00000000 1 [ ] +271 0 212 "" 287.7510 1215.82 0.0 00000000 00000000 1 [ ] +272 0 202 "" 288.2686 517.58 0.0 00000000 00000000 1 [ ] +273 0 112 "" 289.5342 1265.62 0.0 00000000 00000000 1 [ ] +274 0 212 "" 290.7666 1232.42 0.0 00000000 00000000 1 [ ] +275 0 201 "" 291.2842 517.58 0.0 00000000 00000000 1 [ ] +276 0 122 "" 292.3828 1098.63 0.0 00000000 00000000 1 [ ] +277 0 222 "" 293.5322 1149.41 0.0 00000000 00000000 1 [ ] +278 0 201 "" 293.9561 423.83 0.0 00000000 00000000 1 [ ] +279 0 112 "" 295.3320 1375.98 0.0 00000000 00000000 1 [ ] +280 0 212 "" 296.6152 1283.20 0.0 00000000 00000000 1 [ ] +281 0 201 "" 296.8447 229.49 0.0 00000000 00000000 1 [ ] +282 0 122 "" 298.3975 1552.73 0.0 00000000 00000000 1 [ ] +283 0 222 "" 299.6133 1215.82 0.0 00000000 00000000 1 [ ] +284 0 201 "" 300.0361 422.85 0.0 00000000 00000000 1 [ ] +285 0 112 "" 301.3467 1310.55 0.0 00000000 00000000 1 [ ] +286 0 212 "" 302.4463 1099.61 0.0 00000000 00000000 1 [ ] +287 0 201 "" 302.7559 309.57 0.0 00000000 00000000 1 [ ] +288 0 122 "" 304.2451 1489.26 0.0 00000000 00000000 1 [ ] +289 0 222 "" 305.3613 1116.21 0.0 00000000 00000000 1 [ ] +290 0 201 "" 305.7236 362.30 0.0 00000000 00000000 1 [ ] +291 0 112 "" 307.0439 1320.31 0.0 00000000 00000000 1 [ ] +292 0 212 "" 308.2441 1200.20 0.0 00000000 00000000 1 [ ] +293 0 201 "" 308.5400 295.90 0.0 00000000 00000000 1 [ ] +294 0 122 "" 310.0264 1486.33 0.0 00000000 00000000 1 [ ] +295 0 222 "" 311.2266 1200.20 0.0 00000000 00000000 1 [ ] +296 0 201 "" 311.6436 416.99 0.0 00000000 00000000 1 [ ] +297 0 112 "" 313.0254 1381.84 0.0 00000000 00000000 1 [ ] +298 0 212 "" 314.3086 1283.20 0.0 00000000 00000000 1 [ ] +299 0 202 "" 314.6357 327.15 0.0 00000000 00000000 1 [ ] +300 0 112 "" 315.9248 1289.06 0.0 00000000 00000000 1 [ ] +301 0 212 "" 317.1240 1199.22 0.0 00000000 00000000 1 [ ] +302 0 202 "" 317.5479 423.83 0.0 00000000 00000000 1 [ ] +303 0 122 "" 323.9883 6440.43 0.0 00000000 00000000 1 [ ] +304 0 222 "" 325.2715 1283.20 0.0 00000000 00000000 1 [ ] +305 0 201 "" 325.6279 356.45 0.0 00000000 00000000 1 [ ] +306 0 122 "" 326.8877 1259.77 0.0 00000000 00000000 1 [ ] +307 0 222 "" 328.1865 1298.83 0.0 00000000 00000000 1 [ ] +308 0 201 "" 328.6279 441.41 0.0 00000000 00000000 1 [ ] +309 0 112 "" 329.9365 1308.59 0.0 00000000 00000000 1 [ ] +310 0 212 "" 331.0693 1132.81 0.0 00000000 00000000 1 [ ] +311 0 201 "" 331.3320 262.70 0.0 00000000 00000000 1 [ ] +312 0 112 "" 332.6689 1336.91 0.0 00000000 00000000 1 [ ] +313 0 212 "" 333.7686 1099.61 0.0 00000000 00000000 1 [ ] +314 0 201 "" 334.0518 283.20 0.0 00000000 00000000 1 [ ] +315 0 112 "" 335.4678 1416.02 0.0 00000000 00000000 1 [ ] +316 0 212 "" 336.6006 1132.81 0.0 00000000 00000000 1 [ ] +317 0 201 "" 336.9150 314.45 0.0 00000000 00000000 1 [ ] +318 0 122 "" 338.2334 1318.36 0.0 00000000 00000000 1 [ ] +319 0 222 "" 339.4658 1232.42 0.0 00000000 00000000 1 [ ] +320 0 201 "" 339.9238 458.01 0.0 00000000 00000000 1 [ ] +321 0 112 "" 341.1152 1191.41 0.0 00000000 00000000 1 [ ] +322 0 212 "" 342.3818 1266.60 0.0 00000000 00000000 1 [ ] +323 0 202 "" 342.6914 309.57 0.0 00000000 00000000 1 [ ] +324 0 112 "" 344.0312 1339.84 0.0 00000000 00000000 1 [ ] +325 0 212 "" 345.1973 1166.02 0.0 00000000 00000000 1 [ ] +326 0 201 "" 345.4756 278.32 0.0 00000000 00000000 1 [ ] +327 0 122 "" 346.9297 1454.10 0.0 00000000 00000000 1 [ ] +328 0 222 "" 348.1963 1266.60 0.0 00000000 00000000 1 [ ] +329 0 201 "" 348.5791 382.81 0.0 00000000 00000000 1 [ ] +330 0 122 "" 349.9287 1349.61 0.0 00000000 00000000 1 [ ] +331 0 222 "" 351.2119 1283.20 0.0 00000000 00000000 1 [ ] +332 0 201 "" 351.5947 382.81 0.0 00000000 00000000 1 [ ] +333 0 122 "" 352.9277 1333.01 0.0 00000000 00000000 1 [ ] +334 0 222 "" 354.1279 1200.20 0.0 00000000 00000000 1 [ ] +335 0 201 "" 354.5068 378.91 0.0 00000000 00000000 1 [ ] +336 0 112 "" 355.8604 1353.52 0.0 00000000 00000000 1 [ ] +337 0 212 "" 357.0762 1215.82 0.0 00000000 00000000 1 [ ] +338 0 201 "" 357.5547 478.52 0.0 00000000 00000000 1 [ ] +339 0 112 "" 358.7422 1187.50 0.0 00000000 00000000 1 [ ] +340 0 212 "" 360.0254 1283.20 0.0 00000000 00000000 1 [ ] +341 0 201 "" 360.3154 290.04 0.0 00000000 00000000 1 [ ] +342 0 112 "" 361.7744 1458.98 0.0 00000000 00000000 1 [ ] +343 0 212 "" 362.9746 1200.20 0.0 00000000 00000000 1 [ ] +344 0 201 "" 363.2666 291.99 0.0 00000000 00000000 1 [ ] +345 0 122 "" 364.6904 1423.83 0.0 00000000 00000000 1 [ ] +346 0 222 "" 365.9570 1266.60 0.0 00000000 00000000 1 [ ] +347 0 201 "" 366.3232 366.21 0.0 00000000 00000000 1 [ ] +348 0 122 "" 367.6729 1349.61 0.0 00000000 00000000 1 [ ] +349 0 222 "" 368.9385 1265.62 0.0 00000000 00000000 1 [ ] +350 0 201 "" 369.2344 295.90 0.0 00000000 00000000 1 [ ] +351 0 122 "" 370.6387 1404.30 0.0 00000000 00000000 1 [ ] +352 0 222 "" 371.9375 1298.83 0.0 00000000 00000000 1 [ ] +353 0 201 "" 372.4590 521.48 0.0 00000000 00000000 1 [ ] +354 0 112 "" 373.6543 1195.31 0.0 00000000 00000000 1 [ ] +355 0 212 "" 374.8867 1232.42 0.0 00000000 00000000 1 [ ] +356 0 201 "" 375.1543 267.58 0.0 00000000 00000000 1 [ ] +357 0 112 "" 376.6699 1515.62 0.0 00000000 00000000 1 [ ] +358 0 212 "" 377.8193 1149.41 0.0 00000000 00000000 1 [ ] +359 0 201 "" 378.1064 287.11 0.0 00000000 00000000 1 [ ] +360 0 122 "" 379.5020 1395.51 0.0 00000000 00000000 1 [ ] +361 0 222 "" 380.7344 1232.42 0.0 00000000 00000000 1 [ ] +362 0 202 "" 380.9385 204.10 0.0 00000000 00000000 1 [ ] diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_CSD_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_CSD_GUI.m new file mode 100644 index 00000000..45086621 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_CSD_GUI.m @@ -0,0 +1,372 @@ +%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +%Mar. 2024 + +% ERPLAB Studio + +function varargout = f_EEG_CSD_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + + +gui_eeg_CSD = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EEG_CSD_gui; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EEG_CSD_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Convert Voltage to CSD', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EEG_CSD_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Convert Voltage to CSD', 'Padding', 5,... + 'BackgroundColor',ColorB_def); +else + EEG_CSD_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Convert Voltage to CSD', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @tool_link +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_erp_bin_operation(FonsizeDefault); +varargout{1} = EEG_CSD_gui; + + function drawui_erp_bin_operation(FontSize_defualt) + Enable_label = 'off'; + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + gui_eeg_CSD.DataSelBox = uiextras.VBox('Parent', EEG_CSD_gui,'BackgroundColor',ColorB_def); + + %%Parameters + gui_eeg_CSD.sif_title = uiextras.HBox('Parent', gui_eeg_CSD.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_CSD.sif_text = uicontrol('Style','text','Parent', gui_eeg_CSD.sif_title,... + 'String','Spline interpolation flexibility m-constant value (4 is recommended)','FontSize',FontSize_defualt,'Max',10,'BackgroundColor',ColorB_def); % 2F + + gui_eeg_CSD.sif_num = uicontrol('Style','edit','Parent', gui_eeg_CSD.sif_title,... + 'String','4','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_sif,'BackgroundColor',[1 1 1]); % 2F + set(gui_eeg_CSD.sif_title,'Sizes',[210,50]); + gui_eeg_CSD.sif_num.KeyPressFcn = @eeg_csd_presskey; + gui_eeg_CSD.Para{1} = str2num(gui_eeg_CSD.sif_num.String); + gui_eeg_CSD.scl_title = uiextras.HBox('Parent', gui_eeg_CSD.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_CSD.scl_text = uicontrol('Style','text','Parent', gui_eeg_CSD.scl_title,... + 'String','Smoothing constant lambda (0.00001 is recommended)','FontSize',FontSize_defualt,'Max',10,'BackgroundColor',ColorB_def); % 2F + + gui_eeg_CSD.scl_num = uicontrol('Style','edit','Parent', gui_eeg_CSD.scl_title,... + 'String','0.00001','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_scl,'BackgroundColor',[1 1 1]); % 2F + set(gui_eeg_CSD.scl_title,'Sizes',[210,50]); + gui_eeg_CSD.scl_num.KeyPressFcn = @eeg_csd_presskey; + gui_eeg_CSD.Para{2} = str2num(gui_eeg_CSD.scl_num.String); + gui_eeg_CSD.hr_title = uiextras.HBox('Parent', gui_eeg_CSD.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_CSD.hr_text = uicontrol('Style','text','Parent', gui_eeg_CSD.hr_title,... + 'String','Head radius CSD rescaling values (10cm is recommended)','FontSize',FontSize_defualt,'Max',10,'BackgroundColor',ColorB_def); % 2F + + gui_eeg_CSD.hr_num = uicontrol('Style','edit','Parent', gui_eeg_CSD.hr_title,... + 'String','10','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_hr,'BackgroundColor',[1 1 1]); % 2F + set(gui_eeg_CSD.hr_title,'Sizes',[210,50]); + gui_eeg_CSD.hr_num.KeyPressFcn = @eeg_csd_presskey; + gui_eeg_CSD.Para{3} = str2num(gui_eeg_CSD.hr_num.String); + + %%-----------------Run--------------------------------------------- + gui_eeg_CSD.run_title = uiextras.HBox('Parent', gui_eeg_CSD.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', gui_eeg_CSD.run_title); + gui_eeg_CSD.cancel= uicontrol('Style','pushbutton','Parent', gui_eeg_CSD.run_title ,'Enable',Enable_label,... + 'String','Cancel','callback',@tool_cancel,'FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Max',10); % 2F + uiextras.Empty('Parent', gui_eeg_CSD.run_title); + gui_eeg_CSD.run = uicontrol('Style','pushbutton','Parent',gui_eeg_CSD.run_title,... + 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + uiextras.Empty('Parent', gui_eeg_CSD.run_title); + set(gui_eeg_CSD.run_title,'Sizes',[15 105 30 105 15]); + set(gui_eeg_CSD.DataSelBox,'Sizes',[40,40,40,30]); + estudioworkingmemory('EEGTab_csd',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%-------------------Setting value for Spline interpolation flexibility m-constant value---------------- + function csd_sif(source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=19 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_CSD.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_CSD.run.ForegroundColor = [1 1 1]; + EEG_CSD_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_CSD.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_csd',1); + + mcont = str2num(source.String); + if isempty(mcont) || numel(mcont)~=1 + gui_eeg_CSD.sif_num.String='4'; + msgboxText = ['Convert voltage to CSD - Please ensure that the input was a single value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + +%%-------------------Setting value for Smoothing constant lambda--------------------------------------- + function csd_scl(source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=19 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_CSD.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_CSD.run.ForegroundColor = [1 1 1]; + EEG_CSD_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_CSD.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_csd',1); + + mcont = str2num(source.String); + if isempty(mcont) || numel(mcont)~=1 + gui_eeg_CSD.scl_num.String='0.0001'; + msgboxText = ['Convert voltage to CSD - Please ensure that the input was a single value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + +%%-------------------setting Head radius CSD rescaling values--------------------------------------- + function csd_hr(source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=19 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_CSD.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_CSD.run.ForegroundColor = [1 1 1]; + EEG_CSD_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_CSD.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_csd',1); + mcont = str2num(source.String); + if isempty(mcont) || numel(mcont)~=1 + gui_eeg_CSD.hr_num.String='10'; + msgboxText = ['Convert voltage to CSD - Please ensure that the input was a single value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + +%%---------------------Run------------------------------------------------- + function apply_run(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=19 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + + csd_param(1) = str2double(gui_eeg_CSD.sif_num.String); + csd_param(2) = str2double(gui_eeg_CSD.scl_num.String); + csd_param(3) = str2double(gui_eeg_CSD.hr_num.String); + csd_param(4) = 1; + estudioworkingmemory('csd_param',csd_param); + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:)>length(observe_EEGDAT.ALLEEG)) + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(end); + observe_EEGDAT.CURRENTSET = EEGArray; + estudioworkingmemory('EEGArray',EEGArray); + end + gui_eeg_CSD.run.BackgroundColor = [1 1 1]; + gui_eeg_CSD.run.ForegroundColor = [0 0 0]; + EEG_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [1 1 1]; + gui_eeg_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_csd',0); + + %%---------------------Compute CSD for each ERPset---------------- + estudioworkingmemory('f_EEG_proces_messg','Convert Voltage to CSD'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + gui_eeg_CSD.Para{1} = str2num(gui_eeg_CSD.sif_num.String); + gui_eeg_CSD.Para{2} = str2num(gui_eeg_CSD.scl_num.String); + gui_eeg_CSD.Para{3} = str2num(gui_eeg_CSD.hr_num.String); + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + %%Loop for the selcted ERPsets + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + [eloc, labels, theta, radius, indices] = readlocs(EEG.chanlocs); + thetacheck= isnan(theta); + radiuscheck= isnan(radius); + [~,ypostheta] = find(thetacheck(:)==1); + [~,yposradius] = find(radiuscheck(:)==1); + if ~isempty(ypostheta) && ~isempty(yposradius) + msgboxText = ['Current Source Density: Some electrodes for EEGset:',num2str(EEGArray(Numofeeg)),32,'are missing electrode channel locations. Please check channel locations and try again.']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + [EEG, LASTCOM] = pop_currentsourcedensity(EEG,'EStudio'); + EEG = eegh(LASTCOM, EEG); + fprintf([LASTCOM,'\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end%%Loop for eegset end + + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_CSD'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + if Save_file_label + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%----------------------function cancel------------------------------------ + function tool_cancel(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=19 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_CSD.sif_num.String = num2str( gui_eeg_CSD.Para{1}); + gui_eeg_CSD.scl_num.String= num2str( gui_eeg_CSD.Para{2}); + gui_eeg_CSD.hr_num.String = num2str( gui_eeg_CSD.Para{3}); + + gui_eeg_CSD.run.BackgroundColor = [1 1 1]; + gui_eeg_CSD.run.ForegroundColor = [0 0 0]; + EEG_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [1 1 1]; + gui_eeg_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_csd',0); + end + +%%--------Setting current ERPset/session history based on the current updated ERPset------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg~=24 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.ALLEEG) || EEGUpdate==1 + Enable_label = 'off'; + else + Enable_label = 'on'; + end + gui_eeg_CSD.run.Enable = Enable_label; + gui_eeg_CSD.sif_num.Enable = Enable_label; + gui_eeg_CSD.scl_num.Enable = Enable_label; + gui_eeg_CSD.hr_num.Enable = Enable_label; + gui_eeg_CSD.cancel.Enable = Enable_label; + observe_EEGDAT.count_current_eeg=25; + end + +%%--------------press return to execute "Apply"---------------------------- + function eeg_csd_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_csd'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + apply_run(); + gui_eeg_CSD.run.BackgroundColor = [1 1 1]; + gui_eeg_CSD.run.ForegroundColor = [0 0 0]; + EEG_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [1 1 1]; + gui_eeg_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_csd',0); + else + return; + end + end + + + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_EEG_paras_panel~=20 + return; + end + gui_eeg_CSD.run.BackgroundColor = [1 1 1]; + gui_eeg_CSD.run.ForegroundColor = [0 0 0]; + EEG_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_CSD.cancel.BackgroundColor = [1 1 1]; + gui_eeg_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_csd',0); + gui_eeg_CSD.sif_num.String = '4'; + gui_eeg_CSD.scl_num.String = '0.00001'; + gui_eeg_CSD.hr_num.String = '10'; + observe_EEGDAT.Reset_EEG_paras_panel=21; + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_IC_channel_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_IC_channel_GUI.m new file mode 100755 index 00000000..635f553e --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_IC_channel_GUI.m @@ -0,0 +1,528 @@ +%%This function is used to get the ' Channel and IC Selection' Panel and +%%record the change of th selected channels and selected ICs + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2023 + + +function varargout = f_EEG_IC_channel_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ +EStduio_eegtab_EEG_IC_chan = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_eeg_box_ic_chan; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_eeg_box_ic_chan = uiextras.BoxPanel('Parent', fig, 'Title', ' Channel and IC Selection', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_eeg_box_ic_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', ' Channel and IC Selection', 'Padding', 5,'BackgroundColor',ColorB_def); +else + EStudio_eeg_box_ic_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', ' Channel and IC Selection', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_ic_chan_eeg(FonsizeDefault) +varargout{1} = EStudio_eeg_box_ic_chan; + + function drawui_ic_chan_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EStduio_eegtab_EEG_IC_chan.DataSelBox = uiextras.VBox('Parent', EStudio_eeg_box_ic_chan,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_IC_chan.DataSelGrid = uiextras.Grid('Parent', EStduio_eegtab_EEG_IC_chan.DataSelBox,'BackgroundColor',ColorB_def); + % Second column: + uicontrol('Style','text','Parent', EStduio_eegtab_EEG_IC_chan.DataSelGrid,'String','Channels','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1B + try + ALLEEGIN = evalin('base','ALLEEG'); + CURRENTSETIN = evalin('base','CURRENTSET'); + catch + CURRENTSETIN = []; + ALLEEGIN = []; + end + if isempty(ALLEEGIN) || isempty(CURRENTSETIN) + Chanlist_name = 'No EEG is available'; + ICNamestrs = 'No IC is available'; + Enable = 'off'; + ChaNum = 1; + EnableIC = 'off'; + ICNum = 1; + else + if CURRENTSETIN==0 || length(ALLEEGIN) ChaNum + ChanArray = [1:ChaNum]; + estudioworkingmemory('EEG_ChanArray',ChanArray); + end + if length(ChanArray) == ChaNum + EStduio_eegtab_EEG_IC_chan.ElecRange.Value =1; + else + EStduio_eegtab_EEG_IC_chan.ElecRange.Value = ChanArray+1; + end + + % Third column: + uicontrol('Style','text','Parent', EStduio_eegtab_EEG_IC_chan.DataSelGrid,'String','ICs','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1C + + EStduio_eegtab_EEG_IC_chan.ICRange = uicontrol('Parent', EStduio_eegtab_EEG_IC_chan.DataSelGrid,'Style','listbox','Min',1,'Max',length(ICNamestrs)+1,... + 'String', ICNamestrs,'callback',@onIChanged,'FontSize',FonsizeDefault,'Enable',EnableIC,'BackgroundColor',[1 1 1]); % 2C + EStduio_eegtab_EEG_IC_chan.ICRange.KeyPressFcn= @eeg_ichan_presskey; + ICArray = estudioworkingmemory('EEG_ICArray'); + if isempty(ICArray) || length(ICArray)>ICNum + ICArray = 1: ICNum; + estudioworkingmemory('EEG_ICArray',ICArray); + end + if length(ICArray) == ICNum + EStduio_eegtab_EEG_IC_chan.ICRange.Value =1; + else + EStduio_eegtab_EEG_IC_chan.ICRange.Value = ICArray+1; + end + set(EStduio_eegtab_EEG_IC_chan.DataSelGrid, 'ColumnSizes',[ -1.2 -2],'RowSizes',[20 -3]); + + %%Cancel and Apply + EStduio_eegtab_EEG_IC_chan.reset_apply = uiextras.HBox('Parent',EStduio_eegtab_EEG_IC_chan.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EStduio_eegtab_EEG_IC_chan.reset_apply); % 1A + EStduio_eegtab_EEG_IC_chan.plot_reset = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_IC_chan.reset_apply,... + 'String','Cancel','callback',@plot_eeg_cancel,'FontSize',FonsizeDefault,'Enable',Enable,'BackgroundColor',[1 1 1]); + + uiextras.Empty('Parent', EStduio_eegtab_EEG_IC_chan.reset_apply); % 1A + EStduio_eegtab_EEG_IC_chan.plot_apply = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_IC_chan.reset_apply,... + 'String','Apply','callback',@plot_eeg_apply,'FontSize',FonsizeDefault,'Enable',Enable,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_IC_chan.plot_apply.KeyPressFcn= @eeg_ichan_presskey; + uiextras.Empty('Parent', EStduio_eegtab_EEG_IC_chan.reset_apply); % 1A + set(EStduio_eegtab_EEG_IC_chan.reset_apply, 'Sizes',[10,-1,30,-1,10]); + + set(EStduio_eegtab_EEG_IC_chan.DataSelBox,'Sizes',[250 30]); + + estudioworkingmemory('EEGTab_chanic',0); + end + + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + + +%----------------------------Get the changed channels----------------------* + function onElecRange ( src, ~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=1 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_chanic',1); + EStduio_eegtab_EEG_IC_chan.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_IC_chan.plot_apply.ForegroundColor = [1 1 1]; + EStudio_eeg_box_ic_chan.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_eegtab_EEG_IC_chan.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_IC_chan.plot_reset.ForegroundColor = [1 1 1]; + new_chans = src.Value; + if isempty(new_chans) + return; + end + [~,y_chan_index_select] = find(new_chans==1); + if isempty(y_chan_index_select) && numel(new_chans) < numel(src.String)-1 %% 'All' is not slected + else%% 'All' is selected and included or all channels are slected except 'ALL' + EStduio_eegtab_EEG_IC_chan.ElecRange.Value = 1; + end + end + + +%---------------------------get the changed bin---------------------------- + function onIChanged( src, ~ ) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=1 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_chanic',1); + EStduio_eegtab_EEG_IC_chan.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_IC_chan.plot_apply.ForegroundColor = [1 1 1]; + EStudio_eeg_box_ic_chan.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_eegtab_EEG_IC_chan.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_IC_chan.plot_reset.ForegroundColor = [1 1 1]; + + IC_label_select = src.Value; + if isempty(IC_label_select) + return; + end + [~,y_bin_index_select] = find(IC_label_select==1); + if isempty(y_bin_index_select) && numel(IC_label_select) < numel(src.String)-1 + else% 'All' is selected and inlcuded + EStduio_eegtab_EEG_IC_chan.ICRange.Value = 1; + end + + end + +%%---------------------Cancel what have changed---------------------------- + function plot_eeg_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable = 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=1 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + ChangeFlag = estudioworkingmemory('EEGTab_chanic'); + if ChangeFlag~=1 + return; + end + estudioworkingmemory('EEGTab_chanic',0); + EStduio_eegtab_EEG_IC_chan.plot_apply.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_eeg_box_ic_chan.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + EStduio_eegtab_EEG_IC_chan.plot_reset.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_reset.ForegroundColor = [0 0 0]; + + ChanArray = estudioworkingmemory('EEG_ChanArray'); + ChaNum = length(EStduio_eegtab_EEG_IC_chan.ElecRange.String)-1; + if isempty(ChanArray) || any(ChanArray(:)> ChaNum) || any(ChanArray(:)<=0) || numel(ChanArray)== ChaNum + EStduio_eegtab_EEG_IC_chan.ElecRange.Value = 1; + ChanArray = [1:ChaNum]; + else + + EStduio_eegtab_EEG_IC_chan.ElecRange.Value = ChanArray+1; + end + estudioworkingmemory('EEG_ChanArray',ChanArray); + + if ~isempty(observe_EEGDAT.EEG.icachansind) + ICArray= estudioworkingmemory('EEG_ICArray'); + ICNum = length(EStduio_eegtab_EEG_IC_chan.ICRange.String); + if isempty(ICArray) || min(ICArray(:))>ICNum || max(ICArray(:))>ICNum || min(ICArray(:))<=0 || (numel(ICArray)==ICNum) + EStduio_eegtab_EEG_IC_chan.ICRange.Value=1; + ICArray = [1:ICNum]; + else + + EStduio_eegtab_EEG_IC_chan.ICRange.Value = ICArray+1; + end + else + ICArray = []; + end + estudioworkingmemory('EEG_ICArray',ICArray); + end + +%%------------------Apply the changed parameters--------------------------- + function plot_eeg_apply(~,~) + if isempty(observe_EEGDAT.EEG) %%if the current EEG is empty + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=1 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + MessageViewer= char(strcat('Channel and IC Selection > Apply')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=1; + + + new_chans= EStduio_eegtab_EEG_IC_chan.ElecRange.Value; + [~,y_chan_index_select] = find(new_chans==1); + ChanNum = length(EStduio_eegtab_EEG_IC_chan.ElecRange.String)-1; + if isempty(y_chan_index_select) && numel(new_chans) length(chanString)-1 + EStduio_eegtab_EEG_IC_chan.ElecRange.Value =1; + observe_EEGDAT.EEG_chan = [1:length(chanString)-1]; + else + if max(chanArray(:))>length(chanString)-1 + EStduio_eegtab_EEG_IC_chan.ElecRange.Value =1; + observe_EEGDAT.EEG_chan = [1:length(chanString)-1]; + else + if numel(chanArray) == length(chanString)-1 + EStduio_eegtab_EEG_IC_chan.ElecRange.Value =1; + else + EStduio_eegtab_EEG_IC_chan.ElecRange.Value = chanArray+1; + end + end + end + end + + + +%----------displayed bin label will be midified after different channels was selected-------- + function EEG_IC_change(~,~) + if observe_EEGDAT.eeg_panel_message==0 || isempty(observe_EEGDAT.EEG_IC) + return; + end + binArray = estudioworkingmemory('EEG_ICArray'); + binString = EStduio_eegtab_EEG_IC_chan.ICRange.String; + if isemoty(binArray) + EStduio_eegtab_EEG_IC_chan.ICRange.Value =1; + return; + end + + if any(binArray>length(binString)-1) + EStduio_eegtab_EEG_IC_chan.ICRange.Value =1; + % observe_EEGDAT.ERP_bin = [1:length(binString)-1]; + else + if numel(binArray) == length(binString)-1 + EStduio_eegtab_EEG_IC_chan.ICRange.Value =1; + else + EStduio_eegtab_EEG_IC_chan.ICRange.Value = binArray+1; + end + end + + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=2 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + ALLEEGIN = observe_EEGDAT.ALLEEG; + CURRENTEEGIN= observe_EEGDAT.CURRENTSET; + if (~isempty(ALLEEGIN) && CURRENTEEGIN~=0 && ~isempty(observe_EEGDAT.EEG)) || (isfield(observe_EEGDAT.EEG,'chanlocs') && ~isempty(observe_EEGDAT.EEG.chanlocs)) + %The channels and bins will be modified if the ERPset is changed + ChannelValue = EStduio_eegtab_EEG_IC_chan.ElecRange.Value-1; + try + Chanlist = observe_EEGDAT.EEG.chanlocs; + catch + Chanlist = []; + end + Chanlist_name{1} = 'All'; + if ~isempty(Chanlist) + for Numofchan = 1:length(Chanlist) + Chanlist_name{Numofchan+1,1} = strcat(num2str(Numofchan),'.',32,char(Chanlist(Numofchan).labels)); + end + else + for Numofchan = 1:size( observe_EEGDAT.EEG.data,1) + Chanlist_name{Numofchan+1,1} = strcat(num2str(Numofchan),'. chan', num2str(Numofchan)); + end + end + EStduio_eegtab_EEG_IC_chan.ElecRange.String=Chanlist_name; + EStduio_eegtab_EEG_IC_chan.ElecRange.Min = 1; + EStduio_eegtab_EEG_IC_chan.ElecRange.Max = length(Chanlist_name)+1; + if isempty(ChannelValue)|| any(ChannelValue(:)<=0) || any(ChannelValue(:) >length(Chanlist_name)-1) || numel(ChannelValue) == length(Chanlist_name)-1 + EStduio_eegtab_EEG_IC_chan.ElecRange.Value = 1; + ChanArray = [1:length(Chanlist_name)-1]; + else + EStduio_eegtab_EEG_IC_chan.ElecRange.Value =ChannelValue+1; + ChanArray = ChannelValue; + end + EStduio_eegtab_EEG_IC_chan.ElecRange.Enable = 'on'; + EStduio_eegtab_EEG_IC_chan.plot_reset.Enable = 'on'; + EStduio_eegtab_EEG_IC_chan.plot_apply.Enable = 'on'; + if EEGUpdate==1 + EStduio_eegtab_EEG_IC_chan.ElecRange.Enable = 'off'; + EStduio_eegtab_EEG_IC_chan.plot_reset.Enable = 'off'; + EStduio_eegtab_EEG_IC_chan.plot_apply.Enable = 'off'; + end + else + Chanlist_name = 'No EEG is available or chanlocs is empty'; + EStduio_eegtab_EEG_IC_chan.ElecRange.String = Chanlist_name; + EStduio_eegtab_EEG_IC_chan.ElecRange.Value=1; + EStduio_eegtab_EEG_IC_chan.ElecRange.Enable = 'off'; + ChanArray = []; + EStduio_eegtab_EEG_IC_chan.plot_reset.Enable = 'off'; + EStduio_eegtab_EEG_IC_chan.plot_apply.Enable = 'off'; + end + + %%Setting for display ICs + if ~isempty(ALLEEGIN) && CURRENTEEGIN~=0 && ( ~isempty(observe_EEGDAT.EEG) && ~isempty(observe_EEGDAT.EEG.icachansind)) + ICNamestrs{1} = 'All'; + for ii = 1:numel(observe_EEGDAT.EEG.icachansind) + ICNamestrs{ii+1,1} = char(strcat(num2str(ii),'.',32,'IC',32,num2str(ii))); + end + EStduio_eegtab_EEG_IC_chan.ICRange.String = ICNamestrs; + ICValue = EStduio_eegtab_EEG_IC_chan.ICRange.Value-1; + + if isempty(ICValue) || any(ICValue(:)<=0)|| numel(ICValue) == numel(observe_EEGDAT.EEG.icachansind) || any(ICValue(:)>numel(observe_EEGDAT.EEG.icachansind)) + EStduio_eegtab_EEG_IC_chan.ICRange.Value =1; + ICValue = [ 1:numel(observe_EEGDAT.EEG.icachansind)]; + else + EStduio_eegtab_EEG_IC_chan.ICRange.Value =ICValue+1; + end + EStduio_eegtab_EEG_IC_chan.ICRange.Enable = 'on'; + EStduio_eegtab_EEG_IC_chan.ICRange.Min = 1; + EStduio_eegtab_EEG_IC_chan.ICRange.Max = numel(observe_EEGDAT.EEG.icachansind)+1; + if EEGUpdate==1 + EStduio_eegtab_EEG_IC_chan.ICRange.Enable = 'off'; + end + else + %%ICs + ICNamestrs = 'No IC is available'; + EStduio_eegtab_EEG_IC_chan.ICRange.String = ICNamestrs; + EStduio_eegtab_EEG_IC_chan.ICRange.Value = 1; + EStduio_eegtab_EEG_IC_chan.ICRange.Enable = 'off'; + ICValue = []; + end + estudioworkingmemory('EEG_ICArray',ICValue); + estudioworkingmemory('EEG_ChanArray',ChanArray); + observe_EEGDAT.count_current_eeg=3; + end + + +%%------------------------------------------------------------------------- +%%Automatically saving the changed parameters for the current panel if the +%%user change parameters for the other panels. +%%------------------------------------------------------------------------- + function eeg_two_panels_change(~,~) + if observe_EEGDAT.eeg_two_panels==0 + return; + end + ChangeFlag = estudioworkingmemory('EEGTab_chanic'); + if ChangeFlag~=1 + return; + end + plot_eeg_apply(); + estudioworkingmemory('EEGTab_chanic',0); + EStduio_eegtab_EEG_IC_chan.plot_apply.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_eeg_box_ic_chan.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_IC_chan.plot_reset.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_reset.ForegroundColor = [0 0 0]; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_ichan_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_chanic'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + plot_eeg_apply(); + estudioworkingmemory('EEGTab_chanic',0); + EStduio_eegtab_EEG_IC_chan.plot_apply.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_eeg_box_ic_chan.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_IC_chan.plot_reset.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_reset.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=2 + return; + end + %%------------------------------channel---------------------------- + Chanlist_name = EStduio_eegtab_EEG_IC_chan.ElecRange.String; + if length(Chanlist_name)==1 + ChanArray = []; + else + ChanArray = [1:length(Chanlist_name)-1]; + end + EStduio_eegtab_EEG_IC_chan.ElecRange.Value=1; + + %%-------------------------------ICs------------------------------- + ICNamestrs = EStduio_eegtab_EEG_IC_chan.ICRange.String; + if length(ICNamestrs)==1 + ICValue=[]; + else + ICValue = [1:length(ICNamestrs)-1]; + end + EStduio_eegtab_EEG_IC_chan.ICRange.Value=1; + + estudioworkingmemory('EEG_ICArray',ICValue); + estudioworkingmemory('EEG_ChanArray',ChanArray); + estudioworkingmemory('EEGTab_chanic',0); + EStduio_eegtab_EEG_IC_chan.plot_apply.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_apply.ForegroundColor = [0 0 0]; + % EStudio_eeg_box_ic_chan.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_IC_chan.plot_reset.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_IC_chan.plot_reset.ForegroundColor = [0 0 0]; + observe_EEGDAT.Reset_eeg_paras_panel=3; + end + +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_Plot_setting_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_Plot_setting_GUI.m new file mode 100755 index 00000000..286df0c1 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_Plot_setting_GUI.m @@ -0,0 +1,1449 @@ +%%This function is used to set the plotting wave for EEG + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Agust 2023 && 2024 + + +function varargout = f_EEG_Plot_setting_GUI(varargin) + +global observe_EEGDAT; +global EStudio_gui_erp_totl; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ + +EStduio_gui_EEG_plotset = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_box_EEG_plot_set; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_box_EEG_plot_set = uiextras.BoxPanel('Parent', fig, 'Title', 'Plot Settings', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_box_EEG_plot_set = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Settings', 'Padding', 5,'BackgroundColor',ColorB_def); +else + EStudio_box_EEG_plot_set = uiextras.BoxPanel('Parent', varargin{1}, 'Title', ' Plot Settings', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_plot_set_eeg(FonsizeDefault) +varargout{1} = EStudio_box_EEG_plot_set; + + function drawui_plot_set_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EStduio_gui_EEG_plotset.DataSelBox = uiextras.VBox('Parent', EStudio_box_EEG_plot_set,'BackgroundColor',ColorB_def); + + %%display original data? + EStduio_gui_EEG_plotset.datatype_title = uiextras.HBox('Parent', EStduio_gui_EEG_plotset.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.disp_orgdata = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title, 'Style', 'checkbox', 'String', 'Display chans',... + 'Callback', @disp_orgdata,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',1); + EStduio_gui_EEG_plotset.disp_orgdata.KeyPressFcn = @eeg_plotset_presskey; + + EStduio_gui_EEG_plotset.v_scale = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title, 'Style', 'text', 'String', 'Vertical Scale:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.v_scale_edit = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title , 'Style', 'edit', 'String', '50',... + 'Callback', @vscale_edit,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + set(EStduio_gui_EEG_plotset.datatype_title,'Sizes',[120 80 -1]); + EEG_plotset{1} = EStduio_gui_EEG_plotset.disp_orgdata.Value; + + EStduio_gui_EEG_plotset.datatype_title1 = uiextras.HBox('Parent', EStduio_gui_EEG_plotset.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.disp_IC = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title1, 'Style', 'checkbox', 'String', 'Display ICs',... + 'Callback', @disp_IC,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + EStduio_gui_EEG_plotset.disp_IC.KeyPressFcn = @eeg_plotset_presskey; + + EStduio_gui_EEG_plotset.v_scale_ic = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title1, 'Style', 'text', 'String', 'Vertical Scale:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.v_scale_edit_ic = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title1 , 'Style', 'edit', 'String', '20',... + 'Callback', @vscale_edit_ic,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + set(EStduio_gui_EEG_plotset.datatype_title1,'Sizes',[120 80 -1]); + + EEG_plotset{2} = EStduio_gui_EEG_plotset.disp_IC.Value; + + EStduio_gui_EEG_plotset.datatype_title2 = uiextras.HBox('Parent', EStduio_gui_EEG_plotset.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title2, 'Style', 'text', 'String', 'Buffer at top & bottom:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.buffer_top_bom = uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title2, 'Style', 'edit', 'String', '100',... + 'Callback', @buffer_top_bom,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + EStduio_gui_EEG_plotset.buffer_top_bom.KeyPressFcn = @eeg_plotset_presskey; + uicontrol('Parent',EStduio_gui_EEG_plotset.datatype_title2, 'Style', 'text', 'String', '%',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(EStduio_gui_EEG_plotset.datatype_title2, 'Sizes',[130 -1 20]); + EEG_plotset{12} = str2num(EStduio_gui_EEG_plotset.buffer_top_bom.String); + + %%-----------------General settings-------------------------------- + %%time range + EStduio_gui_EEG_plotset.time_scales_title = uiextras.HBox('Parent', EStduio_gui_EEG_plotset.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.timerange = uicontrol('Parent',EStduio_gui_EEG_plotset.time_scales_title , 'Style', 'text', 'String', 'Time Range:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.WinLength_edit = uicontrol('Parent',EStduio_gui_EEG_plotset.time_scales_title , 'Style', 'edit', 'String', '5',... + 'Callback', @WinLength_edit,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + EStduio_gui_EEG_plotset.WinLength_edit.KeyPressFcn = @eeg_plotset_presskey; + EEG_plotset{3} = str2num(EStduio_gui_EEG_plotset.timerange.String); + + uiextras.Empty('Parent', EStduio_gui_EEG_plotset.time_scales_title,'BackgroundColor',ColorB_def); + set(EStduio_gui_EEG_plotset.time_scales_title,'Sizes',[70 80 -1]); + + EStduio_gui_EEG_plotset.v_scale_edit.KeyPressFcn = @eeg_plotset_presskey; + EEG_plotset{4} = str2num(EStduio_gui_EEG_plotset.v_scale_edit.String); + + EEG_plotset{5} = str2num(EStduio_gui_EEG_plotset.v_scale_edit_ic.String); + + + %%Remove DC or display event? + EStduio_gui_EEG_plotset.removedc_event_title = uiextras.HBox('Parent', EStduio_gui_EEG_plotset.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.rem_DC = uicontrol('Parent',EStduio_gui_EEG_plotset.removedc_event_title, 'Style', 'checkbox', 'String', 'Remove DC',... + 'Callback', @rm_DC,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',1); + EStduio_gui_EEG_plotset.rem_DC.KeyPressFcn = @eeg_plotset_presskey; + EStduio_gui_EEG_plotset.disp_event = uicontrol('Parent',EStduio_gui_EEG_plotset.removedc_event_title, 'Style', 'checkbox', 'String', 'Show events',... + 'Callback', @disp_event,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',1); + EStduio_gui_EEG_plotset.disp_event.KeyPressFcn = @eeg_plotset_presskey; + EEG_plotset{6} = EStduio_gui_EEG_plotset.rem_DC.Value; + EEG_plotset{7} = EStduio_gui_EEG_plotset.disp_event.Value; + + %%stack or norm? + EStduio_gui_EEG_plotset.stack_norm_title = uiextras.HBox('Parent', EStduio_gui_EEG_plotset.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.disp_stack = uicontrol('Parent',EStduio_gui_EEG_plotset.stack_norm_title, 'Style', 'checkbox', 'String', 'Stack',... + 'Callback', @disp_stack,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + EStduio_gui_EEG_plotset.disp_stack.KeyPressFcn = @eeg_plotset_presskey; + EStduio_gui_EEG_plotset.disp_norm = uicontrol('Parent',EStduio_gui_EEG_plotset.stack_norm_title, 'Style', 'checkbox', 'String', 'Norm',... + 'Callback', @disp_norm,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + EStduio_gui_EEG_plotset.disp_norm.KeyPressFcn = @eeg_plotset_presskey; + EEG_plotset{8} = EStduio_gui_EEG_plotset.disp_stack.Value; + EEG_plotset{9} = EStduio_gui_EEG_plotset.disp_norm.Value; + + + %%channel order + EStduio_gui_EEG_plotset.chanorder_title = uiextras.HBox('Parent',EStduio_gui_EEG_plotset.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EStduio_gui_EEG_plotset.chanorder_title,'String','Channel Order (for plotting only):',... + 'FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + EStduio_gui_EEG_plotset.chanorder_no_title = uiextras.HBox('Parent',EStduio_gui_EEG_plotset.DataSelBox,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.chanorder_number = uicontrol('Parent',EStduio_gui_EEG_plotset.chanorder_no_title, 'Style', 'radiobutton', 'String', 'Default',... + 'Callback', @chanorder_number,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',1); + EStduio_gui_EEG_plotset.chanorder_number.KeyPressFcn= @eeg_plotset_presskey; + EStduio_gui_EEG_plotset.chanorder_front = uicontrol('Parent',EStduio_gui_EEG_plotset.chanorder_no_title, 'Style', 'radiobutton', 'String', 'Simple 10/20 system order',... + 'Callback', @chanorder_front,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + EStduio_gui_EEG_plotset.chanorder_front.KeyPressFcn= @eeg_plotset_presskey; + set(EStduio_gui_EEG_plotset.chanorder_no_title,'Sizes',[80 -1]); + %%channel order-custom + EStduio_gui_EEG_plotset.chanorder_custom_title = uiextras.HBox('Parent',EStduio_gui_EEG_plotset.DataSelBox,'BackgroundColor',ColorB_def); + EStduio_gui_EEG_plotset.chanorder_custom = uicontrol('Parent',EStduio_gui_EEG_plotset.chanorder_custom_title, 'Style', 'radiobutton', 'String', 'Custom',... + 'Callback', @chanorder_custom,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + EStduio_gui_EEG_plotset.chanorder_custom.KeyPressFcn= @eeg_plotset_presskey; + EStduio_gui_EEG_plotset.chanorder_custom_exp = uicontrol('Parent',EStduio_gui_EEG_plotset.chanorder_custom_title, 'Style', 'pushbutton', 'String', 'Export',... + 'Callback', @chanorder_custom_exp,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + EStduio_gui_EEG_plotset.chanorder_custom_imp = uicontrol('Parent',EStduio_gui_EEG_plotset.chanorder_custom_title, 'Style', 'pushbutton', 'String', 'Import',... + 'Callback', @chanorder_custom_imp,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + + EEG_plotset{10} = 1; + EEG_plotset{11} = []; + + %%----------------cancel and apply--------------------------------- + EStduio_gui_EEG_plotset.reset_apply = uiextras.HBox('Parent',EStduio_gui_EEG_plotset.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EStduio_gui_EEG_plotset.reset_apply); % 1A + EStduio_gui_EEG_plotset.plotset_cancel = uicontrol('Style', 'pushbutton','Parent',EStduio_gui_EEG_plotset.reset_apply,... + 'String','Cancel','callback',@plot_eeg_cancel,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + + uiextras.Empty('Parent', EStduio_gui_EEG_plotset.reset_apply); % 1A + EStduio_gui_EEG_plotset.plot_apply = uicontrol('Style', 'pushbutton','Parent',EStduio_gui_EEG_plotset.reset_apply,... + 'String','Apply','callback',@eeg_plotset_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + EStduio_gui_EEG_plotset.plot_apply.KeyPressFcn= @eeg_plotset_presskey; + uiextras.Empty('Parent', EStduio_gui_EEG_plotset.reset_apply); % 1A + set(EStduio_gui_EEG_plotset.reset_apply, 'Sizes',[10,-1,30,-1,10]); + + set(EStduio_gui_EEG_plotset.DataSelBox,'Sizes',[25 25 25 25 25 25 20 25 25 30]); + estudioworkingmemory('EEG_plotset',EEG_plotset); + + EStduio_gui_EEG_plotset.chanorder{1,1} = []; + EStduio_gui_EEG_plotset.chanorder{1,2} = ''; + estudioworkingmemory('EEGTab_plotset',0); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%------------------------Display original data: on------------------------ + function disp_orgdata(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + if EStduio_gui_EEG_plotset.disp_orgdata.Value==0 + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'off'; + else + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'on'; + end + end + +%%------------------------Display original data: off----------------------- + function disp_IC(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + if EStduio_gui_EEG_plotset.disp_IC.Value==1 + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'on'; + else + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'off'; + end + end + +%%--------------------Time range------------------------------------------- + function WinLength_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + + Winlength = str2num(Source.String); + if ~isempty(observe_EEGDAT.EEG) + [chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); + Frames = sampleNum*trialNum; + if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); + else + multiplier_winleg = observe_EEGDAT.EEG.srate; + end + if isempty(Winlength)|| Winlength<=0 || (Winlength>floor(Frames/multiplier_winleg)) + Winlength = floor(Frames/multiplier_winleg); + % msgboxText= char(strcat('Plot Setting > Time range:The input is invalid which should be a positive value and we therfore use the default one')); + % titlNamerro = 'Warning for EEG Tab'; + % estudio_warning(msgboxText,titlNamerro); + end + else + if isempty(Winlength)|| Winlength<=0 || numel(Winlength)~=1 + Winlength = 5; + % msgboxText= char(strcat('Plot Setting > Time range:The input is invalid which should be a positive value and we therfore use the default one')); + % titlNamerro = 'Warning for EEG Tab'; + % estudio_warning(msgboxText,titlNamerro); + end + end + Source.String = num2str(Winlength); + end + +%%-----------------------------Vertical Scale for original data------------ + function vscale_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + vscale_Value = str2num(Source.String); + + if isempty(vscale_Value) || numel(vscale_Value)~=1 || any(vscale_Value<=0) + Source.String = '50'; + msgboxText= char(strcat('Plot Setting > Vertical scale for original data:The input is invalid which should be a positive value and we therfore use the default one')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + +%%-----------------------------Vertical Scale for ICs---------------------- + function vscale_edit_ic(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + vscale_Value = str2num(Source.String); + if isempty(vscale_Value) || numel(vscale_Value)~=1 || any(vscale_Value<=0) + Source.String = '20'; + msgboxText= char(strcat('Plot Setting > Vertical scale for ICs:The input is invalid which should be a positive value and we therfore use the default one')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + +%%--------------------------Buffer at top and bottom----------------------- + function buffer_top_bom(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + + buffer_top_bomValue = str2num(EStduio_gui_EEG_plotset.buffer_top_bom.String); + if isempty(buffer_top_bomValue) || numel(buffer_top_bomValue)~=1 || any(buffer_top_bomValue(:)<=0) + EStduio_gui_EEG_plotset.buffer_top_bom.String = '100'; + msgboxText= char(strcat('Plot Setting > Buffer at top & bottom:The input is invalid which should be a positive value and we therfore use the default one')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + +%%------------------------Remove DC on------------------------------------- + function rm_DC(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + end + + +%%---------------------------Events:on------------------------------------- + function disp_event(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + end + + +%%--------------------------Stack: on-------------------------------------- + function disp_stack(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + end + + +%%--------------------------Stack: off------------------------------------- + function disp_norm(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + if Source.Value==1 + EStduio_gui_EEG_plotset.v_scale_edit.String = '5'; + EStduio_gui_EEG_plotset.v_scale_edit_ic.String = '5'; + else + EStduio_gui_EEG_plotset.v_scale_edit.String = '50'; + EStduio_gui_EEG_plotset.v_scale_edit_ic.String = '20'; + end + end + +%%----------------------channel order-number------------------------------- + function chanorder_number(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + end + +%%-----------------channel order-Simple 10/20 order--------------------- + function chanorder_front(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.chanorder_number.Value=0; + EStduio_gui_EEG_plotset.chanorder_front.Value=1; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + + try + chanlocs = observe_EEGDAT.EEG.chanlocs; + if isempty(chanlocs(1).X) && isempty(chanlocs(1).Y) + msgboxText= char(strcat('Plot Setting > Channel order>Simple 10/20 system order:please do "chan locations" first in EEGLAB Tool panel.')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message=4; + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + msgboxText = ['Plot Setting > Channel order>Simple 10/20 system order: please do "chan locations" first in EEGLAB Tool panel.']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + catch + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + msgboxText = ['Plot Setting > Channel order>Simple 10/20 system order: It seems that chanloc for the current EEG is empty and please check it out']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + + %%check if the channels belong to 10/20 system + [eloc, labels, theta, radius, indices] = readlocs( observe_EEGDAT.EEG.chanlocs); + [Simplabels,simplabelIndex,SamAll] = Simplelabels(labels); + count = 0; + for ii = 1:length(Simplabels) + [xpos,ypos]= find(simplabelIndex==ii); + if ~isempty(ypos) && numel(ypos)>= floor(length(observe_EEGDAT.EEG.chanlocs)/2) + count = count+1; + if count==1 + msgboxText= char(strcat('Plot Setting > Channel order>Simple 10/20 system order: We cannot use the "Simple 10/20 system order" with your data because your channel labels do not appear to be standard 10/20 names.')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + break; + end + end + end + + end + +%%----------------------channel order-custom------------------------------- + function chanorder_custom(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.chanorder_number.Value=0; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=1; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'on'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'on'; + + if ~isfield(observe_EEGDAT.EEG,'chanlocs') || isempty(observe_EEGDAT.EEG.chanlocs) + msgboxText= char(strcat('Plot Setting > Channel order>Simple 10/20 order: It seems that chanlocs for the current EEG is empty and please check it out')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + + end + +%%---------------------export channel orders------------------------------- + function chanorder_custom_exp(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + if ~isfield(observe_EEGDAT.EEG,'chanlocs') || isempty(observe_EEGDAT.EEG.chanlocs) + msgboxText= char(strcat('Plot Setting > Channel order>Custom>Export: It seems that chanlocs for the current EEG is empty and please check it out')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + + MessageViewer= char(strcat('Plot Setting > Channel order>Custom>Export')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=1; + + if isempty(EStduio_gui_EEG_plotset.chanorder{1,1}) || isempty(EStduio_gui_EEG_plotset.chanorder{1,2}) + chanOrders = [1:observe_EEGDAT.EEG.nbchan]; + [eloc, labels, theta, radius, indices] = readlocs(observe_EEGDAT.EEG.chanlocs); + else + chanOrders = EStduio_gui_EEG_plotset.chanorder{1,1} ; + labels= EStduio_gui_EEG_plotset.chanorder{1,2}; + end + Data = cell(length(chanOrders),1); + for ii =1:length(chanOrders) + try + Data{ii,1} = [num2str(chanOrders(ii)),'.',32,labels{ii}]; + catch + end + end + pathstr = estudioworkingmemory('EEG_save_folder'); + if isempty(pathstr) + pathstr =cd; + end + namedef ='Channel_order_eeg'; + [erpfilename, erppathname, indxs] = uiputfile({'*.tsv'}, ... + ['Export EEG channel order (for plotting only)'],... + fullfile(pathstr,namedef)); + if isequal(erpfilename,0) + return + end + + [pathstr, erpfilename, ext] = fileparts(erpfilename) ; + ext = '.tsv'; + erpFilename = char(strcat(erppathname,erpfilename,ext)); + fileID = fopen(erpFilename,'w+'); + + formatSpec =['%s\t',32,'%s\n']; + columName = {'Row','Channel'}; + fprintf(fileID,'%s\t %s\n',columName{1,:}); + for row = 1:numel(chanOrders) + rowdata = cell(1,2); + rowdata{1,1} = char(num2str(row)); + rowdata{1,2} = Data{row,1}; + fprintf(fileID,formatSpec,rowdata{1,:}); + end + fclose(fileID); + disp(['A new EEG channel order file was created at ' erpFilename '']) + + MessageViewer= char(strcat('Plot Setting > Channel order>Custom>Export')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=2; + end + +%%-------------------------import channel orders--------------------------- + function chanorder_custom_imp(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_plotset',1); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_EEG_plot_set.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [1 1 1]; + + + if ~isfield(observe_EEGDAT.EEG,'chanlocs') || isempty(observe_EEGDAT.EEG.chanlocs) + msgboxText= char(strcat('Plot Setting > Channel order>Custom>Import: It seems that chanlocs for the current EEG is empty and please check it out')); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + + %%import data chan orders + [eloc, labels, theta, radius, indices] = readlocs(observe_EEGDAT.EEG.chanlocs); + + [erpfilename, erppathname, indxs] = uigetfile({'*.tsv;*.txt';'*.*'}, ... + ['Import EEG channel order (for plotting only)']); + if isequal(erpfilename,0) || indxs~=1 + return + end + + [pathstr, erpfilename, ext] = fileparts(erpfilename) ; + if ~strcmpi(ext,'.tsv') && ~strcmpi(ext,'.txt') + msgboxText = ['Estudio: Plot Settings > Channel Order > Custom > Import: Either ",tsv" or ".txt" is allowed']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + erpFilename = char(strcat(erppathname,erpfilename,ext)); + + DataInput = readtable(erpFilename, "FileType","text",'Delimiter', '\t','PreserveVariableNames',true); + if isempty(DataInput) + EStduio_gui_EEG_plotset.chanorder{1,1}=[]; + EStduio_gui_EEG_plotset.chanorder{1,2} = ''; + end + DataInput = table2cell(DataInput); + chanorders = []; + chanlabes = []; + DataInput = DataInput(:,2:end); + chan_check = ones(length(labels),1); + + for ii = 1:size(DataInput,1) + if isnumeric(DataInput{ii,1}) + chanorders(ii) = DataInput{ii,1}; + if chanorders(ii)>length(labels) + msgboxText = ['Plot Settings > Channel Order > Custom > Import: The defined channel order should be not more than',32,num2str(length(labels)),32,'for row',32,num2str(ii)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + chanlabes{ii} = labels{chanorders(ii)}; + chan_check(ii) = DataInput{ii,1}; + elseif ischar(DataInput{ii,1}) + newStr = split(DataInput{ii,1},["."]); + if length(newStr)~=2 || ~isnumeric(str2num(newStr{1,1})) || ~ischar(newStr{2,1}) + msgboxText = ['Plot Settings > Channel Order > Custom > Import: The defined channel format for row',32,num2str(ii),32, 'should be:\n Row Channel\n 1 1. FP1\n ... ...\n']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + chanorders(ii) = str2num(newStr{1,1}); + chan_check(ii) = f_chanlabel_check(newStr{2,1},labels); + if chan_check(ii)==0 + msgboxText = ['Plot Settings > Channel Order > Custom > Import: The defined channel format for row',32,num2str(ii),32,'can not match any of channel labels']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + chanlabes{ii} = labels{chan_check(ii)}; + else + msgboxText = ['Plot Settings > Channel Order > Custom > Import: The defined channel format should be either numberic or char for row',32,num2str(ii)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + end + chanorders1 = unique(chanorders); + if any(chanorders(:)>length(labels)) || any(chanorders(:)<=0) + msgboxText = ['Plot Settings > Channel Order > Custom > Import: It seems that some of the defined chan orders are invalid or replicated, please check the file']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + + if numel(chanorders1)~= observe_EEGDAT.EEG.nbchan + msgboxText = ['Plot Settings > Channel Order > Custom > Import: The number of the defined chan orders must be',32,num2str(observe_EEGDAT.EEG.nbchan)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + + if any(chan_check==0) + msgboxText = ['Plot Settings > Channel Order > Custom > Import: The channel labels are not the same to those for the current EEG']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + [xpos,ypos] =find(chan_check==0); + if ~isempty(ypos) + labelsmatch = ''; + for ii = 1:numel(ypos) + if ii==1 + labelsmatch = [labelsmatch,32,chanlabes{ypos(ii)}]; + else + labelsmatch = [labelsmatch,',',32,chanlabes{ypos(ii)}]; + end + end + disp(['The defined labels that didnot match: ',32,labelsmatch]); + end + ypos = setdiff([1:length(labels)],setdiff(chan_check,0)); + if ~isempty(ypos) + labelsmatch = ''; + for ii = 1:numel(ypos) + if ii==1 + labelsmatch = [labelsmatch,32,labels{ypos(ii)}]; + else + labelsmatch = [labelsmatch,',',32,labels{ypos(ii)}]; + end + end + disp(['The labels that didnot match for the current data: ',32,labelsmatch]); + end + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + + if ~isempty(chan_check) + chan_check = unique(chan_check); + end + if numel(chan_check)~=observe_EEGDAT.EEG.nbchan + msgboxText = ['Plot Settings > Channel Order > Custom > Import: There are some replicated channel labels']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + return; + end + EStduio_gui_EEG_plotset.chanorder{1,1}=chanorders; + EStduio_gui_EEG_plotset.chanorder{1,2} = chanlabes; + end + + + +%%-------------------Cancel------------------------------------------------ + function plot_eeg_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + ChangeFlag = estudioworkingmemory('EEGTab_plotset'); + if ChangeFlag~=1 + return; + end + + EEG_plotset = estudioworkingmemory('EEG_plotset'); + + %%display original data? + try OrigFlag = EEG_plotset{1};catch OrigFlag= 1; end + if isempty(OrigFlag) || numel(OrigFlag)~=1 || (OrigFlag~=0 && OrigFlag~=1) + OrigFlag=1; + end + EStduio_gui_EEG_plotset.disp_orgdata.Value = OrigFlag; + + %%display IC? + try ICFlag = EEG_plotset{2};catch ICFlag= 0; end + if isempty(ICFlag) || numel(ICFlag)~=1 || (ICFlag~=0 && ICFlag~=1) + ICFlag=0; + end + EStduio_gui_EEG_plotset.disp_IC.Value = ICFlag; + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.EEG.icachansind) + EStduio_gui_EEG_plotset.disp_IC.Value = 0; + EStduio_gui_EEG_plotset.disp_IC.Enable = 'off'; + else + EStduio_gui_EEG_plotset.disp_IC.Enable = 'on'; + end + + %%Displayed Window length (the defalut is 5s/trials )? + try Winlength = EEG_plotset{3}; catch Winlength =5; end + if isempty(Winlength) || Winlength<=0 + Winlength=5; + EEG_plotset{3}=5; + end + if ~isempty(observe_EEGDAT.EEG) + [chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); + Frames = sampleNum*trialNum; + if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); + else + multiplier_winleg = observe_EEGDAT.EEG.srate; + end + if isempty(Winlength)|| Winlength<=0 || (Winlength>floor(Frames/multiplier_winleg)) || numel(Winlength)~=1 + Winlength = floor(Frames/multiplier_winleg); + EEG_plotset{3} = floor(Frames/multiplier_winleg); + end + end + EStduio_gui_EEG_plotset.WinLength_edit.String = num2str(Winlength); + + %%vertical scale for original data + try VScale = EEG_plotset{4}; catch VScale =50; end + if isempty(VScale) || numel(VScale)~=1 || VScale<=0 + VScale=50; + EEG_plotset{4} =50; + end + EStduio_gui_EEG_plotset.v_scale_edit.String = num2str(VScale); + + %%vertical scale for ICs + try VScale_ic = EEG_plotset{5}; catch VScale =10; end + if isempty(VScale_ic) || numel(VScale_ic)~=1 || any(VScale_ic(:)<=0) + VScale_ic=20; + EEG_plotset{5} =20; + end + EStduio_gui_EEG_plotset.v_scale_edit_ic.String = num2str(VScale_ic); + + %%Buffer at top and bottom + try buffer_top_bom = EEG_plotset{12};catch buffer_top_bom =100; end + if isempty(buffer_top_bom) || numel(buffer_top_bom)~=1 ||any(buffer_top_bom(:)<=0) + buffer_top_bom=100; EEG_plotset{12} =100; + end + EStduio_gui_EEG_plotset.buffer_top_bom.String = num2str(buffer_top_bom); + + %%Remove DC + try RMean = EEG_plotset{6}; catch RMean =0; end + if isempty(RMean) || numel(RMean)~=1 || (RMean~=0 && RMean~=1) + RMean=0; + EEG_plotset{6}=0; + end + EStduio_gui_EEG_plotset.rem_DC.Value=RMean; + + %%display event? + try EventFlag = EEG_plotset{7}; catch EventFlag =1; end + if isempty(EventFlag) || numel(EventFlag)~=1 || (EventFlag~=0 && EventFlag~=1) + EventFlag=1; + EEG_plotset{7}=1; + end + EStduio_gui_EEG_plotset.disp_event.Value = EventFlag; + + %%Stack? + try StackFlag = EEG_plotset{8}; catch StackFlag =0; end + if isempty(StackFlag) || numel(StackFlag)~=1 || (StackFlag~=0 && StackFlag~=1) + StackFlag=0; + EEG_plotset{8}=0; + end + EStduio_gui_EEG_plotset.disp_stack.Value = StackFlag; + + %%Norm? + try NormFlag = EEG_plotset{9}; catch NormFlag =0; end + if isempty(NormFlag) || numel(NormFlag)~=1 || (NormFlag~=0 && NormFlag~=1) + NormFlag=0; + EEG_plotset{9}=0; + end + EStduio_gui_EEG_plotset.disp_norm.Value = NormFlag; + + try chanOrder = EEG_plotset{10}; catch chanOrder =1; end + if chanOrder==2 + EStduio_gui_EEG_plotset.chanorder_number.Value=0; + EStduio_gui_EEG_plotset.chanorder_front.Value=1; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + EEG_plotset{10}=2; + EStduio_gui_EEG_plotset.chanorder{1,1} = []; + EStduio_gui_EEG_plotset.chanorder{1,2} = ''; + elseif chanOrder==3 + EStduio_gui_EEG_plotset.chanorder_number.Value=0; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=1; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'on'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'on'; + EEG_plotset{10}=3; + else + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + EEG_plotset{10}=1; + EStduio_gui_EEG_plotset.chanorder{1,1} = []; + EStduio_gui_EEG_plotset.chanorder{1,2} = ''; + end + + if EStduio_gui_EEG_plotset.disp_orgdata.Value==0 + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'off'; + else + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'on'; + end + if EStduio_gui_EEG_plotset.disp_IC.Value==1 + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'on'; + else + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'off'; + end + + estudioworkingmemory('EEG_plotset',EEG_plotset); + estudioworkingmemory('EEGTab_plotset',0); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_EEG_plot_set.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [0 0 0]; + end + +%%-------------------------------Apply------------------------------------- + function eeg_plotset_apply(~,~) + if isempty(observe_EEGDAT.EEG) %%if current eeg is empty + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=2 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + MessageViewer= char(strcat('Plot Setting > Apply')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=1; + + %%display original data? + EEG_plotset{1}= EStduio_gui_EEG_plotset.disp_orgdata.Value; + %%display IC? + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.EEG.icachansind) + EEG_plotset{2}=0; + else + EEG_plotset{2}= EStduio_gui_EEG_plotset.disp_IC.Value; + end + + EEG_plotset{12} = str2num(EStduio_gui_EEG_plotset.buffer_top_bom.String); + + + %%Displayed Window length (the defalut is 5s/trials )? + Winlength = str2num(EStduio_gui_EEG_plotset.WinLength_edit.String); + if isempty(Winlength) || Winlength<=0 + Winlength=5; + end + if ~isempty(observe_EEGDAT.EEG) + [chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); + Frames = sampleNum*trialNum; + if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); + else + multiplier_winleg = observe_EEGDAT.EEG.srate; + end + if isempty(Winlength)|| Winlength<=0 || (Winlength>floor(Frames/multiplier_winleg)) || numel(Winlength)~=1 + Winlength = floor(Frames/multiplier_winleg); + EStduio_gui_EEG_plotset.WinLength_edit.String = num2str(Winlength); + end + end + EEG_plotset{3}=Winlength; + %%vertical scale + VScale= str2num(EStduio_gui_EEG_plotset.v_scale_edit.String); + if isempty(VScale) || numel(VScale)~=1 || any(VScale(:)<=0) + VScale=50; + EStduio_gui_EEG_plotset.v_scale_edit.String = num2str(VScale); + end + EEG_plotset{4} =VScale; + %%Channel labels name/number? + VScale_IC= str2num(EStduio_gui_EEG_plotset.v_scale_edit_ic.String); + if isempty(VScale_IC) || numel(VScale_IC)~=1 || any(VScale_IC(:)<=0) + VScale_IC=20; + EStduio_gui_EEG_plotset.v_scale_edit_ic.String= num2str(VScale_IC); + end + EEG_plotset{5}=VScale_IC; + + %%Remove DC + EEG_plotset{6}=EStduio_gui_EEG_plotset.rem_DC.Value; + %%display event? + EEG_plotset{7}= EStduio_gui_EEG_plotset.disp_event.Value; + %%Stack? + EEG_plotset{8}= EStduio_gui_EEG_plotset.disp_stack.Value; + %%Norm? + EEG_plotset{9}=EStduio_gui_EEG_plotset.disp_norm.Value; + %%channel orders + try + [eloc, labels, theta, radius, indices] = readlocs(observe_EEGDAT.EEG.chanlocs); + catch + labels = []; + end + if EStduio_gui_EEG_plotset.chanorder_number.Value==1 + EEG_plotset{10} = 1; + EEG_plotset{11}= {1:length(labels),labels}; + EStduio_gui_EEG_plotset.chanorder{1,1} = 1:length(labels); + EStduio_gui_EEG_plotset.chanorder{1,2} = labels; + elseif EStduio_gui_EEG_plotset.chanorder_front.Value==1 + EEG_plotset{10} = 2; + chanindexnew = f_estudio_chan_frontback_left_right(observe_EEGDAT.EEG.chanlocs); + if ~isempty(chanindexnew) + EEG_plotset{11} = {1:numel(chanindexnew),labels(chanindexnew)}; + EStduio_gui_EEG_plotset.chanorder{1,1} = 1:numel(chanindexnew); + EStduio_gui_EEG_plotset.chanorder{1,2} = labels(chanindexnew); + else + EEG_plotset{11}= {1:length(labels),labels}; + EStduio_gui_EEG_plotset.chanorder{1,1} = 1:length(labels); + EStduio_gui_EEG_plotset.chanorder{1,2} = labels; + end + elseif EStduio_gui_EEG_plotset.chanorder_custom.Value==1 + EEG_plotset{10} = 3; + if isempty(EStduio_gui_EEG_plotset.chanorder{1,1}) + EEG_plotset{11}= {1:length(labels),labels}; + MessageViewer= char(strcat('There were no custom-defined chan orders and we therefore used the default orders.')); + titlNamerro = 'Warning for EEG Tab - Plot Setting > Apply'; + estudio_warning(MessageViewer,titlNamerro); + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + else + EEG_plotset{11} = EStduio_gui_EEG_plotset.chanorder; + end + end + + estudioworkingmemory('EEG_plotset',EEG_plotset); + + estudioworkingmemory('EEGTab_plotset',0); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_EEG_plot_set.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [0 0 0]; + MessageViewer= char(strcat('Plot Setting > Apply')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + f_redrawEEG_Wave_Viewer(); + observe_EEGDAT.eeg_panel_message=2; + end + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=3 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || EEGUpdate==1 + Enableflag = 'off'; + else + Enableflag = 'on'; + if size(observe_EEGDAT.EEG.data,3)==1 + EStduio_gui_EEG_plotset.timerange.String = 'Time Range:'; + else + EStduio_gui_EEG_plotset.timerange.String = '# of Epochs:'; + end + end + + EStduio_gui_EEG_plotset.disp_orgdata.Enable = Enableflag; + EStduio_gui_EEG_plotset.disp_IC.Enable = Enableflag; + EStduio_gui_EEG_plotset.buffer_top_bom.Enable = Enableflag; + EStduio_gui_EEG_plotset.WinLength_edit.Enable = Enableflag; + EStduio_gui_EEG_plotset.v_scale_edit.Enable = Enableflag; + EStduio_gui_EEG_plotset.rem_DC.Enable = Enableflag; + EStduio_gui_EEG_plotset.disp_event.Enable = Enableflag; + EStduio_gui_EEG_plotset.disp_stack.Enable = Enableflag; + EStduio_gui_EEG_plotset.disp_norm.Enable = Enableflag; + EStduio_gui_EEG_plotset.chanorder_number.Enable = Enableflag; + EStduio_gui_EEG_plotset.chanorder_front.Enable = Enableflag; + EStduio_gui_EEG_plotset.chanorder_custom.Enable = Enableflag; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = Enableflag; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = Enableflag; + EStduio_gui_EEG_plotset.plotset_cancel.Enable = Enableflag; + EStduio_gui_EEG_plotset.plot_apply.Enable = Enableflag; + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = Enableflag; + if isempty(observe_EEGDAT.EEG) || EEGUpdate==1 + observe_EEGDAT.count_current_eeg=4; + return; + end + EEG_plotset= estudioworkingmemory('EEG_plotset'); + if ~isempty(observe_EEGDAT.EEG) && ~isempty(observe_EEGDAT.EEG.icachansind) && EEGUpdate==0 + EStduio_gui_EEG_plotset.disp_IC.Enable = 'on'; + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'on'; + else + EStduio_gui_EEG_plotset.disp_IC.Enable = 'off'; + EStduio_gui_EEG_plotset.disp_IC.Value = 0; + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'off'; + end + if EStduio_gui_EEG_plotset.disp_IC.Value==0 + EEG_plotset{2}=0; + end + if strcmp(Enableflag,'on') + if EStduio_gui_EEG_plotset.chanorder_custom.Value ==1 + Enableflag = 'on'; + else + Enableflag = 'off'; + end + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = Enableflag; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = Enableflag; + end + if ~isempty(observe_EEGDAT.EEG) || EEGUpdate==0 + if observe_EEGDAT.EEG.trials>1 + EStduio_gui_EEG_plotset.rem_DC.Enable = 'off'; + EStduio_gui_EEG_plotset.rem_DC.Value=0; + else + EStduio_gui_EEG_plotset.rem_DC.Enable = 'on'; + if EStudio_gui_erp_totl.EEG_transf ==1%%indicate if the users transfer Continous (or epoched) EEG to epoched (or cont.) + EStduio_gui_EEG_plotset.rem_DC.Value=1; + EEG_plotset{6}=1; + end + end + end + %% + if ~isempty(observe_EEGDAT.EEG) && EEGUpdate==0 + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + SetFlags = check_chanlocs(observe_EEGDAT.ALLEEG(EEGArray)); + if any(SetFlags(:)==0) + if EStduio_gui_EEG_plotset.chanorder_number.Value==0 + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + try + [eloc, labels, theta, radius, indices] = readlocs(observe_EEGDAT.EEG.chanlocs); + catch + labels = []; + end + EEG_plotset{10} = 1; + EEG_plotset{11}= {1:length(labels),labels}; + EStduio_gui_EEG_plotset.chanorder{1,1} = 1:length(labels); + EStduio_gui_EEG_plotset.chanorder{1,2} = labels; + end + end + if EStduio_gui_EEG_plotset.disp_orgdata.Value==0 + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'off'; + else + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'on'; + end + if EStduio_gui_EEG_plotset.disp_IC.Value==1 + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'on'; + else + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'off'; + end + end + %% + estudioworkingmemory('EEG_plotset',EEG_plotset); + observe_EEGDAT.count_current_eeg=4; + end + +%%------------------------------------------------------------------------- +%%Automatically saving the changed parameters for the current panel if the +%%user change parameters for the other panels. +%%------------------------------------------------------------------------- + function eeg_two_panels_change(~,~) + if observe_EEGDAT.eeg_two_panels==0 + return; + end + ChangeFlag = estudioworkingmemory('EEGTab_plotset'); + if ChangeFlag~=1 + return; + end + eeg_plotset_apply(); + estudioworkingmemory('EEGTab_plotset',0); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_EEG_plot_set.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [0 0 0]; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_plotset_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_plotset'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + eeg_plotset_apply(); + estudioworkingmemory('EEGTab_plotset',0); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_EEG_plot_set.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=3 + return; + end + estudioworkingmemory('EEGTab_plotset',0); + EStduio_gui_EEG_plotset.plot_apply.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plot_apply.ForegroundColor = [0 0 0]; + % EStudio_box_EEG_plot_set.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_gui_EEG_plotset.plotset_cancel.BackgroundColor = [1 1 1]; + EStduio_gui_EEG_plotset.plotset_cancel.ForegroundColor = [0 0 0]; + + %%display original data? + EStduio_gui_EEG_plotset.disp_orgdata.Value=1; + EEG_plotset{1}=1; + %%display IC? + EEG_plotset{2}=0; + EStduio_gui_EEG_plotset.disp_IC.Value = 0; + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.EEG.icachansind) + EStduio_gui_EEG_plotset.disp_IC.Enable = 'off'; + else + EStduio_gui_EEG_plotset.disp_IC.Enable = 'on'; + end + EStduio_gui_EEG_plotset.buffer_top_bom.String = '100'; + EEG_plotset{12}=100; + %%Displayed Window length (the defalut is 5s/trials )? + EEG_plotset{3} =5; + if ~isempty(observe_EEGDAT.EEG) + Winlength =5; + [chaNum,sampleNum,trialNum]=size(observe_EEGDAT.EEG.data); + Frames = sampleNum*trialNum; + if observe_EEGDAT.EEG.trials>1 % time in second or in trials + multiplier_winleg = size(observe_EEGDAT.EEG.data,2); + else + multiplier_winleg = observe_EEGDAT.EEG.srate; + end + if isempty(Winlength)|| Winlength<=0 || (Winlength>floor(Frames/multiplier_winleg)) || numel(Winlength)~=1 + EEG_plotset{3} = floor(Frames/multiplier_winleg); + end + if EStduio_gui_EEG_plotset.disp_orgdata.Value==0 + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'off'; + else + EStduio_gui_EEG_plotset.v_scale_edit.Enable = 'on'; + end + if EStduio_gui_EEG_plotset.disp_IC.Value==1 + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'on'; + else + EStduio_gui_EEG_plotset.v_scale_edit_ic.Enable = 'off'; + end + else + EEG_plotset{3} =5; + end + EStduio_gui_EEG_plotset.WinLength_edit.String = num2str(EEG_plotset{3}); + %%vertical scale + EEG_plotset{4} =50; + EStduio_gui_EEG_plotset.v_scale_edit.String = num2str(EEG_plotset{4}); + EStduio_gui_EEG_plotset.v_scale_edit_ic.String = '20'; + EEG_plotset{5} = str2num(EStduio_gui_EEG_plotset.v_scale_edit_ic.String); + %%Remove DC + if ~isempty(observe_EEGDAT.EEG) + if observe_EEGDAT.EEG.trials>1 + EEG_plotset{6}=0; + EStduio_gui_EEG_plotset.rem_DC.Enable='off'; + else + EEG_plotset{6}=1; + EStduio_gui_EEG_plotset.rem_DC.Enable='on'; + end + else + EEG_plotset{6}=1; + end + EStduio_gui_EEG_plotset.rem_DC.Value=EEG_plotset{6}; + %%display event? + EEG_plotset{7} =1; + EStduio_gui_EEG_plotset.disp_event.Value = 1; + %%Stack? + EEG_plotset{8}=0; + EStduio_gui_EEG_plotset.disp_stack.Value = 0; + %%Norm? + EEG_plotset{9}=0; + EStduio_gui_EEG_plotset.disp_norm.Value = 0; + %%channel order + EEG_plotset{10} =1; + EStduio_gui_EEG_plotset.chanorder_number.Value=1; + EStduio_gui_EEG_plotset.chanorder_front.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom.Value=0; + EStduio_gui_EEG_plotset.chanorder_custom_exp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder_custom_imp.Enable = 'off'; + EStduio_gui_EEG_plotset.chanorder{1,1} = []; + EStduio_gui_EEG_plotset.chanorder{1,2} = ''; + estudioworkingmemory('EEG_plotset',EEG_plotset); + observe_EEGDAT.Reset_eeg_paras_panel=4; + end +end + + +function IA = f_chanlabel_check(Checklabel,allabels) +IA = 0; +for ii = 1:length(allabels) + if strcmpi(strtrim(Checklabel),strtrim(allabels{ii})) + IA = ii; + break; + end +end +end + +%%--------------------------check the labels------------------------------- +function [Simplabels,simplabelIndex,SamAll] = Simplelabels(labels) +labelsrm = ['[']; +for ii=1:1000 + labelsrm = char([labelsrm,',',num2str(ii)]); +end +labelsrm = char([labelsrm,',z,Z]']); + +SamAll = 0; +for ii = 1:length(labels) + labelcell = labels{ii}; + labelcell(regexp(labelcell,labelsrm))=[]; + labelsNew{ii} = labelcell; +end + +%%get the simple +[~,X,Z] = unique(labelsNew,'stable'); +Simplabels = labelsNew(X); +if length(Simplabels)==1 + SamAll = 1; +end + +simplabelIndex = zeros(1,length(labels)); +count = 0; +for jj = 1:length(Simplabels) + for kk = 1:length(labelsNew) + if strcmp(Simplabels{jj},labelsNew{kk}) + count = count+1; + simplabelIndex(kk) = jj; + end + end +end +end + + +%%-----------------check if the channel location is empty------------------ +function SetFlags = check_chanlocs(ALLEEG) +SetFlags = zeros(length(ALLEEG),1); + +for Numofset = 1:length(ALLEEG) + EEG = ALLEEG(Numofset); + try + if ~isempty(EEG.chanlocs) + for Numofchan = 1:EEG.nbchan + if ~isempty(EEG.chanlocs(Numofchan).X) + SetFlags(Numofset)=1; + end + end + end + %%10-10 system? + [eloc, labels, theta, radius, indices] = readlocs(EEG.chanlocs); + [Simplabels,simplabelIndex,SamAll] = Simplelabels(labels); + count = 0; + for ii = 1:length(Simplabels) + [xpos,ypos]= find(simplabelIndex==ii); + if ~isempty(ypos) && numel(ypos)>= floor(length(EEG.chanlocs)/2) + count = count+1; + if count==1 + SetFlags(Numofset)=0; + break; + end + end + end + catch + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_conus_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_conus_GUI.m new file mode 100644 index 00000000..2bee1747 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_conus_GUI.m @@ -0,0 +1,1952 @@ +%%This function is to detect artifacts for continuous EEG. + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 + + +function varargout = f_EEG_arf_det_conus_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + + +%---------------------------Initialize parameters------------------------------------ +Eegtab_EEG_art_det_conus = struct(); +%-----------------------------Name the title---------------------------------------------- + +% global Eegtab_box_art_det_conus; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_art_det_conus = uiextras.BoxPanel('Parent', fig, 'Title', 'Reject Artifactual Time Segments (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_art_det_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Reject Artifactual Time Segments (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_art_det_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Reject Artifactual Time Segments (Continuous EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @art_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_art_det_conus_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_art_det_conus; + + function drawui_art_det_conus_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + Eegtab_EEG_art_det_conus.DataSelBox = uiextras.VBox('Parent', Eegtab_box_art_det_conus,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + %%Manua rejection + Eegtab_EEG_art_det_conus.manuar_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.manuar_checkbox = uicontrol('Style','checkbox','Parent', Eegtab_EEG_art_det_conus.manuar_title,'Value',0,... + 'String','Manual rejection','callback',@manuar_checkbox,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.manuar_button = uicontrol('Style','pushbutton','Parent', Eegtab_EEG_art_det_conus.manuar_title,... + 'String','View & Reject','callback',@manuar_button,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set( Eegtab_EEG_art_det_conus.manuar_title ,'Sizes',[120 -1]); + Eegtab_EEG_art_det_conus.manuar_checkbox_Value = 0; + %%channels that detect artifact + Eegtab_EEG_art_det_conus.chan_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.chan_title,... + 'String','Chans:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.chan_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.chan_title,... + 'String','','FontSize',FontSize_defualt,'callback',@chan_edit,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_conus.chan_edit.KeyPressFcn= @eeg_artdetect_presskey; + Eegtab_EEG_art_det_conus.chan_browse = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_art_det_conus.chan_title,... + 'String','Browse','FontSize',FontSize_defualt,'callback',@chan_browse,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + set( Eegtab_EEG_art_det_conus.chan_title,'Sizes',[60 -1 80]); + + + %%Voltage limits + Eegtab_EEG_art_det_conus.voltage_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.voltage_text = uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.voltage_title,... + 'String',[32,'Voltage threshold',32,32,32,32,'(1 or 2 values)'],'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.voltage_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.voltage_title,... + 'callback',@voltage_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_conus.voltage_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_conus.voltage_title,'Sizes',[120,-1]); + + + %%moving window full width + Eegtab_EEG_art_det_conus.movewindow_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.movewindow_text = uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.movewindow_title,... + 'String','Moving window width [ms]','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.movewindow_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.movewindow_title,... + 'callback',@movewindow_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_conus.movewindow_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_conus.movewindow_title,'Sizes',[120,-1]); + + %%Window steps + Eegtab_EEG_art_det_conus.windowstep_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.windowstep_text = uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.windowstep_title,... + 'String','Window step [ms]','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.windowstep_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.windowstep_title,... + 'callback',@windowstep_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_conus.windowstep_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_conus.windowstep_title,'Sizes',[120,-1]); + + %%optional + Eegtab_EEG_art_det_conus.option_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.option_title ,'FontWeight','bold',... + 'String','Optional:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + %%prefilter + Eegtab_EEG_art_det_conus.filter_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.filter_checkbox = uicontrol('Style','checkbox','Parent', Eegtab_EEG_art_det_conus.filter_title,'Value',0,'Enable','off',... + 'callback',@filter_checkbox,'String','Pre-filtering (only for identifying artifacts)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.filter_title2 = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', Eegtab_EEG_art_det_conus.filter_title2,... + 'String','Fre. cutoff (Hz): Low','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.lowfre_edit = uicontrol('Style','edit','Parent', Eegtab_EEG_art_det_conus.filter_title2,'Enable','off',... + 'callback',@lowfre_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',[1 1 1]); % 2F + uicontrol('Style','text','Parent', Eegtab_EEG_art_det_conus.filter_title2,... + 'String',', High','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.highfre_edit = uicontrol('Style','edit','Parent', Eegtab_EEG_art_det_conus.filter_title2,'Enable','off',... + 'callback',@highfre_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',[1 1 1]); % 2F + set(Eegtab_EEG_art_det_conus.filter_title2,'Sizes',[120,60,40,60]); + %%include or exclude + Eegtab_EEG_art_det_conus.filter_title3 = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_conus.filter_title3); + Eegtab_EEG_art_det_conus.include_fre = uicontrol('Style','radiobutton','Parent', Eegtab_EEG_art_det_conus.filter_title3,'Value',1,'Enable','off',... + 'callback',@include_fre,'String','Include this band','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_conus.exclude_fre = uicontrol('Style','radiobutton','Parent', Eegtab_EEG_art_det_conus.filter_title3,'Value',0,'Enable','off',... + 'callback',@exclude_fre,'String','Exclude this band','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + set( Eegtab_EEG_art_det_conus.filter_title3 ,'Sizes',[20,-1,-1]); + + %%join artifactual segments separated by less than + Eegtab_EEG_art_det_conus.joinarseg_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.joinarseg_checkbox = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_conus.joinarseg_title,'Value',0,'Enable','off',... + 'callback',@joinarseg_checkbox,'String','Join artifactual segments separated by less than','FontSize',FontSize_defualt-1,'BackgroundColor',ColorB_def); % 2F + + Eegtab_EEG_art_det_conus.joinarseg_title1 = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_conus.joinarseg_title1 ); + Eegtab_EEG_art_det_conus.joinarseg_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.joinarseg_title1,'Enable','off',... + 'callback',@joinarseg_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1]); % 2F + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.joinarseg_title1 ,... + 'String','ms','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); + set( Eegtab_EEG_art_det_conus.joinarseg_title1,'Sizes',[20,-1,40]); + + %%Unmark artifactual segments shorter than + Eegtab_EEG_art_det_conus.unmarkarseg_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox = uicontrol('Style','checkbox','Parent', Eegtab_EEG_art_det_conus.unmarkarseg_title,'Value',0,'Enable','off' ,... + 'callback',@unmarkarseg_checkbox,'String','Unmark artifactual segments shorter than','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + + Eegtab_EEG_art_det_conus.unmarkarseg_title1 = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_conus.unmarkarseg_title1 ); + Eegtab_EEG_art_det_conus.unmarkarseg_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.unmarkarseg_title1,'Enable','off' ,... + 'callback',@unmarkarseg_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1]); % 2F + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.unmarkarseg_title1 ,... + 'String','ms','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_det_conus.unmarkarseg_title1,'Sizes',[20,-1,40]); + + + %%Add extra time to negining and end of regions + Eegtab_EEG_art_det_conus.addtime_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.addtime_checkbox = uicontrol('Style','checkbox','Parent', Eegtab_EEG_art_det_conus.addtime_title,'Value',0,'Enable','off' ,... + 'callback',@addtime_checkbox,'String','Add extra time to start and end of regions','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + + Eegtab_EEG_art_det_conus.addtime_title1 = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_conus.addtime_title1 ); + Eegtab_EEG_art_det_conus.addtime_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_conus.addtime_title1,'Enable','off',... + 'callback',@addtime_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1]); % 2F + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_conus.addtime_title1 ,... + 'String','ms','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_det_conus.addtime_title1,'Sizes',[20,-1,40]); + + + %%-----------------------Cancel and Run---------------------------- + Eegtab_EEG_art_det_conus.detar_run_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_conus.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_conus.detectar_cancel = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_det_conus.detar_run_title,... + 'String','Cancel','callback',@detectar_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + Eegtab_EEG_art_det_conus.detectar_preview = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_det_conus.detar_run_title,... + 'String','Preview','callback',@detectar_preview,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + Eegtab_EEG_art_det_conus.detectar_run = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_art_det_conus.detar_run_title,... + 'String','Finalize','callback',@detectar_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set(Eegtab_EEG_art_det_conus.DataSelBox,'Sizes',[30 30 35 35 35 20 20 30 20 20 30 20 30 20 30 30]); + estudioworkingmemory('EEGTab_detect_arts_conus',0); + + + %%set the default parameters + prompt = {'Threshold (1 or 2 values)', 'Moving Windows Width (ms)',... + 'Window Step (ms)','Channel(s)', 'Frequency cutoffs (Hz)', 'lowest freq', 'highest freq'}; + dlg_title = 'Input threshold'; + def = {500 500 250 [] [] [] [] 0 0 0 0}; + + colorseg = [1.0000 0.9765 0.5294]; % default + memoryCARTGUI.prompt = prompt; + memoryCARTGUI.dlg_title = dlg_title; + memoryCARTGUI.def=def; + memoryCARTGUI.defx=[]; + memoryCARTGUI.colorseg=colorseg; + estudioworkingmemory('continuousartifactGUI',memoryCARTGUI); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------------------checkbox for manual rejection---------------------- + function manuar_checkbox(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials >1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + + + if Eegtab_EEG_art_det_conus.manuar_checkbox.Value==0 + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'off'; + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'on'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'on'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + end + + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + end + + else + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'on'; + end + end + +%%----------------------botton for manual rejection------------------------ + function manuar_button(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials >1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Reject Artifactual Time Segments (Continuous EEG) > View & reject'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + estudioworkingmemory('f_EEG_proces_messg','The main ERPLAB Studio window will be fronzen when you are using "Reject Artifactual Time Segments (Continuous EEG) > View & reject" tool. Please click "Reject"'); + observe_EEGDAT.eeg_panel_message =1; + + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_conus',0); + + OutputViewereegpar = f_preparms_eegwaviewer(observe_EEGDAT.EEG,0); + try EEGdisp = OutputViewereegpar{3}; catch EEGdisp=1; end + if EEGdisp==0 + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > View & reject: "Display chans" should be active in the "Plot Settings panel" ']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + estudioworkingmemory('EEGUpdate',1); + observe_EEGDAT.count_current_eeg=1; + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Artifact Detection (Continuous EEG) > View & reject*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + [EEG, LASTCOM] = f_ploteeg(EEG); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg=1; + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf([LASTCOM,'\n']); + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_manreject'); + if isempty(Answer) + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=1; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + EEGArray = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',EEGArray); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + + + + +%%----------------------edit chans----------------------------------------- + function chan_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + ChaNum = observe_EEGDAT.EEG.nbchan; + ChanArray = str2num(Source.String); + if isempty(ChanArray) || any(ChanArray(:)<=0) + msgboxText = 'Reject Artifactual Time Segments (Continuous EEG) > Index(es) of chans should be positive number(s)'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + ChanArray = vect2colon(ChanArray,'Sort','on'); + ChanArray = erase(ChanArray,{'[',']'}); + Source.String= ChanArray; + return; + end + + if any(ChanArray(:)> ChaNum) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Index(es) of chans should be between 1 and ',32,num2str(ChaNum)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + ChanArray = vect2colon(ChanArray,'Sort','on'); + ChanArray = erase(ChanArray,{'[',']'}); + Source.String= ChanArray; + return; + end + end + +%%----------------------------Browse chans--------------------------------- + function chan_browse(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + + %%-------Browse and select chans that will be interpolated--------- + EEG = observe_EEGDAT.EEG; + for Numofchan = 1:EEG.nbchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',EEG.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + ChanArray = str2num(Eegtab_EEG_art_det_conus.chan_edit.String); + if isempty(ChanArray) + indxlistb = EEG.nbchan; + else + if min(ChanArray(:)) >0 && max(ChanArray(:)) <= EEG.nbchan + indxlistb = ChanArray; + else + indxlistb = 1:EEG.nbchan; + end + end + titlename = 'Select Channel(s):'; + + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + chan_label_select = vect2colon(chan_label_select,'Sort','on'); + chan_label_select = erase(chan_label_select,{'[',']'}); + Eegtab_EEG_art_det_conus.chan_edit.String = chan_label_select; + else + return + end + end + +%%-----------------------------volatge------------------------------------- + function voltage_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + Voltagevalue= str2num(Source.String); + if isempty(Voltagevalue) || (numel(Voltagevalue)~=1 && numel(Voltagevalue)~=2) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Voltage threshold must have one or two values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = '500'; + return; + end + if numel(Voltagevalue)==2 + if Voltagevalue(2) >= Voltagevalue(1) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Voltage threshold: When 2 thresholds are specified, the first one must be lesser than the second one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = '500'; + return; + end + end + end + + +%%------------------------moving window------------------------------------ + function movewindow_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + windowlength= str2num(Source.String); + if isempty(windowlength) || numel(windowlength) ~=1 || any(windowlength(:)<=0) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Move window width must be a positive number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = '500'; + return; + end + + windowStep = str2num(Eegtab_EEG_art_det_conus.windowstep_edit.String); + if any(windowStep(:)>=windowlength ) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Step width cannot be larger than the window width']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + + +%%-------------------------moving step------------------------------------- + function windowstep_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + windowstep= str2num(Source.String); + if isempty(windowstep) || numel(windowstep) ~=1 || any(windowstep(:)<=0) + msgboxText= ['Reject Artifactual Time Segments (Continuous EEG) > Window step width must be a positive number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + + windowStep = str2num(Eegtab_EEG_art_det_conus.windowstep_edit.String); + windowlength = str2num(Eegtab_EEG_art_det_conus.movewindow_edit.String); + if any(windowStep(:)>=windowlength) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Step width must be smaller than the window width']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%----------------------prefilter checkbox-------------------------------- + function filter_checkbox(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + enableflag = 'on'; + else + enableflag = 'off'; + end + Eegtab_EEG_art_det_conus.lowfre_edit.Enable = enableflag; + Eegtab_EEG_art_det_conus.highfre_edit.Enable = enableflag; + Eegtab_EEG_art_det_conus.include_fre.Enable = enableflag; + Eegtab_EEG_art_det_conus.exclude_fre.Enable = enableflag; + end + +%%--------------------------------lowest filter---------------------------- + function lowfre_edit(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + + lowfre_edit = str2num(Eegtab_EEG_art_det_conus.lowfre_edit.String); + if isempty(lowfre_edit) || numel(lowfre_edit)~=1 || any(lowfre_edit(:)<0) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: The lowest frequency should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + highfre_edit = str2num(Eegtab_EEG_art_det_conus.highfre_edit.String); + + if any(lowfre_edit(:)>=highfre_edit(:)) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: The lowest frequency should be smaller than the highest one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if any(lowfre_edit(:)>=observe_EEGDAT.EEG.srate/2) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: The lowest frequency should be smaller than',32,num2str(roundn(observe_EEGDAT.EEG.srate/2,-2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%---------------------------Highest frequency----------------------------- + function highfre_edit(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + + highfre_edit = str2num(Eegtab_EEG_art_det_conus.highfre_edit.String); + + lowfre_edit = str2num(Eegtab_EEG_art_det_conus.lowfre_edit.String); + if isempty(highfre_edit) || numel(highfre_edit)~=1 || any(highfre_edit(:)<0) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: The highest frequency should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if any(lowfre_edit(:)>=highfre_edit(:)) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: The highest frequency should be larger than the lowest one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if any(highfre_edit(:)>=observe_EEGDAT.EEG.srate/2) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: The highest frequency should be smaller than',32,num2str(roundn(observe_EEGDAT.EEG.srate/2,-2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%------------------------include this frequency band---------------------- + function include_fre(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + Eegtab_EEG_art_det_conus.include_fre.Value=1; + Eegtab_EEG_art_det_conus.exclude_fre.Value=0; + end + +%%-----------------exclude this frequency---------------------------------- + function exclude_fre(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + Eegtab_EEG_art_det_conus.include_fre.Value=0; + Eegtab_EEG_art_det_conus.exclude_fre.Value=1; + end + +%%-------------Join artifactual segments separated by less than------------ + function joinarseg_checkbox(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value ==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable = 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable = 'off'; + end + end + +%%------------------edit join------------------- + function joinarseg_edit(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + joinarseg_edit = str2num(Eegtab_EEG_art_det_conus.joinarseg_edit.String); + if isempty(joinarseg_edit) || numel(joinarseg_edit)~=1 || any(joinarseg_edit(:)<=0) + Eegtab_EEG_art_det_conus.joinarseg_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: Invalid input for segements separation and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + +%%----------------unmark artifactual segments shorter than----------------- + function unmarkarseg_checkbox(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable = 'on'; + else + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable = 'off'; + end + end +%%----------------edit for unmark artifactual segments shorter than-------- + function unmarkarseg_edit(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + unmarkarseg_edit = str2num(Eegtab_EEG_art_det_conus.unmarkarseg_edit.String); + if isempty(unmarkarseg_edit) || numel(unmarkarseg_edit)~=1 || any(unmarkarseg_edit(:)<=0) + Eegtab_EEG_art_det_conus.unmarkarseg_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: Invalid input for unmark artifactual segments and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + +%%-----------------------------add extra time------------------------------ + function addtime_checkbox(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + Eegtab_EEG_art_det_conus.addtime_edit.Enable = 'on'; + else + Eegtab_EEG_art_det_conus.addtime_edit.Enable = 'off'; + end + end + +%%------------edit for adding extra time----------------------------------- + function addtime_edit(~,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_conus.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_conus',1); + addtime_edit = str2num( Eegtab_EEG_art_det_conus.addtime_edit.String); + if isempty(addtime_edit) || numel(addtime_edit)~=1 || any(addtime_edit(:)<=0) + Eegtab_EEG_art_det_conus.addtime_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Optional: Invalid input for "add extra time" and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + +%%--------------------------advanced options------------------------------- + function detectar_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + return; + end + estudioworkingmemory('f_EEG_proces_messg','Reject Artifactual Time Segments (Continuous EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_conus',0); + memoryCARTGUI = estudioworkingmemory('continuousartifactGUI'); + + try Volthreshold = memoryCARTGUI.def{1};catch Volthreshold = 500;end + Eegtab_EEG_art_det_conus.voltage_edit.String = num2str(Volthreshold); + + try WindowLength = memoryCARTGUI.def{2};catch WindowLength=500;end + Eegtab_EEG_art_det_conus.movewindow_edit.String = num2str(WindowLength); + try windowStep = memoryCARTGUI.def{3};catch windowStep = 250; end + Eegtab_EEG_art_det_conus.windowstep_edit.String = num2str(windowStep); + try ChanArray = memoryCARTGUI.def{4};catch ChanArray= [1:observe_EEGDAT.EEG.nbchan];end + if isempty(ChanArray) || any(ChanArray(:)<=0) || any(ChanArray(:)>observe_EEGDAT.EEG.nbchan) + ChanArray= [1:observe_EEGDAT.EEG.nbchan]; + end + ChanArraystr = vect2colon(ChanArray,'Sort','on'); + ChanArraystr = erase(ChanArraystr,{'[',']'}); + Eegtab_EEG_art_det_conus.chan_edit.String = ChanArraystr; + + try includef = memoryCARTGUI.def{7};catch includef=[];end + + if isempty(includef) + Eegtab_EEG_art_det_conus.filter_checkbox.Value =0; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable = 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable = 'off'; + Eegtab_EEG_art_det_conus.include_fre.Value = 1; + Eegtab_EEG_art_det_conus.exclude_fre.Enable = 'off'; + else + if numel(includef)~=1 || (includef~=0 && includef~=1) + includef = 1; + end + Eegtab_EEG_art_det_conus.include_fre.Value = includef; + Eegtab_EEG_art_det_conus.exclude_fre.Value = ~includef; + Eegtab_EEG_art_det_conus.filter_checkbox.Value =1; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable = 'on'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable = 'on'; + Eegtab_EEG_art_det_conus.include_fre.Enable = 'on'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable = 'on'; + end + try lowfre_edit= memoryCARTGUI.def{5} ; catch lowfre_edit =[]; end + try highfre_edit= memoryCARTGUI.def{6} ; catch highfre_edit =[]; end + + if numel(lowfre_edit)~=1 || any(lowfre_edit<=0) || any(lowfre_edit>=highfre_edit) || any(lowfre_edit(:)>observe_EEGDAT.EEG.srate/2) + lowfre_edit =[]; + end + Eegtab_EEG_art_det_conus.lowfre_edit.String = num2str(lowfre_edit); + + if numel(highfre_edit)~=1|| any(highfre_edit<=0) || any(lowfre_edit>=highfre_edit) || any(highfre_edit(:)>observe_EEGDAT.EEG.srate/2) + highfre_edit =[]; + end + Eegtab_EEG_art_det_conus.highfre_edit.String = num2str(highfre_edit); + + try shortisi = memoryCARTGUI.def{9} ;catch shortisi = [];end + + if numel(shortisi)~=1 || any(shortisi(:)<=0) + shortisi = []; + end + if ~isempty(shortisi) + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value = 1; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable = 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value = 0; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable = 'off'; + end + Eegtab_EEG_art_det_conus.joinarseg_edit.String = num2str(shortisi); + + try shortseg = memoryCARTGUI.def{10};catch shortseg = [];end + + if numel(shortseg)~=1 || any(shortseg(:)<=0) + shortseg = []; + end + if isempty(shortseg) + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value = 0; + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable = 'off'; + else + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value = 1; + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable = 'on'; + end + Eegtab_EEG_art_det_conus.unmarkarseg_edit.String = num2str(shortseg); + + try winoffset = memoryCARTGUI.def{11} ; catch winoffset = []; end + if numel(winoffset)~=1 || any(winoffset(:)<=0) + winoffset = []; + end + + if isempty(winoffset); + Eegtab_EEG_art_det_conus.addtime_checkbox.Value = 0; + Eegtab_EEG_art_det_conus.addtime_edit.Enable = 'off'; + else + Eegtab_EEG_art_det_conus.addtime_checkbox.Value = 1; + Eegtab_EEG_art_det_conus.addtime_edit.Enable = 'on'; + end + Eegtab_EEG_art_det_conus.addtime_edit.String = num2str(winoffset); + memoryCARTGUI.def{1} = Volthreshold; + memoryCARTGUI.def{2} = WindowLength; + memoryCARTGUI.def{3} = windowStep; + memoryCARTGUI.def{4} = ChanArray; + memoryCARTGUI.def{5} = lowfre_edit; + memoryCARTGUI.def{6} = highfre_edit; + memoryCARTGUI.def{7} = includef; + memoryCARTGUI.def{9} = shortisi; + memoryCARTGUI.def{10} = shortseg; + memoryCARTGUI.def{11} = winoffset; + estudioworkingmemory('continuousartifactGUI',memoryCARTGUI); + + try Eegtab_EEG_art_det_conus.manuar_checkbox.Value= Eegtab_EEG_art_det_conus.manuar_checkbox_Value;catch Eegtab_EEG_art_det_conus.manuar_checkbox.Value=0;end + if Eegtab_EEG_art_det_conus.manuar_checkbox.Value==0 + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'off'; + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'on'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'on'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + end + + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + end + else + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'on'; + end + + + estudioworkingmemory('f_EEG_proces_messg','Reject Artifactual Time Segments (Continuous EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + +%%%----------------------Preview------------------------------------ + function detectar_preview(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Reject Artifactual Time Segments (Continuous EEG) > Preview'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if numel(EEGArray)~=1 + msgboxText= 'Reject Artifactual Time Segments (Continuous EEG) > Preview: Only work for single EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = 'Only for single EEG'; + Source.Enable = 'off'; + return; + end + + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_conus',0); + + %%chans + ChanArray = str2num(Eegtab_EEG_art_det_conus.chan_edit.String); + nbchan = observe_EEGDAT.EEG.nbchan; + if isempty(ChanArray) || any(ChanArray(:) <=0) || any(ChanArray(:) > nbchan) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview: Chans are empty or index(es) are not between 1 and',32,num2str(nbchan)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + %%----------if simple voltage threshold------------ + Volthreshold = sort(str2num(Eegtab_EEG_art_det_conus.voltage_edit.String)); + if isempty(Volthreshold) || (numel(Volthreshold)~=1 && numel(Volthreshold)~=2) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview: Voltage threshold must have one or two values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if numel(Volthreshold)==2 + if Volthreshold(2) >= Volthreshold(1) + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview: When 2 thresholds are specified, the first one must be lesser than the second one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + + % + %%Moving window full width + WindowLength = str2num(Eegtab_EEG_art_det_conus.movewindow_edit.String); + if isempty(WindowLength) || numel(WindowLength) ~=1 || any(WindowLength(:)<=0) + msgboxText= ['Reject Artifactual Time Segments (Continuous EEG) > Preview: Move window width must be a positive number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.movewindow_edit.String = '500'; + return; + end + + windowStep = str2num(Eegtab_EEG_art_det_conus.windowstep_edit.String); + if any(windowStep(:)>=WindowLength) + msgboxText= ['Reject Artifactual Time Segments (Continuous EEG) > Preview: Step width cannot be larger than the window width']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.windowstep_edit.String = ''; + return; + end + + if isempty(windowStep) || numel(windowStep) ~=1 || any(windowStep(:)<=0) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Preview: Window step width must be a positive number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.windowstep_edit.String = ''; + return; + end + %%WindowStep + if any(windowStep(:)>=WindowLength) + msgboxText= ['Reject Artifactual Time Segments (Continuous EEG) > Preview: Step width must be smaller than the window width']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.windowstep_edit.String = ''; + return; + end + + + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==0 + fcutoff = []; + includef =[]; + lowfre_edit = []; + highfre_edit = []; + end + + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + lowfre_edit = str2num(Eegtab_EEG_art_det_conus.lowfre_edit.String); + if isempty(lowfre_edit) || numel(lowfre_edit)~=1 || any(lowfre_edit(:)<0) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview >Optional: The lowest frequency should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + highfre_edit = str2num(Eegtab_EEG_art_det_conus.highfre_edit.String); + + if any(lowfre_edit(:)>=observe_EEGDAT.EEG.srate/2) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: The lowest frequency should be smaller than',32,num2str(roundn(observe_EEGDAT.EEG.srate/2,-2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if isempty(highfre_edit) || numel(highfre_edit)~=1 || any(highfre_edit(:)<0) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: The highest frequency should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if any(lowfre_edit(:)>=highfre_edit(:)) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: The highest frequency should be larger than the lowest one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if any(highfre_edit(:)>=observe_EEGDAT.EEG.srate/2) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: The highest frequency should be smaller than',32,num2str(roundn(observe_EEGDAT.EEG.srate/2,-2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + includef=Eegtab_EEG_art_det_conus.include_fre.Value; + fcutoff = [lowfre_edit,highfre_edit]; + if includef==0 && fcutoff(1)~=fcutoff(2)% when it means "excluded" frequency cuttof is inverse to make a notch filter + fcutoff = circshift(fcutoff',1)'; + elseif includef==1 && fcutoff(1)==0 && fcutoff(2)==0 + fcutoff = [inf inf]; % [inf inf] to include the mean of data; fcutoff = [0 0] means exclude the mean + else + % fcutoff = []; + end + end + + %%Joint artifactual segments separated by less than + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==0 + shortisi = []; + end + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==1 + shortisi = str2num(Eegtab_EEG_art_det_conus.joinarseg_edit.String); + if isempty(shortisi) || numel(shortisi)~=1 || any(shortisi(:)<=0) + Eegtab_EEG_art_det_conus.joinarseg_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: Invalid input for segements separation and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + %%unmark + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==0 + shortseg = []; + end + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + shortseg = str2num(Eegtab_EEG_art_det_conus.unmarkarseg_edit.String); + if isempty(shortseg) || numel(shortseg)~=1 || any(shortseg(:)<=0) + Eegtab_EEG_art_det_conus.unmarkarseg_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: Invalid input for unmark artifactual segments and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + %%add extra time + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==0 + winoffset=[]; + end + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + winoffset = str2num( Eegtab_EEG_art_det_conus.addtime_edit.String); + if isempty(winoffset) || numel(winoffset)~=1 || any(winoffset(:)<=0) + Eegtab_EEG_art_det_conus.addtime_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Preview > Optional: Invalid input for "add extra time" and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + memoryCARTGUI = estudioworkingmemory('continuousartifactGUI'); + colorseg = [ 0.83 0.82 0.79]; + memoryCARTGUI.def{1} = Volthreshold; + memoryCARTGUI.def{2} = WindowLength; + memoryCARTGUI.def{3} = windowStep; + memoryCARTGUI.def{4} = ChanArray; + memoryCARTGUI.def{5} = lowfre_edit; + memoryCARTGUI.def{6} = highfre_edit; + memoryCARTGUI.def{7} = includef; + memoryCARTGUI.def{9} = shortisi; + memoryCARTGUI.def{10} = shortseg; + memoryCARTGUI.def{11} = winoffset; + estudioworkingmemory('continuousartifactGUI',memoryCARTGUI); + fdet = 'off'; + forder =100; + try + EEG = observe_EEGDAT.ALLEEG(EEGArray); + catch + EEG = observe_EEGDAT.EEG; + end + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Reject Artifactual Time Segments (Continuous EEG) > Preview*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray),'):',32,EEG.setname,'\n\n']); + + + [EEG,LASTCOM]= pop_continuousartdet(EEG, 'chanArray' , ChanArray ... + , 'ampth' , Volthreshold ... + , 'winms' , WindowLength ... + , 'stepms' , windowStep ... + , 'firstdet' , fdet ... + , 'fcutoff' , fcutoff ...%% + , 'forder' , forder ...%%fixed + , 'shortisi' , shortisi ...%%join + , 'shortseg' , shortseg ...%%unmark + , 'winoffset' , winoffset ...%%add extra + , 'colorseg' , colorseg ... + ,'review','on','History','implicit'); + + if isempty(LASTCOM) + else + fprintf([LASTCOM,'\n']); + end + eegh(LASTCOM); + fprintf( [repmat('-',1,100) '\n']); + estudioworkingmemory('f_EEG_proces_messg','Reject Artifactual Time Segments (Continuous EEG) > Preview'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + + +%%-----------------------Finalize------------------------------------------ + function detectar_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Reject Artifactual Time Segments (Continuous EEG) > Finalize'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_conus',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + %%chans + ChanArray = str2num(Eegtab_EEG_art_det_conus.chan_edit.String); + nbchan = observe_EEGDAT.EEG.nbchan; + if isempty(ChanArray) || any(ChanArray(:) <=0) || any(ChanArray(:) > nbchan) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Finalize: Chans are empty or index(es) are not between 1 and',32,num2str(nbchan)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + %%----------if simple voltage threshold------------ + Volthreshold = sort(str2num(Eegtab_EEG_art_det_conus.voltage_edit.String)); + if isempty(Volthreshold) || (numel(Volthreshold)~=1 && numel(Volthreshold)~=2) + msgboxText= ['Reject Artifactual Time Segments (Continuous EEG) > Finalize: Voltage threshold must have one or two values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if numel(Volthreshold)==2 + if Volthreshold(2) >= Volthreshold(1) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Finalize: When 2 thresholds are specified, the first one must be lesser than the second one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + + % + %%Moving window full width + WindowLength = str2num(Eegtab_EEG_art_det_conus.movewindow_edit.String); + if isempty(WindowLength) || numel(WindowLength) ~=1 || any(WindowLength(:)<=0) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Finalize: Move window width must be a positive number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.movewindow_edit.String = '500'; + observe_EEGDAT.eeg_panel_message =2; + return; + end + + windowStep = str2num(Eegtab_EEG_art_det_conus.windowstep_edit.String); + if any(windowStep(:)>=WindowLength) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Finalize: Step width cannot be larger than the window width']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.windowstep_edit.String = ''; + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if isempty(windowStep) || numel(windowStep) ~=1 || any(windowStep(:)<=0) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Finalize: Window step width must be a positive number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.windowstep_edit.String = ''; + observe_EEGDAT.eeg_panel_message =2; + return; + end + %%WindowStep + if any(windowStep(:)>=WindowLength) + msgboxText=['Reject Artifactual Time Segments (Continuous EEG) > Finalize: Step width must be smaller than the window width']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Eegtab_EEG_art_det_conus.windowstep_edit.String = ''; + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==0 + fcutoff = []; + lowfre_edit = []; + highfre_edit = []; + includef = []; + end + + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + lowfre_edit = str2num(Eegtab_EEG_art_det_conus.lowfre_edit.String); + if isempty(lowfre_edit) || numel(lowfre_edit)~=1 || any(lowfre_edit(:)<0) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize >Optional: The lowest frequency should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + highfre_edit = str2num(Eegtab_EEG_art_det_conus.highfre_edit.String); + if any(lowfre_edit(:)>=highfre_edit(:)) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize> Optional: The lowest frequency should be smaller than the highest one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if any(lowfre_edit(:)>=observe_EEGDAT.EEG.srate/2) + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize > Optional: The lowest frequency should be smaller than',32,num2str(roundn(observe_EEGDAT.EEG.srate/2,-2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if isempty(highfre_edit) || numel(highfre_edit)~=1 || any(highfre_edit(:)<0) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize > Optional: The highest frequency should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if any(highfre_edit(:)>=observe_EEGDAT.EEG.srate/2) + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize > Optional: The highest frequency should be smaller than',32,num2str(roundn(observe_EEGDAT.EEG.srate/2,-2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + includef=Eegtab_EEG_art_det_conus.include_fre.Value; + fcutoff = [lowfre_edit,highfre_edit]; + if includef==0 && fcutoff(1)~=fcutoff(2)% when it means "excluded" frequency cuttof is inverse to make a notch filter + fcutoff = circshift(fcutoff',1)'; + elseif includef==1 && fcutoff(1)==0 && fcutoff(2)==0 + fcutoff = [inf inf]; % [inf inf] to include the mean of data; fcutoff = [0 0] means exclude the mean + else + % fcutoff = []; + end + end + + %%Joint artifactual segments separated by less than + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==0 + shortisi = []; + end + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==1 + shortisi = str2num(Eegtab_EEG_art_det_conus.joinarseg_edit.String); + if isempty(shortisi) || numel(shortisi)~=1 || any(shortisi(:)<=0) + Eegtab_EEG_art_det_conus.joinarseg_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize > Optional: Invalid input for segements separation and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + %%unmark + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==0 + shortseg = []; + end + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + shortseg = str2num(Eegtab_EEG_art_det_conus.unmarkarseg_edit.String); + if isempty(shortseg) || numel(shortseg)~=1 || any(shortseg(:)<=0) + Eegtab_EEG_art_det_conus.unmarkarseg_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize > Optional: Invalid input for unmark artifactual segments and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + %%add extra time + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==0 + winoffset=[]; + end + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + winoffset = str2num( Eegtab_EEG_art_det_conus.addtime_edit.String); + if isempty(winoffset) || numel(winoffset)~=1 || any(winoffset(:)<=0) + Eegtab_EEG_art_det_conus.addtime_edit.String = ''; + msgboxText = ['Reject Artifactual Time Segments (Continuous EEG) > Finalize > Optional: Invalid input for "add extra time" and it should be a positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + Eegtab_EEG_art_det_conus.manuar_checkbox_Value = Eegtab_EEG_art_det_conus.manuar_checkbox.Value; + + fdet = 'off'; + forder =100; + + memoryCARTGUI = estudioworkingmemory('continuousartifactGUI'); + colorseg = [ 0.83 0.82 0.79]; + memoryCARTGUI.def{1} = Volthreshold; + memoryCARTGUI.def{2} = WindowLength; + memoryCARTGUI.def{3} = windowStep; + memoryCARTGUI.def{4} = ChanArray; + memoryCARTGUI.def{5} = lowfre_edit; + memoryCARTGUI.def{6} = highfre_edit; + memoryCARTGUI.def{7} = includef; + memoryCARTGUI.def{9} = shortisi; + memoryCARTGUI.def{10} = shortseg; + memoryCARTGUI.def{11} = winoffset; + estudioworkingmemory('continuousartifactGUI',memoryCARTGUI); + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Reject Artifactual Time Segments (Continuous EEG) > Finalize*',32,32,32,32,datestr(datetime('now')),'\n']); + + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + if any(ChanArray(:) > EEG.nbchan) + ChanArray = [1:EEG.nbchan]; + fprintf(['We used all chans for the EEGset because the defined ones were invalid']); + end + + [EEG,LASTCOM]= pop_continuousartdet(EEG, 'chanArray' , ChanArray ... + , 'ampth' , Volthreshold ... + , 'winms' , WindowLength ... + , 'stepms' , windowStep ... + , 'firstdet' , fdet ... + , 'fcutoff' , fcutoff ...%% + , 'forder' , forder ...%%fixed + , 'shortisi' , shortisi ...%%join + , 'shortseg' , shortseg ...%%unmark + , 'winoffset' , winoffset ...%%add extra + , 'colorseg' , colorseg ... + ,'review','off','History','implicit'); + + + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),''); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=16 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 || EEGUpdate==1 + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.manuar_checkbox.Enable = 'off'; + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ~=1 + Eegtab_box_art_det_conus.TitleColor= [0.75 0.75 0.75]; + else + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=17; + return; + end + Eegtab_EEG_art_det_conus.manuar_checkbox.Enable = 'on'; + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'on'; + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_conus.periods_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'on'; + + EEGArray= estudioworkingmemory('EEGArray'); + if numel(EEGArray)~=1 + Eegtab_EEG_art_det_conus.detectar_preview.String = 'Only for single EEG'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable = 'off'; + else + Eegtab_EEG_art_det_conus.detectar_preview.String = 'Preview'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable = 'on'; + end + chanArray = str2num(Eegtab_EEG_art_det_conus.chan_edit.String); + if isempty(chanArray) || min(chanArray(:)) > observe_EEGDAT.EEG.nbchan || max(chanArray(:)) > observe_EEGDAT.EEG.nbchan + Eegtab_EEG_art_det_conus.chan_edit.String = vect2colon([1:observe_EEGDAT.EEG.nbchan]); + end + %%set default parameters + if isempty(str2num(Eegtab_EEG_art_det_conus.voltage_edit.String)) + Eegtab_EEG_art_det_conus.voltage_edit.String = '500'; + end + if isempty(str2num(Eegtab_EEG_art_det_conus.movewindow_edit.String)) + Eegtab_EEG_art_det_conus.movewindow_edit.String = '500'; + end + if isempty(str2num(Eegtab_EEG_art_det_conus.windowstep_edit.String)) + Eegtab_EEG_art_det_conus.windowstep_edit.String = '250'; + end + + %%optionals + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + enableflag = 'on'; + else + enableflag = 'off'; + end + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= enableflag; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= enableflag; + Eegtab_EEG_art_det_conus.include_fre.Enable= enableflag; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= enableflag; + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable= 'off'; + end + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + end + + if Eegtab_EEG_art_det_conus.manuar_checkbox.Value==0 + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'off'; + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'on'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.filter_checkbox.Value==1 + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'on'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'on'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + end + + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value==1 + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + end + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_conus.addtime_checkbox.Value==1 + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'on'; + else + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + end + else + Eegtab_EEG_art_det_conus.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_conus.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.windowstep_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_conus.detectar_preview.Enable= 'off'; + Eegtab_EEG_art_det_conus.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_conus.filter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.include_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_conus.addtime_edit.Enable= 'off'; + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'on'; + end + Eegtab_EEG_art_det_conus.manuar_checkbox_Value = Eegtab_EEG_art_det_conus.manuar_checkbox.Value; + observe_EEGDAT.count_current_eeg=17; + end + + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_artdetect_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_detect_arts_conus'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + detectar_run(); + estudioworkingmemory('EEGTab_detect_arts_conus',0); + Eegtab_box_art_det_conus.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=13 + return; + end + estudioworkingmemory('EEGTab_detect_arts_conus',0); + Eegtab_EEG_art_det_conus.detectar_preview.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_preview.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_conus.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_conus.detectar_cancel.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_conus.detectar_cancel.ForegroundColor = [0 0 0]; + if isempty(observe_EEGDAT.EEG) + Eegtab_EEG_art_det_conus.chan_edit.String = ''; + else + Eegtab_EEG_art_det_conus.chan_edit.String = vect2colon([1:observe_EEGDAT.EEG.nbchan]); + end + Eegtab_EEG_art_det_conus.voltage_edit.String = '500'; + Eegtab_EEG_art_det_conus.movewindow_edit.String = '500'; + Eegtab_EEG_art_det_conus.windowstep_edit.String = '250'; + + Eegtab_EEG_art_det_conus.manuar_checkbox.Value=0; + Eegtab_EEG_art_det_conus.manuar_checkbox.Enable = 'off'; + Eegtab_EEG_art_det_conus.manuar_button.Enable = 'off'; + Eegtab_EEG_art_det_conus.filter_checkbox.Value=0; + Eegtab_EEG_art_det_conus.lowfre_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.lowfre_edit.String = ''; + Eegtab_EEG_art_det_conus.highfre_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.highfre_edit.String = ''; + Eegtab_EEG_art_det_conus.include_fre.Enable = 'off'; + Eegtab_EEG_art_det_conus.exclude_fre.Enable = 'off'; + Eegtab_EEG_art_det_conus.joinarseg_checkbox.Value = 0; + Eegtab_EEG_art_det_conus.joinarseg_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.joinarseg_edit.String = ''; + Eegtab_EEG_art_det_conus.unmarkarseg_checkbox.Value = 0; + Eegtab_EEG_art_det_conus.unmarkarseg_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.unmarkarseg_edit.String = ''; + Eegtab_EEG_art_det_conus.addtime_checkbox.Value = 0; + Eegtab_EEG_art_det_conus.addtime_edit.Enable = 'off'; + Eegtab_EEG_art_det_conus.addtime_edit.String = ''; + Eegtab_EEG_art_det_conus.manuar_checkbox_Value = 0; + observe_EEGDAT.Reset_eeg_paras_panel=14; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_epoch_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_epoch_GUI.m new file mode 100644 index 00000000..e7f7f6a2 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_epoch_GUI.m @@ -0,0 +1,2021 @@ +%%This function is to detect artifacts for epoched EEG. + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 && Jan. 2024 + + +function varargout = f_EEG_arf_det_epoch_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ + +Eegtab_EEG_art_det_epoch = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global Eegtab_box_art_det_epoch; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_art_det_epoch = uiextras.BoxPanel('Parent', fig, 'Title', 'Artifact Detection (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_art_det_epoch = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Artifact Detection (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_art_det_epoch = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Artifact Detection (Epoched EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @artepo_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_art_det_epoch_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_art_det_epoch; + + function drawui_art_det_epoch_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + Eegtab_EEG_art_det_epoch.DataSelBox = uiextras.VBox('Parent', Eegtab_box_art_det_epoch,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + %%Manua rejection + Eegtab_EEG_art_det_epoch.manuar_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.manuar_checkbox = uicontrol('Style','checkbox','Parent', Eegtab_EEG_art_det_epoch.manuar_title,'Value',0,... + 'String','Manual detection','callback',@manuar_checkbox,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.manuar_button = uicontrol('Style','pushbutton','Parent', Eegtab_EEG_art_det_epoch.manuar_title,... + 'String','View & Mark','callback',@manuar_button,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set( Eegtab_EEG_art_det_epoch.manuar_title ,'Sizes',[120 -1]); + Eegtab_EEG_art_det_epoch.Paras{11} = Eegtab_EEG_art_det_epoch.manuar_checkbox.Value; + + + %%display original data? + Eegtab_EEG_art_det_epoch.art_det_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent',Eegtab_EEG_art_det_epoch.art_det_title,... + 'String','Algorithms:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.det_algo = uicontrol('Style', 'popupmenu','Parent',Eegtab_EEG_art_det_epoch.art_det_title,... + 'String','','callback',@det_algo,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + Eegtab_EEG_art_det_epoch.det_algo.KeyPressFcn= @eeg_artdetect_presskey; + + Det_algostr = {'Simple voltage threshold','Moving window peak-to-peak',... + 'Step-like artifacts','Sample to sample voltage',... + 'Blocking & flat line'}; + Eegtab_EEG_art_det_epoch.det_algo.String = Det_algostr; + Eegtab_EEG_art_det_epoch.det_algo.Value =1; + set(Eegtab_EEG_art_det_epoch.art_det_title, 'Sizes',[70 -1]); + Eegtab_EEG_art_det_epoch.Paras{1} = Eegtab_EEG_art_det_epoch.det_algo.Value; + %%channels that detect artifact + Eegtab_EEG_art_det_epoch.chan_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_epoch.chan_title,... + 'String','Chans:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_epoch.chan_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_epoch.chan_title,... + 'String','','FontSize',FontSize_defualt,'callback',@chan_edit,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_epoch.chan_edit.KeyPressFcn= @eeg_artdetect_presskey; + Eegtab_EEG_art_det_epoch.chan_browse = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_art_det_epoch.chan_title,... + 'String','Browse','FontSize',FontSize_defualt,'callback',@chan_browse,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + set( Eegtab_EEG_art_det_epoch.chan_title,'Sizes',[60 -1 80]); + Eegtab_EEG_art_det_epoch.Paras{2} = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + + %%Flags + Eegtab_EEG_art_det_epoch.markflgas_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',Eegtab_EEG_art_det_epoch.markflgas_title,'FontWeight','bold',... + 'String','Mark Flag (flag 1 is reserved):','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + + Eegtab_EEG_art_det_epoch.markflgas_title1 = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.mflag1 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag1,'String','1','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','off','BackgroundColor',ColorB_def,'Value',1); % 2F + Eegtab_EEG_art_det_epoch.mflag2 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag2,'String','2','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag3 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag3,'String','3','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag4 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag4,'String','4','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag5 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag5,'String','5','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag6 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag6,'String','6','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag7 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag7,'String','7','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag8 = uicontrol('Style','checkbox','Parent',Eegtab_EEG_art_det_epoch.markflgas_title1,... + 'callback',@mflag8,'String','8','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_art_det_epoch.mflag = [1,0,0,0,0,0,0,0]; + Eegtab_EEG_art_det_epoch.Paras{3} = Eegtab_EEG_art_det_epoch.mflag; + set( Eegtab_EEG_art_det_epoch.markflgas_title1,'Sizes',[33 33 33 33 33 33 33 33]); + %%test period + Eegtab_EEG_art_det_epoch.periods_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.periods_editext=uicontrol('Style','text','Parent',Eegtab_EEG_art_det_epoch.periods_title,... + 'String','Test period [ms] (start end)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_epoch.periods_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_epoch.periods_title,... + 'callback',@periods_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_epoch.periods_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_epoch.periods_title,'Sizes',[90,-1]); + Eegtab_EEG_art_det_epoch.Paras{4} = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + + %%Voltage limits + Eegtab_EEG_art_det_epoch.voltage_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.voltage_text = uicontrol('Style','text','Parent',Eegtab_EEG_art_det_epoch.voltage_title,... + 'String','Voltage limits [uV] (e.g., -100 100)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_epoch.voltage_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_epoch.voltage_title,... + 'callback',@voltage_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_epoch.voltage_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.Paras{5} = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + + %%moving window full width + Eegtab_EEG_art_det_epoch.movewindow_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.movewindow_text = uicontrol('Style','text','Parent',Eegtab_EEG_art_det_epoch.movewindow_title,... + 'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_epoch.movewindow_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_epoch.movewindow_title,... + 'callback',@movewindow_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_epoch.movewindow_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_epoch.movewindow_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.Paras{6} = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + + %%Window steps + Eegtab_EEG_art_det_epoch.windowstep_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.windowstep_text = uicontrol('Style','text','Parent',Eegtab_EEG_art_det_epoch.windowstep_title,... + 'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_art_det_epoch.windowstep_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_art_det_epoch.windowstep_title,... + 'callback',@windowstep_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_art_det_epoch.windowstep_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(Eegtab_EEG_art_det_epoch.windowstep_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.Paras{7} = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + + %%------------------------------refilter--------------------------- + Eegtab_EEG_art_det_epoch.prefilter_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.prefilter_checkbox = uicontrol('Style','checkbox','Parent', Eegtab_EEG_art_det_epoch.prefilter_title,'Value',0,... + 'String','Prefilter at','callback',@prefilter_checkbox,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_det_epoch.prefilter_edit = uicontrol('Style','edit','Parent', Eegtab_EEG_art_det_epoch.prefilter_title,... + 'String','30','callback',@prefilter_edit,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uicontrol('Style','text','Parent', Eegtab_EEG_art_det_epoch.prefilter_title,... + 'String','Hz (low-pass)','FontSize',FontSize_defualt,'Enable','on','BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_det_epoch.prefilter_title,'Sizes',[80 -1 80]); + Eegtab_EEG_art_det_epoch.Paras{9} = Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value; + Eegtab_EEG_art_det_epoch.Paras{10}= str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + + %%-----------------------Cancel and Run---------------------------- + Eegtab_EEG_art_det_epoch.detar_run_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_epoch.detar_run_title); + Eegtab_EEG_art_det_epoch.detectar_cancel = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_det_epoch.detar_run_title,... + 'String','Cancel','callback',@detectar_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_art_det_epoch.detar_run_title); + Eegtab_EEG_art_det_epoch.detectar_run = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_art_det_epoch.detar_run_title,... + 'String','Run','callback',@detectar_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_art_det_epoch.detar_run_title); + set(Eegtab_EEG_art_det_epoch.detar_run_title,'Sizes',[10,-1,30,-1,10]); + + Eegtab_EEG_art_det_epoch.show_sumy_title = uiextras.HBox('Parent', Eegtab_EEG_art_det_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_epoch.show_sumy_title); + Eegtab_EEG_art_det_epoch.show_sumy_ar = uicontrol('Style', 'checkbox','Parent',Eegtab_EEG_art_det_epoch.show_sumy_title,'Value',1,... + 'String','Show summary window','callback',@show_sumy_ar,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_det_epoch.show_sumy_title); + set(Eegtab_EEG_art_det_epoch.show_sumy_title,'Sizes',[-1 180 -1]); + + Eegtab_EEG_art_det_epoch.Paras{8} = Eegtab_EEG_art_det_epoch.show_sumy_ar.Value; + set(Eegtab_EEG_art_det_epoch.DataSelBox,'Sizes',[30 30 30 25 25 35 35 35 30 20 30 20]); + estudioworkingmemory('EEGTab_detect_arts_epoch',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------------------checkbox for manual rejection---------------------- + function manuar_checkbox(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Eegtab_EEG_art_det_epoch.manuar_checkbox.Value==0 + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='off'; + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'on'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'on'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'on'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'on'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value==0 + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + else + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'on'; + end + + algValue =Eegtab_EEG_art_det_epoch.det_algo.Value; + + if algValue==1 + Eegtab_EEG_art_det_epoch.periods_editext.String='Test period [ms] (start end)'; + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Voltage limits[uV] (e.g., -100 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=2 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '-100 100'; + end + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif algValue==2%%peak-to-peak + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '100'; + end + elseif algValue==3 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '50'; + end + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + elseif algValue==4 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '30'; + end + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif algValue==5 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Amp. tolerance [uV] (e.g., 2)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_text.String = 'Flat line duration [ms] '; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '1'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = num2str(floor((observe_EEGDAT.EEG.times(end)-observe_EEGDAT.EEG.times(1))/2)); + end + end + else + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='on'; + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'on'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'off'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + end + end + +%%----------------------botton for manual rejection------------------------ + function manuar_button(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Artifact Detection (Epoched EEG) > View & Mark'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_epoch',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + [~,Flagmarks] = find(Eegtab_EEG_art_det_epoch.mflag==1); + %% + OutputViewereegpar = f_preparms_eegwaviewer(observe_EEGDAT.EEG,0); + try EEGdisp = OutputViewereegpar{3}; catch EEGdisp=1; end + if EEGdisp==0 + msgboxText=['Artifact Detection (Epoched EEG) > View & Mark: "Display chans" should be active in the "Plot Settings panel" ']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + estudioworkingmemory('f_EEG_proces_messg','Artifact Detection (Epoched EEG) > View & Mark: The main ERPLAB Studio window will be fronzen until you close that window for marking epochs'); + observe_EEGDAT.eeg_panel_message =1; + + mflag = [Eegtab_EEG_art_det_epoch.mflag1.Value,... + Eegtab_EEG_art_det_epoch.mflag2.Value,... + Eegtab_EEG_art_det_epoch.mflag3.Value,... + Eegtab_EEG_art_det_epoch.mflag4.Value,... + Eegtab_EEG_art_det_epoch.mflag5.Value,... + Eegtab_EEG_art_det_epoch.mflag6.Value,... + Eegtab_EEG_art_det_epoch.mflag7.Value,... + Eegtab_EEG_art_det_epoch.mflag8.Value]; + [~,Flagmarks] = find(mflag==1); + + + estudioworkingmemory('EEGUpdate',1); + observe_EEGDAT.count_current_eeg=1; + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Artifact Detection (Epoched EEG) > View & Mark*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + [EEG, LASTCOM] = f_ploteeg(EEG,Flagmarks); + if isempty(EEG) || isempty(LASTCOM) + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=1; + fprintf( [repmat('-',1,100) '\n']); + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf([LASTCOM,'\n']); + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_manmark'); + if isempty(Answer) + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=1; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + EEGArray = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',EEGArray); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + if Eegtab_EEG_art_det_epoch.mflag2.Value==2 + Eegtab_EEG_art_det_epoch.mflag= [1,1,0,0,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag3.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,1,0,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag4.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,1,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag5.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,1,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag6.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,1,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag7.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,1,0]; + elseif Eegtab_EEG_art_det_epoch.mflag8.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,1]; + else + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,0]; + end + Eegtab_EEG_art_det_epoch.Paras{1} = Eegtab_EEG_art_det_epoch.det_algo.Value; + Eegtab_EEG_art_det_epoch.Paras{2} = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + Eegtab_EEG_art_det_epoch.Paras{3} = Eegtab_EEG_art_det_epoch.mflag; + Eegtab_EEG_art_det_epoch.Paras{4} = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + Eegtab_EEG_art_det_epoch.Paras{5} = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + Eegtab_EEG_art_det_epoch.Paras{6} = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + Eegtab_EEG_art_det_epoch.Paras{7} = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.Paras{8} = Eegtab_EEG_art_det_epoch.show_sumy_ar.Value; + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg=1; + estudioworkingmemory('f_EEG_proces_messg','Artifact Detection (Epoched EEG) > View & Mark'); + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-------------------Artifact detection algorithms------------------------- + function det_algo(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + chanArray = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + if isempty(chanArray) || min(chanArray(:)) > observe_EEGDAT.EEG.nbchan || max(chanArray(:)) > observe_EEGDAT.EEG.nbchan + Eegtab_EEG_art_det_epoch.chan_edit.String = vect2colon([1:observe_EEGDAT.EEG.nbchan]); + end + temperiod = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + if isempty(temperiod) || numel(temperiod)~=2 + temperiod = [roundn(observe_EEGDAT.EEG.times(1),-1),roundn(observe_EEGDAT.EEG.times(end),-1)]; + Eegtab_EEG_art_det_epoch.periods_edit.String = num2str(temperiod); + end + if Source.Value==1 + Eegtab_EEG_art_det_epoch.periods_editext.String='Test period [ms] (start end)'; + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Voltage limits[uV] (e.g., -100 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=2 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '-100 100'; + end + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif Source.Value==2%%peak-to-peak + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '100'; + end + elseif Source.Value==3 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '50'; + end + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + elseif Source.Value==4 + + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '30'; + end + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif Source.Value==5 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Amp. tolerance [uV] (e.g., 2)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_text.String = 'Flat line duration [ms] '; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '1'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = num2str(floor((observe_EEGDAT.EEG.times(end)-observe_EEGDAT.EEG.times(1))/2)); + end + end + end + +%%----------------------edit chans----------------------------------------- + function chan_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + ChaNum = observe_EEGDAT.EEG.nbchan; + ChanArray = str2num(Source.String); + + if isempty(ChanArray) || any(ChanArray(:)<=0 ) || any(ChanArray(:)> ChaNum) + msgboxText=['Artifact Detection (Epoched EEG) > Index(es) of chans should be between 1 and ',32,num2str(ChaNum)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String= vect2colon([1:ChaNum]); + return; + end + ChanArray = vect2colon(ChanArray); + ChanArray = erase(ChanArray,{'[',']'}); + Source.String = ChanArray; + end + +%%----------------------------Browse chans--------------------------------- + function chan_browse(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + + %%-------Browse and select chans that will be interpolated--------- + EEG = observe_EEGDAT.EEG; + for Numofchan = 1:EEG.nbchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',EEG.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + ChanArray = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + if isempty(ChanArray) + indxlistb = EEG.nbchan; + else + if min(ChanArray(:)) >0 && max(ChanArray(:)) <= EEG.nbchan + indxlistb = ChanArray; + else + indxlistb = 1:EEG.nbchan; + end + end + titlename = 'Select Channel(s):'; + + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + chan_label_select = vect2colon(chan_label_select); + chan_label_select = erase(chan_label_select,{'[',']'}); + Eegtab_EEG_art_det_epoch.chan_edit.String = chan_label_select; + else + return + end + end + +%%------------------Mark flag1--------------------------------------------- + function mflag1(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=1; + Source.Enable= 'off'; + return; + end + Source.Value=1; + Source.Enable= 'off'; + end + +%%------------------------Mark flag2--------------------------------------- + function mflag2(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(2) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=1; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + else + Eegtab_EEG_art_det_epoch.mflag(2) = 0; + end + end + + +%%------------------------Mark flag3--------------------------------------- + function mflag3(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(3) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=1; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + else + Eegtab_EEG_art_det_epoch.mflag(3) = 0; + end + end + + +%%------------------------Mark flag4--------------------------------------- + function mflag4(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(4) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=1; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + else + Eegtab_EEG_art_det_epoch.mflag(4) = 0; + end + end + + +%%------------------------Mark flag5--------------------------------------- + function mflag5(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(5) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=1; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + else + Eegtab_EEG_art_det_epoch.mflag(5) = 0; + end + end + + +%%------------------------Mark flag6--------------------------------------- + function mflag6(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(6) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=1; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + else + Eegtab_EEG_art_det_epoch.mflag(6) = 0; + end + end + + +%%------------------------Mark flag7--------------------------------------- + function mflag7(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(7) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=1; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + else + Eegtab_EEG_art_det_epoch.mflag(7) = 0; + end + end + +%%------------------------Mark flag8--------------------------------------- + function mflag8(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Value=0; + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + if Source.Value ==1 + Eegtab_EEG_art_det_epoch.mflag(8) = 1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=1; + else + Eegtab_EEG_art_det_epoch.mflag(8) = 0; + end + end + + +%%-------------------------test period------------------------------------- + function periods_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + TimeRangedef = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + TimeRange = str2num(Source.String); + if isempty(TimeRange) || numel(TimeRange)~=2 + msgboxText = ['Artifact Detection (Epoched EEG) > Test period should be two numbers']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String= num2str(TimeRangedef); + return; + end + if TimeRange(1)TimeRangedef(2) || TimeRange(2)TimeRangedef(2) + msgboxText= ['Artifact Detection (Epoched EEG) > Test period should be between',32,num2str(TimeRangedef(1)),32,'and',32,num2str(TimeRangedef(2))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String= num2str(TimeRangedef); + return; + end + if TimeRange(2) < TimeRange(1) + Source.String = num2str(sort(TimeRange)); + end + end + +%%-----------------------------volatge------------------------------------- + function voltage_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + Voltagevalue= str2num(Source.String); + AlgorithmFlag= Eegtab_EEG_art_det_epoch.det_algo.Value; + errorMessage = ''; + if AlgorithmFlag==1 + if isempty(Voltagevalue) || numel(Voltagevalue)~=2 + errorMessage= ['Artifact Detection (Epoched EEG) > Voltage limits should have two numbers']; + Source.String = '-100 100'; + else + Source.String = num2str(sort(Voltagevalue)); + end + else + if isempty(Voltagevalue) || numel(Voltagevalue)~=1 + if AlgorithmFlag==2 || AlgorithmFlag==3 + errorMessage= ['Artifact Detection (Epoched EEG) > Voltage threshold should have one number']; + Source.String = '100'; + elseif AlgorithmFlag==4 + errorMessage= ['Artifact Detection (Epoched EEG) > Voltage threshold should have one number']; + Source.String = '30'; + elseif AlgorithmFlag==5 + errorMessage= ['Artifact Detection (Epoched EEG) > Amplitude tolerance should have one number']; + Source.String = '2'; + end + end + end + if ~isempty(errorMessage) + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + return; + end + end + + +%%------------------------moving window------------------------------------ + function movewindow_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + windowlength= str2num(Source.String); + AlgorithmFlag= Eegtab_EEG_art_det_epoch.det_algo.Value; + errorMessage = ''; + if isempty(windowlength) || numel(windowlength)~=1 + if AlgorithmFlag==2 || AlgorithmFlag==3 + errorMessage= ['Artifact Detection (Epoched EEG) > Moving window full width should have one number']; + Source.String = '200'; + elseif AlgorithmFlag==5 + errorMessage= ['Artifact Detection (Epoched EEG) > Duration should have one number']; + Source.String = num2str(floor((observe_EEGDAT.EEG.times(end)-observe_EEGDAT.EEG.times(1))/2)); + end + end + if AlgorithmFlag==5 && min(windowlength(:))<=0 + errorMessage= ['Artifact Detection (Epoched EEG) > Duration should be a positive number']; + Source.String = num2str(floor((observe_EEGDAT.EEG.times(end)-observe_EEGDAT.EEG.times(1))/2)); + elseif min(windowlength(:))<=0 + errorMessage= ['Artifact Detection (Epoched EEG) > Moving window full width should be a positive number']; + Source.String = '200'; + end + if ~isempty(errorMessage) + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + return; + end + end + + +%%-------------------------moving step------------------------------------- + function windowstep_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + windowstep= str2num(Source.String); + AlgorithmFlag= Eegtab_EEG_art_det_epoch.det_algo.Value; + + errorMessage = ''; + if isempty(windowstep) || numel(windowstep)~=1 + if AlgorithmFlag==2 || AlgorithmFlag==3 + errorMessage= ['Artifact Detection (Epoched EEG) > Moving step should have one number']; + Source.String = '100'; + end + end + if min(windowstep(:))< 1/observe_EEGDAT.EEG.srate + errorMessage= ['Artifact Detection (Epoched EEG) > Moving step should be equal to the sampling period (1/fs msec)']; + if AlgorithmFlag==2 + Source.String = '100'; + else + Source.String = '50'; + end + end + if ~isempty(errorMessage) + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + return; + end + end + +%%-----------------------------Prefilter checkbox-------------------------- + function prefilter_checkbox(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + prefilter_checkboxvalue = Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value; + if prefilter_checkboxvalue==1 + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable = 'on'; + else + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable = 'off'; + end + end + +%%-------------------------prefilter edit---------------------------------- + function prefilter_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + + lowcutoff = str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + if isempty(lowcutoff) || numel(lowcutoff)~=1 || any(lowcutoff(:)<=0) + Eegtab_EEG_art_det_epoch.prefilter_edit.String = '30'; + titlNamerro = 'Warning for EEG Tab'; + errorMessage= ['Artifact Detection (Epoched EEG) > prefilter: The cutoff for low-pass filter must be a single positive value']; + estudio_warning(errorMessage,titlNamerro); + end + end + + + +%%%-------------------------------Cancel----------------------------------- + function detectar_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Artifact Detection (Epoched EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + + try manuar_checkbox = Eegtab_EEG_art_det_epoch.Paras{11}; catch manuar_checkbox=0;end + if isempty(manuar_checkbox) || numel(manuar_checkbox)~=1 || any(manuar_checkbox~=0 && manuar_checkbox~=1) + manuar_checkbox=0; + end + Eegtab_EEG_art_det_epoch.manuar_checkbox.Value= manuar_checkbox; + if Eegtab_EEG_art_det_epoch.manuar_checkbox.Value==0 + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='off'; + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'on'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'on'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'on'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'on'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'on'; + if Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value==0 + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + else + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'on'; + end + end + + Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_epoch',0); + Eegtab_EEG_art_det_epoch.det_algo.Value = Eegtab_EEG_art_det_epoch.Paras{1}; + ChanArray = vect2colon(Eegtab_EEG_art_det_epoch.Paras{2}); + ChanArray = erase(ChanArray,{'[',']'}); + Eegtab_EEG_art_det_epoch.chan_edit.String = ChanArray; + Eegtab_EEG_art_det_epoch.mflag=Eegtab_EEG_art_det_epoch.Paras{3}; + Eegtab_EEG_art_det_epoch.mflag1.Value=1; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + if Eegtab_EEG_art_det_epoch.mflag(2)==1 + Eegtab_EEG_art_det_epoch.mflag2.Value=1; + elseif Eegtab_EEG_art_det_epoch.mflag(3)==1 + Eegtab_EEG_art_det_epoch.mflag3.Value=1; + elseif Eegtab_EEG_art_det_epoch.mflag(4)==1 + Eegtab_EEG_art_det_epoch.mflag4.Value=1; + elseif Eegtab_EEG_art_det_epoch.mflag(5)==1 + Eegtab_EEG_art_det_epoch.mflag5.Value=1; + elseif Eegtab_EEG_art_det_epoch.mflag(6)==1 + Eegtab_EEG_art_det_epoch.mflag6.Value=1; + elseif Eegtab_EEG_art_det_epoch.mflag(7)==1 + Eegtab_EEG_art_det_epoch.mflag7.Value=1; + elseif Eegtab_EEG_art_det_epoch.mflag(8)==1 + Eegtab_EEG_art_det_epoch.mflag8.Value=1; + end + Eegtab_EEG_art_det_epoch.periods_edit.String = num2str(Eegtab_EEG_art_det_epoch.Paras{4}); + Eegtab_EEG_art_det_epoch.voltage_edit.String = num2str(Eegtab_EEG_art_det_epoch.Paras{5}); + Eegtab_EEG_art_det_epoch.movewindow_edit.String = num2str(Eegtab_EEG_art_det_epoch.Paras{6}); + Eegtab_EEG_art_det_epoch.windowstep_edit.String = num2str(Eegtab_EEG_art_det_epoch.Paras{7}); + + if Eegtab_EEG_art_det_epoch.det_algo.Value==1 + Eegtab_EEG_art_det_epoch.periods_editext.String='Test period [ms] (start end)'; + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Voltage limits[uV] (e.g., -100 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=2 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '-100 100'; + end + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif Eegtab_EEG_art_det_epoch.det_algo.Value==2%%peak-to-peak + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '100'; + end + elseif Eegtab_EEG_art_det_epoch.det_algo.Value==3 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '50'; + end + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + elseif Eegtab_EEG_art_det_epoch.det_algo.Value==4 + + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '30'; + end + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif Eegtab_EEG_art_det_epoch.det_algo.Value==5 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Amp. tolerance [uV] (e.g., 2)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_text.String = 'Flat line duration [ms] '; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '1'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = num2str(floor((observe_EEGDAT.EEG.times(end)-observe_EEGDAT.EEG.times(1))/2)); + end + end + try show_sumy_ar = Eegtab_EEG_art_det_epoch.Paras{8}; catch show_sumy_ar=1; end + if isempty(show_sumy_ar) || numel(show_sumy_ar)~=1 || (show_sumy_ar~=1 && show_sumy_ar~=0) + show_sumy_ar=1; + end + Eegtab_EEG_art_det_epoch.show_sumy_ar.Value = show_sumy_ar; + + try prefilter_value = Eegtab_EEG_art_det_epoch.Paras{9}; catch prefilter_value = 0;end + if isempty(prefilter_value) || numel(prefilter_value)~=1 || (prefilter_value~=0 && prefilter_value~=1) + prefilter_value=0; + end + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value=prefilter_value; + try prefilter_editValue = Eegtab_EEG_art_det_epoch.Paras{10}; catch prefilter_editValue=30;end + if isempty(prefilter_editValue) || numel(prefilter_editValue)~=1 || any(prefilter_editValue(:)<=0) + prefilter_editValue=30; + end + Eegtab_EEG_art_det_epoch.prefilter_edit.String = num2str(prefilter_editValue); + if Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value==1 + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable = 'on'; + else + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable = 'off'; + end + + + if Eegtab_EEG_art_det_epoch.manuar_checkbox.Value==1 + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='on'; + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'off'; + + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'on'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'off'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'off'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + end + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'off'; + Eegtab_EEG_art_det_epoch.Paras{1} = Eegtab_EEG_art_det_epoch.det_algo.Value; + Eegtab_EEG_art_det_epoch.Paras{2} = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + % Eegtab_EEG_art_det_epoch.Paras{3} = Eegtab_EEG_art_det_epoch.mflag; + Eegtab_EEG_art_det_epoch.Paras{4} = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + Eegtab_EEG_art_det_epoch.Paras{5} = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + Eegtab_EEG_art_det_epoch.Paras{6} = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + Eegtab_EEG_art_det_epoch.Paras{7} = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.Paras{8} = Eegtab_EEG_art_det_epoch.show_sumy_ar.Value; + Eegtab_EEG_art_det_epoch.Paras{9} = Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value; + Eegtab_EEG_art_det_epoch.Paras{10}= str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + Eegtab_EEG_art_det_epoch.Paras{11}=Eegtab_EEG_art_det_epoch.manuar_checkbox.Value; + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + + +%%----------------------show summary window-------------------------------- + function show_sumy_ar(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_arts_epoch',1); + end + +%%-----------------------Run------------------------------------------ + function detectar_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Artifact Detection (Epoched EEG) > Run'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_detect_arts_epoch',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + %%Algorithm that uses to detect artifacts + try + AlgFlag = Eegtab_EEG_art_det_epoch.det_algo.Value; + catch + AlgFlag = 1; + end + + %%chans + ChanArray = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + nbchan = observe_EEGDAT.EEG.nbchan; + if isempty(ChanArray) || any(ChanArray(:) <=0) || any(ChanArray(:) > nbchan) + errorMessage = ['Artifact Detection (Epoched EEG) > Run: Chans are empty or index(es) are not between 1 and',32,num2str(nbchan)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + %%flags for marking artifacts + mflag = [Eegtab_EEG_art_det_epoch.mflag1.Value,... + Eegtab_EEG_art_det_epoch.mflag2.Value,... + Eegtab_EEG_art_det_epoch.mflag3.Value,... + Eegtab_EEG_art_det_epoch.mflag4.Value,... + Eegtab_EEG_art_det_epoch.mflag5.Value,... + Eegtab_EEG_art_det_epoch.mflag6.Value,... + Eegtab_EEG_art_det_epoch.mflag7.Value,... + Eegtab_EEG_art_det_epoch.mflag8.Value]; + [~,Flagmarks] = find(mflag==1); + + epochStart = roundn(observe_EEGDAT.EEG.times(1),-1); epochEnd = roundn(observe_EEGDAT.EEG.times(end),-1); + %%test time period + Testperiod = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + if isempty(Testperiod) || numel(Testperiod)~=2 + errorMessage=['Artifact Detection (Epoched EEG) > Run: Time perid should have two numbers']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if Testperiod(1) < epochStart || Testperiod(2) > epochEnd || Testperiod(1) > epochEnd || Testperiod(2) < epochStart + errorMessage=['Artifact Detection (Epoched EEG) > Run: Time perid should should be between',32,num2str(epochStart),32,'and',32,numstr(epochEnd)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + Det_algostr = {'Simple voltage threshold','Moving window peak-to-peak threshold',... + 'Step-like artifacts','Sample to sample voltage threshold',... + 'Blocking & flat line'}; + %%----------if simple voltage threshold------------ + Volthreshold = sort(str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String)); + if AlgFlag==1 + if isempty(Volthreshold) || numel(Volthreshold)~=2 + errorMessage=['Artifact Detection (Epoched EEG) > Run: Voltage limits should have two numbers for "simple voltage threshold"']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(errorMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + else + erroMessage = ''; + if AlgFlag==5 + if isempty(Volthreshold) || numel(Volthreshold)~=1 + erroMessage= ['Artifact Detection (Epoched EEG) > Run: Amplitude tolerance only has one number for "Blocking & flat line"']; + end + else + if isempty(Volthreshold) || numel(Volthreshold)~=1 + erroMessage= ['Artifact Detection (Epoched EEG) > Run: Voltage threshold only has one number for "',Det_algostr{AlgFlag},'"']; + end + end + if ~isempty(erroMessage) + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + + % + %%Moving window full width + WindowLength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + erroMessage= ''; + if AlgFlag==5 + if isempty(WindowLength)|| any(WindowLength(:)<=0) + erroMessage=['Artifact Detection (Epoched EEG) > Run: Duration should be a positive number for "Blocking & flat line"']; + end + if any(WindowLength(:) > epochEnd-epochStart) + erroMessage=['Artifact Detection (Epoched EEG) > Run: Duration cannot be greater than epoch size for "Blocking & flat line"']; + end + elseif AlgFlag==2 || AlgFlag==3 + erroMessage= ''; + if isempty(WindowLength)|| any(WindowLength(:)<2) + erroMessage=['Artifact Detection (Epoched EEG) > Run: Moving window should be greater than 2 for "',Det_algostr{AlgFlag},'"']; + end + if any(WindowLength(:) > epochEnd-epochStart) + erroMessage=['Artifact Detection (Epoched EEG) > Run: Moving window should be greater than 2 for "',Det_algostr{AlgFlag},'"']; + end + end + if ~isempty(erroMessage) + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + %%WindowStep + WindowStep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + stepnts = floor(WindowStep*observe_EEGDAT.EEG.srate/1000); + if AlgFlag==2 || AlgFlag==3 + if isempty(stepnts) || stepnts<1 + erroMessage= ['Artifact Detection (Epoched EEG) > Run: The minimun window step value should be equal to the sampling period (1/fs msec) for "',Det_algostr{AlgFlag},'"']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + if Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value==1 + lowcutoff = str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + if isempty(lowcutoff) || numel(lowcutoff)~=1 || any(lowcutoff(:)<=0) + Eegtab_EEG_art_det_epoch.prefilter_edit.String = '30'; + titlNamerro = 'Warning for EEG Tab'; + errorMessage= ['Artifact Detection (Epoched EEG) > prefilter: The cutoff for low-pass filter must be a single positive value and we used the default one.']; + estudio_warning(errorMessage,titlNamerro); + lowcutoff=30; + end + else + lowcutoff = -1; + end + Eegtab_EEG_art_det_epoch.Paras{9} = Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value; + Eegtab_EEG_art_det_epoch.Paras{10}= str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + Eegtab_EEG_art_det_epoch.Paras{11}=Eegtab_EEG_art_det_epoch.manuar_checkbox.Value; + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Artifact Detection (Epoched EEG) > Run*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Artifact detection algorithm:',32,Det_algostr{AlgFlag},'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + if AlgFlag==1 + [EEG, LASTCOM] = pop_artextval( EEG , 'Channel', ChanArray, 'Flag', Flagmarks,'LowPass',lowcutoff,... + 'Threshold', Volthreshold, 'Twindow',Testperiod ,'Review', 'off', 'History', 'implicit'); + elseif AlgFlag==2 + [EEG, LASTCOM] = pop_artmwppth( EEG , 'Channel', ChanArray, 'Flag', Flagmarks,'LowPass',lowcutoff,... + 'Threshold', Volthreshold, 'Twindow', Testperiod, 'Windowsize', WindowLength,... + 'Windowstep', WindowStep,'Review', 'off', 'History', 'implicit'); + elseif AlgFlag==3 + [EEG, LASTCOM] = pop_artstep( EEG , 'Channel', ChanArray, 'Flag', Flagmarks, 'LowPass',lowcutoff,... + 'Threshold', Volthreshold,'Twindow', Testperiod, 'Windowsize', WindowLength,... + 'Windowstep', WindowStep ,'Review', 'off', 'History', 'implicit'); + elseif AlgFlag==4 + [EEG, LASTCOM] = pop_artdiff( EEG , 'Channel', ChanArray, 'Flag', Flagmarks, 'LowPass', lowcutoff,... + 'Threshold', Volthreshold, 'Twindow',Testperiod,'Review', 'off', 'History', 'implicit' ); + elseif AlgFlag==5 + [EEG, LASTCOM] = pop_artflatline( EEG , 'Channel', ChanArray, 'Duration', WindowLength, 'Flag', Flagmarks,... + 'LowPass', lowcutoff, 'Threshold', Volthreshold, 'Twindow',Testperiod ,'Review', 'off', 'History', 'implicit'); + end + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_ar'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + EEGArray = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + %%----------------------display summary of artifacts--------------- + if Eegtab_EEG_art_det_epoch.show_sumy_ar.Value==1 + LASTCOM = pop_eeg_ar_summary(ALLEEG,EEGArray); + if ~isempty(LASTCOM) + eegh(LASTCOM); + end + + end + + estudioworkingmemory('EEGArray',EEGArray); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + if Eegtab_EEG_art_det_epoch.mflag2.Value==2 + Eegtab_EEG_art_det_epoch.mflag= [1,1,0,0,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag3.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,1,0,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag4.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,1,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag5.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,1,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag6.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,1,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag7.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,1,0]; + elseif Eegtab_EEG_art_det_epoch.mflag8.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,1]; + else + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,0]; + end + Eegtab_EEG_art_det_epoch.Paras{1} = Eegtab_EEG_art_det_epoch.det_algo.Value; + Eegtab_EEG_art_det_epoch.Paras{2} = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + Eegtab_EEG_art_det_epoch.Paras{3} = Eegtab_EEG_art_det_epoch.mflag; + Eegtab_EEG_art_det_epoch.Paras{4} = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + Eegtab_EEG_art_det_epoch.Paras{5} = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + Eegtab_EEG_art_det_epoch.Paras{6} = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + Eegtab_EEG_art_det_epoch.Paras{7} = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.Paras{8} = Eegtab_EEG_art_det_epoch.show_sumy_ar.Value; + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=19 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 || EEGUpdate==1 + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'off'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'off'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'off'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.manuar_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ==1 + Eegtab_box_art_det_epoch.TitleColor= [0.7500 0.7500 0.75000]; + else + Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=20; + return; + end + + Eegtab_EEG_art_det_epoch.manuar_checkbox.Enable= 'on'; + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='on'; + if Eegtab_EEG_art_det_epoch.manuar_checkbox.Value==0 + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='off'; + end + Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'on'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'on'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'on'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'on'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'on'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'on'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'on'; + if Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value==0 + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + end + + Eegtab_EEG_art_det_epoch.detectar_cancel.String = 'Cancel'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable = 'on'; + chanArray = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + if isempty(chanArray) || any(chanArray(:) > observe_EEGDAT.EEG.nbchan) || any(chanArray(:)<1) + Eegtab_EEG_art_det_epoch.chan_edit.String = vect2colon([1:observe_EEGDAT.EEG.nbchan]); + end + + temperiod = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + if isempty(temperiod) || numel(temperiod)~=2 + temperiod = [roundn(observe_EEGDAT.EEG.times(1),-1),roundn(observe_EEGDAT.EEG.times(end),-1)]; + Eegtab_EEG_art_det_epoch.periods_edit.String = num2str(temperiod); + end + algValue =Eegtab_EEG_art_det_epoch.det_algo.Value; + + if algValue==1 + Eegtab_EEG_art_det_epoch.periods_editext.String='Test period [ms] (start end)'; + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Voltage limits[uV] (e.g., -100 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=2 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '-100 100'; + end + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif algValue==2%%peak-to-peak + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '100'; + end + elseif algValue==3 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.movewindow_text.String='Moving window width [ms]'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '100'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = '200'; + end + windwostep = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + if isempty(windwostep) || numel(windwostep)~=1 + Eegtab_EEG_art_det_epoch.windowstep_edit.String = '50'; + end + Eegtab_EEG_art_det_epoch.windowstep_text.String='Window step [ms]'; + elseif algValue==4 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Threshold [uV] (e.g., 100)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '30'; + end + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + elseif algValue==5 + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Amp. tolerance [uV] (e.g., 2)'; + set(Eegtab_EEG_art_det_epoch.voltage_title,'Sizes',[100,-1]); + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='on'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_text.String = 'Flat line duration [ms] '; + VoltageValue = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + if isempty(VoltageValue) || numel(VoltageValue)~=1 + Eegtab_EEG_art_det_epoch.voltage_edit.String = '1'; + end + windowlength = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String);%%moving window + if isempty(windowlength) || numel(windowlength)~=1 + Eegtab_EEG_art_det_epoch.movewindow_edit.String = num2str(floor((observe_EEGDAT.EEG.times(end)-observe_EEGDAT.EEG.times(1))/2)); + end + end + if Eegtab_EEG_art_det_epoch.mflag2.Value==2 + Eegtab_EEG_art_det_epoch.mflag= [1,1,0,0,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag3.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,1,0,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag4.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,1,0,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag5.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,1,0,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag6.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,1,0,0]; + elseif Eegtab_EEG_art_det_epoch.mflag7.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,1,0]; + elseif Eegtab_EEG_art_det_epoch.mflag8.Value==1 + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,1]; + else + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,0]; + end + + if Eegtab_EEG_art_det_epoch.manuar_checkbox.Value==1 + + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='on'; + Eegtab_EEG_art_det_epoch.det_algo.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.chan_browse.Enable= 'off'; + Eegtab_EEG_art_det_epoch.mflag1.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag2.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag3.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag4.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag5.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag6.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag7.Enable= 'on'; + Eegtab_EEG_art_det_epoch.mflag8.Enable= 'on'; + Eegtab_EEG_art_det_epoch.periods_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.voltage_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.windowstep_text.Enable= 'off'; + Eegtab_EEG_art_det_epoch.detectar_cancel.Enable= 'on'; + Eegtab_EEG_art_det_epoch.detectar_run.Enable= 'off'; + Eegtab_EEG_art_det_epoch.show_sumy_ar.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable= 'off'; + end + + Eegtab_EEG_art_det_epoch.Paras{1} = Eegtab_EEG_art_det_epoch.det_algo.Value; + Eegtab_EEG_art_det_epoch.Paras{2} = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + Eegtab_EEG_art_det_epoch.Paras{3} = Eegtab_EEG_art_det_epoch.mflag; + Eegtab_EEG_art_det_epoch.Paras{4} = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + Eegtab_EEG_art_det_epoch.Paras{5} = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + Eegtab_EEG_art_det_epoch.Paras{6} = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + Eegtab_EEG_art_det_epoch.Paras{7} = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.Paras{8} = Eegtab_EEG_art_det_epoch.show_sumy_ar.Value; + Eegtab_EEG_art_det_epoch.Paras{9} = Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value; + Eegtab_EEG_art_det_epoch.Paras{10}= str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + Eegtab_EEG_art_det_epoch.Paras{11}=Eegtab_EEG_art_det_epoch.manuar_checkbox.Value; + Eegtab_EEG_art_det_epoch.mflag1.Enable = 'off'; + observe_EEGDAT.count_current_eeg=20; + end + +%%--------------press return to execute "Apply"---------------------------- + function eeg_artdetect_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_detect_arts_epoch'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + detectar_run(); + estudioworkingmemory('EEGTab_detect_arts_epoch',0); + Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=16 + return; + end + estudioworkingmemory('EEGTab_detect_arts_epoch',0); + % Eegtab_box_art_det_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_det_epoch.detectar_cancel.BackgroundColor = [1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_epoch.detectar_run.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_art_det_epoch.detectar_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_art_det_epoch.det_algo.Value=1; + Eegtab_EEG_art_det_epoch.periods_editext.String='Test period [ms] (start end)'; + Eegtab_EEG_art_det_epoch.voltage_text.String = 'Voltage limits[uV] (e.g., -100 100)'; + Eegtab_EEG_art_det_epoch.voltage_edit.String = '-100 100'; + + Eegtab_EEG_art_det_epoch.manuar_checkbox.Value=0; + Eegtab_EEG_art_det_epoch.manuar_button.Enable ='off'; + Eegtab_EEG_art_det_epoch.movewindow_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.windowstep_edit.Enable ='off'; + Eegtab_EEG_art_det_epoch.movewindow_text.String=''; + Eegtab_EEG_art_det_epoch.windowstep_text.String=''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.movewindow_edit.String = ''; + Eegtab_EEG_art_det_epoch.windowstep_edit.String = ''; + Eegtab_EEG_art_det_epoch.mflag2.Value=0; + Eegtab_EEG_art_det_epoch.mflag3.Value=0; + Eegtab_EEG_art_det_epoch.mflag4.Value=0; + Eegtab_EEG_art_det_epoch.mflag5.Value=0; + Eegtab_EEG_art_det_epoch.mflag6.Value=0; + Eegtab_EEG_art_det_epoch.mflag7.Value=0; + Eegtab_EEG_art_det_epoch.mflag8.Value=0; + Eegtab_EEG_art_det_epoch.mflag= [1,0,0,0,0,0,0,0]; + if isempty(observe_EEGDAT.EEG) + Eegtab_EEG_art_det_epoch.chan_edit.String = ''; + Eegtab_EEG_art_det_epoch.periods_edit.String = ''; + else + if observe_EEGDAT.EEG.trials==1 + Eegtab_EEG_art_det_epoch.periods_edit.String = ''; + else + Eegtab_EEG_art_det_epoch.periods_edit.String = num2str([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + end + Eegtab_EEG_art_det_epoch.chan_edit.String=vect2colon([1:observe_EEGDAT.EEG.nbchan]); + end + Eegtab_EEG_art_det_epoch.show_sumy_ar.Value=1; + Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value =0; + Eegtab_EEG_art_det_epoch.prefilter_edit.String = '30'; + Eegtab_EEG_art_det_epoch.prefilter_edit.Enable = 'off'; + Eegtab_EEG_art_det_epoch.Paras{1} = Eegtab_EEG_art_det_epoch.det_algo.Value; + Eegtab_EEG_art_det_epoch.Paras{2} = str2num(Eegtab_EEG_art_det_epoch.chan_edit.String); + Eegtab_EEG_art_det_epoch.Paras{3} = Eegtab_EEG_art_det_epoch.mflag; + Eegtab_EEG_art_det_epoch.Paras{4} = str2num(Eegtab_EEG_art_det_epoch.periods_edit.String); + Eegtab_EEG_art_det_epoch.Paras{5} = str2num(Eegtab_EEG_art_det_epoch.voltage_edit.String); + Eegtab_EEG_art_det_epoch.Paras{6} = str2num(Eegtab_EEG_art_det_epoch.movewindow_edit.String); + Eegtab_EEG_art_det_epoch.Paras{7} = str2num(Eegtab_EEG_art_det_epoch.windowstep_edit.String); + Eegtab_EEG_art_det_epoch.Paras{8} = 1; + Eegtab_EEG_art_det_epoch.Paras{9} = Eegtab_EEG_art_det_epoch.prefilter_checkbox.Value; + Eegtab_EEG_art_det_epoch.Paras{10}= str2num(Eegtab_EEG_art_det_epoch.prefilter_edit.String); + Eegtab_EEG_art_det_epoch.Paras{11}= Eegtab_EEG_art_det_epoch.manuar_checkbox.Value; + observe_EEGDAT.Reset_eeg_paras_panel=17; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_segmt_conus_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_segmt_conus_GUI.m new file mode 100644 index 00000000..0df12534 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_arf_det_segmt_conus_GUI.m @@ -0,0 +1,734 @@ +%%This function is to detect time segements for continuous EEG. + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 + + +function varargout = f_EEG_arf_det_segmt_conus_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +%---------------------------Initialize parameters------------------------------------ +EEG_art_det_segmt_conus = struct(); +%-----------------------------Name the title---------------------------------------------- + +% global Eegtab_box_art_det_segmt_conus; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_art_det_segmt_conus = uiextras.BoxPanel('Parent', fig, 'Title', 'Delete Time Segments (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_art_det_segmt_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Delete Time Segments (Continuous EEG)', ... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_art_det_segmt_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Delete Time Segments (Continuous EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @segment_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_art_det_segmt_conus_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_art_det_segmt_conus; + + function drawui_art_det_segmt_conus_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EEG_art_det_segmt_conus.DataSelBox = uiextras.VBox('Parent', Eegtab_box_art_det_segmt_conus,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + def = estudioworkingmemory('pop_erplabDeleteTimeSegments'); + if isempty(def) + def = {[1500], [500], [1500], [], ['ignore'], 0, 0}; + end + + try + timethreshold = def{1}; + catch + timethreshold = 1500; + end + if isnan(timethreshold) || isempty(timethreshold) || numel(timethreshold)~=1 || min(timethreshold(:)) <=0 + timethreshold = 1500; + end + %%channels that detect artifact + EEG_art_det_segmt_conus.chan_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_art_det_segmt_conus.chan_title,... + 'String','Time Threshold:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + EEG_art_det_segmt_conus.time_threshold_edit = uicontrol('Style','edit','Parent',EEG_art_det_segmt_conus.chan_title,... + 'String',num2str(timethreshold),'FontSize',FontSize_defualt,'callback',@time_threshold_edit,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_art_det_segmt_conus.time_threshold_edit.KeyPressFcn= @eeg_artdetect_presskey; + set( EEG_art_det_segmt_conus.chan_title,'Sizes',[120 -1]); + + + %%buffer before eventcode in ms + try + bufferbefore = def{2}; + catch + bufferbefore = 500; + end + if isnan(bufferbefore) || isempty(bufferbefore) || numel(bufferbefore)~=1 || min(bufferbefore(:)) <=0 + bufferbefore = 500; + end + EEG_art_det_segmt_conus.voltage_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_art_det_segmt_conus.voltage_text = uicontrol('Style','text','Parent',EEG_art_det_segmt_conus.voltage_title,... + 'String',['Buffer before eventcode (ms)'],'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + EEG_art_det_segmt_conus.buffer_before_edit = uicontrol('Style','edit','Parent',EEG_art_det_segmt_conus.voltage_title,... + 'callback',@buffer_before_edit,'String',num2str(bufferbefore),'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_art_det_segmt_conus.buffer_before_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(EEG_art_det_segmt_conus.voltage_title,'Sizes',[120,-1]); + + + %%buffer after eventcode in ms + try + bufferafter = def{3}; + catch + bufferafter = 1500; + end + if isnan(bufferafter) || isempty(bufferafter) || numel(bufferafter)~=1 || min(bufferafter(:)) <=0 + bufferafter = 1500; + end + EEG_art_det_segmt_conus.movewindow_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_art_det_segmt_conus.movewindow_text = uicontrol('Style','text','Parent',EEG_art_det_segmt_conus.movewindow_title,... + 'String',[32,'Buffer after eventcode (ms)'],'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + EEG_art_det_segmt_conus.buffer_after_edit = uicontrol('Style','edit','Parent',EEG_art_det_segmt_conus.movewindow_title,... + 'callback',@buffer_after_edit,'String',num2str(bufferafter),'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_art_det_segmt_conus.buffer_after_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(EEG_art_det_segmt_conus.movewindow_title,'Sizes',[120,-1]); + + %%eventcode exceptions + EEG_art_det_segmt_conus.windowstep_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_art_det_segmt_conus.windowstep_text = uicontrol('Style','text','Parent',EEG_art_det_segmt_conus.windowstep_title,... + 'String','Eventcode exceptions (optional)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + EEG_art_det_segmt_conus.event_exp_edit = uicontrol('Style','edit','Parent',EEG_art_det_segmt_conus.windowstep_title,... + 'callback',@event_exp_edit,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_art_det_segmt_conus.event_exp_edit.KeyPressFcn= @eeg_artdetect_presskey; + set(EEG_art_det_segmt_conus.windowstep_title,'Sizes',[120,-1]); + + + %%Ignore or use these exceptions + try + ignoreUseType = def{5}; + catch + ignoreUseType = 'ignore'; + end + if isempty(ignoreUseType) || numel(ignoreUseType)~=1 || min(ignoreUseType(:)) <=0 + ignoreUseType = 'ignore'; + end + + EEG_art_det_segmt_conus.eventcode_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_art_det_segmt_conus.eventcode_title ); + EEG_art_det_segmt_conus.event_exp_select = uicontrol('Style','popupmenu','Parent',EEG_art_det_segmt_conus.eventcode_title,... + 'callback',@event_exp_select,'String',{'Ignore','Use'},'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + if strcmp(ignoreUseType,'ignore') + EEG_art_det_segmt_conus.event_exp_select.Value = 1; + else + EEG_art_det_segmt_conus.event_exp_select.Value = 2; + end + uicontrol('Style','text','Parent',EEG_art_det_segmt_conus.eventcode_title,... + 'String','these exceptions','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + EEG_art_det_segmt_conus.event_exp_select.KeyPressFcn= @eeg_artdetect_presskey; + set(EEG_art_det_segmt_conus.eventcode_title,'Sizes',[80,90,-1]); + + + %%Ignore boundary events + try + ignoreBoundary = def{7}; + catch + ignoreBoundary = 0; + end + if isempty(ignoreBoundary) || numel(ignoreBoundary)~=1 || min(ignoreBoundary(:)) <=0 || (ignoreBoundary ~=0 && ignoreBoundary~=1) + ignoreBoundary = 0; + end + EEG_art_det_segmt_conus.boundaryevent_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_art_det_segmt_conus.boundaryevent_title ); + EEG_art_det_segmt_conus.boundaryevent = uicontrol('Style','checkbox','Parent',EEG_art_det_segmt_conus.boundaryevent_title,... + 'callback',@boundaryevent,'String','Ignore boundary events','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,... + 'Enable',EnableFlag,'BackgroundColor',ColorB_def,'Value',ignoreBoundary); % 2F + EEG_art_det_segmt_conus.boundaryevent.KeyPressFcn= @eeg_artdetect_presskey; + uiextras.Empty('Parent', EEG_art_det_segmt_conus.boundaryevent_title ); + set(EEG_art_det_segmt_conus.boundaryevent_title,'Sizes',[80,150,-1]); + + + %%-----------------------Cancel and Run---------------------------- + EEG_art_det_segmt_conus.detar_run_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_art_det_segmt_conus.detar_run_title,'BackgroundColor',ColorB_def); + EEG_art_det_segmt_conus.detectsegmt_preview = uicontrol('Style', 'pushbutton','Parent',EEG_art_det_segmt_conus.detar_run_title,... + 'String','Preview','callback',@detectsegmt_preview,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_art_det_segmt_conus.detar_run_title,'BackgroundColor',ColorB_def); + EEG_art_det_segmt_conus.detectsegmt_run = uicontrol('Style','pushbutton','Parent',EEG_art_det_segmt_conus.detar_run_title,... + 'String','Finalize','callback',@detectsegmt_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_art_det_segmt_conus.detar_run_title,'BackgroundColor',ColorB_def); + set(EEG_art_det_segmt_conus.detar_run_title,'Sizes',[15 105 30 105 15]); + + %%note/warning + EEG_art_det_segmt_conus.note_title = uiextras.HBox('Parent', EEG_art_det_segmt_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_art_det_segmt_conus.note_title,... + 'String','Warning: Any previously created Eventlist will be deleted','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + + set(EEG_art_det_segmt_conus.DataSelBox,'Sizes',[30 35 35 35 25 30 30 30]); + estudioworkingmemory('EEGTab_detect_segmt_conus',0); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------------------edit chans----------------------------------------- + function time_threshold_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_segmt_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_segmt_conus',1); + timeThresholdMS = str2num(Source.String); + + if isempty(timeThresholdMS) || numel(timeThresholdMS)~=1|| any(timeThresholdMS(:)<=0) + msgboxText = 'Delete Time Segments (Continuous EEG) > The value of "Time Threshold" should be a positive number'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String= '1500'; + return; + end + end + +%%-----------------------------volatge------------------------------------- + function buffer_before_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_segmt_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [1 1 1]; + + estudioworkingmemory('EEGTab_detect_segmt_conus',1); + beforeEventcodeBufferMS= str2num(Source.String); + if isempty(beforeEventcodeBufferMS) || numel(beforeEventcodeBufferMS)~=1 + msgboxText = ['Delete Time Segments (Continuous EEG) > Buffer before eventcode should have one number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = '500'; + return; + end + end + +%%------------------------moving window------------------------------------ + function buffer_after_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_segmt_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_segmt_conus',1); + afterEventcodeBufferMS= str2num(Source.String); + if isempty(afterEventcodeBufferMS) || numel(afterEventcodeBufferMS) ~=1 + msgboxText = ['Delete Time Segments (Continuous EEG) > Buffer after eventcode should have one number']; + Source.String = '1500'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + + +%%-------------------------moving step------------------------------------- + function event_exp_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_segmt_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_segmt_conus',1); + evntcodes = Source.String; + evntcodes = colonrange2num(evntcodes); + editString = regexprep(evntcodes, '[\D]', ' '); + Source.String = editString; + end + + +%%------------------Ignore/use--------------------------------------------- + function event_exp_select(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_segmt_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_segmt_conus',1); + end + + +%%%------------------------Ignore boundary evnets-------------------------- + function boundaryevent(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_art_det_segmt_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_detect_segmt_conus',1); + end + + +%%%----------------------Preview------------------------------------------- + function detectsegmt_preview(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Delete Time Segments (Continuous EEG) > Preview'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + + Eegtab_box_art_det_segmt_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [0 0 0]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_detect_segmt_conus',0); + + timeThresholdMS = str2double(EEG_art_det_segmt_conus.time_threshold_edit.String); + if isempty(timeThresholdMS) || numel(timeThresholdMS)~=1|| any(timeThresholdMS(:)<=0) + msgboxText = ['Delete Time Segments (Continuous EEG) > Preview: The value of "Time Threshold" should be a positive value']; + EEG_art_det_segmt_conus.time_threshold_edit.String= '7000'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + beforeEventcodeBufferMS = str2double(EEG_art_det_segmt_conus.buffer_before_edit.String); + if isempty(beforeEventcodeBufferMS) || numel(beforeEventcodeBufferMS)~=1 + msgboxText = ['Delete Time Segments (Continuous EEG) > Preview: Buffer before eventcode should have one number']; + EEG_art_det_segmt_conus.buffer_before_edit.String = '3000'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + afterEventcodeBufferMS = str2double(EEG_art_det_segmt_conus.buffer_after_edit.String); + if isempty(afterEventcodeBufferMS) || numel(afterEventcodeBufferMS) ~=1 + msgboxText = ['Delete Time Segments (Continuous EEG) > Buffer after eventcode should have one number']; + EEG_art_det_segmt_conus.buffer_after_edit.String = '3000'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + ignoreUseEventcodes = str2num(EEG_art_det_segmt_conus.event_exp_edit.String); + ignoreUseTypeValue = EEG_art_det_segmt_conus.event_exp_select.Value; + if ignoreUseTypeValue==1 + ignoreUseType = 'ignore'; + else + ignoreUseType = 'use'; + end + if isempty(ignoreUseEventcodes) + ignoreUseType = 'ignore'; + EEG_art_det_segmt_conus.event_exp_select.Value=1; + disp("We force 'these exceptions' to be ignored because there is no input for Eventcode exceptions."); + end + ignoreBoundary = EEG_art_det_segmt_conus.boundaryevent.Value; + displayEEG = 1; + % Save the GUI inputs to memory + estudioworkingmemory('pop_erplabDeleteTimeSegments', ... + { timeThresholdMS, ... + beforeEventcodeBufferMS, ... + afterEventcodeBufferMS, ... + ignoreUseEventcodes, ... + ignoreUseType, ... + displayEEG, ... + ignoreBoundary}); + + for Numofeeg = 1:numel(EEGArray) + try + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + catch + EEG = observe_EEGDAT.EEG; + end + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Delete Time Segments (Continuous EEG) > Preview*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %% Run the pop_ command with the user input from the GUI + [EEG, LASTCOM] = pop_erplabDeleteTimeSegments(EEG, ... + 'timeThresholdMS' , timeThresholdMS, ... + 'beforeEventcodeBufferMS' , beforeEventcodeBufferMS, ... + 'afterEventcodeBufferMS' , afterEventcodeBufferMS, ... + 'ignoreUseEventcodes' , ignoreUseEventcodes, ... + 'ignoreUseType' , ignoreUseType, ... + 'displayEEG' , displayEEG, ... + 'ignoreBoundary' , ignoreBoundary, ... + 'History' , 'implicit'); + if isempty(LASTCOM) + disp('User selected cancel or errors occur.'); + fprintf( [repmat('-',1,100) '\n']); + return; + else + fprintf([LASTCOM,'\n']); + end + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end + estudioworkingmemory('f_EEG_proces_messg','Delete Time Segments (Continuous EEG) > Preview'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + + +%%-----------------------Finalize------------------------------------------ + function detectsegmt_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Delete Time Segments (Continuous EEG) > Finalize'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_art_det_segmt_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [0 0 0]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_detect_segmt_conus',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + timeThresholdMS = str2double(EEG_art_det_segmt_conus.time_threshold_edit.String); + if isempty(timeThresholdMS) || numel(timeThresholdMS)~=1|| any(timeThresholdMS(:)<=0) + msgboxText = ['Delete Time Segments (Continuous EEG) > Finalize: The value of "Time Threshold" should be a positive value']; + EEG_art_det_segmt_conus.time_threshold_edit.String= '7000'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + beforeEventcodeBufferMS = str2double(EEG_art_det_segmt_conus.buffer_before_edit.String); + if isempty(beforeEventcodeBufferMS) || numel(beforeEventcodeBufferMS)~=1 + msgboxText = ['Delete Time Segments (Continuous EEG) > Finalize: Buffer before eventcode should be a single value']; + EEG_art_det_segmt_conus.buffer_before_edit.String = '3000'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + afterEventcodeBufferMS = str2double(EEG_art_det_segmt_conus.buffer_after_edit.String); + if isempty(afterEventcodeBufferMS) || numel(afterEventcodeBufferMS) ~=1 + msgboxText = ['Delete Time Segments (Continuous EEG) >Finalize: Buffer after eventcode should be a single value']; + EEG_art_det_segmt_conus.buffer_after_edit.String = '3000'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + ignoreUseEventcodes = str2num(EEG_art_det_segmt_conus.event_exp_edit.String); + ignoreUseTypeValue = EEG_art_det_segmt_conus.event_exp_select.Value; + if ignoreUseTypeValue==1 + ignoreUseType = 'ignore'; + else + ignoreUseType = 'use'; + end + ignoreBoundary = EEG_art_det_segmt_conus.boundaryevent.Value; + displayEEG = 0; + if isempty(ignoreUseEventcodes) + ignoreUseType = 'ignore'; + EEG_art_det_segmt_conus.event_exp_select.Value=1; + disp("We force 'these exceptions' to be ignored because there is no input for Eventcode exceptions."); + end + % Save the GUI inputs to memory + estudioworkingmemory('pop_erplabDeleteTimeSegments', ... + { timeThresholdMS, ... + beforeEventcodeBufferMS, ... + afterEventcodeBufferMS, ... + ignoreUseEventcodes, ... + ignoreUseType, ... + displayEEG, ... + ignoreBoundary}); + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Delete Time Segments (Continuous EEG) > Finalize*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + %% Run the pop_ command with the user input from the GUI + [EEG, LASTCOM] = pop_erplabDeleteTimeSegments(EEG, ... + 'timeThresholdMS' , timeThresholdMS, ... + 'beforeEventcodeBufferMS' , beforeEventcodeBufferMS, ... + 'afterEventcodeBufferMS' , afterEventcodeBufferMS, ... + 'ignoreUseEventcodes' , ignoreUseEventcodes, ... + 'ignoreUseType' , ignoreUseType, ... + 'displayEEG' , displayEEG, ... + 'ignoreBoundary' , ignoreBoundary, ... + 'History' , 'implicit'); + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_del'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=15 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 || EEGUpdate==1 + EEG_art_det_segmt_conus.time_threshold_edit.Enable= 'off'; + EEG_art_det_segmt_conus.chan_browse.Enable= 'off'; + EEG_art_det_segmt_conus.buffer_before_edit.Enable= 'off'; + EEG_art_det_segmt_conus.buffer_after_edit.Enable= 'off'; + EEG_art_det_segmt_conus.event_exp_edit.Enable= 'off'; + EEG_art_det_segmt_conus.event_exp_select.Enable= 'off'; + EEG_art_det_segmt_conus.boundaryevent.Enable= 'off'; + EEG_art_det_segmt_conus.detectsegmt_preview.Enable= 'off'; + EEG_art_det_segmt_conus.detectsegmt_run.Enable= 'off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ~=1 + Eegtab_box_art_det_segmt_conus.TitleColor= [0.7500 0.7500 0.750]; + else + Eegtab_box_art_det_segmt_conus.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=16; + return; + end + + Eegtab_box_art_det_segmt_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_art_det_segmt_conus.time_threshold_edit.Enable= 'on'; + EEG_art_det_segmt_conus.chan_browse.Enable= 'on'; + EEG_art_det_segmt_conus.periods_edit.Enable= 'on'; + EEG_art_det_segmt_conus.buffer_before_edit.Enable= 'on'; + EEG_art_det_segmt_conus.buffer_after_edit.Enable= 'on'; + EEG_art_det_segmt_conus.event_exp_edit.Enable= 'on'; + EEG_art_det_segmt_conus.event_exp_select.Enable= 'on'; + EEG_art_det_segmt_conus.boundaryevent.Enable= 'on'; + EEG_art_det_segmt_conus.detectsegmt_preview.Enable= 'on'; + EEG_art_det_segmt_conus.detectsegmt_run.Enable= 'on'; + + EEG_art_det_segmt_conus.detectsegmt_preview.String = 'Preview'; + time_threshold_edit = str2num(EEG_art_det_segmt_conus.time_threshold_edit.String); + if isempty(time_threshold_edit) + EEG_art_det_segmt_conus.time_threshold_edit.String = '1500'; + end + %%set default parameters + if isempty(str2num(EEG_art_det_segmt_conus.buffer_before_edit.String)) + EEG_art_det_segmt_conus.buffer_before_edit.String = '500'; + end + if isempty(str2num(EEG_art_det_segmt_conus.buffer_after_edit.String)) + EEG_art_det_segmt_conus.buffer_after_edit.String = '1500'; + end + if isempty(str2num(EEG_art_det_segmt_conus.event_exp_edit.String)) + EEG_art_det_segmt_conus.event_exp_edit.String = ''; + end + observe_EEGDAT.count_current_eeg=16; + end + + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_artdetect_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_detect_segmt_conus'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + detectsegmt_run(); + estudioworkingmemory('EEGTab_detect_segmt_conus',0); + Eegtab_box_art_det_segmt_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [0 0 0]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [0 0 0]; + else + return; + end + end + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=12 + return; + end + estudioworkingmemory('EEGTab_detect_segmt_conus',0); + EEG_art_det_segmt_conus.detectsegmt_preview.BackgroundColor = [1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_preview.ForegroundColor = [0 0 0]; + EEG_art_det_segmt_conus.detectsegmt_run.BackgroundColor = [ 1 1 1]; + EEG_art_det_segmt_conus.detectsegmt_run.ForegroundColor = [0 0 0]; + EEG_art_det_segmt_conus.time_threshold_edit.String = '1500'; + EEG_art_det_segmt_conus.buffer_before_edit.String = '500'; + EEG_art_det_segmt_conus.buffer_after_edit.String = '1500'; + EEG_art_det_segmt_conus.event_exp_edit.String = ''; + EEG_art_det_segmt_conus.event_exp_select.Value = 1; + EEG_art_det_segmt_conus.boundaryevent.Value = 0; + observe_EEGDAT.Reset_eeg_paras_panel=13; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end + diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_arf_sumop_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_arf_sumop_GUI.m new file mode 100644 index 00000000..504a2e51 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_arf_sumop_GUI.m @@ -0,0 +1,530 @@ +%%This function is to detect and summarize artifact for epoched EEG. + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + +function varargout = f_EEG_arf_sumop_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); + +%---------------------------Initialize parameters------------------------------------ + +Eegtab_EEG_art_sumop = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global Eegtab_box_art_sumop; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_art_sumop = uiextras.BoxPanel('Parent', fig, 'Title', 'Artifact Info & Tools (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_art_sumop = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Artifact Info & Tools (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_art_sumop = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Artifact Info & Tools (Epoched EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @sumart_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_art_sumop_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_art_sumop; + + function drawui_art_sumop_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + Eegtab_EEG_art_sumop.DataSelBox = uiextras.VBox('Parent', Eegtab_box_art_sumop,'BackgroundColor',ColorB_def); + + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + %%clear marks for artifact detection + Eegtab_EEG_art_sumop.clear_art_det_title = uiextras.HBox('Parent', Eegtab_EEG_art_sumop.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.clear_art_det_title,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_sumop.clear_art_det = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_sumop.clear_art_det_title,... + 'String','Clear artifact detection marks on EEG','callback',@clear_art_det,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.clear_art_det_title,'BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_sumop.clear_art_det_title, 'Sizes',[13 -1 13]); + + + %%Sync artifact info in EEG and EVENTLIST + Eegtab_EEG_art_sumop.syn_arfinfo_title = uiextras.HBox('Parent', Eegtab_EEG_art_sumop.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.syn_arfinfo_title,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_sumop.syn_arfinfo = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_sumop.syn_arfinfo_title,... + 'String','Sync artifact info in EEG and EVENTLIST','callback',@syn_arfinfo,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.syn_arfinfo_title,'BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_sumop.syn_arfinfo_title, 'Sizes',[13 -1 13]); + + + %%Classic Artifact Summary + Eegtab_EEG_art_sumop.Classic_ar_sum_title = uiextras.HBox('Parent', Eegtab_EEG_art_sumop.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.Classic_ar_sum_title,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_sumop.Classic_ar_sum = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_sumop.Classic_ar_sum_title,... + 'String','Classic Artifact Summary','callback',@Classic_ar_sum,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.Classic_ar_sum_title,'BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_sumop.Classic_ar_sum_title, 'Sizes',[13 -1 13]); + + %%Summarize EEG artifact in a table + Eegtab_EEG_art_sumop.total_reject_ops_title = uiextras.HBox('Parent', Eegtab_EEG_art_sumop.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.total_reject_ops_title,'BackgroundColor',ColorB_def); + Eegtab_EEG_art_sumop.total_reject_ops = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_art_sumop.total_reject_ops_title,... + 'String','Artifact Summary','callback',@total_reject_ops,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_art_sumop.total_reject_ops_title,'BackgroundColor',ColorB_def); + set(Eegtab_EEG_art_sumop.total_reject_ops_title, 'Sizes',[13 -1 13]); + + set(Eegtab_EEG_art_sumop.DataSelBox,'Sizes',[30 30 30 30]); + end + + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------------clear artifact detection marks--------------------------- + function clear_art_det(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable = 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','Artifact Info & Tools (Epoched EEG) > Clear artifact detection marks on EEG'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + inputoption = resetrejGUI; % open GUI + if isempty(inputoption) + observe_EEGDAT.eeg_panel_message =2; + return + end + arjm = inputoption{1}; + bflag = inputoption{2}; + + if arjm==1 + arjmstr = 'on'; + else + arjmstr = 'off'; + end + + [arflag usflag] = dec2flag(bflag); + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Clear artifact detection marks on EEG*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + if EEG.trials==1 + erroMessage= 'Artifact Info & Tools (Epoched EEG) > Clear artifact detection marks on EEG: cannot work on a continuous EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [EEG, LASTCOM] = pop_resetrej(EEG, 'ResetArtifactFields', arjmstr, 'ArtifactFlag', arflag, 'UserFlag', usflag, 'History', 'implicit'); + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_resetrej'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG =ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%------------Sync artifact info in EEG and EVENTLIST---------------------- + function syn_arfinfo(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable = 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','Artifact Info & Tools (Epoched EEG) > Sync artifact info in EEG and EVENTLIST'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG) ) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + direction = synchroartifactsGUI; + if isempty(direction) + observe_EEGDAT.eeg_panel_message =2; + return + end + if direction==1 % erplab to eeglab synchro + dircom = 'erplab2eeglab'; + elseif direction==2 %eeglab to erplab synchro + dircom = 'eeglab2erplab'; + elseif direction==3 % both + dircom = 'bidirectional'; + else + dircom = 'none'; + end + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Sync artifact info in EEG and EVENTLIST*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + if EEG.trials==1 + erroMessage= 'Artifact Info & Tools (Epoched EEG) > Sync artifact info in EEG and EVENTLIST: cannot work on a continuous EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [EEG, LASTCOM] = pop_syncroartifacts(EEG, 'Direction', dircom, 'History', 'implicit'); + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_synctrej'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------Classic Artifact Summary--------------------- + function Classic_ar_sum(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable = 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','Artifact Info & Tools (Epoched EEG) > Classic Artifact Summary'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; estudioworkingmemory('EEGArray',EEGArray); + end + app = feval('estudio_classic_ar_summary_gui',[1 0 0]); + waitfor(app,'Finishbutton',1); + try + New_pos1 = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.01); %wait for app to leave + catch + observe_EEGDAT.eeg_panel_message =2; + return; + end + if isempty(New_pos1) + observe_EEGDAT.eeg_panel_message =2; + return; + end + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + if New_pos1(1)==1 + fprintf(['*Classic Artifact Summary>Summarize EEG artifact in a graphic*',32,32,32,32,datestr(datetime('now')),'\n']); + elseif New_pos1(2)==1 + fprintf(['*Classic Artifact Summary>Summarize EEG artifact in a table*',32,32,32,32,datestr(datetime('now')),'\n']); + elseif New_pos1(3)==1 + fprintf(['*Classic Artifact Summary>Summarize EEG artifact in a graphic*',32,32,32,32,datestr(datetime('now')),'\n']); + end + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + if EEG.trials==1 + erroMessage= 'Artifact Info & Tools (Epoched EEG) > Classic Artifact Summary: cannot work on a continuous EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if New_pos1(1)==1 + %%check if epochs were marked as artifacts + histoflags = summary_rejectflags(EEG); + %check currently activated flags + flagcheck = sum(histoflags); + active_flags = (flagcheck>1); + if isempty(active_flags) + erroMessage= 'Artifact Info & Tools (Epoched EEG) > Classic Artifact Summary: None of epochs was marked'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [EEG, MPD, LASTCOM] = getardetection(EEG, 1); + elseif New_pos1(2)==1 + %%check if epochs were marked as artifacts + histoflags = summary_rejectflags(EEG); + %check currently activated flags + flagcheck = sum(histoflags); + active_flags = (flagcheck>1); + if isempty(active_flags) + erroMessage= 'Artifact Info & Tools (Epoched EEG) > Summarize EEG artifact in a table: None of epochs was marked'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [EEG, tprej, acce, rej, histoflags,LASTCOM ] = pop_summary_AR_eeg_detection(EEG); + if isempty(LASTCOM) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + elseif New_pos1(3)==1 + %%check if epochs were marked as artifacts + histoflags = summary_rejectflags(EEG); + %check currently activated flags + flagcheck = sum(histoflags); + active_flags = (flagcheck>1); + + if isempty(active_flags) + erroMessage = 'Artifact Info & Tools (Epoched EEG) > Summarize EEG artifact in a graphic: None of epochs was marked'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + return; + end + [EEG, goodbad, histeEF, histoflags, LASTCOM] = pop_summary_rejectfields(EEG); + end + if New_pos1(2)~=1 + fprintf([LASTCOM,'\n']); + fprintf( [repmat('-',1,100) '\n']); + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + + end + + estudioworkingmemory('f_EEG_proces_messg','Artifact Info & Tools (Epoched EEG) > Classic Artifact Summary'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + +%%----------------Rejection option---------------------------------------- + function total_reject_ops(~,~) + if isempty(observe_EEGDAT.ALLEEG) || isempty(observe_EEGDAT.EEG) + return; + end + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + ALLEEG = observe_EEGDAT.ALLEEG; + LASTCOM = pop_eeg_ar_summary(ALLEEG,EEGArray); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['*Artifact Info & Tools (Epoched EEG)>Artifact Summary*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(LASTCOM); + fprintf( ['\n',repmat('-',1,100) '\n']); + for NumofEEG = 1:numel(EEGArray) + observe_EEGDAT.ALLEEG(EEGArray(NumofEEG)) = eegh(LASTCOM,observe_EEGDAT.ALLEEG(EEGArray(NumofEEG))); + if NumofEEG==1 + eegh(LASTCOM); + end + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26;%%to history panel + end + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=20 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 || EEGUpdate==1 + Eegtab_EEG_art_sumop.clear_art_det.Enable = 'off'; + Eegtab_EEG_art_sumop.syn_arfinfo.Enable = 'off'; + Eegtab_EEG_art_sumop.art_interp.Enable = 'off'; + Eegtab_EEG_art_sumop.Classic_ar_sum.Enable = 'off'; + Eegtab_EEG_art_sumop.total_reject_ops.Enable = 'off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ==1 + Eegtab_box_art_sumop.TitleColor= [0.7500 0.7500 0.75000]; + else + Eegtab_box_art_sumop.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=21; + return; + end + + Eegtab_box_art_sumop.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_art_sumop.clear_art_det.Enable = 'on'; + Eegtab_EEG_art_sumop.syn_arfinfo.Enable = 'on'; + Eegtab_EEG_art_sumop.art_interp.Enable = 'on'; + Eegtab_EEG_art_sumop.Classic_ar_sum.Enable = 'on'; + Eegtab_EEG_art_sumop.total_reject_ops.Enable = 'on'; + observe_EEGDAT.count_current_eeg=21; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_avg_erp_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_avg_erp_GUI.m new file mode 100644 index 00000000..71a7d54d --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_avg_erp_GUI.m @@ -0,0 +1,815 @@ +%%This function is to Compute Averaged ERPs (Epoched EEG). + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 + + +function varargout = f_EEG_avg_erp_GUI(varargin) + +global observe_EEGDAT; +global EStudio_gui_erp_totl; +global observe_ERPDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + + +%---------------------------Initialize parameters------------------------------------ +EEG_avg_erp = struct(); +%-----------------------------Name the title---------------------------------------------- + +% global Eegtab_box_avg_erp; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_avg_erp = uiextras.BoxPanel('Parent', fig, 'Title', 'Compute Averaged ERPs (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_avg_erp = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Compute Averaged ERPs (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_avg_erp = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Compute Averaged ERPs (Epoched EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @avg_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_dq_epoch_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_avg_erp; + + function drawui_dq_epoch_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EEG_avg_erp.DataSelBox = uiextras.VBox('Parent', Eegtab_box_avg_erp,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + def = estudioworkingmemory('pop_averager'); + if isempty(def) || numel(def)~=12 + % Should not be empty, and have exactly 12 elements. Else, fallback to: + def = {1 1 1 1 1 0 0 [] 1 [] 0 0}; + end + + try + artcrite = def{2}; + catch + artcrite=1; + end + if artcrite==0 + Valueround1 = 1; + Valueround2 =0; + Valueround3 = 0; + elseif artcrite==2 + Valueround1 = 0; + Valueround2 =0; + Valueround3 = 1; + else + Valueround1 = 0; + Valueround2 = 1; + Valueround3 = 0; + end + %%Round to arlier time sample (recommended) + EEG_avg_erp.movewindow_title1 = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_avg_erp.movewindow_title1,'HorizontalAlignment','center','FontWeight','bold',... + 'String','Epochs to Include in ERP Average:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on','BackgroundColor',ColorB_def); % 2F + + %%all epochs + EEG_avg_erp.movewindow_title = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.all_marks = uicontrol('Style','radiobutton','Parent',EEG_avg_erp.movewindow_title,'HorizontalAlignment','left',... + 'callback',@all_marks,'String','Include All epochs (ignore artifact detections)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.all_marks.KeyPressFcn= @eeg_avg_erp_presskey; + uiextras.Empty('Parent', EEG_avg_erp.movewindow_title ,'BackgroundColor',ColorB_def); + set(EEG_avg_erp.movewindow_title,'Sizes',[270,-1]); + + %%exclude marked epochs + EEG_avg_erp.windowstep_title = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.excld_marks = uicontrol('Style','radiobutton','Parent',EEG_avg_erp.windowstep_title,'HorizontalAlignment','left',... + 'callback',@excld_marks,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.excld_marks.String = 'Exclude epochs marked during artifact
                            detection (highly recommended)'; + EEG_avg_erp.excld_marks.KeyPressFcn= @eeg_avg_erp_presskey; + uiextras.Empty('Parent',EEG_avg_erp.windowstep_title ,'BackgroundColor',ColorB_def); + set(EEG_avg_erp.windowstep_title,'Sizes',[260,-1]); + + %%marked epochs + EEG_avg_erp.eventcode_title = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.marked_epochs = uicontrol('Style','radiobutton','Parent',EEG_avg_erp.eventcode_title,'HorizontalAlignment','left',... + 'callback',@marked_epochs,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.marked_epochs.String = 'Include ONLY epochs marked with artifact
                            detection (by cautious!)'; + uiextras.Empty('Parent', EEG_avg_erp.eventcode_title ); + set(EEG_avg_erp.eventcode_title,'Sizes',[260,-1]); + EEG_avg_erp.all_marks.Value = Valueround1; + EEG_avg_erp.excld_marks.Value = Valueround2; + EEG_avg_erp.marked_epochs.Value = Valueround3; + + + %%selection for invalid epochs + EEG_avg_erp.invalidepoch_title = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.invalidepoch = uicontrol('Style','checkbox','Parent',EEG_avg_erp.invalidepoch_title ,'HorizontalAlignment','left',... + 'callback',@invalidepoch,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.invalidepoch.String = 'Exclude epochs with either "boundary"
                            or invalid events (highly recommended)'; + EEG_avg_erp.invalidepoch.KeyPressFcn= @eeg_avg_erp_presskey; + excbound=1; + EEG_avg_erp.invalidepoch.Value = excbound; + + try + DQcustom_wins = def{12}; + catch + DQcustom_wins = 0; + end + oldDQ = def{10}; + EEG_avg_erp.DQ_spec = []; + if isempty(oldDQ) + dq_times_def = [1:6;-100:100:400;0:100:500]'; + EEG_avg_erp.dq_times = dq_times_def; + EEG_avg_erp.DQ_spec = []; + else + try + dq_times_def = oldDQ(3).times; + EEG_avg_erp.dq_times = dq_times_def; + EEG_avg_erp.DQ_spec = oldDQ; + catch + dq_times_def = [1:6;-100:100:400;0:100:500]'; + EEG_avg_erp.dq_times = dq_times_def; + EEG_avg_erp.DQ_spec = oldDQ; + end + end + try + EEG_avg_erp.DQpreavg_txt =def{11}; + catch + EEG_avg_erp.DQpreavg_txt =1; + end + + EEG_avg_erp.para_title1 = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_avg_erp.para_title1,'HorizontalAlignment','center','FontWeight','bold',... + 'String','Data Quality Quantification:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on','BackgroundColor',ColorB_def); % 2F + %%Default Parameters + EEG_avg_erp.para_title2 = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.def_para = uicontrol('Style','radiobutton','Parent',EEG_avg_erp.para_title2,'HorizontalAlignment','left',... + 'callback',@def_para,'String','On - default parameters','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.def_para.KeyPressFcn= @eeg_avg_erp_presskey; + + uiextras.Empty('Parent', EEG_avg_erp.para_title2 ,'BackgroundColor',ColorB_def); + set(EEG_avg_erp.para_title2,'Sizes',[160,-1]); + + %%Custom Parameters + EEG_avg_erp.para_title3 = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.custom_para = uicontrol('Style','radiobutton','Parent',EEG_avg_erp.para_title3,'HorizontalAlignment','left',... + 'callback',@custom_para,'String','On - custom parameters','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.def_para.KeyPressFcn= @eeg_avg_erp_presskey; + + EEG_avg_erp.custom_para_op = uicontrol('Style','pushbutton','Parent',EEG_avg_erp.para_title3,'HorizontalAlignment','left',... + 'callback',@custom_para_op,'String','Options','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 2F + uiextras.Empty('Parent', EEG_avg_erp.para_title3 ,'BackgroundColor',ColorB_def); + set(EEG_avg_erp.para_title3,'Sizes',[160,60 -1]); + + + %%no dq + EEG_avg_erp.para_title4 = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + EEG_avg_erp.no_dq = uicontrol('Style','radiobutton','Parent',EEG_avg_erp.para_title4,'HorizontalAlignment','left',... + 'callback',@no_dq,'String','No data quality measures','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_avg_erp.no_dq.KeyPressFcn= @eeg_avg_erp_presskey; + uiextras.Empty('Parent', EEG_avg_erp.para_title4 ,'BackgroundColor',ColorB_def); + set(EEG_avg_erp.para_title4,'Sizes',[160 -1]); + if DQcustom_wins==0 + EEG_avg_erp.def_para.Value = 1; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.no_dq.Value=0; + elseif DQcustom_wins==1 + EEG_avg_erp.def_para.Value = 0; + EEG_avg_erp.custom_para.Value=1; + EEG_avg_erp.no_dq.Value=0; + else + EEG_avg_erp.def_para.Value = 0; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.no_dq.Value=1; + end + + %%-----------------------Cancel and Run---------------------------- + EEG_avg_erp.detar_run_title = uiextras.HBox('Parent', EEG_avg_erp.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_avg_erp.detar_run_title,'BackgroundColor',ColorB_def); + EEG_avg_erp.avg_cancel = uicontrol('Style', 'pushbutton','Parent',EEG_avg_erp.detar_run_title,... + 'String','Cancel','callback',@avg_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_avg_erp.detar_run_title,'BackgroundColor',ColorB_def); + EEG_avg_erp.avg_run = uicontrol('Style','pushbutton','Parent',EEG_avg_erp.detar_run_title,... + 'String','Run','callback',@avg_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_avg_erp.detar_run_title,'BackgroundColor',ColorB_def); + set(EEG_avg_erp.detar_run_title,'Sizes',[15 105 30 105 15]); + + set(EEG_avg_erp.DataSelBox,'Sizes',[20 25 30 30 30 20 25 25 25 30]); + estudioworkingmemory('EEGTab_avg_erp',0); + estudioworkingmemory('EEGTab_eeg2erp',0); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%--------------------------------default parameters----------------------- + function def_para(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + EEG_avg_erp.def_para.Value=1; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.no_dq.Value=0; + EEG_avg_erp.custom_para_op.Enable = 'off'; + end + +%%-------------------------custom parameters------------------------------- + function custom_para(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + EEG_avg_erp.def_para.Value=0; + EEG_avg_erp.custom_para.Value=1; + EEG_avg_erp.custom_para_op.Enable = 'on'; + EEG_avg_erp.no_dq.Value=0; + end + +%%------------------------Custom define------------------------------------ + function custom_para_op(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + + timelimits = 1000 * [observe_EEGDAT.EEG.xmin observe_EEGDAT.EEG.xmax]; + old_DQ_spec = EEG_avg_erp.DQ_spec; + custom_DQ_spec = avg_data_quality(old_DQ_spec,timelimits); + EEG_avg_erp.timelimits = timelimits; + if ~isempty(custom_DQ_spec) + EEG_avg_erp.DQ_spec = custom_DQ_spec; + end + end + +%%---------------------------------No data quality------------------------- + function no_dq(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + EEG_avg_erp.def_para.Value=0; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.custom_para_op.Enable = 'off'; + EEG_avg_erp.no_dq.Value=1; + end + + +%%---------------------------all epochs------------------------------------ + function all_marks(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + + estudioworkingmemory('EEGTab_avg_erp',1); + EEG_avg_erp.all_marks.Value = 1; + EEG_avg_erp.excld_marks.Value = 0; + EEG_avg_erp.marked_epochs.Value = 0; + end + + +%%-------------------------exclude marked epochs--------------------------- + function excld_marks(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + + EEG_avg_erp.all_marks.Value = 0; + EEG_avg_erp.excld_marks.Value = 1; + EEG_avg_erp.marked_epochs.Value = 0; + end + + +%%-------------------------Only marked epochs------------------------------ + function marked_epochs(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + EEG_avg_erp.all_marks.Value = 0; + EEG_avg_erp.excld_marks.Value = 0; + EEG_avg_erp.marked_epochs.Value = 1; + end + + +%%-------------exclude invalide epochs or boundary------------------------- + function invalidepoch(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_avg_erp.TitleColor= [0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_cancel.ForegroundColor = [1 1 1]; + EEG_avg_erp.avg_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_avg_erp.avg_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_avg_erp',1); + end + + +%%%----------------------Preview------------------------------------------- + function avg_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Compute Averaged ERPs (Epoched EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + Eegtab_box_avg_erp.TitleColor= [0.0500 0.2500 0.5000]; + EEG_avg_erp.avg_cancel.BackgroundColor = [1 1 1]; + EEG_avg_erp.avg_cancel.ForegroundColor = [0 0 0]; + EEG_avg_erp.avg_run.BackgroundColor = [ 1 1 1]; + EEG_avg_erp.avg_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_avg_erp',0); + + def = estudioworkingmemory('pop_averager'); + if isempty(def) || numel(def)~=12 + % Should not be empty, and have exactly 12 elements. Else, fallback to: + def = {1 1 1 1 1 0 0 [] 1 [] 1 0}; + end + try + DQcustom_wins = def{12}; + catch + DQcustom_wins = 0; + end + + if DQcustom_wins==0 + EEG_avg_erp.def_para.Value = 1; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.custom_para_op.Enable = 'off'; + EEG_avg_erp.timelimits = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + DQ_defaults = make_DQ_spec([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + EEG_avg_erp.DQ_spec=DQ_defaults; + EEG_avg_erp.no_dq.Value =0; + elseif DQcustom_wins==1 + EEG_avg_erp.def_para.Value = 0; + EEG_avg_erp.custom_para.Value=1; + EEG_avg_erp.custom_para_op.Enable = 'on'; + EEG_avg_erp.no_dq.Value =0; + else + EEG_avg_erp.def_para.Value = 0; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.custom_para_op.Enable = 'off'; + EEG_avg_erp.no_dq.Value =1; + end + %%setting for selection of epoch types + try + artcrite = def{2}; + catch + artcrite=1; + end + if artcrite==0 + Valueround1 = 1; + Valueround2 =0; + Valueround3 = 0; + elseif artcrite==2 + Valueround1 = 0; + Valueround2 =0; + Valueround3 = 1; + else + Valueround1 = 0; + Valueround2 = 1; + Valueround3 = 0; + end + EEG_avg_erp.all_marks.Value = Valueround1; + EEG_avg_erp.excld_marks.Value = Valueround2; + EEG_avg_erp.marked_epochs.Value = Valueround3; + + excbound = def{5}; + if isempty(excbound) || numel(excbound)~=1 || (excbound~=0 && excbound~=1) + excbound=1; + end + EEG_avg_erp.invalidepoch.Value = excbound; + + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------------Run-------------------------------------- + function avg_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=17 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Compute Averaged ERPs (Epoched EEG) > Run'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_avg_erp.TitleColor= [0.0500 0.2500 0.5000]; + EEG_avg_erp.avg_cancel.BackgroundColor = [1 1 1]; + EEG_avg_erp.avg_cancel.ForegroundColor = [0 0 0]; + EEG_avg_erp.avg_run.BackgroundColor = [ 1 1 1]; + EEG_avg_erp.avg_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_avg_erp',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + incALL=EEG_avg_erp.all_marks.Value; + excart=EEG_avg_erp.excld_marks.Value; + onlyart=EEG_avg_erp.marked_epochs.Value; + incart = 0; + incIndx = 0; + excbound = EEG_avg_erp.invalidepoch.Value; % exclude epochs having boundary events + Tspectrum = 0; % total power spectrum + Espectrum = 0; % evoked power spectrum + iswindowed = 0; + winparam = ''; + compu2do = 0; %do ERP only + + if incALL + artcrite = 0; + elseif excart + artcrite = 1; + else + artcrite = 2; + end + try + DQ_defaults = make_DQ_spec(EEG_avg_erp.timelimits); + catch + EEG_avg_erp.timelimits = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + DQ_defaults = make_DQ_spec([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + end + DQ_defaults(1).comments{1} = 'Defaults'; + + + DQ_flag = max(EEG_avg_erp.def_para.Value,EEG_avg_erp.custom_para.Value); + + use_defaults = EEG_avg_erp.def_para.Value; + if DQ_flag + stderror = 1; + if use_defaults || isempty(EEG_avg_erp.DQ_spec) + DQ_spec = DQ_defaults; + else + DQ_spec = EEG_avg_erp.DQ_spec; + end + else + stderror = 0; + DQ_spec = []; + end + + if EEG_avg_erp.def_para.Value==1 + DQ_customWins = 0; + else + DQ_customWins = 1; + end + try + DQ_preavg_txt = EEG_avg_erp.DQpreavg_txt; + catch + DQ_preavg_txt=1; + end + wavg = 1; + + answer = {EEGArray(1), artcrite, wavg, stderror, excbound, compu2do, iswindowed, winparam,DQ_flag,DQ_spec,DQ_preavg_txt,DQ_customWins}; + + artcrite = answer{2}; + if ~iscell(artcrite) + if artcrite==0 + artcritestr = 'all'; + elseif artcrite==1 + artcritestr = 'good'; + elseif artcrite==2 + artcritestr = 'bad'; + else + artcritestr = artcrite; + end + else + artcritestr = artcrite; % fixed bug. May 1, 2012 + end + + stderror = answer{4}; + + % exclude epochs having boundary events + excbound = answer{5}; + + % Compute ERP, evoked power spectrum (EPS), and total power + % spectrum (TPS). + compu2do = answer{6}; % 0:ERP; 1:ERP+TPS; 2:ERP+EPS; 3:ERP+BOTH + wintype = answer{7}; % taper data with window: 0:no; 1:yes + wintfunc = answer{8}; % taper function and (sub)window + + % Write the analytic Standardized Measurment Error info + DQ_flag = answer{9}; + DQ_spec = answer{10}; + DQ_preavg_txt = answer{11}; + DQcustom_wins = answer{12}; + + answer(1:12) = {EEGArray(1), artcrite, 1, stderror, excbound, compu2do, wintype, wintfunc,DQ_flag,DQ_spec,DQ_preavg_txt,DQcustom_wins}; + estudioworkingmemory('pop_averager', answer); + + if stderror==1 + stdsstr = 'on'; + else + stdsstr = 'off'; + end + if excbound==1 + excboundstr = 'on'; + else + excboundstr = 'off'; + end + + ALLEEG1 = observe_EEGDAT.ALLEEG; + try + ALLERPCOM = evalin('base','ALLERPCOM'); + catch + ALLERPCOM = []; + assignin('base','ALLERPCOM',ALLERPCOM); + end + + try + ERPCOM = evalin('base','ERPCOM'); + catch + ERPCOM = []; + assignin('base','ALLERPCOM',ERPCOM); + end + + Answer = f_ERP_save_multi_file(ALLEEG1,EEGArray,'',0); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG = Answer{1}; + Save_file_label = Answer{2}; + end + ALLERP = []; + for Numofeeg = 1:numel(EEGArray) + setindex =EEGArray(Numofeeg); + EEG = ALLEEG(setindex); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Compute Averaged ERPs (Epoched EEG) > Apply*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %% Run the pop_ command with the user input from the GUI + + [ERP, ERPCOM] = pop_averager(ALLEEG, 'DSindex', setindex, 'Criterion', artcritestr,... + 'SEM', stdsstr, 'Warning', 'on', 'ExcludeBoundary', excboundstr,... + 'DQ_flag',DQ_flag,'DQ_spec',DQ_spec, 'DQ_preavg_txt', DQ_preavg_txt, 'DQ_custom_wins', DQcustom_wins, ... + 'History', 'implicit','Saveas','off'); + if isempty(ERPCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + if Numofeeg==1 + eegh(ERPCOM); + end + fprintf([ERPCOM,'\n']); + if Numofeeg ==numel(EEGArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + ERP.erpname = EEG.setname; + [pathstr, file_name, ~] = fileparts(EEG.filename); + ERP.filename = [file_name,'.erp']; + ERP.filepath=EEG.filepath; + if Save_file_label + [pathstr, file_name, ext] = fileparts(ERP.filename); + ext = '.erp'; + pathstr= ERP.filepath; + if strcmp(pathstr,'') + pathstr = cd; + end + ERP.filename = [file_name,ext]; + ERP.filepath = pathstr; + %%----------save the current sdata as-------------------- + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + if Numofeeg ==numel(EEGArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if Numofeeg==1 + eegh(ERPCOM); + end + end + + if isempty(observe_ERPDAT.ALLERP) + observe_ERPDAT.ALLERP = ERP; + else + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) =ERP; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + estudioworkingmemory('EEGTab_eeg2erp',1); + end%%end for loop of subjects + ALLERP = observe_ERPDAT.ALLERP; + for numofeeg = 1:numel(EEGArray) + EEGNames{numofeeg} = ALLEEG1(EEGArray(numofeeg)).setname; + end + ERPArray = [length(ALLERP)-numel(EEGArray)+1:length(ALLERP)]; + ERPCOM = pop_erp_ar_summary(ALLERP,ERPArray,EEGNames); + + observe_EEGDAT.eeg_panel_message =2; + EStudio_gui_erp_totl.context_tabs.SelectedChild = 2; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + [observe_ERPDAT.ERP,ALLERPCOM] = erphistory( observe_ERPDAT.ERP, ALLERPCOM, ERPCOM,2); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.Count_currentERP=1; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=23 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 || EEGUpdate==1 + EEG_avg_erp.def_para.Enable= 'off'; + EEG_avg_erp.custom_para.Enable= 'off'; + EEG_avg_erp.custom_para_op.Enable = 'off'; + EEG_avg_erp.no_dq.Enable = 'off'; + EEG_avg_erp.all_marks.Enable= 'off'; + EEG_avg_erp.excld_marks.Enable= 'off'; + EEG_avg_erp.marked_epochs.Enable= 'off'; + EEG_avg_erp.invalidepoch.Enable= 'off'; + EEG_avg_erp.avg_run.Enable= 'off'; + EEG_avg_erp.avg_cancel.Enable= 'off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ==1 + Eegtab_box_avg_erp.TitleColor= [0.7500 0.7500 0.75000]; + else + Eegtab_box_avg_erp.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=24; + return; + end + + EEG_avg_erp.timelimits = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + if EEG_avg_erp.def_para.Value==1 + DQ_defaults = make_DQ_spec([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + EEG_avg_erp.DQ_spec=DQ_defaults; + end + Eegtab_box_avg_erp.TitleColor= [0.0500 0.2500 0.5000]; + EEG_avg_erp.def_para.Enable= 'on'; + EEG_avg_erp.custom_para.Enable= 'on'; + EEG_avg_erp.custom_para_op.Enable = 'on'; + EEG_avg_erp.no_dq.Enable = 'on'; + EEG_avg_erp.all_marks.Enable= 'on'; + EEG_avg_erp.excld_marks.Enable= 'on'; + EEG_avg_erp.marked_epochs.Enable= 'on'; + EEG_avg_erp.invalidepoch.Enable= 'on'; + EEG_avg_erp.avg_run.Enable= 'on'; + EEG_avg_erp.avg_cancel.Enable= 'on'; + if EEG_avg_erp.def_para.Value==1 + EEG_avg_erp.custom_para_op.Enable = 'off'; + end + observe_EEGDAT.count_current_eeg=24; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_avg_erp_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_avg_erp'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + avg_run(); + estudioworkingmemory('EEGTab_avg_erp',0); + Eegtab_box_avg_erp.TitleColor= [0.0500 0.2500 0.5000]; + EEG_avg_erp.avg_cancel.BackgroundColor = [1 1 1]; + EEG_avg_erp.avg_cancel.ForegroundColor = [0 0 0]; + EEG_avg_erp.avg_run.BackgroundColor = [ 1 1 1]; + EEG_avg_erp.avg_run.ForegroundColor = [0 0 0]; + end + end + + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=19 + return; + end + estudioworkingmemory('EEGTab_avg_erp',0); + EEG_avg_erp.avg_cancel.BackgroundColor = [1 1 1]; + EEG_avg_erp.avg_cancel.ForegroundColor = [0 0 0]; + EEG_avg_erp.avg_run.BackgroundColor = [ 1 1 1]; + EEG_avg_erp.avg_run.ForegroundColor = [0 0 0]; + EEG_avg_erp.all_marks.Value = 0; + EEG_avg_erp.excld_marks.Value = 1; + EEG_avg_erp.marked_epochs.Value = 0; + EEG_avg_erp.def_para.Value=1; + EEG_avg_erp.custom_para.Value=0; + EEG_avg_erp.no_dq.Value=0; + EEG_avg_erp.custom_para_op.Enable = 'off'; + EEG_avg_erp.invalidepoch.Value = 0; + observe_EEGDAT.Reset_eeg_paras_panel=20; + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_baselinecorr_detrend_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_baselinecorr_detrend_GUI.m new file mode 100644 index 00000000..7f789d98 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_baselinecorr_detrend_GUI.m @@ -0,0 +1,766 @@ +%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +% 2024 + +% EEGLAB Studio + +function varargout = f_EEG_baselinecorr_detrend_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + + +%%---------------------------gui------------------------------------------- +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EEG_basecorr_detrend_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Baseline Correction & Linear Detrend (Epoched EEG)', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EEG_basecorr_detrend_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Baseline Correction & Linear Detrend (Epoched EEG)', 'Padding', 5,'BackgroundColor',ColorB_def); +else + EEG_basecorr_detrend_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Baseline Correction & Linear Detrend (Epoched EEG)', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +gui_eeg_blc_dt = struct(); +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +EEG_blc_dt_gui(FonsizeDefault); +varargout{1} = EEG_basecorr_detrend_box; + + + function EEG_blc_dt_gui(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + + Enable_label = 'off'; + gui_eeg_blc_dt.blc_dt = uiextras.VBox('Parent',EEG_basecorr_detrend_box,'Spacing',1,'BackgroundColor',ColorB_def); + + %%Measurement type + gui_eeg_blc_dt.blc_dt_type_title = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', gui_eeg_blc_dt.blc_dt_type_title,... + 'String','Type:','FontWeight','bold','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.blc_dt_option = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.blc = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_dt_option,... + 'String','Baseline Correction','callback',@baseline_correction_EEG,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.blcp.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.dt = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_dt_option,... + 'String','Linear detrend','callback',@detrend_EEG,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.dt.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.EEGTab_baseline_detrend{1} = gui_eeg_blc_dt.blc.Value; + + %%Baseline period: Pre, post whole custom + gui_eeg_blc_dt.blc_dt_baseline_period_title = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.blc_dt_title = uicontrol('Style', 'text','Parent', gui_eeg_blc_dt.blc_dt_baseline_period_title,... + 'String','Baseline Period:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + gui_eeg_blc_dt.blc_dt_bp_option = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.pre = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_dt_bp_option,... + 'String','Pre','callback',@pre_EEG,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.pre.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.post = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_dt_bp_option,... + 'String','Post','callback',@post_EEG,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.post.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.whole = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_dt_bp_option,... + 'String','Whole','callback',@whole_EEG,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.whole.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.blc_dt_bp_option_cust = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.custom = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_dt_bp_option_cust,... + 'String','Custom (ms) [start stop]','callback',@custom_EEG,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.custom.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.custom_edit = uicontrol('Style', 'edit','Parent', gui_eeg_blc_dt.blc_dt_bp_option_cust,... + 'String','','callback',@custom_edit,'Enable',Enable_label,'FontSize',FonsizeDefault); + gui_eeg_blc_dt.custom_edit.KeyPressFcn= @EEG_blcorrdetrend_presskey; + set(gui_eeg_blc_dt.blc_dt_bp_option_cust, 'Sizes',[160 100]); + if gui_eeg_blc_dt.pre.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = 1; + elseif gui_eeg_blc_dt.post.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = 2; + elseif gui_eeg_blc_dt.whole.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = 3; + elseif gui_eeg_blc_dt.custom.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = str2num(gui_eeg_blc_dt.custom_edit.String); + else + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} =1; + end + %%Bin and channels selection + gui_eeg_blc_dt.blc_dt_bin_chan_title = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', gui_eeg_blc_dt.blc_dt_bin_chan_title,... + 'String','Chan Selection:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.blc_bin_chan_option = uiextras.HBox('Parent', gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.all_bin_chan = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_bin_chan_option,... + 'String','All (Recommended)','callback',@All_bin_chan,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.all_bin_chan.KeyPressFcn= @EEG_blcorrdetrend_presskey; + gui_eeg_blc_dt.Selected_bin_chan = uicontrol('Style', 'radiobutton','Parent', gui_eeg_blc_dt.blc_bin_chan_option,... + 'String','Selected chan','callback',@Selected_bin_chan,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.Selected_bin_chan.KeyPressFcn= @EEG_blcorrdetrend_presskey; + set(gui_eeg_blc_dt.blc_bin_chan_option, 'Sizes',[135 175]); + gui_eeg_blc_dt.EEGTab_baseline_detrend{3} = gui_eeg_blc_dt.all_bin_chan.Value; + %%Cancel and advanced + gui_eeg_blc_dt.other_option = uiextras.HBox('Parent',gui_eeg_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', gui_eeg_blc_dt.other_option,'BackgroundColor',ColorB_def); + gui_eeg_blc_dt.Cancel = uicontrol('Parent',gui_eeg_blc_dt.other_option,'Style','pushbutton',... + 'String','Cancel','callback',@Cancel_blc_dt,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_eeg_blc_dt.other_option); + gui_eeg_blc_dt.apply = uicontrol('Style','pushbutton','Parent',gui_eeg_blc_dt.other_option,... + 'String','Apply','callback',@apply_blc_dt,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_eeg_blc_dt.other_option); + set(gui_eeg_blc_dt.other_option, 'Sizes',[15 105 30 105 15]); + + set(gui_eeg_blc_dt.blc_dt,'Sizes',[18 25 15 25 25 15 25 30]); + + estudioworkingmemory('EEGTab_baseline_detrend',0); + end +%%************************************************************************* +%%******************* Subfunctions ************************************ +%%************************************************************************* + +%%--------------------------------setting for amplitude-------------------- + function baseline_correction_EEG(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.blc.Value =1; + gui_eeg_blc_dt.dt.Value = 0; + gui_eeg_blc_dt.blc_dt_title.String = 'Baseline Period:'; + end + +%%--------------------------Setting for phase------------------------------ + function detrend_EEG(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.dt.Value = 1; + gui_eeg_blc_dt.blc.Value =0; + gui_eeg_blc_dt.blc_dt_title.String = 'Calculate Trend During:'; + end + +%%----------------Setting for "pre"---------------------------------------- + function pre_EEG(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.pre.Value=1; + gui_eeg_blc_dt.post.Value=0; + gui_eeg_blc_dt.whole.Value=0; + gui_eeg_blc_dt.custom.Value=0; + gui_eeg_blc_dt.custom_edit.Enable = 'off'; + if observe_EEGDAT.EEG.times(1)>=0 + CUstom_String = ''; + else + CUstom_String = num2str([observe_EEGDAT.EEG.times(1),0]); + end + gui_eeg_blc_dt.custom_edit.String = CUstom_String; + end + + +%%----------------Setting for "post"--------------------------------------- + function post_EEG(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.pre.Value=0; + gui_eeg_blc_dt.post.Value=1; + gui_eeg_blc_dt.whole.Value=0; + gui_eeg_blc_dt.custom.Value=0; + gui_eeg_blc_dt.custom_edit.Enable = 'off'; + if observe_EEGDAT.EEG.times(end)<=0 + CUstom_String = ''; + else + CUstom_String = num2str([0 observe_EEGDAT.EEG.times(end)]); + end + gui_eeg_blc_dt.custom_edit.String = CUstom_String; + end + +%%----------------Setting for "whole"-------------------------------------- + function whole_EEG(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.pre.Value=0; + gui_eeg_blc_dt.post.Value=0; + gui_eeg_blc_dt.whole.Value=1; + gui_eeg_blc_dt.custom.Value=0; + gui_eeg_blc_dt.custom_edit.Enable = 'off'; + CUstom_String = num2str([observe_EEGDAT.EEG.times(1) observe_EEGDAT.EEG.times(end)]); + gui_eeg_blc_dt.custom_edit.String = CUstom_String; + end + +%%----------------Setting for "custom"------------------------------------- + function custom_EEG(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.pre.Value=0; + gui_eeg_blc_dt.post.Value=0; + gui_eeg_blc_dt.whole.Value=0; + gui_eeg_blc_dt.custom.Value=1; + gui_eeg_blc_dt.custom_edit.Enable = 'on'; + end + +%%----------------input baseline period defined by user-------------------- + function custom_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + + lat_osci = str2num(Source.String); + if isempty(lat_osci) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - Invalid input for "baseline range"']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if numel(lat_osci) ==1 + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - Wrong baseline range. Please, enter two values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if lat_osci(1)>= lat_osci(2) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - The first value must be smaller than the second one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if lat_osci(2) > observe_EEGDAT.EEG.times(end) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - Second value must be smaller than',32,num2str(observe_EEGDAT.EEG.times(end))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if lat_osci(1) < observe_EEGDAT.EEG.times(1) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - First value must be larger than',32,num2str(observe_EEGDAT.EEG.times(1))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + end + +%%---------------------Setting for all chan and bin------------------------ + function All_bin_chan(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.all_bin_chan.Value = 1; + gui_eeg_blc_dt.Selected_bin_chan.Value = 0; + end + +%%----------------Setting for selected bin and chan------------------------ + function Selected_bin_chan(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + gui_eeg_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.apply.ForegroundColor = [1 1 1]; + EEG_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_baseline_detrend',1); + gui_eeg_blc_dt.all_bin_chan.Value = 0; + gui_eeg_blc_dt.Selected_bin_chan.Value = 1; + end +%%--------------------------Setting for plot------------------------------- + function apply_blc_dt(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(end); + observe_EEGDAT.CURRENTSET = EEGArray; + estudioworkingmemory('EEGArray',EEGArray); + end + try + if gui_eeg_blc_dt.pre.Value==1 + BaselineMethod = 'pre'; + elseif gui_eeg_blc_dt.post.Value==1 + BaselineMethod = 'post'; + elseif gui_eeg_blc_dt.whole.Value==1 + BaselineMethod = 'all'; + elseif gui_eeg_blc_dt.custom.Value ==1 + BaselineMethod = str2num(gui_eeg_blc_dt.custom_edit.String); + end + catch + BaselineMethod = 'pre'; + end + %%Check the baseline period defined by the custom. + if gui_eeg_blc_dt.custom.Value ==1 + if isempty(BaselineMethod) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - Invalid input for baseline range; Please Cancel two values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if numel(BaselineMethod) ==1 + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - Wrong baseline range. Please, enter two values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if BaselineMethod(1)>= BaselineMethod(2) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - The first value must be smaller than the second one']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if roundn(BaselineMethod(2),-3) > roundn(observe_EEGDAT.EEG.times(end),-3) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - Second value must be smaller than',32,num2str(observe_EEGDAT.EEG.times(end))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if roundn(BaselineMethod(1),-3) < roundn(observe_EEGDAT.EEG.times(1),-3) + msgboxText = ['Baseline Correction & Linear Detrend (Epoched EEG) - First value must be larger than',32,num2str(observe_EEGDAT.EEG.times(1))]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + %%Run the function based on the defined parameters + %%--------------Loop start for removeing baseline for the selected EEGsets------------ + if gui_eeg_blc_dt.dt.Value ==1 + Suffix_str = '_detrend'; + else + Suffix_str = '_baselinecorr'; + end + + %%%%-------------------Loop fpor baseline correction--------------- + estudioworkingmemory('f_EEG_proces_messg','Baseline Correction & Linear Detrend (Epoched EEG)'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + gui_eeg_blc_dt.apply.BackgroundColor = [ 1 1 1]; + gui_eeg_blc_dt.apply.ForegroundColor = [0 0 0]; + EEG_basecorr_detrend_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [1 1 1]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_baseline_detrend',0); + + gui_eeg_blc_dt.EEGTab_baseline_detrend{1} = gui_eeg_blc_dt.blc.Value; + if gui_eeg_blc_dt.pre.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = 1; + elseif gui_eeg_blc_dt.post.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = 2; + elseif gui_eeg_blc_dt.whole.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = 3; + elseif gui_eeg_blc_dt.custom.Value==1 + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} = str2num(gui_eeg_blc_dt.custom_edit.String); + else + gui_eeg_blc_dt.EEGTab_baseline_detrend{2} =1; + end + gui_eeg_blc_dt.EEGTab_baseline_detrend{3} = gui_eeg_blc_dt.all_bin_chan.Value; + + ALLEEG = observe_EEGDAT.ALLEEG; + ChanArray = estudioworkingmemory('EEG_ChanArray'); + if isempty(ChanArray) || any(ChanArray(:)<=0) || any(ChanArray(:)>observe_EEGDAT.EEG.nbchan) + ChanArray = [1:observe_EEGDAT.EEG.nbchan]; + end + + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + if EEG.trials==1 + msgboxText = 'Baseline Correction & Linear Detrend (Epoched EEG) cannot work for continous EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if gui_eeg_blc_dt.all_bin_chan.Value == 1 + ChanArray = [1:EEG.nbchan]; + else + if any(ChanArray(:)>observe_EEGDAT.EEG.nbchan) + ChanArray = [1:EEG.nbchan]; + end + end + + if gui_eeg_blc_dt.dt.Value ==1 + [EEG LASTCOM] = pop_eeglindetrend( EEG, 'Baseline', BaselineMethod,'ChanArray',ChanArray, 'History','gui' ); + else + [EEG LASTCOM]= pop_blceeg( EEG , 'Baseline', BaselineMethod,'ChanArray',ChanArray,... + 'Saveas', 'off','History','gui'); + end + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end%%Loop end for the selected ERset + + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),Suffix_str); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + if Save_file_label + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + estudioworkingmemory('f_EEG_BLS_Detrend',{BaselineMethod,0,1}); + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------Setting for save option--------------------------------- + function Cancel_blc_dt(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=15 + observe_EEGDAT.EEG_two_panels = observe_EEGDAT.EEG_two_panels+1;%%call the functions from the other panel + end + try + methodtype = gui_eeg_blc_dt.EEGTab_baseline_detrend{1}; + catch + methodtype=1; + gui_eeg_blc_dt.EEGTab_baseline_detrend{1}=1; + end + if isempty(methodtype) || numel(methodtype)~=1 || (methodtype~=0 && methodtype~=1) + methodtype=1; + gui_eeg_blc_dt.EEGTab_baseline_detrend{1}=1; + end + gui_eeg_blc_dt.blc.Value =methodtype; + gui_eeg_blc_dt.dt.Value = ~methodtype; + if gui_eeg_blc_dt.blc.Value==1 + gui_eeg_blc_dt.blc_dt_title.String = 'Baseline Period:'; + else + gui_eeg_blc_dt.blc_dt_title.String = 'Calculate Trend During:'; + end + %%baseline period + try + bsperiod = gui_eeg_blc_dt.EEGTab_baseline_detrend{2}; + catch + bsperiod=1; + gui_eeg_blc_dt.EEGTab_baseline_detrend{2}=1; + end + if isempty(bsperiod) || (numel(bsperiod)~=1 && numel(bsperiod)~=2) + bsperiod=1; + gui_eeg_blc_dt.EEGTab_baseline_detrend{2}=1; + end + + if numel(bsperiod)==1 + if bsperiod~=1 && bsperiod~=2 && bsperiod~=3 + bsperiod=1; + gui_eeg_blc_dt.EEGTab_baseline_detrend{2}=1; + end + if bsperiod==2 + gui_eeg_blc_dt.pre.Value=0; + gui_eeg_blc_dt.post.Value=1; + gui_eeg_blc_dt.whole.Value=0; + elseif bsperiod==3 + gui_eeg_blc_dt.pre.Value=0; + gui_eeg_blc_dt.post.Value=0; + gui_eeg_blc_dt.whole.Value=1; + else + gui_eeg_blc_dt.pre.Value=1; + gui_eeg_blc_dt.post.Value=0; + gui_eeg_blc_dt.whole.Value=0; + end + gui_eeg_blc_dt.custom.Value=0; + gui_eeg_blc_dt.custom_edit.Enable = 'off'; + gui_eeg_blc_dt.custom_edit.String = ''; + elseif numel(bsperiod)==2 + gui_eeg_blc_dt.pre.Value=0; + gui_eeg_blc_dt.post.Value=0; + gui_eeg_blc_dt.whole.Value=0; + gui_eeg_blc_dt.custom.Value=1; + gui_eeg_blc_dt.custom_edit.Enable = 'on'; + if any(bsperiod> observe_EEGDAT.EEG.times(end)) || any(bsperiod< observe_EEGDAT.EEG.times(1)) + bsperiod = []; + gui_eeg_blc_dt.EEGTab_baseline_detrend{2}=[]; + end + gui_eeg_blc_dt.custom_edit.String = num2str(bsperiod); + end + + %%bin & chan selection + try + all_bin_chan = gui_eeg_blc_dt.EEGTab_baseline_detrend{3}; + catch + all_bin_chan=1; + end + if isempty(all_bin_chan) || numel(all_bin_chan)~=1 || (all_bin_chan~=0&& all_bin_chan~=1) + gui_eeg_blc_dt.EEGTab_baseline_detrend{3}=1; + all_bin_chan=1; + end + gui_eeg_blc_dt.all_bin_chan.Value = all_bin_chan; + gui_eeg_blc_dt.Selected_bin_chan.Value = ~all_bin_chan; + + estudioworkingmemory('EEGTab_baseline_detrend',0); + gui_eeg_blc_dt.apply.BackgroundColor = [ 1 1 1]; + gui_eeg_blc_dt.apply.ForegroundColor = [0 0 0]; + EEG_basecorr_detrend_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_blc_dt.Cancel.BackgroundColor = [1 1 1]; + gui_eeg_blc_dt.Cancel.ForegroundColor = [0 0 0]; + end + + +%%-------------------Setting for the whole panel of fitering based on ALLEEG and CURRENTEEG-------------- + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg~=21 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || (~isempty(observe_EEGDAT.EEG)&& observe_EEGDAT.EEG.trials==1)|| EEGUpdate==1 + Enable_Label = 'off'; + else + Enable_Label = 'on'; + end + gui_eeg_blc_dt.blc.Enable = Enable_Label; + gui_eeg_blc_dt.dt.Enable = Enable_Label; + gui_eeg_blc_dt.apply.Enable = Enable_Label; + gui_eeg_blc_dt.Cancel.Enable = Enable_Label; + gui_eeg_blc_dt.pre.Enable= Enable_Label; + gui_eeg_blc_dt.post.Enable= Enable_Label; + gui_eeg_blc_dt.whole.Enable= Enable_Label; + gui_eeg_blc_dt.custom.Enable= Enable_Label; + gui_eeg_blc_dt.custom_edit.Enable = Enable_Label; + gui_eeg_blc_dt.apply.Enable = Enable_Label; + gui_eeg_blc_dt.Cancel.Enable = Enable_Label; + gui_eeg_blc_dt.all_bin_chan.Enable = Enable_Label; + gui_eeg_blc_dt.Selected_bin_chan.Enable = Enable_Label; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ==1 + EEG_basecorr_detrend_box.TitleColor= [0.7500 0.7500 0.75000]; + else + EEG_basecorr_detrend_box.TitleColor= [0.0500 0.2500 0.5000]; + end + + if gui_eeg_blc_dt.custom.Value==1 + gui_eeg_blc_dt.custom_edit.Enable = 'on'; + else + gui_eeg_blc_dt.custom_edit.Enable = 'off'; + end + if isempty(observe_EEGDAT.EEG) || (~isempty(observe_EEGDAT.EEG)&& observe_EEGDAT.EEG.trials==1)|| EEGUpdate==1 + observe_EEGDAT.count_current_eeg=22; + return; + end + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray> length(observe_EEGDAT.ALLEEG)) + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(end); + estudioworkingmemory('EEGArray',EEGArray); + observe_EEGDAT.CURRENTSET = EEGArray; + end + + if gui_eeg_blc_dt.custom.Value==1 + baseline = str2num(gui_eeg_blc_dt.custom_edit.String); + if ~isempty(baseline) + if any(baseline>observe_EEGDAT.EEG.times(end)) || any(baseline= lat_osci(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - The first value must be smaller than the second one for time range']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + gui_eegtab_binepoch.timerange_edit.String = ''; + return; + end + if lat_osci(2) > observe_EEGDAT.EEG.times(end) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Second value must be smaller than',32,num2str(observe_EEGDAT.EEG.times(end)),32,'for time range']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + gui_eegtab_binepoch.timerange_edit.String = ''; + return; + end + end + +%%----------------------None baseline correction--------------------------- + function none_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + %%change color for cancel and apply + gui_eegtab_binepoch.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.apply.ForegroundColor = [1 1 1]; + EEG_binepoch_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_binepoch',1); + gui_eegtab_binepoch.none.Value =1; + gui_eegtab_binepoch.pre.Value=0; + gui_eegtab_binepoch.post.Value=0; + gui_eegtab_binepoch.whole.Value=0; + gui_eegtab_binepoch.custom.Value=0; + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + gui_eegtab_binepoch.custom_edit.String = ''; + end + +%%----------------Setting for "pre"----------------------------------------- + function pre_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + %%change color for cancel and apply + gui_eegtab_binepoch.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.apply.ForegroundColor = [1 1 1]; + EEG_binepoch_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_binepoch',1); + gui_eegtab_binepoch.none.Value =0; + gui_eegtab_binepoch.pre.Value=1; + gui_eegtab_binepoch.post.Value=0; + gui_eegtab_binepoch.whole.Value=0; + gui_eegtab_binepoch.custom.Value=0; + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + gui_eegtab_binepoch.custom_edit.String = ''; + end + + +%%----------------Setting for "post"----------------------------------------- + function post_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + %%change color for cancel and apply + gui_eegtab_binepoch.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.apply.ForegroundColor = [1 1 1]; + EEG_binepoch_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_binepoch',1); + gui_eegtab_binepoch.none.Value =0; + gui_eegtab_binepoch.pre.Value=0; + gui_eegtab_binepoch.post.Value=1; + gui_eegtab_binepoch.whole.Value=0; + gui_eegtab_binepoch.custom.Value=0; + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + gui_eegtab_binepoch.custom_edit.String = ''; + end + +%%----------------Setting for "whole"----------------------------------------- + function whole_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + %%change color for cancel and apply + gui_eegtab_binepoch.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.apply.ForegroundColor = [1 1 1]; + EEG_binepoch_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_binepoch',1); + gui_eegtab_binepoch.none.Value =0; + gui_eegtab_binepoch.pre.Value=0; + gui_eegtab_binepoch.post.Value=0; + gui_eegtab_binepoch.whole.Value=1; + gui_eegtab_binepoch.custom.Value=0; + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + gui_eegtab_binepoch.custom_edit.String = ''; + end + +%%----------------Setting for "custom"----------------------------------------- + function custom_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + %%change color for cancel and apply + gui_eegtab_binepoch.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.apply.ForegroundColor = [1 1 1]; + EEG_binepoch_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_binepoch',1); + gui_eegtab_binepoch.none.Value =0; + gui_eegtab_binepoch.pre.Value=0; + gui_eegtab_binepoch.post.Value=0; + gui_eegtab_binepoch.whole.Value=0; + gui_eegtab_binepoch.custom.Value=1; + gui_eegtab_binepoch.custom_edit.Enable = 'on'; + end + +%%-----------------------Custom baseline period---------------------------- + function precustom_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + %%change color for cancel and apply + gui_eegtab_binepoch.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.apply.ForegroundColor = [1 1 1]; + EEG_binepoch_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_binepoch.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_binepoch',1); + + %%check the time period for the epoch + EpochRange = str2num(gui_eegtab_binepoch.timerange_edit.String); + if isempty(EpochRange) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Invalid input for "Time range"']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if numel(EpochRange) ~=2 + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Wrong time range for the epoch. Please, enter two values']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if EpochRange(1)>= EpochRange(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - The first value must be smaller than the second one for time range']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if EpochRange(2) > observe_EEGDAT.EEG.times(end) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Second value must be smaller than',32,num2str(observe_EEGDAT.EEG.times(end)),32,'for time range']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + Baselineperiod = str2num(Source.String); + %%check the defined baseline period + if isempty(Baselineperiod) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Invalid input for "baseline period"']; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if numel(Baselineperiod) ~=2 + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Wrong baseline period for the epoch. Please, enter two values']; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if Baselineperiod(1)>= Baselineperiod(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - The first value must be smaller than the second one for "baseline period"']; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if Baselineperiod(2) > EpochRange(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - Second value must be smaller than',32,num2str(EpochRange(2)),32,"baseline period"]; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if Baselineperiod(1) < EpochRange(1) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) - First value must be larger than',32,num2str(EpochRange(1)),32,"baseline period"]; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%--------------------------Setting for plot------------------------------- + function apply_blc_dt(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + %%-------------loop start for filtering the selected ERPsets----------------------------------- + estudioworkingmemory('f_EEG_proces_messg','Extract Bin-Based Epochs (Continuous EEG) > Apply'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + gui_eegtab_binepoch.apply.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.apply.ForegroundColor = [0 0 0]; + EEG_binepoch_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_binepoch.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_binepoch',0); + + %%check the time period for the epoch + EpochRange = str2num(gui_eegtab_binepoch.timerange_edit.String); + if isempty(EpochRange) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - Invalid input for "Time range"']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if numel(EpochRange) ~=2 + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - Wrong time range for the epoch. Please, enter two values']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if EpochRange(1)>= EpochRange(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - The first value must be smaller than the second one for time range']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if EpochRange(2) > observe_EEGDAT.EEG.times(end) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - Second value must be smaller than',32,num2str(observe_EEGDAT.EEG.times(end)),32,'for time range']; + gui_eegtab_binepoch.timerange_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + %%Check the baseline period defined by the custom. + if gui_eegtab_binepoch.custom.Value ==1 + Baselineperiod = str2num(gui_eegtab_binepoch.custom_edit.String); + %%check the defined baseline period + if isempty(Baselineperiod) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - Invalid input for "baseline period"']; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if numel(Baselineperiod) ~=2 + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - Wrong baseline period for the epoch. Please, enter two values']; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if Baselineperiod(1)>= Baselineperiod(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - The first value must be smaller than the second one for "baseline period"']; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if Baselineperiod(2) > EpochRange(2) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) > Apply - Second value must be smaller than',32,num2str(EpochRange(2)),32,"baseline period"]; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if Baselineperiod(1) < EpochRange(1) + msgboxText = ['Extract Bin-Based Epochs (Continuous EEG) Apply - First value must be larger than',32,num2str(EpochRange(1)),32,"baseline period"]; + gui_eegtab_binepoch.custom_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + + try + if gui_eegtab_binepoch.none.Value==1 + BaselineMethod = 'none'; + elseif gui_eegtab_binepoch.pre.Value==1 + BaselineMethod = 'pre'; + elseif gui_eegtab_binepoch.post.Value==1 + BaselineMethod = 'post'; + elseif gui_eegtab_binepoch.whole.Value==1 + BaselineMethod = 'all'; + elseif gui_eegtab_binepoch.custom.Value ==1 + BaselineMethod = str2num(gui_eegtab_binepoch.custom_edit.String); + end + catch + BaselineMethod = 'pre'; + end + %%save the changed parameters to memory file + estudioworkingmemory('pop_epochbin',{EpochRange,BaselineMethod}); + + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['**Your current EEGset(No.',num2str(EEGArray(Numofeeg)),')**\n',32,EEG.setname,'\n']); + %%epoch EEG data + [EEG, LASTCOM] = pop_epochbin( EEG , EpochRange, BaselineMethod, 'History', 'implicit'); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + estudioworkingmemory('Change2epocheeg',1);%%force the option to be Epoched EEG in "EEGsets" panel + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( [repmat('-',1,100) '\n']); + end + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_be'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------Setting for save option--------------------------------- + function Cancel_binepoch(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_binepoch',0); + gui_eegtab_binepoch.apply.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.apply.ForegroundColor = [0 0 0]; + EEG_binepoch_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_binepoch.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.cancel.ForegroundColor = [0 0 0]; + + if isempty(observe_EEGDAT.EEG) + Enable_Label = 'off'; + else + if isempty(observe_EEGDAT.EEG.data)|| ~isfield(observe_EEGDAT.EEG,'EVENTLIST') || ~isfield(observe_EEGDAT.EEG.EVENTLIST,'eventinfo') || ~isfield(observe_EEGDAT.EEG.EVENTLIST.eventinfo,'binlabel') + Enable_Label = 'off'; + else + Enable_Label = 'on'; + end + end + gui_eegtab_binepoch.timerange_edit.Enable = Enable_Label; + gui_eegtab_binepoch.none.Enable= Enable_Label; + gui_eegtab_binepoch.pre.Enable= Enable_Label; + gui_eegtab_binepoch.post.Enable= Enable_Label; + gui_eegtab_binepoch.whole.Enable= Enable_Label; + gui_eegtab_binepoch.custom.Enable= Enable_Label; + gui_eegtab_binepoch.custom_edit.Enable= Enable_Label; + gui_eegtab_binepoch.cancel.Enable= Enable_Label; + gui_eegtab_binepoch.apply.Enable= Enable_Label; + if ~isempty(observe_EEGDAT.EEG) && strcmpi(Enable_Label,'on') && gui_eegtab_binepoch.custom.Value==1 + gui_eegtab_binepoch.custom_edit.Enable = 'on'; + else + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + end + + def = estudioworkingmemory('pop_epochbin'); + if isempty(def) + def = {[-200 800] 'pre'}; + end + if isnumeric(def{1}) && numel(def{1})==2 + gui_eegtab_binepoch.timerange_edit.String = num2str(def{1}); + else + gui_eegtab_binepoch.timerange_edit.String = ''; + end + try + BaelineMethod = def{2}; + catch + BaelineMethod = 'pre'; + end + if isempty(BaelineMethod) + BaelineMethod = 'pre'; + end + if numel(BaelineMethod)==2 + noneFlag = 0; + preFlag = 0; + postFlag = 0; + wholeFlag = 0; + customFlag = 1; + if numel(BaelineMethod)~=2 + BaelineMethod = 'pre'; + noneFlag = 0; + preFlag = 1; + postFlag = 0; + wholeFlag = 0; + customFlag = 0; + end + else + if strcmpi(BaelineMethod,'none') + noneFlag = 1; + preFlag = 0; + postFlag = 0; + wholeFlag = 0; + customFlag = 0; + elseif strcmpi(BaelineMethod,'pre') + noneFlag = 0; + preFlag = 1; + postFlag = 0; + wholeFlag = 0; + customFlag = 0; + elseif strcmpi(BaelineMethod,'post') + noneFlag = 0; + preFlag = 0; + postFlag = 1; + wholeFlag = 0; + customFlag = 0; + elseif strcmpi(BaelineMethod,'whole') || strcmpi(BaelineMethod,'all') + noneFlag = 0; + preFlag = 0; + postFlag = 0; + wholeFlag = 1; + customFlag = 0; + else + noneFlag = 0; + preFlag = 1; + postFlag = 0; + wholeFlag = 0; + customFlag = 0; + end + end + gui_eegtab_binepoch.none.Value =noneFlag; + gui_eegtab_binepoch.pre.Value=preFlag; + gui_eegtab_binepoch.post.Value=postFlag; + gui_eegtab_binepoch.whole.Value=wholeFlag; + gui_eegtab_binepoch.custom.Value=customFlag; + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + if customFlag==1 + gui_eegtab_binepoch.custom_edit.String = num2str(BaelineMethod); + else + gui_eegtab_binepoch.custom_edit.String =''; + end + end + + +%%-------------------Setting for the whole panel of fitering based on ALLERP and CURRENTERP-------------- + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=14 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials~=1 || EEGUpdate==1 + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials~=1 + EEG_binepoch_box.TitleColor= [0.7500 0.7500 0.75000]; + else + EEG_binepoch_box.TitleColor= [0.0500 0.2500 0.5000]; + end + Enable_Label = 'off'; + else + if isempty(observe_EEGDAT.EEG.data)|| ~isfield(observe_EEGDAT.EEG,'EVENTLIST') || ~isfield(observe_EEGDAT.EEG.EVENTLIST,'eventinfo') || ~isfield(observe_EEGDAT.EEG.EVENTLIST.eventinfo,'binlabel') + Enable_Label = 'off'; + else + Enable_Label = 'on'; + end + EEG_binepoch_box.TitleColor= [0.0500 0.2500 0.5000]; + end + gui_eegtab_binepoch.timerange_edit.Enable = Enable_Label; + gui_eegtab_binepoch.none.Enable= Enable_Label; + gui_eegtab_binepoch.pre.Enable= Enable_Label; + gui_eegtab_binepoch.post.Enable= Enable_Label; + gui_eegtab_binepoch.whole.Enable= Enable_Label; + gui_eegtab_binepoch.custom.Enable= Enable_Label; + gui_eegtab_binepoch.custom_edit.Enable= Enable_Label; + gui_eegtab_binepoch.cancel.Enable= Enable_Label; + gui_eegtab_binepoch.apply.Enable= Enable_Label; + if ~isempty(observe_EEGDAT.EEG) && strcmpi(Enable_Label,'on') && gui_eegtab_binepoch.custom.Value==1 + gui_eegtab_binepoch.custom_edit.Enable = 'on'; + else + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + end + observe_EEGDAT.count_current_eeg =15; + end + +%%--------------press return to execute "Apply"---------------------------- + function eeg_binepoch_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_binepoch'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + apply_blc_dt(); + estudioworkingmemory('EEGTab_binepoch',0); + gui_eegtab_binepoch.apply.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.apply.ForegroundColor = [0 0 0]; + EEG_binepoch_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_binepoch.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=11 + return; + end + estudioworkingmemory('EEGTab_binepoch',0); + gui_eegtab_binepoch.apply.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.apply.ForegroundColor = [0 0 0]; + gui_eegtab_binepoch.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_binepoch.cancel.ForegroundColor = [0 0 0]; + gui_eegtab_binepoch.timerange_edit.String = '-200 800'; + gui_eegtab_binepoch.none.Value =0; + gui_eegtab_binepoch.pre.Value=1; + gui_eegtab_binepoch.post.Value=0; + gui_eegtab_binepoch.whole.Value=0; + gui_eegtab_binepoch.custom.Value=0; + gui_eegtab_binepoch.custom_edit.Enable = 'off'; + gui_eegtab_binepoch.custom_edit.String = ''; + estudioworkingmemory('pop_epochbin',{[-200 800] 'pre'}); + observe_EEGDAT.Reset_eeg_paras_panel=12; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end +%Progem end: ERP Measurement tool \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_chanoperation_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_chanoperation_GUI.m new file mode 100755 index 00000000..4c77cb52 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_chanoperation_GUI.m @@ -0,0 +1,863 @@ +%Author: Guanghui ZHANG && Steve LUCK +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +%Sep. 2023 + +% ERPLAB Studio + + + +function varargout = f_EEG_chanoperation_GUI(varargin) +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +gui_eegtab_chan_optn = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EEG_chan_operation_gui; +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end +if nargin == 0 + fig = figure(); % Parent figure + EEG_chan_operation_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Channel Operations', ... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EEG_chan_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Channel Operations',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + EEG_chan_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Channel Operations',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @chanop_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_erp_bin_operation(FonsizeDefault); +varargout{1} = EEG_chan_operation_gui; + + function drawui_erp_bin_operation(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.ALLEEG) && isempty(observe_EEGDAT.EEG) + Enable_label = 'off'; + else + Enable_label = 'on'; + end + %%--------------------channel and bin setting---------------------- + gui_eegtab_chan_optn.DataSelBox = uiextras.VBox('Parent', EEG_chan_operation_gui,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + end + gui_eegtab_chan_optn.erp_history_table = uiextras.HBox('Parent', gui_eegtab_chan_optn.DataSelBox,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.edit_bineq = uitable( ... + 'Parent' , gui_eegtab_chan_optn.erp_history_table,... + 'Data' , dsnames, ... + 'ColumnWidth' , {1000}, ... + 'ColumnName' , [], ... + 'RowName' , []); + gui_eegtab_chan_optn.Paras{1} = gui_eegtab_chan_optn.edit_bineq.Data; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,length(dsnames)),'FontSize',FontSize_defualt); + gui_eegtab_chan_optn.edit_bineq.KeyPressFcn= @eeg_chanop_presskey; + gui_eegtab_chan_optn.equation_selection = uiextras.HBox('Parent', gui_eegtab_chan_optn.DataSelBox,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.eq_editor = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.equation_selection,... + 'String','Advanced','callback',@eq_advanced,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_eegtab_chan_optn.eq_load = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.equation_selection,... + 'String','Load EQ','callback',@eq_load,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_eegtab_chan_optn.eq_save = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.equation_selection,... + 'String','Save EQ','callback',@eq_save,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_eegtab_chan_optn.eq_clear = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.equation_selection,... + 'String','Clear','callback',@eq_clear,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + + gui_eegtab_chan_optn.asst_locaInfo = uiextras.HBox('Parent', gui_eegtab_chan_optn.DataSelBox,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.ref_asst = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.asst_locaInfo,... + 'String','Reference Asst','callback',@ref_asst,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_eegtab_chan_optn.locaInfor = uicontrol('Style','checkbox','Parent',gui_eegtab_chan_optn.asst_locaInfo,... + 'String','','callback',@loca_infor,'FontSize',FontSize_defualt,'Value',1,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + gui_eegtab_chan_optn.locaInfor.String = 'Try to Preserve
                            Location Information'; + gui_eegtab_chan_optn.Paras{2} = gui_eegtab_chan_optn.locaInfor.Value; + set(gui_eegtab_chan_optn.asst_locaInfo,'Sizes',[105 180]); + %%%----------------Mode----------------------------------- + gui_eegtab_chan_optn.mode_1 = uiextras.HBox('Parent', gui_eegtab_chan_optn.DataSelBox,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.mode_modify_title = uicontrol('Style','text','Parent',gui_eegtab_chan_optn.mode_1 ,... + 'String','Mode:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + gui_eegtab_chan_optn.mode_modify = uicontrol('Style','radiobutton','Parent',gui_eegtab_chan_optn.mode_1 ,... + 'String','Modify Existing ERPset','callback',@mode_modify,'Value',1,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + gui_eegtab_chan_optn.mode_modify.KeyPressFcn= @eeg_chanop_presskey; + gui_eegtab_chan_optn.mode_modify.String = 'Modify Existing dataset
                            (recursive updating)'; + set(gui_eegtab_chan_optn.mode_1,'Sizes',[55 -1]); + gui_eegtab_chan_optn.Paras{3} =gui_eegtab_chan_optn.mode_modify.Value; + %%--------------For create a new ERPset---------------------------- + gui_eegtab_chan_optn.mode_2 = uiextras.HBox('Parent', gui_eegtab_chan_optn.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', gui_eegtab_chan_optn.mode_2,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.mode_create = uicontrol('Style','radiobutton','Parent',gui_eegtab_chan_optn.mode_2 ,... + 'String',{'', ''},'callback',@mode_create,'Value',0,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + gui_eegtab_chan_optn.mode_create.KeyPressFcn= @eeg_chanop_presskey; + gui_eegtab_chan_optn.mode_create.String = 'Create New dataset
                            (independent transformations)'; + set(gui_eegtab_chan_optn.mode_2,'Sizes',[55 -1]); + + %%-----------------Run--------------------------------------------- + gui_eegtab_chan_optn.run_title = uiextras.HBox('Parent', gui_eegtab_chan_optn.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', gui_eegtab_chan_optn.run_title,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.cancel = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.run_title,... + 'String','Cancel','callback',@chanop_cancel,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_eegtab_chan_optn.run_title,'BackgroundColor',ColorB_def); + gui_eegtab_chan_optn.chanop_apply = uicontrol('Style','pushbutton','Parent',gui_eegtab_chan_optn.run_title,... + 'String','Run','callback',@chanop_eeg_apply,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + uiextras.Empty('Parent', gui_eegtab_chan_optn.run_title,'BackgroundColor',ColorB_def); + set(gui_eegtab_chan_optn.run_title,'Sizes',[15 105 30 105 15]); + + set(gui_eegtab_chan_optn.DataSelBox,'Sizes',[130,30,35,35,35,30]); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%-------------------Equation editor--------------------------------------- + function eq_advanced(Source_editor,~) + if isempty(observe_EEGDAT.EEG) + Source_editor.Enable = 'off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_chanop',1); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [1 1 1]; + EEG_chan_operation_gui.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [1 1 1]; + + def = estudioworkingmemory('pop_eegchanoperator'); + if isempty(def) + def = { [], 1}; + end + chanopGUI = estudioworkingmemory('chanopGUI'); + if gui_eegtab_chan_optn.mode_modify.Value==1 + chanopGUI.emode=0; + else + chanopGUI.emode=1; + end + if isfield(chanopGUI,'hmode') + hmode = chanopGUI.hmode; + if isnumeric(hmode) + if numel(hmode)~=1 || (hmode~=0&& hmode~=1) + chanopGUI.hmode = 0; + end + else + chanopGUI.hmode = 0; + end + else + chanopGUI.hmode = 0; + end + if isfield(chanopGUI,'listname') + if ~ischar(chanopGUI.listname) + chanopGUI.listname = ''; + end + else + chanopGUI.listname = ''; + end + localInfor = gui_eegtab_chan_optn.locaInfor.Value; + chanopGUI.keeplocs = localInfor; + estudioworkingmemory('chanopGUI',chanopGUI); + + EEG = observe_EEGDAT.EEG; + answer = chanoperGUI(EEG, def); + if isempty(answer) + return + end + chanopGUI = estudioworkingmemory('chanopGUI'); + try ModeValue = chanopGUI.emode;catch ModeValue=0; end + if ModeValue==0 + gui_eegtab_chan_optn.mode_modify.Value=1 ; + gui_eegtab_chan_optn.mode_create.Value = 0; + else + gui_eegtab_chan_optn.mode_modify.Value=0 ; + gui_eegtab_chan_optn.mode_create.Value = 1; + end + try localInfor = chanopGUI.keeplocs;catch localInfor=1; end + if localInfor==1 + gui_eegtab_chan_optn.locaInfor.Value=1; + else + gui_eegtab_chan_optn.locaInfor.Value=0; + end + + formulas = answer{1}; + wbmsgon = answer{2}; + keeplocs = answer{3}; + if keeplocs ==1 + gui_eegtab_chan_optn.locaInfor.Value = 1; + else + gui_eegtab_chan_optn.locaInfor.Value = 0; + end + + def = {formulas, wbmsgon}; + estudioworkingmemory('pop_eegchanoperator', def); + for ii = 1:1000 + dsnames{ii,1} = ''; + end + + if ~isempty(def{1,1}) + Eqs = def{1,1}; + for ii = 1:length(def{1,1}) + dsnames{ii,1} = Eqs{ii}; + end + gui_eegtab_chan_optn.edit_bineq.Data = dsnames; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + end + end + +%%-------------------Equation Load--------------------------------------- + function eq_load(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_chanop',1); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [1 1 1]; + EEG_chan_operation_gui.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [1 1 1]; + + [filename, filepath] = uigetfile({'*.txt';'*.*'},'Select a formulas-file'); + if isequal(filename,0) + observe_EEGDAT.eeg_panel_message =2; + return + else + fullname = fullfile(filepath, filename); + disp(['f_EEG_chanoperation_GUI(): For formulas-file, user selected ', fullname]) + end + + fid_formula = fopen( fullname ); + try + formcell = textscan(fid_formula, '%s','delimiter', '\r'); + formulas = char(formcell{:}); + catch + msgboxText = ['Channel Operations - Please, check your file: '... + fullname]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if size(formulas,2)>256 + msgboxText = ['Channel Operations - Formulas length exceed 256 characters,'... + 'Be sure to press [Enter] after you have entered each formula.']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + fclose(fid_formula); + gui_eegtab_chan_optn.edit_bineq.Data = formcell{1,1}; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + end + + +%%------------------------------Save eq.----------------------------------- + function eq_save(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + + pathName = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName) + pathName = [cd,filesep]; + end + + Eq_Data = gui_eegtab_chan_optn.edit_bineq.Data; + Formula_str = {}; + count = 0; + for ii = 1:length(Eq_Data) + if ~isempty(Eq_Data{ii}) + count = count +1; + Formula_str{count} = Eq_Data{ii}; + end + end + msgboxText = ['Channel Operations >Save']; + estudioworkingmemory('f_EEG_proces_messg',msgboxText); + observe_EEGDAT.eeg_panel_message =1; + if isempty(Formula_str) + msgboxText = ['Channel Operations >Save - You have not yet written a formula']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [filename, filepath, filterindex] = uiputfile({'*.txt';'*.*'},'Save formulas-file as',pathName); + if isequal(filename,0) + observe_EEGDAT.eeg_panel_message =2; + return + else + [px, fname, ext] = fileparts(filename); + ext = '.txt'; + fname = [ fname ext]; + fullname = fullfile(filepath, fname); + fid_list = fopen( fullname , 'w'); + for i=1:length(Formula_str) + fprintf(fid_list,'%s\n', Formula_str{i}); + end + + fclose(fid_list); + disp(['Saving equation list at ' fullname '']) + end + observe_EEGDAT.eeg_panel_message =2; + end + +%%-------------------Equation Clear--------------------------------------- + function eq_clear(~,~) + + for ii = 1:1000 + dsnames{ii,1} = ''; + end + gui_eegtab_chan_optn.edit_bineq.Data = dsnames; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + end + +%%-------------------Reference assist-------------------------------------- + function ref_asst(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_chanop',1); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [1 1 1]; + EEG_chan_operation_gui.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [1 1 1]; + + gui_eegtab_chan_optn.mode_modify.Value = 0; + gui_eegtab_chan_optn.mode_create.Value = 1; + + try + EEG = observe_EEGDAT.EEG; + nchan = EEG.nbchan; + catch + EEG.chanlocs = []; + nchan = 1; + end + listch=[]; + if isempty(EEG.chanlocs) + for Numofchan=1:nchan + EEG.chanlocs(Numofchan).labels = ['Ch' num2str(Numofchan)]; + end + end + listch = cell(1,nchan); + for ch =1:nchan + listch{ch} = [num2str(ch) ' = ' EEG.chanlocs(ch).labels ]; + end + + % open reference wizard + formulalist = f_rerefassistantGUI(nchan, listch); + if isempty(formulalist) + return; + end + formulas = char(gui_eegtab_chan_optn.edit_bineq.Data); + for ii = 1:1000 + dsnames{ii,1} = ''; + end + + if gui_eegtab_chan_optn.mode_create.Value + formulalist = cellstr([formulalist{:}]); + for t=1:length(formulalist) + [expspliter parts] = regexp(formulalist, '=','match','split'); + formulalist{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '[^n]*ch','nch','ignorecase')), strtrim(parts{t}{2})); + end + end + if isempty(formulas) + for ii = 1:length(formulalist) + dsnames{ii,1} = formulalist{ii}; + end + gui_eegtab_chan_optn.edit_bineq.Data =dsnames; + else + formulas = cellstr(formulas); + count = 0; + for ii = 1:length(formulas) + if ~isempty(formulas{ii}) + count = count+1; + dsnames{count,1} = formulas{ii}; + end + end + + for ii = 1:length(formulalist) + dsnames{count+ii,1} = formulalist{ii}; + end + clear count; + gui_eegtab_chan_optn.edit_bineq.Data =dsnames; + end + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + end + +%%--------------------Preserve location information------------------------ + function loca_infor(source,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_chanop',1); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [1 1 1]; + EEG_chan_operation_gui.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [1 1 1]; + + Value = source.Value; + gui_eegtab_chan_optn.locaInfor.Value = Value; + end + +%%------------------Modify Existing ERPset--------------------------------------- + function mode_modify(Source_editor,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_chanop',1); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [1 1 1]; + EEG_chan_operation_gui.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [1 1 1]; + gui_eegtab_chan_optn.mode_modify.Value = 1; + gui_eegtab_chan_optn.mode_create.Value = 0; + + FormulaArrayIn = gui_eegtab_chan_optn.edit_bineq.Data; + if isempty(FormulaArrayIn) + val = 0; + def = estudioworkingmemory('pop_eegchanoperator'); + try FormulaArrayIn_default = def{1};catch FormulaArrayIn_default = '';end + if ~isempty(FormulaArrayIn_default) + [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn_default, 'recu'); + def{1} = formulaArray; + estudioworkingmemory('pop_eegchanoperator',def); + end + else + [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn, 'recu'); + end + if val ==1 + for ii = 1:100 + try + formulaArray{ii,1} = formulaArray{ii}; + catch + formulaArray{ii,1} = ''; + end + end + gui_eegtab_chan_optn.edit_bineq.Data =formulaArray; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + def = estudioworkingmemory('pop_eegchanoperator'); + if isempty(def) + def = { [], 1}; + end + def{1} = formulaArray; + estudioworkingmemory('pop_eegchanoperator',def); + end + end + +%%------------------Create New ERPset--------------------------------------- + function mode_create(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_chanop',1); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [1 1 1]; + EEG_chan_operation_gui.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [1 1 1]; + + gui_eegtab_chan_optn.mode_modify.Value = 0; + gui_eegtab_chan_optn.mode_create.Value = 1; + FormulaArrayIn = char(gui_eegtab_chan_optn.edit_bineq.Data); + if isempty(FormulaArrayIn) + val = 0; + def = estudioworkingmemory('pop_eegchanoperator'); + if isempty(def) + def = { [], 1}; + end + try + FormulaArrayIn_default = def{1}; + catch + FormulaArrayIn_default = ''; + end + if ~isempty(FormulaArrayIn_default) + [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn_default, 'norecu'); + def{1} = formulaArray; + estudioworkingmemory('pop_eegchanoperator',def); + else + for ii = 1:100 + formulaArray{ii,1} = ''; + end + end + else + [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn, 'norecu'); + end + if val ==1 + for ii = 1:100 + try + formulaArray{ii,1} = formulaArray{ii}; + catch + formulaArray{ii,1} = ''; + end + end + gui_eegtab_chan_optn.edit_bineq.Data =formulaArray; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + def = estudioworkingmemory('pop_eegchanoperator'); + if isempty(def) + def = { [], 1}; + end + def{1} = formulaArray; + estudioworkingmemory('pop_eegchanoperator',def); + end + end + +%%-----------------------cancel-------------------------------------------- + function chanop_cancel(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Channel Operations > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + estudioworkingmemory('EEGTab_chanop',0); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [0 0 0]; + EEG_chan_operation_gui.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [0 0 0]; + %% + Data = gui_eegtab_chan_optn.Paras{1}; + gui_eegtab_chan_optn.edit_bineq.Data=Data; + locaInfor = gui_eegtab_chan_optn.Paras{2}; + gui_eegtab_chan_optn.locaInfor.Value=locaInfor; + mode_modify = gui_eegtab_chan_optn.Paras{3}; + gui_eegtab_chan_optn.mode_modify.Value=mode_modify; + gui_eegtab_chan_optn.mode_create.Value=~mode_modify; + observe_EEGDAT.eeg_panel_message =2; + end + +%%---------------------Run------------------------------------------------- + function chanop_eeg_apply(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Channel Operations > Apply'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + estudioworkingmemory('EEGTab_chanop',0); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [0 0 0]; + EEG_chan_operation_gui.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [0 0 0]; + + pathName_def = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName_def) + pathName_def =cd; + end + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + Eq_Data = gui_eegtab_chan_optn.edit_bineq.Data; + Formula_str = {}; + count = 0; + for ii = 1:length(Eq_Data) + if ~isempty(Eq_Data{ii}) + count = count +1; + Formula_str{count} = Eq_Data{ii}; + end + end + + if isempty(Formula_str) + msgboxText = ['Channel Operations - You have not yet written a formula']; + estudioworkingmemory('f_EEG_proces_messg',msgboxText); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + %%check the format of equations + if gui_eegtab_chan_optn.mode_modify.Value + editormode = 0; + else + editormode = 1; + end + [option, recall, goeson] = checkformulas(cellstr(Formula_str), ['pop_eegchanoperator'], editormode); + if goeson==0 + msgboxText = ['Channel Operations - error might be found and please see Command Window']; + estudioworkingmemory('f_EEG_proces_messg',msgboxText); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + %%%Create a new ERPset for the bin-operated ERPsets + if gui_eegtab_chan_optn.locaInfor.Value==1 + keeplocs ='on'; + else + keeplocs ='off'; + end + gui_eegtab_chan_optn.Paras{1} = gui_eegtab_chan_optn.edit_bineq.Data; + gui_eegtab_chan_optn.Paras{2} = gui_eegtab_chan_optn.locaInfor.Value; + gui_eegtab_chan_optn.Paras{3} =gui_eegtab_chan_optn.mode_modify.Value; + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray)%%Bin Operations for each selected ERPset + EEG = ALLEEG(EEGArray(Numofeeg)); + [EEG, LASTCOM] = pop_eegchanoperator(EEG, Formula_str, 'Warning', 'off', 'Saveas', 'off','ErrorMsg', 'command','KeepChLoc',keeplocs, 'History', 'gui'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out EEG,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + ALLEEG_out(end).filename = EEG.filename; + ALLEEG_out(end).filepath = EEG.filepath; + end + + Save_file_label = []; + if gui_eegtab_chan_optn.mode_create.Value + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_chop'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + + if gui_eegtab_chan_optn.mode_modify.Value%% If select "Modify Existing EEGset (recursive updating)" + ALLEEG(EEGArray)=ALLEEG_out; + elseif gui_eegtab_chan_optn.mode_create.Value==1 %% If select "Create New EEGset (independent transformations)" + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + if Numofeeg==1 + eegh(LASTCOM); + end + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label==1 && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG EEG,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + + end + end + observe_EEGDAT.ALLEEG = ALLEEG; + if gui_eegtab_chan_optn.mode_create.Value%%Save the labels of the selected ERPsets + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + estudioworkingmemory('EEGArray',Selected_EEG_afd); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Setting current ERPset/session history based on the current updated ERPset------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=6 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || EEGUpdate==1 + Enable_label = 'off'; + end + if ~isempty(observe_EEGDAT.EEG) + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) <=0 || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + ChaNumAll = []; + for Numofeeg = 1:numel(EEGArray) + ChaNumAll(Numofeeg) = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)).nbchan; + end + + if numel(EEGArray)>1 && numel(unique(ChaNumAll)) >1 + Enable_label = 'off'; + for ii = 1:100 + if ii==1 + dsnames{ii,1} = 'The number of channels should be the same for the selected EEGsets!'; + else + dsnames{ii,1} = ''; + end + end + gui_eegtab_chan_optn.edit_bineq.Data = dsnames; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + else + Enable_label = 'on'; + chanopDataor = gui_eegtab_chan_optn.edit_bineq.Data; + for ii = 1:100 + chanopDataorcell = char(chanopDataor{ii,1}); + aa = 'The number of channels should be the same for the selected EEGsets!'; + if isempty(chanopDataorcell) || strcmpi(chanopDataorcell,aa) + dsnames{ii,1} = ''; + else + dsnames{ii,1} = chanopDataorcell; + end + end + gui_eegtab_chan_optn.edit_bineq.Data = dsnames; + set(gui_eegtab_chan_optn.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); + end + end + if EEGUpdate==1 + Enable_label = 'off'; + end + gui_eegtab_chan_optn.mode_modify.Enable=Enable_label; + gui_eegtab_chan_optn.mode_create.Enable=Enable_label; + gui_eegtab_chan_optn.eq_save.Enable = Enable_label; + gui_eegtab_chan_optn.eq_editor.Enable = Enable_label; + gui_eegtab_chan_optn.eq_load.Enable = Enable_label; + gui_eegtab_chan_optn.eq_clear.Enable = Enable_label; + gui_eegtab_chan_optn.chanop_apply.Enable = Enable_label; + gui_eegtab_chan_optn.ref_asst.Enable = Enable_label; + gui_eegtab_chan_optn.locaInfor.Enable = Enable_label; + gui_eegtab_chan_optn.cancel.Enable = Enable_label; + observe_EEGDAT.count_current_eeg =7; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_chanop_presskey(hObject, eventdata) + if isempty(observe_EEGDAT.EEG) + return; + end + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_chanop'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + chanop_eeg_apply(); + estudioworkingmemory('EEGTab_chanop',0); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [0 0 0]; + EEG_chan_operation_gui.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=6 + return; + end + estudioworkingmemory('EEGTab_chanop',0); + gui_eegtab_chan_optn.chanop_apply.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.chanop_apply.ForegroundColor = [0 0 0]; + % EEG_chan_operation_gui.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_chan_optn.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_chan_optn.cancel.ForegroundColor = [0 0 0]; + for ii = 1:100 + dsnames{ii,1} = ''; + end + gui_eegtab_chan_optn.edit_bineq.Data= dsnames; + gui_eegtab_chan_optn.locaInfor.Value=1; + gui_eegtab_chan_optn.mode_modify.Value = 1; + gui_eegtab_chan_optn.mode_create.Value = 0; + observe_EEGDAT.Reset_eeg_paras_panel=7; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; + +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_dq_epoch_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_dq_epoch_GUI.m new file mode 100644 index 00000000..13debff6 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_dq_epoch_GUI.m @@ -0,0 +1,662 @@ +%%This function is to compute Data Quality Metrics (Epoched EEG). + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 + + +function varargout = f_EEG_dq_epoch_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +%---------------------------Initialize parameters------------------------------------ +EEG_dq_epoch = struct(); +%-----------------------------Name the title---------------------------------------------- + +% global Eegtab_box_dq_epoch; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_dq_epoch = uiextras.BoxPanel('Parent', fig, 'Title', 'Compute Data Quality Metrics (Epoched EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_dq_epoch = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Compute Data Quality Metrics (Epoched EEG)', ... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_dq_epoch = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Compute Data Quality Metrics (Epoched EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @dq_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_dq_epoch_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_dq_epoch; + + function drawui_dq_epoch_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EEG_dq_epoch.DataSelBox = uiextras.VBox('Parent', Eegtab_box_dq_epoch,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + def = estudioworkingmemory('pop_DQ_preavg'); + if isempty(def) || numel(def)~=12 + % Should not be empty, and have exactly 12 elements. Else, fallback to: + def = {1 1 1 1 1 0 0 [] 1 [] 1 0}; + end + try + DQcustom_wins = def{12}; + catch + DQcustom_wins = 0; + end + oldDQ = def{10}; + EEG_dq_epoch.DQ_spec = []; + if isempty(oldDQ) + dq_times_def = [1:6;-100:100:400;0:100:500]'; + EEG_dq_epoch.dq_times = dq_times_def; + EEG_dq_epoch.DQ_spec = []; + else + try + dq_times_def = oldDQ(3).times; + EEG_dq_epoch.dq_times = dq_times_def; + EEG_dq_epoch.DQ_spec = oldDQ; + catch + dq_times_def = [1:6;-100:100:400;0:100:500]'; + EEG_dq_epoch.dq_times = dq_times_def; + EEG_dq_epoch.DQ_spec = oldDQ; + end + end + try + EEG_dq_epoch.DQpreavg_txt =def{11}; + catch + EEG_dq_epoch.DQpreavg_txt =1; + end + + EEG_dq_epoch.para_title1 = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_dq_epoch.para_title1,'HorizontalAlignment','center','FontWeight','bold',... + 'String','Data Quality Quantification:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on','BackgroundColor',ColorB_def); % 2F + %%Default Parameters + EEG_dq_epoch.para_title2 = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_epoch.def_para = uicontrol('Style','radiobutton','Parent',EEG_dq_epoch.para_title2,'HorizontalAlignment','left',... + 'callback',@def_para,'String','Default parameters','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_dq_epoch.def_para.KeyPressFcn= @eeg_shiftcodes_presskey; + + uiextras.Empty('Parent', EEG_dq_epoch.para_title2 ,'BackgroundColor',ColorB_def); + set(EEG_dq_epoch.para_title2,'Sizes',[150,-1]); + + + %%Custom Parameters + EEG_dq_epoch.para_title3 = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_epoch.custom_para = uicontrol('Style','radiobutton','Parent',EEG_dq_epoch.para_title3,'HorizontalAlignment','left',... + 'callback',@custom_para,'String','Custom parameters','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_dq_epoch.def_para.KeyPressFcn= @eeg_shiftcodes_presskey; + + if DQcustom_wins==0 + EEG_dq_epoch.def_para.Value = 1; + EEG_dq_epoch.custom_para.Value=0; + else + EEG_dq_epoch.def_para.Value = 0; + EEG_dq_epoch.custom_para.Value=1; + end + EEG_dq_epoch.custom_para_op = uicontrol('Style','pushbutton','Parent',EEG_dq_epoch.para_title3,'HorizontalAlignment','left',... + 'callback',@custom_para_op,'String','Options','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 2F + uiextras.Empty('Parent', EEG_dq_epoch.para_title3 ,'BackgroundColor',ColorB_def); + set(EEG_dq_epoch.para_title3,'Sizes',[150,60 -1]); + + try + artcrite = def{2}; + catch + artcrite=1; + end + if artcrite==0 + Valueround1 = 1; + Valueround2 =0; + Valueround3 = 0; + elseif artcrite==2 + Valueround1 = 0; + Valueround2 =0; + Valueround3 = 1; + else + Valueround1 = 0; + Valueround2 = 1; + Valueround3 = 0; + end + %%Round to arlier time sample (recommended) + EEG_dq_epoch.movewindow_title1 = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_dq_epoch.movewindow_title1,'HorizontalAlignment','center','FontWeight','bold',... + 'String','Epochs to Include in DQ metrics:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on','BackgroundColor',ColorB_def); % 2F + + %%all epochs + EEG_dq_epoch.movewindow_title = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_epoch.all_marks = uicontrol('Style','radiobutton','Parent',EEG_dq_epoch.movewindow_title,'HorizontalAlignment','left',... + 'callback',@all_marks,'String','Include All epochs (ignore artifact detections)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_dq_epoch.all_marks.KeyPressFcn= @eeg_shiftcodes_presskey; + uiextras.Empty('Parent', EEG_dq_epoch.movewindow_title ,'BackgroundColor',ColorB_def); + set(EEG_dq_epoch.movewindow_title,'Sizes',[270,-1]); + + %%exclude marked epochs + EEG_dq_epoch.windowstep_title = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_epoch.excld_marks = uicontrol('Style','radiobutton','Parent',EEG_dq_epoch.windowstep_title,'HorizontalAlignment','left',... + 'callback',@excld_marks,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_dq_epoch.excld_marks.String = 'Exclude epochs marked during artifact
                            detection (highly recommended)'; + EEG_dq_epoch.excld_marks.KeyPressFcn= @eeg_shiftcodes_presskey; + uiextras.Empty('Parent',EEG_dq_epoch.windowstep_title ,'BackgroundColor',ColorB_def); + set(EEG_dq_epoch.windowstep_title,'Sizes',[260,-1]); + + %%marked epochs + EEG_dq_epoch.eventcode_title = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_epoch.marked_epochs = uicontrol('Style','radiobutton','Parent',EEG_dq_epoch.eventcode_title,'HorizontalAlignment','left',... + 'callback',@marked_epochs,'String','','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_dq_epoch.marked_epochs.String = 'Include ONLY epochs marked with artifact
                            detection (by cautious!)'; + uiextras.Empty('Parent', EEG_dq_epoch.eventcode_title ); + set(EEG_dq_epoch.eventcode_title,'Sizes',[260,-1]); + EEG_dq_epoch.all_marks.Value = Valueround1; + EEG_dq_epoch.excld_marks.Value = Valueround2; + EEG_dq_epoch.marked_epochs.Value = Valueround3; + + %%-----------------------Cancel and Run---------------------------- + EEG_dq_epoch.detar_run_title = uiextras.HBox('Parent', EEG_dq_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_dq_epoch.detar_run_title,'BackgroundColor',ColorB_def); + EEG_dq_epoch.dq_cancel = uicontrol('Style', 'pushbutton','Parent',EEG_dq_epoch.detar_run_title,... + 'String','Cancel','callback',@dq_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_dq_epoch.detar_run_title,'BackgroundColor',ColorB_def); + EEG_dq_epoch.dq_run = uicontrol('Style','pushbutton','Parent',EEG_dq_epoch.detar_run_title,... + 'String','Run','callback',@dq_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_dq_epoch.detar_run_title,'BackgroundColor',ColorB_def); + set(EEG_dq_epoch.detar_run_title,'Sizes',[15 105 30 105 15]); + + set(EEG_dq_epoch.DataSelBox,'Sizes',[20 25 25 20 25 30 30 30]); + estudioworkingmemory('EEGTab_dq_epoch',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%--------------------------------default parameters----------------------- + function def_para(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_epoch.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [1 1 1]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_epoch',1); + EEG_dq_epoch.def_para.Value=1; + EEG_dq_epoch.custom_para.Value=0; + EEG_dq_epoch.custom_para_op.Enable = 'off'; + end + +%%-------------------------custom parameters------------------------------- + function custom_para(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_epoch.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [1 1 1]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_epoch',1); + EEG_dq_epoch.def_para.Value=0; + EEG_dq_epoch.custom_para.Value=1; + EEG_dq_epoch.custom_para_op.Enable = 'on'; + end + +%%------------------------Custom define------------------------------------ + function custom_para_op(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_epoch.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [1 1 1]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_epoch',1); + + timelimits = 1000 * [observe_EEGDAT.EEG.xmin observe_EEGDAT.EEG.xmax]; + old_DQ_spec = EEG_dq_epoch.DQ_spec; + custom_DQ_spec = avg_data_quality(old_DQ_spec,timelimits); + EEG_dq_epoch.timelimits = timelimits; + if ~isempty(custom_DQ_spec) + EEG_dq_epoch.DQ_spec = custom_DQ_spec; + end + + end + +%%---------------------------all epochs------------------------------------ + function all_marks(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_epoch.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [1 1 1]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_run.ForegroundColor = [1 1 1]; + + estudioworkingmemory('EEGTab_dq_epoch',1); + EEG_dq_epoch.all_marks.Value = 1; + EEG_dq_epoch.excld_marks.Value = 0; + EEG_dq_epoch.marked_epochs.Value = 0; + end + + +%%-------------------------exclude marked epochs--------------------------- + function excld_marks(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_epoch.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [1 1 1]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_epoch',1); + + EEG_dq_epoch.all_marks.Value = 0; + EEG_dq_epoch.excld_marks.Value = 1; + EEG_dq_epoch.marked_epochs.Value = 0; + end + + +%%-------------------------Only marked epochs------------------------------ + function marked_epochs(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_epoch.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [1 1 1]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_epoch.dq_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_epoch',1); + EEG_dq_epoch.all_marks.Value = 0; + EEG_dq_epoch.excld_marks.Value = 0; + EEG_dq_epoch.marked_epochs.Value = 1; + end + + +%%%----------------------Preview------------------------------------------- + function dq_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Compute Data Quality Metrics (Epoched EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + Eegtab_box_dq_epoch.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [1 1 1]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [0 0 0]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 1 1 1]; + EEG_dq_epoch.dq_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_dq_epoch',0); + + def = estudioworkingmemory('pop_DQ_preavg'); + if isempty(def) || numel(def)~=12 + % Should not be empty, and have exactly 12 elements. Else, fallback to: + def = {1 1 1 1 1 0 0 [] 1 [] 1 0}; + end + try + DQcustom_wins = def{12}; + catch + DQcustom_wins = 0; + end + + if DQcustom_wins==0 + EEG_dq_epoch.def_para.Value = 1; + EEG_dq_epoch.custom_para.Value=0; + EEG_dq_epoch.custom_para_op.Enable = 'off'; + EEG_dq_epoch.timelimits = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + DQ_defaults = make_DQ_spec([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + EEG_dq_epoch.DQ_spec=DQ_defaults; + else + EEG_dq_epoch.def_para.Value = 0; + EEG_dq_epoch.custom_para.Value=1; + EEG_dq_epoch.custom_para_op.Enable = 'on'; + end + %%setting for selection of epoch types + try + artcrite = def{2}; + catch + artcrite=1; + end + if artcrite==0 + Valueround1 = 1; + Valueround2 =0; + Valueround3 = 0; + elseif artcrite==2 + Valueround1 = 0; + Valueround2 =0; + Valueround3 = 1; + else + Valueround1 = 0; + Valueround2 = 1; + Valueround3 = 0; + end + EEG_dq_epoch.all_marks.Value = Valueround1; + EEG_dq_epoch.excld_marks.Value = Valueround2; + EEG_dq_epoch.marked_epochs.Value = Valueround3; + + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------------Shift events-------------------------------------- + function dq_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=16 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Compute Data Quality Metrics (Epoched EEG) > Shift events'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_dq_epoch.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [1 1 1]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [0 0 0]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 1 1 1]; + EEG_dq_epoch.dq_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_dq_epoch',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + incALL=EEG_dq_epoch.all_marks.Value; + excart=EEG_dq_epoch.excld_marks.Value; + onlyart=EEG_dq_epoch.marked_epochs.Value; + incart = 0; + incIndx = 0; + excbound = 1; % exclude epochs having boundary events + Tspectrum = 0; % total power spectrum + Espectrum = 0; % evoked power spectrum + iswindowed = 0; + winparam = ''; + compu2do = 0; %do ERP only + + if incALL + artcrite = 0; + + elseif excart + artcrite = 1; + else + artcrite = 2; + end + try + DQ_defaults = make_DQ_spec(EEG_dq_epoch.timelimits); + catch + EEG_dq_epoch.timelimits = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + DQ_defaults = make_DQ_spec([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + end + DQ_defaults(1).comments{1} = 'Defaults'; + + + DQ_flag = max(EEG_dq_epoch.def_para.Value,EEG_dq_epoch.custom_para.Value); + + use_defaults = EEG_dq_epoch.def_para.Value; + if DQ_flag + stderror = 1; + if use_defaults || isempty(EEG_dq_epoch.DQ_spec) + DQ_spec = DQ_defaults; + else + DQ_spec = EEG_dq_epoch.DQ_spec; + end + else + stderror = 0; + DQ_spec = []; + end + + if EEG_dq_epoch.def_para.Value==1 + DQ_customWins = 0; + else + DQ_customWins = 1; + end + try + DQ_preavg_txt = EEG_dq_epoch.DQpreavg_txt; + catch + DQ_preavg_txt=1; + end + wavg = 1; + + answer = {EEGArray(1), artcrite, wavg, stderror, excbound, compu2do, iswindowed, winparam,DQ_flag,DQ_spec,DQ_preavg_txt,DQ_customWins}; + + artcrite = answer{2}; + if ~iscell(artcrite) + if artcrite==0 + artcritestr = 'all'; + elseif artcrite==1 + artcritestr = 'good'; + elseif artcrite==2 + artcritestr = 'bad'; + else + artcritestr = artcrite; + end + else + artcritestr = artcrite; % fixed bug. May 1, 2012 + end + + stderror = answer{4}; + + % exclude epochs having boundary events + excbound = answer{5}; + + % Compute ERP, evoked power spectrum (EPS), and total power + % spectrum (TPS). + compu2do = answer{6}; % 0:ERP; 1:ERP+TPS; 2:ERP+EPS; 3:ERP+BOTH + wintype = answer{7}; % taper data with window: 0:no; 1:yes + wintfunc = answer{8}; % taper function and (sub)window + + % Write the analytic Standardized Measurment Error info + DQ_flag = answer{9}; + DQ_spec = answer{10}; + DQ_preavg_txt = answer{11}; + DQcustom_wins = answer{12}; + + answer(1:12) = {EEGArray(1), artcrite, 1, stderror, excbound, compu2do, wintype, wintfunc,DQ_flag,DQ_spec,DQ_preavg_txt,DQcustom_wins}; + estudioworkingmemory('pop_DQ_preavg', answer); + + if stderror==1 + stdsstr = 'on'; + else + stdsstr = 'off'; + end + if excbound==1 + excboundstr = 'on'; + else + excboundstr = 'off'; + end + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLERP = []; + for Numofeeg = 1:numel(EEGArray) + setindex =EEGArray(Numofeeg); + EEG = ALLEEG(setindex); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Compute Data Quality Metrics (Epoched EEG) > Apply*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %% Run the pop_ command with the user input from the GUI + [ERPpreavg, erpcom] = pop_averager(ALLEEG, 'DSindex', setindex, 'Criterion', artcritestr,... + 'SEM', stdsstr, 'Saveas', 'off', 'Warning', 'off', 'ExcludeBoundary', excboundstr,... + 'DQ_flag',DQ_flag,'DQ_spec',DQ_spec, 'DQ_preavg_txt', DQ_preavg_txt,'DQ_custom_wins', DQcustom_wins, 'History', ''); + + ERPpreavg.erpname = ALLEEG(setindex).setname; %setname instead of erpname in DQ Table + LASTCOM = 'pop_DQ_preavg(ALLEEG);'; + if Numofeeg==1 + ALLERP=ERPpreavg; + else + ALLERP(Numofeeg) = ERPpreavg; + end + disp(LASTCOM); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end for loop of subjects + CURRENTPREAVG = 1; + DQ_Table_GUI(ALLERP(1),ALLERP,CURRENTPREAVG,1); + + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + assignin('base','EEG',observe_EEGDAT.EEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=22 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 || EEGUpdate==1 + EEG_dq_epoch.def_para.Enable= 'off'; + EEG_dq_epoch.custom_para.Enable= 'off'; + EEG_dq_epoch.custom_para_op.Enable = 'off'; + EEG_dq_epoch.all_marks.Enable= 'off'; + EEG_dq_epoch.excld_marks.Enable= 'off'; + EEG_dq_epoch.marked_epochs.Enable= 'off'; + EEG_dq_epoch.dq_run.Enable= 'off'; + EEG_dq_epoch.dq_cancel.Enable= 'off'; + + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ==1 + Eegtab_box_dq_epoch.TitleColor= [0.7500 0.7500 0.75000]; + else + Eegtab_box_dq_epoch.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=23; + return; + end + Eegtab_box_dq_epoch.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_epoch.timelimits = [observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]; + if EEG_dq_epoch.def_para.Value==1 + DQ_defaults = make_DQ_spec([observe_EEGDAT.EEG.times(1),observe_EEGDAT.EEG.times(end)]); + EEG_dq_epoch.DQ_spec=DQ_defaults; + end + EEG_dq_epoch.def_para.Enable= 'on'; + EEG_dq_epoch.custom_para.Enable= 'on'; + EEG_dq_epoch.custom_para_op.Enable = 'on'; + EEG_dq_epoch.all_marks.Enable= 'on'; + EEG_dq_epoch.excld_marks.Enable= 'on'; + EEG_dq_epoch.marked_epochs.Enable= 'on'; + EEG_dq_epoch.dq_run.Enable= 'on'; + EEG_dq_epoch.dq_cancel.Enable= 'on'; + if EEG_dq_epoch.def_para.Value==1 + EEG_dq_epoch.custom_para_op.Enable = 'off'; + end + observe_EEGDAT.count_current_eeg=23; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_shiftcodes_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_dq_epoch'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + dq_run(); + estudioworkingmemory('EEGTab_dq_epoch',0); + Eegtab_box_dq_epoch.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_epoch.dq_cancel.BackgroundColor = [1 1 1]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [0 0 0]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 1 1 1]; + EEG_dq_epoch.dq_run.ForegroundColor = [0 0 0]; + else + return; + end + end + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=18 + return; + end + estudioworkingmemory('EEGTab_dq_epoch',0); + EEG_dq_epoch.dq_cancel.BackgroundColor = [1 1 1]; + EEG_dq_epoch.dq_cancel.ForegroundColor = [0 0 0]; + EEG_dq_epoch.dq_run.BackgroundColor = [ 1 1 1]; + EEG_dq_epoch.dq_run.ForegroundColor = [0 0 0]; + + EEG_dq_epoch.def_para.Value=1; + EEG_dq_epoch.custom_para.Value=0; + EEG_dq_epoch.custom_para_op.Enable = 'off'; + EEG_dq_epoch.all_marks.Value = 1; + EEG_dq_epoch.excld_marks.Value = 0; + EEG_dq_epoch.marked_epochs.Value = 0; + observe_EEGDAT.Reset_eeg_paras_panel=19; + end + +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_dq_fre_conus_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_dq_fre_conus_GUI.m new file mode 100644 index 00000000..7a83844d --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_dq_fre_conus_GUI.m @@ -0,0 +1,564 @@ +%%This function is to compute Spectral Data Quality (Continuous EEG). + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 + + +function varargout = f_EEG_dq_fre_conus_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ +EEG_dq_fre_conus = struct(); +%-----------------------------Name the title---------------------------------------------- + +% global Eegtab_box_dq_fre_conus; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_dq_fre_conus = uiextras.BoxPanel('Parent', fig, 'Title', 'Spectral Data Quality (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_dq_fre_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Spectral Data Quality (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_dq_fre_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Spectral Data Quality (Continuous EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @freqd_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_dq_fre_conus_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_dq_fre_conus; + + function drawui_dq_fre_conus_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EEG_dq_fre_conus.DataSelBox = uiextras.VBox('Parent', Eegtab_box_dq_fre_conus,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + def_labels = {'delta','theta','alpha','beta','gamma','50hz-noise','60hz-noise','broadband'}; %defaults + def_bands = [0 3;3 8;8 12;8 30;30 48;49 51;59 61;0 256]; %default bands + + defx = {[] def_bands def_labels'}; + def = estudioworkingmemory('pop_continuousFFT'); + + if isempty(def) + def = defx; + end + try + fqband = def{2}; + fqlabels = def{3}; + catch + fqband = [0 3;3 8;8 12;8 30;30 48;49 51;59 61; 0 256]; %defaults + fqlabels = {'delta','theta','alpha','beta','gamma','50hz-noise','60hz-noise','broadband'}; + end + data_tab = [fqlabels num2cell(fqband)]; + + %%Event codes + EEG_dq_fre_conus.chan_title = uiextras.HBox('Parent', EEG_dq_fre_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_dq_fre_conus.chan_title,'HorizontalAlignment','left',... + 'String','Chans:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + EEG_dq_fre_conus.chans_edit = uicontrol('Style','edit','Parent',EEG_dq_fre_conus.chan_title,... + 'String','','FontSize',FontSize_defualt,'callback',@chans_edit,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_dq_fre_conus.chans_edit.KeyPressFcn= @eeg_shiftcodes_presskey; + EEG_dq_fre_conus.chans_browse = uicontrol('Style','pushbutton','Parent',EEG_dq_fre_conus.chan_title,... + 'String','Browse','FontSize',FontSize_defualt,'callback',@chans_browse,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + set( EEG_dq_fre_conus.chan_title,'Sizes',[60 -1,60]); + + EEG_dq_fre_conus.bandtable_title = uiextras.HBox('Parent', EEG_dq_fre_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_fre_conus.bandtable = uitable( ... + 'Parent' , EEG_dq_fre_conus.bandtable_title,... + 'Data' , data_tab, ... + 'ColumnName' , {'Lable','Low Hz','High Hz'}); + EEG_dq_fre_conus.bandtable.CellSelectionCallback = @selectedrow; + EEG_dq_fre_conus.sel_row = size(EEG_dq_fre_conus.bandtable.Data,1); % set to max on load + EEG_dq_fre_conus.bandtable.ColumnEditable = [true,true,true]; + EEG_dq_fre_conus.bandtable.CellEditCallback = @checkcellchanged; + EEG_dq_fre_conus.bandtable.Enable = 'off'; + %%Round to later time sample + EEG_dq_fre_conus.eventcode_title = uiextras.HBox('Parent', EEG_dq_fre_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_dq_fre_conus.add_rows = uicontrol('Style','pushbutton','Parent',EEG_dq_fre_conus.eventcode_title,'HorizontalAlignment','left',... + 'callback',@add_rows,'String','+Add a row ','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 2F + EEG_dq_fre_conus.remove_rows = uicontrol('Style','pushbutton','Parent',EEG_dq_fre_conus.eventcode_title,'HorizontalAlignment','left',... + 'callback',@remove_rows,'String','-Remove selected rows','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 2F + EEG_dq_fre_conus.resetable = uicontrol('Style','pushbutton','Parent',EEG_dq_fre_conus.eventcode_title,'HorizontalAlignment','left',... + 'callback',@resetable,'String','Reset','FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 2F + set(EEG_dq_fre_conus.eventcode_title,'Sizes',[70,140,-1]); + + %%-----------------------Cancel and Run---------------------------- + EEG_dq_fre_conus.detar_run_title = uiextras.HBox('Parent', EEG_dq_fre_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_dq_fre_conus.detar_run_title,'BackgroundColor',ColorB_def); + EEG_dq_fre_conus.dq_fre_cancel = uicontrol('Style', 'pushbutton','Parent',EEG_dq_fre_conus.detar_run_title,... + 'String','Cancel','callback',@dq_fre_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_dq_fre_conus.detar_run_title,'BackgroundColor',ColorB_def); + EEG_dq_fre_conus.dq_fre_run = uicontrol('Style','pushbutton','Parent',EEG_dq_fre_conus.detar_run_title,... + 'String','Run','callback',@dq_fre_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_dq_fre_conus.detar_run_title,'BackgroundColor',ColorB_def); + set(EEG_dq_fre_conus.detar_run_title,'Sizes',[15 105 30 105 15]); + + set(EEG_dq_fre_conus.DataSelBox,'Sizes',[30 160 30 30]); + estudioworkingmemory('EEGTab_dq_fre_conus',0); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + + +%%----------------------check changed cell(s)------------------------------ + function checkcellchanged(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_fre_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_fre_conus',1); + + Data = EEG_dq_fre_conus.bandtable.Data; + [rowNum,columNum] = size(Data); + for Numofrow = 1:rowNum + for Numofcolumn = 2:columNum + datacell = Data{Numofrow,Numofcolumn}; + if ~isnumeric(datacell) + Data{Numofrow,Numofcolumn} = str2num(char(datacell)); + end + end + end + EEG_dq_fre_conus.bandtable.Data = Data; + end + + +%%----------------------edit chans----------------------------------------- + function chans_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_fre_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_fre_conus',1); + + ChaNum = observe_EEGDAT.EEG.nbchan; + ChanArray = str2num(Source.String); + if isempty(ChanArray) || any(ChanArray(:)<=0) + msgboxText = ['Spectral Data Quality (Continuous EEG) > Index(es) of chans should be positive number(s)']; + Source.String= vect2colon([1:ChaNum]); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if any(ChanArray(:)> ChaNum) + msgboxText = ['Spectral Data Quality (Continuous EEG) > Index(es) of chans should be between 1 and ',32,num2str(ChaNum)]; + Source.String= vect2colon([1:ChaNum]); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + ChanArray = vect2colon(ChanArray); + ChanArray = erase(ChanArray,{'[',']'}); + Source.String = ChanArray; + end + + + +%%--------------------------Browse event codes----------------------------- + function chans_browse(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_fre_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [1 1 1]; + + %%-------Browse and select chans--------- + EEG = observe_EEGDAT.EEG; + for Numofchan = 1:EEG.nbchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',EEG.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + ChanArray = str2num(EEG_dq_fre_conus.chans_edit.String); + if isempty(ChanArray) + indxlistb = EEG.nbchan; + else + if min(ChanArray(:)) >0 && max(ChanArray(:)) <= EEG.nbchan + indxlistb = ChanArray; + else + indxlistb = 1:EEG.nbchan; + end + end + titlename = 'Select Channel(s):'; + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + chan_label_select = vect2colon(chan_label_select); + chan_label_select = erase(chan_label_select,{'[',']'}); + EEG_dq_fre_conus.chans_edit.String = chan_label_select; + else + return + end + end + +%%------------------Ignore/use--------------------------------------------- + function add_rows(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_fre_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_fre_conus',1); + EEG_dq_fre_conus.add_rows.Value = 1; + + curr_rows = size(EEG_dq_fre_conus.bandtable.Data,1); + new_rows = curr_rows + 1; + old_fqout = EEG_dq_fre_conus.bandtable.Data; + new_row_str = ['Custom Band' num2str(new_rows)]; + new_row_cell = {new_row_str,[],[]}; + new_fqout = [old_fqout;new_row_cell]; + set(EEG_dq_fre_conus.bandtable,'Data',new_fqout); + end + + +%%----------------------------Remove selected row-------------------------- + function remove_rows(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + Eegtab_box_dq_fre_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_fre_conus',1); + + curr_rows = size(EEG_dq_fre_conus.bandtable.Data,1); + row_del = EEG_dq_fre_conus.sel_row; + if curr_rows <= 1 + msgboxText = ['Spectral Data Quality (Continuous EEG) > Remove selected rows: Already at 1 rows']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + else + new_rows = curr_rows - 1; + new_Tout = EEG_dq_fre_conus.bandtable.Data; + new_Tout(row_del,:) = []; % pop the selected row out + set(EEG_dq_fre_conus.bandtable,'Data',new_Tout) + pause(0.3); + EEG_dq_fre_conus.sel_row = new_rows; + end + end + + +%%---------------------Reset table----------------------------------------- + function resetable(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_dq_fre_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_dq_fre_conus',1); + + fqnyq = observe_EEGDAT.EEG.srate/2; + def_labels = {'delta','theta','alpha','beta','gamma','50hz-noise','60hz-noise','broadband'}; %defaults + def_bands = [0 3;3 8;8 12;8 30;30 48;49 51;59 61; 0 fqnyq]; + %make table + data_tab = [def_labels' num2cell(def_bands)]; + EEG_dq_fre_conus.bandtable.Data = data_tab; + end + + +%%-------------------------capture the selected row------------------------ + function selectedrow(Source,eventdata) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + if numel(eventdata.Indices) + row_here = eventdata.Indices(1); + EEG_dq_fre_conus.sel_row = row_here; + end + EEG_dq_fre_conus.bandtable.ColumnEditable = [true,true,true]; + end + + + +%%%----------------------Preview------------------------------------------- + function dq_fre_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Spectral Data Quality (Continuous EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + Eegtab_box_dq_fre_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [0 0 0]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 1 1 1]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_dq_fre_conus',0); + + chan_label_select = [1:observe_EEGDAT.EEG.nbchan]; + EEG_dq_fre_conus.chans_edit.String = vect2colon(chan_label_select); + fqnyq = observe_EEGDAT.EEG.srate/2; + def_labels = {'delta','theta','alpha','beta','gamma','50hz-noise','60hz-noise','broadband'}; %defaults + def_bands = [0 3;3 8;8 12;8 30;30 48;49 51;59 61; 0 fqnyq]; + %make table + data_tab = [def_labels' num2cell(def_bands)]; + EEG_dq_fre_conus.bandtable.Data = data_tab; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------------Shift events-------------------------------------- + function dq_fre_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Spectral Data Quality (Continuous EEG) > Run'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_dq_fre_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [0 0 0]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 1 1 1]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_dq_fre_conus',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + chanArray = str2num(EEG_dq_fre_conus.chans_edit.String); + bnchan = observe_EEGDAT.EEG.nbchan; + if isempty(chanArray) || any(chanArray(:)<=0) || any(chanArray(:)>bnchan) + msgboxText = ['Spectral Data Quality (Continuous EEG) > Run: Index(es) of the chans must be between 1 and ',32,num2str(bnchan)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + fqbands = [EEG_dq_fre_conus.bandtable.Data{:,2}; EEG_dq_fre_conus.bandtable.Data{:,3}]'; + fqlabels = {EEG_dq_fre_conus.bandtable.Data{:,1}}' ; + for ii = 1:size(fqbands,1) + fqlabelsNew{ii,1} = fqlabels{ii}; + end + fqlabels = fqlabelsNew; + estudioworkingmemory('pop_continuousFFT',{chanArray,fqbands,fqlabels}); + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Spectral Data Quality (Continuous EEG) > Run*',32,32,32,32,datestr(datetime('now')),'\n']); + + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + if isempty(chanArray) || any(chanArray(:)>EEG.nbchan) + chanArray = [1:EEG.nbchan]; + fprintf(['We have changed chans as below:\n']); + fprintf(['Chans:',num2str(chanArray),'\n']); + end + [EEG, ~, LASTCOM] = pop_continuousFFT(EEG, 'ChannelIndex',chanArray,'Frequencies',fqbands,'FrequencyLabel', ... + fqlabels, 'viewGUI','true','History', 'implicit'); + if isempty(LASTCOM) + fprintf([LASTCOM,'\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + fprintf([LASTCOM,'\n']); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( [repmat('-',1,100) '\n']); + end%%end for loop of subjects + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=26; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=18 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 || EEGUpdate==1 + EEG_dq_fre_conus.chans_edit.Enable= 'off'; + EEG_dq_fre_conus.chans_browse.Enable= 'off'; + EEG_dq_fre_conus.bandtable.Enable = 'off'; + EEG_dq_fre_conus.add_rows.Enable= 'off'; + EEG_dq_fre_conus.remove_rows.Enable= 'off'; + EEG_dq_fre_conus.resetable.Enable= 'off'; + EEG_dq_fre_conus.dq_fre_run.Enable= 'off'; + EEG_dq_fre_conus.dq_fre_cancel.Enable= 'off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ~=1 + Eegtab_box_dq_fre_conus.TitleColor= [0.7500 0.7500 0.750]; + else + Eegtab_box_dq_fre_conus.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=19; + return; + end + + chanOld = str2num(EEG_dq_fre_conus.chans_edit.String); + if isempty(chanOld) + ChanArray = vect2colon(1:observe_EEGDAT.EEG.nbchan); + ChanArray = erase(ChanArray,{'[',']'}); + EEG_dq_fre_conus.chans_edit.String= ChanArray; + end + + data_tab = EEG_dq_fre_conus.bandtable.Data; + if (ischar(data_tab{8,1}) && strcmpi(data_tab{8,1},'broadband')) && data_tab{8,3}> observe_EEGDAT.EEG.srate/2 + EEG_dq_fre_conus.bandtable.Data{8,3}= floor(observe_EEGDAT.EEG.srate/2); + end + + Eegtab_box_dq_fre_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_fre_conus.chans_edit.Enable= 'on'; + EEG_dq_fre_conus.chans_browse.Enable= 'on'; + EEG_dq_fre_conus.bandtable.Enable = 'on'; + EEG_dq_fre_conus.add_rows.Enable= 'on'; + EEG_dq_fre_conus.remove_rows.Enable= 'on'; + EEG_dq_fre_conus.resetable.Enable= 'on'; + EEG_dq_fre_conus.dq_fre_run.Enable= 'on'; + EEG_dq_fre_conus.dq_fre_cancel.Enable= 'on'; + observe_EEGDAT.count_current_eeg=19; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_shiftcodes_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_dq_fre_conus'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + dq_fre_run(); + estudioworkingmemory('EEGTab_dq_fre_conus',0); + Eegtab_box_dq_fre_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [0 0 0]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 1 1 1]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [0 0 0]; + else + return; + end + end + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=15 + return; + end + estudioworkingmemory('EEGTab_dq_fre_conus',0); + % Eegtab_box_dq_fre_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_dq_fre_conus.dq_fre_cancel.BackgroundColor = [1 1 1]; + EEG_dq_fre_conus.dq_fre_cancel.ForegroundColor = [0 0 0]; + EEG_dq_fre_conus.dq_fre_run.BackgroundColor = [ 1 1 1]; + EEG_dq_fre_conus.dq_fre_run.ForegroundColor = [0 0 0]; + if isempty(observe_EEGDAT.EEG) + EEG_dq_fre_conus.chans_edit.String = ''; + else + EEG_dq_fre_conus.chans_edit.String = vect2colon([1:observe_EEGDAT.EEG.nbchan]); + end + fqband = [0 3;3 8;8 12;8 30;30 48;49 51;59 61; 0 100]; %defaults + if ~isempty(observe_EEGDAT.EEG) + fqband(8,2) = floor(observe_EEGDAT.EEG.srate/2); + end + fqlabels = {'delta','theta','alpha','beta','gamma','50hz-noise','60hz-noise','broadband'}; + data_tab = [fqlabels' num2cell(fqband)]; + EEG_dq_fre_conus.bandtable.Data=data_tab; + observe_EEGDAT.Reset_eeg_paras_panel=16; + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_duplicate_GUI.fig b/studio_functions/GUIs/EEG Tab/f_EEG_duplicate_GUI.fig new file mode 100755 index 00000000..cf80a5a1 Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_duplicate_GUI.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_duplicate_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_duplicate_GUI.m new file mode 100755 index 00000000..84bf479a --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_duplicate_GUI.m @@ -0,0 +1,248 @@ +function varargout = f_EEG_duplicate_GUI(varargin) +% F_EEG_DUPLICATE_GUI MATLAB code for f_EEG_duplicate_GUI.fig +% F_EEG_DUPLICATE_GUI, by itself, creates a new F_EEG_DUPLICATE_GUI or raises the existing +% singleton*. +% +% H = F_EEG_DUPLICATE_GUI returns the handle to a new F_EEG_DUPLICATE_GUI or the handle to +% the existing singleton*. +% +% F_EEG_DUPLICATE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_DUPLICATE_GUI.M with the given input arguments. +% +% F_EEG_DUPLICATE_GUI('Property','Value',...) creates a new F_EEG_DUPLICATE_GUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_EEG_duplicate_GUI_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_EEG_duplicate_GUI_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 f_EEG_duplicate_GUI + +% Last Modified by GUIDE v2.5 14-Aug-2023 08:24:40 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_EEG_duplicate_GUI_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_duplicate_GUI_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 f_EEG_duplicate_GUI is made visible. +function f_EEG_duplicate_GUI_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_duplicate_GUI + +try + EEG = varargin{1}; + chanArray = varargin{2}; +catch + EEG.setname = 'No erp was imported'; + EEG.nbchan = 1; + EEG.chanlocs(1).labels = 'None'; + chanArray = 1; + currentset = []; + EEG.data = zeros(1,10,1); +end + +% handles.erpnameor = ERP.erpname; +handles.output = []; +handles.EEG = EEG; + + +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Duplicate EEGset GUI']) + + +nchan = EEG.nbchan; % Total number of channels +if ~isfield(EEG.chanlocs,'labels') + for e=1:nchan + EEG.chanlocs(e).labels = ['Ch' num2str(e)]; + end +end +listch = {''}; +try + for ch =1:nchan + listch{ch} = [num2str(ch) ' = ' EEG.chanlocs(ch).labels ]; + end +catch + listch = ''; +end +handles.listch = listch; +handles.indxlistch = chanArray; +set(handles.edit7_chan,'String', vect2colon(chanArray, 'Delimiter', 'off')); + +% Color GUI +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + + + +% Update handles structure +guidata(hObject, handles); + + +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_EEG_duplicate_GUI_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +% try +% set(handles.menuerp.Children, 'Enable','on'); +% catch +% disp('EEGset menu was not found...') +% end +varargout{1} = handles.output; +delete(handles.gui_chassis); +pause(0.1) + + + + + + + + + + +function edit7_chan_Callback(hObject, eventdata, handles) +chanString = str2num(handles.edit7_chan.String); +EEG = handles.EEG; +msgboxText = f_EEG_chck_chan(EEG, chanString); + +if ~isempty(msgboxText); + title = 'EStudio: Duplicate EEGset GUI for channel input!'; + errorfound(msgboxText, title); + return; +end + + +% --- Executes during object creation, after setting all properties. +function edit7_chan_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in pushbutton_chan_browse. +function pushbutton_chan_browse_Callback(hObject, eventdata, handles) +listch = handles.listch; +indxlistch = handles.indxlistch; +indxlistch = indxlistch(indxlistch<=length(listch)); +titlename = 'Select Channel(s)'; + +if get(hObject, 'Value') + if ~isempty(listch) + ch = browsechanbinGUI(listch, indxlistch, titlename); + if ~isempty(ch) + set(handles.edit7_chan, 'String', vect2colon(ch, 'Delimiter', 'off')); + handles.indxlistch = ch; + % Update handles structure + guidata(hObject, handles); + else + disp('User selected Cancel') + return + end + else + msgboxText = 'No channel information was found'; + title = 'Duplicate EEGset GUI for channel input'; + errorfound(msgboxText, title); + return + end +end + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = []; + +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) +EEG = handles.EEG; + +ChanArray = str2num(handles.edit7_chan.String); +if isempty(ChanArray) || min(ChanArray(:)) > EEG.nbchan || max(ChanArray(:)) > EEG.nbchan + ChanArray = 1:EEG.nbchan; +end +msgboxText = f_EEG_chck_chan(EEG, ChanArray); +if ~isempty(msgboxText) + title = 'EStudio: Duplicate EEGset GUI for channel input!'; + errorfound(msgboxText, title); + return; +end + + +handles.output = ChanArray; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + + +function msgboxText = f_EEG_chck_chan(EEG, chanArray) +msgboxText = ''; + +if isempty(chanArray) + msgboxText = 'You have not specified any channel'; + return +end +if any(chanArray<=0) + msgboxText = sprintf('Invalid channel index.\n Please specify only positive integer values.'); + return +end +if any(chanArray>EEG.nbchan) + msgboxText = sprintf(['Channel index out of range!\nYou only have %g channels in this EEGset']); + return +end +if length(chanArray)~=length(unique_bc2(chanArray)) + msgboxText = 'You have specified repeated channels.'; + return +end +return; diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_edit_channel_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_edit_channel_GUI.m new file mode 100644 index 00000000..79575fd6 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_edit_channel_GUI.m @@ -0,0 +1,663 @@ +%%This function is to Edit/Delete Channels & Locations + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep.2023 + + +function varargout = f_EEG_edit_channel_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ + +EStduio_eegtab_EEG_edit_chan = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_eeg_box_edit_chan; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_eeg_box_edit_chan = uiextras.BoxPanel('Parent', fig, 'Title', 'Edit/Delete Channels & Locations', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_eeg_box_edit_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Edit/Delete Channels & Locations', 'Padding', 5,'BackgroundColor',ColorB_def); +else + EStudio_eeg_box_edit_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Edit/Delete Channels & Locations', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_ic_chan_eeg(FonsizeDefault) +varargout{1} = EStudio_eeg_box_edit_chan; + + function drawui_ic_chan_eeg(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + Enable_label = 'off'; + %%--------------------channel and bin setting---------------------- + EStduio_eegtab_EEG_edit_chan.DataSelBox = uiextras.VBox('Parent', EStudio_eeg_box_edit_chan,'BackgroundColor',ColorB_def); + + %%%----------------Mode----------------------------------- + EStduio_eegtab_EEG_edit_chan.mode_1 = uiextras.HBox('Parent', EStduio_eegtab_EEG_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_edit_chan.mode_modify_title = uicontrol('Style','text','Parent',EStduio_eegtab_EEG_edit_chan.mode_1 ,... + 'String','Mode:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + EStduio_eegtab_EEG_edit_chan.mode_modify = uicontrol('Style','radiobutton','Parent',EStduio_eegtab_EEG_edit_chan.mode_1 ,... + 'String','Modify existing dataset','callback',@mode_modify,'Value',1,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + % EStduio_eegtab_EEG_edit_chan.mode_modify.String = 'Modify existing dataset
                            (recursive updating)'; + set(EStduio_eegtab_EEG_edit_chan.mode_1,'Sizes',[55 -1]); + %%--------------For create a new ERPset---------------------------- + EStduio_eegtab_EEG_edit_chan.mode_2 = uiextras.HBox('Parent', EStduio_eegtab_EEG_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EStduio_eegtab_EEG_edit_chan.mode_2,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_edit_chan.mode_create = uicontrol('Style','radiobutton','Parent',EStduio_eegtab_EEG_edit_chan.mode_2 ,... + 'String','Create new dataset','callback',@mode_create,'Value',0,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + % EStduio_eegtab_EEG_edit_chan.mode_create.String = 'Create new dataset
                            (independent transformations)'; + set(EStduio_eegtab_EEG_edit_chan.mode_2,'Sizes',[55 -1]); + + + %%Select channels that will be deleted and renamed + EStduio_eegtab_EEG_edit_chan.select_chan_title = uiextras.HBox('Parent', EStduio_eegtab_EEG_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EStduio_eegtab_EEG_edit_chan.select_chan_title,... + 'String','Chan:','FontSize',FontSize_defualt,'Enable','on','BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_edit_chan.select_edit_chan = uicontrol('Style','edit','Parent',EStduio_eegtab_EEG_edit_chan.select_chan_title,... + 'String',' ','callback',@select_edit_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + EStduio_eegtab_EEG_edit_chan.browse_chan = uicontrol('Style','pushbutton','Parent',EStduio_eegtab_EEG_edit_chan.select_chan_title,... + 'String','Browse','callback',@browse_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + set(EStduio_eegtab_EEG_edit_chan.select_chan_title,'sizes',[40 -1 60]) + + + %%Delete selected channels && Rename selected channels + EStduio_eegtab_EEG_edit_chan.delete_rename = uiextras.HBox('Parent', EStduio_eegtab_EEG_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_edit_chan.delete_chan = uicontrol('Style','pushbutton','Parent',EStduio_eegtab_EEG_edit_chan.delete_rename ,... + 'String','Delete chan','callback',@delete_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + EStduio_eegtab_EEG_edit_chan.rename_chan = uicontrol('Style','pushbutton','Parent',EStduio_eegtab_EEG_edit_chan.delete_rename ,... + 'String','Rename chan','callback',@rename_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + + %%Add/edit chan locations + % EStduio_eegtab_EEG_edit_chan.edit_chanlocs_title = uiextras.HBox('Parent', EStduio_eegtab_EEG_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_edit_chan.edit_chanlocs = uicontrol('Style','pushbutton','Parent',EStduio_eegtab_EEG_edit_chan.delete_rename,... + 'String','Add/edit chanlocs','callback',@edit_chanlocs,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + % set(EStduio_eegtab_EEG_edit_chan.interpolate_epoch_title,'Sizes',[160 -1]); + EStduio_eegtab_EEG_edit_chan.edit_chanlocs.String = ' Add or edit
                            chan locations'; + EStduio_eegtab_EEG_edit_chan.edit_chanlocs.HorizontalAlignment='Center'; + set(EStduio_eegtab_EEG_edit_chan.DataSelBox,'sizes',[30 30 30 40]) + estudioworkingmemory('EEGTab_editchan',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%---------------------Modify Existing dataset----------------------------- + function mode_modify(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + EStudio_eeg_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('EEGTab_editchan',1); + EStduio_eegtab_EEG_edit_chan.mode_modify.Value =1; + EStduio_eegtab_EEG_edit_chan.mode_create.Value = 0; + end + +%%---------------------Create new dataset---------------------------------- + function mode_create(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + EStudio_eeg_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('EEGTab_editchan',1); + EStduio_eegtab_EEG_edit_chan.mode_modify.Value =0; + EStduio_eegtab_EEG_edit_chan.mode_create.Value = 1; + end + +%%-----------------------input channels------------------------------------ + function select_edit_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + EStudio_eeg_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('EEGTab_editchan',1); + + New_chans = str2num(Source.String); + if isempty(New_chans) || any(New_chans(:)<=0) + msgboxText = ['Edit/Delete Channels & Locations > Index(es) of channels should be positive values']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + chanNum = observe_EEGDAT.EEG.nbchan; + if any(New_chans(:) > chanNum) + msgboxText = ['Edit/Delete Channels & Locations > Index(es) of channels should be smaller than',32,num2str(chanNum)]; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%-----------------------browse channels----------------------------------- + function browse_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + EStudio_eeg_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('EEGTab_editchan',1); + + EEG = observe_EEGDAT.EEG; + for Numofchan = 1:EEG.nbchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',EEG.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + chanIgnore = str2num(EStduio_eegtab_EEG_edit_chan.select_edit_chan.String); + if isempty(chanIgnore) + indxlistb = EEG.nbchan; + else + if min(chanIgnore(:)) >0 && max(chanIgnore(:)) <= EEG.nbchan + indxlistb = chanIgnore; + else + indxlistb = EEG.nbchan; + end + end + titlename = 'Select Channel(s):'; + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + EStduio_eegtab_EEG_edit_chan.select_edit_chan.String = vect2colon(chan_label_select); + else + return + end + end + +%%---------------------Delete selected chan-------------------------------- + function delete_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + EStudio_eeg_box_edit_chan.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('EEGTab_editchan',0); + + estudioworkingmemory('f_EEG_proces_messg','Edit/Delete Channels & Locations > Delete selected chan'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + + ChanArray = str2num(EStduio_eegtab_EEG_edit_chan.select_edit_chan.String); + if isempty(ChanArray) || any(ChanArray(:)<=0) + msgboxText = ['Edit/Delete Channels & Locations > Delete selected chan > Indexes of chans should be positive values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + CreateeegFlag = EStduio_eegtab_EEG_edit_chan.mode_create.Value; %%create new eeg dataset + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + %%check the selected chans + if any(ChanArray(:) > EEG.nbchan) + Erromesg = ['Edit/Delete Channels & Locations > Delete selected chan > Selected channel should be between 1 and ',32, num2str(EEG.nbchan)]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(Erromesg,titlNamerro); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if numel(ChanArray) == EEG.nbchan + Erromesg = ['Edit/Delete Channels & Locations > Delete selected chan > Please clear this EEGset in "EEGsets" panel if you want to delete all channels']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(Erromesg,titlNamerro); + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + [eloc, chanlabels, theta, radius, indices] = readlocs( EEG.chanlocs ); + [EEG, LASTCOM] = pop_select( EEG, 'rmchannel',{chanlabels{ChanArray}}); + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + ALLEEG_out(end).filename = EEG.filename; + ALLEEG_out(end).filepath = EEG.filepath; + end + + if CreateeegFlag==1 + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_delchan'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + if CreateeegFlag==0 + ALLEEG(EEGArray) = ALLEEG_out; + else + for Numofeeg= 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + end + + observe_EEGDAT.ALLEEG = ALLEEG; + if CreateeegFlag==1 + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------------Rename selected chan------------------------------ + function rename_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + EStudio_eeg_box_edit_chan.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('EEGTab_editchan',0); + + estudioworkingmemory('f_EEG_proces_messg','Edit/Delete Channels & Locations > Rename selected chan'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + ChanArray = str2num(EStduio_eegtab_EEG_edit_chan.select_edit_chan.String); + + if isempty(ChanArray) || any(ChanArray(:)<=0) + Erromesg = ['Edit/Delete Channels & Locations > Rename selected chan > Indexes of chans should be positive values']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(Erromesg,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + + CreateeegFlag = EStduio_eegtab_EEG_edit_chan.mode_create.Value; %%create new eeg dataset + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + %%check the selected chans + if any(ChanArray(:) > observe_EEGDAT.EEG.nbchan) + fprintf( ['Edit/Delete Channels & Locations > Rename selected chan: Some of chan indexes exceed',32,num2str(observe_EEGDAT.EEG.nbchan),32,', we therefore select all channels.\n']); + ChanArray = [1:observe_EEGDAT.EEG.nbchan]; + end + try + [eloc, Chanlabelsold, theta, radius, indices] = readlocs(observe_EEGDAT.EEG.chanlocs); + Chanlabelsold = Chanlabelsold(ChanArray); + catch + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + def = estudioworkingmemory('pop_rename2chan'); + if isempty(def) + def = Chanlabelsold; + end + + titleName= ['ERPLAB Studio Change Channel Name']; + Chanlabelsnew= f_change_chan_name_GUI(Chanlabelsold,def,titleName); + if isempty(Chanlabelsnew) + observe_EEGDAT.eeg_panel_message =2; + return + end + estudioworkingmemory('pop_rename2chan',Chanlabelsnew); + + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Rename selected chan*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + CURRENTSET = EEGArray(Numofeeg); + + [EEG, LASTCOM] = pop_rename2chan(ALLEEG,CURRENTSET,'ChanArray',ChanArray,'Chanlabels',Chanlabelsnew,'History', 'implicit'); + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf([LASTCOM,'\n']); + fprintf( [repmat('-',1,100) '\n']); + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + ALLEEG_out(end).filename = EEG.filename; + ALLEEG_out(end).filepath = EEG.filepath; + end + + Save_file_label=0; + if CreateeegFlag==1 + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_rnchan'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + + if CreateeegFlag==0 + ALLEEG(EEGArray) = ALLEEG_out; + else + for Numofeeg= 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + end + + observe_EEGDAT.ALLEEG = ALLEEG; + if CreateeegFlag==1 + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%------------------edit channel locations--------------------------------- + function edit_chanlocs(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + EStudio_eeg_box_edit_chan.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('EEGTab_editchan',0); + + estudioworkingmemory('f_EEG_proces_messg','Edit/Delete Channels & Locations > Add or edit channel locations'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:)> length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + CreateeegFlag = EStduio_eegtab_EEG_edit_chan.mode_create.Value; %%create new eeg dataset + %%loop for the selected EEGsets + ALLEEG = observe_EEGDAT.ALLEEG; + titleName= ['EStudio: Add or edit channel locations']; + app = feval('f_editchan_gui',observe_EEGDAT.EEG,titleName); + waitfor(app,'Finishbutton',1); + try + EEGoutput = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.5); %wait for app to leave + catch + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if isempty(EEGoutput) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + Chanlocs = EEGoutput.chanlocs; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Add or edit all channel locations*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + ChanArray = [1:EEG.nbchan]; + [EEG, LASTCOM] = pop_editdatachanlocs(ALLEEG,EEGArray(Numofeeg),... + 'ChanArray',ChanArray,'Chanlocs',Chanlocs,'History', 'implicit'); + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','Edit/Delete Channels & Locations > Add or edit channel locations: Please check you data or you selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + fprintf(['\n',LASTCOM,'\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( ['\n',repmat('-',1,100) '\n']); + ALLEEG_out(end).filename = EEG.filename; + ALLEEG_out(end).filepath = EEG.filepath; + end + + Save_file_label=0; + if CreateeegFlag==1 + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_editchan'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + if CreateeegFlag==0 + ALLEEG(EEGArray) = ALLEEG_out; + else + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + end + end + observe_EEGDAT.ALLEEG = ALLEEG; + if CreateeegFlag==1 + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=4 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || (~isempty(observe_EEGDAT.EEG) && isempty(observe_EEGDAT.EEG.chanlocs)) || EEGUpdate==1 + EStduio_eegtab_EEG_edit_chan.mode_modify.Enable ='off'; + EStduio_eegtab_EEG_edit_chan.mode_create.Enable = 'off'; + EStduio_eegtab_EEG_edit_chan.delete_chan.Enable='off'; + EStduio_eegtab_EEG_edit_chan.rename_chan.Enable='off'; + EStduio_eegtab_EEG_edit_chan.edit_chanlocs.Enable='off'; + EStduio_eegtab_EEG_edit_chan.select_edit_chan.Enable='off'; + EStduio_eegtab_EEG_edit_chan.browse_chan.Enable='off'; + observe_EEGDAT.count_current_eeg=5; + return; + end + EStduio_eegtab_EEG_edit_chan.mode_modify.Enable ='on'; + EStduio_eegtab_EEG_edit_chan.mode_create.Enable = 'on'; + EStduio_eegtab_EEG_edit_chan.delete_chan.Enable='on'; + EStduio_eegtab_EEG_edit_chan.rename_chan.Enable='on'; + EStduio_eegtab_EEG_edit_chan.edit_chanlocs.Enable='on'; + EStduio_eegtab_EEG_edit_chan.select_edit_chan.Enable='on'; + EStduio_eegtab_EEG_edit_chan.browse_chan.Enable='on'; + observe_EEGDAT.count_current_eeg=5; + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=4 + return; + end + estudioworkingmemory('EEGTab_editchan',0); + EStduio_eegtab_EEG_edit_chan.mode_modify.Value =1; + EStduio_eegtab_EEG_edit_chan.mode_create.Value = 0; + EStduio_eegtab_EEG_edit_chan.select_edit_chan.String = ''; + observe_EEGDAT.Reset_eeg_paras_panel=5; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end + diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_eeg_sets_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_eeg_sets_GUI.m new file mode 100755 index 00000000..2fb3e7dd --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_eeg_sets_GUI.m @@ -0,0 +1,1441 @@ +% EEG sets selector panel +% +% Author: Guanghui ZHANG & Steve Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2023 && 2024 + +% ERPLAB Studio Toolbox +% + + + +function varargout = f_EEG_eeg_sets_GUI(varargin) +global observe_EEGDAT; +global EStudio_gui_erp_totl; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_panel_change_message',@eeg_panel_change_message); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + + +EStduio_eegtab_EEG_set = struct(); +%---------Setting the parameter which will be used in the other panels----------- +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end + +% global box; +if nargin == 0 + fig = figure(); % Parent figure + box_eegset_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'EEGsets', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + box_eegset_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEGsets', 'Padding', 5,'BackgroundColor',ColorB_def); +else + box_eegset_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEGsets', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +% global selectedData; +sel_path = cd; +estudioworkingmemory('EEG_save_folder',sel_path); +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_EEGset(FonsizeDefault); + +varargout{1} = box_eegset_gui; + +estudioworkingmemory('Startimes',0);%%set default value + + +% Draw the ui + function drawui_EEGset(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.7020 0.77 0.85]; + end + vBox = uiextras.VBox('Parent', box_eegset_gui, 'Spacing', 5,'BackgroundColor',ColorB_def); % VBox for everything + %%continuous or epoch + EStduio_eegtab_EEG_set.datatype_title = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_set.eeg_contns = uicontrol('Parent',EStduio_eegtab_EEG_set.datatype_title, 'Style', 'radiobutton', 'String', 'Continuous EEG',... + 'Callback', @continuous_eeg,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',1); + EStduio_eegtab_EEG_set.eeg_epoch = uicontrol('Parent',EStduio_eegtab_EEG_set.datatype_title, 'Style', 'radiobutton', 'String', 'Epoched EEG',... + 'Callback', @epoch_eeg,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + + %%-----------------------ERPset display--------------------------------------- + panelshbox = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + panelsv2box = uiextras.VBox('Parent',panelshbox,'Spacing',5,'BackgroundColor',ColorB_def); + dsnames = getDatasets(); + if isempty(observe_EEGDAT.ALLEEG) + Edit_label = 'off'; + else + Edit_label = 'on'; + end + EEGArray = estudioworkingmemory('EEGArray'); + EStduio_eegtab_EEG_set.butttons_datasets = uicontrol('Parent', panelsv2box, 'Style', 'listbox', 'min', 1,'max',... + length(dsnames)+1,'String', dsnames,'Callback',@selectdata,'FontSize',FonsizeDefault,'Enable',Edit_label,'BackgroundColor',[1 1 1]); + if isempty(EEGArray) || any(EEGArray(:)>length(dsnames)) + EEGArray=1; + estudioworkingmemory('EEGArray',EEGArray); + end + try + EStduio_eegtab_EEG_set.butttons_datasets.Value = EEGArray; + catch + end + %%---------------------Options for EEGsets----------------------------------------------------- + EStduio_eegtab_EEG_set.buttons2 = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_set.dupeselected = uicontrol('Parent', EStduio_eegtab_EEG_set.buttons2, 'Style', 'pushbutton', 'String', 'Duplicate', ... + 'Callback', @duplicateSelected,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.renameselected = uicontrol('Parent', EStduio_eegtab_EEG_set.buttons2, 'Style', 'pushbutton', 'String', 'Rename',... + 'Callback', @renamedata,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.suffix = uicontrol('Parent', EStduio_eegtab_EEG_set.buttons2, 'Style', 'pushbutton', 'String', 'Add Suffix',... + 'Callback', @add_suffix,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.refresh_eegset = uicontrol('Parent', EStduio_eegtab_EEG_set.buttons2, 'Style', 'pushbutton', 'String', 'Refresh',... + 'Callback', @refresh_eegset,'Enable','on','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + + buttons3 = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_set.importexport = uicontrol('Parent',buttons3, 'Style', 'pushbutton', 'String', 'Import',... + 'Callback', @imp_eeg,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.loadbutton = uicontrol('Parent', buttons3, 'Style', 'pushbutton', 'String', 'Load', ... + 'Callback', @load,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.appendbutton = uicontrol('Parent', buttons3, 'Style', 'pushbutton', 'String', 'Append', ... + 'Callback', @append_eeg,'FontSize',FonsizeDefault,'Enable',Edit_label,'BackgroundColor',[1 1 1]); + + EStduio_eegtab_EEG_set.clearselected = uicontrol('Parent', buttons3, 'Style', 'pushbutton', 'String', 'Clear', ... + 'Callback', @cleardata,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + buttons4 = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_set.savebutton = uicontrol('Parent', buttons4, 'Style', 'pushbutton',... + 'String', 'Save', 'Callback', @eegset_save,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.saveasbutton = uicontrol('Parent', buttons4, 'Style', 'pushbutton',... + 'String', 'Save a Copy', 'Callback', @eegset_saveas,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_set.curr_folder = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Current Folder', ... + 'Callback', @curr_folder,'Enable','on','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + set(buttons4,'Sizes',[70 90 95]); + set(vBox, 'Sizes', [20 150 25 25 25]); + estudioworkingmemory('EEGTab_eegset',0); + EStudio_gui_erp_totl.EEG_transf = 0;%%reveaal if transfter continous EEG to epoched EEG or from epoched to continous EEG + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%---------------------------------------------- Subfunctions --------------------------------------------%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%-----------------------continuous EEG------------------------------------ + function continuous_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_eegset',0); + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 0; + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(); + if isempty(EEGtypeFlag) + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + return; + end + EEGArray = EStduio_eegtab_EEG_set.butttons_datasets.Value; + if any(EEGArray(:) > length(EEGlistName)) || any(EEGArray(:) <1) + EEGArray = length(EEGlistName); + estudioworkingmemory('EEGArray',EEGArray);%%May replot the waves wiht addtionl codes Aug. 8 2023 + end + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.butttons_datasets.Value = EEGArray; + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 1; + EStduio_eegtab_EEG_set.butttons_datasets.Value = EEGArray; + end + %%contains the both continuous and epoched EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + % EStduio_eegtab_EEG_set.butttons_datasets.String = EEgNamelist; + [xpos, ypos] = find(EEGtypeFlag==1); + Diffnum = setdiff(EEGArray,ypos); + if ~isempty(Diffnum) + EStduio_eegtab_EEG_set.butttons_datasets.Value =ypos(end); + estudioworkingmemory('EEGArray',ypos(end)); + CURRENTSET = ypos(end); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + %%save to workspace + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + end + end + estudioworkingmemory('Startimes',0); + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + whichpanel = [19:23]; + EEGTab_close_open_Panels(whichpanel); + EStudio_gui_erp_totl.EEG_transf = 1; + end + +%%--------------------------epoched EEG-------------------------------------- + function epoch_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('EEGTab_eegset',0); + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 1; + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(); + if isempty(EEGtypeFlag) + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + return; + end + EEGArray = EStduio_eegtab_EEG_set.butttons_datasets.Value; + if any(EEGArray(:) > length(EEGlistName)) + EEGArray = length(EEGlistName); + end + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 0; + EStduio_eegtab_EEG_set.butttons_datasets.Value = EEGArray; + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + end + + %%contains the both continuous and epoched EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + [xpos, ypos] = find(EEGtypeFlag==0); + Diffnum = setdiff(EEGArray,ypos); + if ~isempty(Diffnum) + EStduio_eegtab_EEG_set.butttons_datasets.Value =ypos(end); %%May recall the plotting function + estudioworkingmemory('EEGArray',ypos(end)); + CURRENTSET = ypos(end); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + end + end + estudioworkingmemory('Startimes',1); + observe_EEGDAT.count_current_eeg=2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + whichpanel = [13:18]; + EEGTab_close_open_Panels(whichpanel); + EStudio_gui_erp_totl.EEG_transf= 1; + end + + +%------------------duplicate the selected EEGsets-------------------------- + function duplicateSelected(Source,~)%%The defualt channels and bins that come from "bin and channel" panel but user can select bins and channels. + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Duplicate'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray= EStduio_eegtab_EEG_set.butttons_datasets.Value; + if isempty(EEGArray) + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = EEGArray; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(end); + EStduio_eegtab_EEG_set.butttons_datasets.Value=EEGArray; + end + ChanArray=estudioworkingmemory('EEG_ChanArray'); + ChanArray = f_EEG_duplicate_GUI(observe_EEGDAT.EEG,ChanArray); + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + + if isempty(ChanArray) || any(ChanArray(:)>EEG.nbchan) || any(ChanArray(:)<=0) + ChanArray = [1:EEG.nbchan]; + estudioworkingmemory('EEG_ChanArray',ChanArray); + end + [EEG, LASTCOM] = pop_duplicateeg( EEG, 'ChanArray',ChanArray,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(LASTCOM) + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end + + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_duplicated'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + if Save_file_label + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + + try + Selected_ERP_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + catch + Selected_ERP_afd = length(observe_EEGDAT.ALLEEG); + end + EStduio_eegtab_EEG_set.butttons_datasets.Value = Selected_ERP_afd; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_ERP_afd); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + + observe_EEGDAT.count_current_eeg=1;%%to channel & IC panel + observe_EEGDAT.eeg_panel_message =2; + end + +%%-------------------Rename the selcted files------------------------------ + function renamedata(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Rename'); + observe_EEGDAT.eeg_panel_message =1; + + SelectedEEG= EStduio_eegtab_EEG_set.butttons_datasets.Value; + + app = feval('EEG_Tab_rename_gui',observe_EEGDAT.ALLEEG(SelectedEEG),SelectedEEG); + waitfor(app,'Finishbutton',1); + try + setnames = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + if isempty(setnames) + return; + end + ALLEEG = observe_EEGDAT.ALLEEG(SelectedEEG); + [ALLEEG, LASTCOM] = pop_renameeg( ALLEEG, 'eegnames',setnames,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(LASTCOM) + return; + end + for Numofeeg = 1:numel(SelectedEEG) + + ALLEEG(Numofeeg) = eegh(LASTCOM, ALLEEG(Numofeeg)); + if Numofeeg ==numel(SelectedEEG) + eegh(LASTCOM); + end + + end + observe_EEGDAT.ALLEEG(SelectedEEG) = ALLEEG; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + EEGlistName = getDatasets(); + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + EStduio_eegtab_EEG_set.butttons_datasets.Min = 1; + EStduio_eegtab_EEG_set.butttons_datasets.Max = length(EEGlistName)+1; + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + observe_EEGDAT.count_current_eeg=1;%%to channel & IC panel + observe_EEGDAT.eeg_panel_message =2; + end + +%%--------------------------------Add Suffix--------------------------------- + function add_suffix(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Add Suffix'); + observe_EEGDAT.eeg_panel_message =1; + SelectedEEG= EStduio_eegtab_EEG_set.butttons_datasets.Value; + suffixstr = f_EEG_suffix_gui('Suffix'); + if ~isempty(suffixstr) + ALLEEG = observe_EEGDAT.ALLEEG(SelectedEEG); + [ALLEEG, LASTCOM] = pop_suffixeeg( ALLEEG, 'suffixstr',suffixstr,... + 'Saveas', 'off', 'History', 'gui'); + for Numofeeg = 1:length(SelectedEEG) + ALLEEG(Numofeeg)=eegh(LASTCOM, ALLEEG(Numofeeg)); + if Numofeeg ==length(SelectedEEG) + eegh(LASTCOM); + end + end + observe_EEGDAT.ALLEEG(SelectedEEG) =ALLEEG; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + + EEGlistName = getDatasets(); + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + EStduio_eegtab_EEG_set.butttons_datasets.Min = 1; + EStduio_eegtab_EEG_set.butttons_datasets.Max = length(EEGlistName)+1; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + observe_EEGDAT.count_current_eeg=1;%%to channel & IC panel + observe_EEGDAT.eeg_panel_message =2; + else + return; + end + end + +%%----------------------Refresh alleeg and eeg----------------------------- + function refresh_eegset(Source,~) + % if isempty(observe_EEGDAT.EEG) + % Source.Enable= 'off'; + % return; + % end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Refresh'); + try + ALLEEG = evalin('base', 'ALLEEG'); + catch + ALLEEG = []; + end + try + EEG = evalin('base', 'EEG'); + catch + EEG = []; + end + try + CURRENTSET = evalin('base', 'CURRENTSET'); + catch + CURRENTSET = 1; + end + if isempty(ALLEEG) && ~isempty(EEG) + ALLEEG = EEG; + CURRENTSET =1; + end + if ~isempty(ALLEEG) && isempty(EEG) + if isempty(CURRENTSET) || numel(CURRENTSET)~=1 || any(CURRENTSET(:)>length(ALLEEG)) + CURRENTSET = length(ALLEEG); + end + EEG = ALLEEG(CURRENTSET); + end + observe_EEGDAT.ALLEEG = ALLEEG; + observe_EEGDAT.EEG =EEG; + observe_EEGDAT.CURRENTSET =CURRENTSET ; + try + observe_EEGDAT.ALLEEG(CURRENTSET) = observe_EEGDAT.EEG; + catch + end + if isempty(observe_EEGDAT.ALLEEG) && isempty(observe_EEGDAT.EEG) + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 1; + Edit_label = 'off'; + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'off'; + else + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets();%%all EEGset + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + if EStduio_eegtab_EEG_set.eeg_contns.Value==0 + EStudio_gui_erp_totl.EEG_transf=1; + end + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + EStudio_gui_erp_totl.EEG_transf=1; + end + end + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + + %%contains the both continuous and epoched EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + end + Edit_label = 'on'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'on'; + + end + if ~isempty(observe_EEGDAT.EEG) + if observe_EEGDAT.EEG.trials>1 + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value=1; + else + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value=0; + end + else + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value=0; + end + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + + EStduio_eegtab_EEG_set.butttons_datasets.Value =observe_EEGDAT.CURRENTSET; + EStduio_eegtab_EEG_set.dupeselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.renameselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.suffix.Enable= Edit_label; + EStduio_eegtab_EEG_set.clearselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.savebutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.saveasbutton.Enable=Edit_label; + EStduio_eegtab_EEG_set.curr_folder.Enable='on'; + EStduio_eegtab_EEG_set.butttons_datasets.Min =1; + EStduio_eegtab_EEG_set.butttons_datasets.Max =length(EEGlistName)+1; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = Edit_label; + EStduio_eegtab_EEG_set.appendbutton.Enable = Edit_label; + EStduio_eegtab_EEG_set.refresh_eegset.Enable= 'on'; + EEGArray= EStduio_eegtab_EEG_set.butttons_datasets.Value; + estudioworkingmemory('EEGArray',EEGArray); + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets > Refresh'); + observe_EEGDAT.eeg_panel_message=2; + end + +%----------------------- Import-------------------------------------------- + function imp_eeg( ~, ~ ) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Import'); + observe_EEGDAT.eeg_panel_message =1; + %-----------Setting for import------------------------------------- + ALLEEG = f_EEG_import_GUI(observe_EEGDAT.ALLEEG); + if isempty(ALLEEG) + observe_EEGDAT.eeg_panel_message =2; + return; + end + + [~,EEGConts_epoch_Flag,~] = getDatasets(ALLEEG);%%all EEGset + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + end + %%contains both continuous and epoched EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + end + CURRENTSET = length(ALLEEG); + EEG = ALLEEG(CURRENTSET); + if EEG.trials==1 + if EStduio_eegtab_EEG_set.eeg_contns.Value==0 + EStudio_gui_erp_totl.EEG_transf=1; + end + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 0; + else + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + EStudio_gui_erp_totl.EEG_transf=1; + end + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 1; + end + [EEGlistName,~,~] = getDatasets(ALLEEG); + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + + observe_EEGDAT.ALLEEG = ALLEEG; + EStduio_eegtab_EEG_set.butttons_datasets.Min = 1; + EStduio_eegtab_EEG_set.butttons_datasets.Max = length(observe_EEGDAT.ALLEEG)+1; + EStduio_eegtab_EEG_set.butttons_datasets.Value = CURRENTSET; + estudioworkingmemory('EEGArray',CURRENTSET); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + %%save to workspace + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + + Edit_label = 'on'; + EStduio_eegtab_EEG_set.dupeselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.renameselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.suffix.Enable= Edit_label; + EStduio_eegtab_EEG_set.clearselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.savebutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.saveasbutton.Enable=Edit_label; + EStduio_eegtab_EEG_set.curr_folder.Enable='on'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = Edit_label; + EStduio_eegtab_EEG_set.appendbutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.refresh_eegset.Enable= 'on'; + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + observe_EEGDAT.eeg_panel_message=2; + + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + whichpanel = [19:23]; + else + whichpanel = [13:18]; + end + EEGTab_close_open_Panels(whichpanel); + end + + +%%---------------------Load EEG-------------------------------------------- + function load(~,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_eegset',0); + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Load'); + observe_EEGDAT.eeg_panel_message =1; + + ALLEEG = observe_EEGDAT.ALLEEG; + + [filename, filepath] = uigetfile({'*.set','EEG (*.set)'}, ... + 'Load EEG', ... + 'MultiSelect', 'on'); + if isequal(filename,0) + return; + end + if ischar(filename) + [EEG, Lastcom]= pop_loadset('filename',filename,'filepath',filepath); + try + EEG.history = [ EEG.history 10 Lastcom ]; + catch + EEG.history = strvcat(EEG.history, Lastcom); + end + eegh(Lastcom);%%ALLCOM + if isempty(observe_EEGDAT.EEG) + OLDSET =0; + else + OLDSET = length(ALLEEG); + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, OLDSET,'study',0,'gui','off'); + elseif iscell(filename) + for Numofeeg = 1:length(filename) + + [EEG, Lastcom]= pop_loadset('filename',filename{Numofeeg},'filepath',filepath); + try + EEG.history = [ EEG.history 10 Lastcom ]; + catch + EEG.history = strvcat(EEG.history, Lastcom); + end + eegh(Lastcom);%%ALLCOM + if isempty(observe_EEGDAT.EEG) + OLDSET =0; + else + OLDSET = length(ALLEEG); + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, OLDSET,'study',0,'gui','off'); + end + else + return; + end + + [~,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(ALLEEG);%%all EEGset + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + end + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + end + + CURRENTSET = length(ALLEEG); + EEG = ALLEEG(CURRENTSET); + if EEG.trials==1 + if EStduio_eegtab_EEG_set.eeg_contns.Value==0 + EStudio_gui_erp_totl.EEG_transf=1; + end + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 0; + else + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + EStudio_gui_erp_totl.EEG_transf=1; + end + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 1; + end + [EEGlistName,~,~] = getDatasets(ALLEEG); + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + %%contains the both continuous and epoched EEG + observe_EEGDAT.ALLEEG = ALLEEG; + EStduio_eegtab_EEG_set.butttons_datasets.Min = 1; + EStduio_eegtab_EEG_set.butttons_datasets.Max = length(observe_EEGDAT.ALLEEG)+1; + EStduio_eegtab_EEG_set.butttons_datasets.Value = CURRENTSET; + estudioworkingmemory('EEGArray',CURRENTSET); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + %%save to workspace + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + + Edit_label = 'on'; + EStduio_eegtab_EEG_set.dupeselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.renameselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.suffix.Enable= Edit_label; + EStduio_eegtab_EEG_set.clearselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.savebutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.saveasbutton.Enable=Edit_label; + EStduio_eegtab_EEG_set.curr_folder.Enable='on'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = Edit_label; + EStduio_eegtab_EEG_set.appendbutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.refresh_eegset.Enable= 'on'; + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + observe_EEGDAT.eeg_panel_message=2; + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + whichpanel = [19:23]; + else + whichpanel = [13:18]; + end + EEGTab_close_open_Panels(whichpanel); + end + +%%----------------------------Append two or more files--------------------- + function append_eeg(~,~) + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.ALLEEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets > Append'); + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) + EEGArray = ''; + end + %%Popup the selection + uilist = { { 'style' 'text' 'string' 'Dataset indices to merge' } ... + { 'style' 'edit' 'string' num2str(EEGArray) } ... + { 'style' 'text' 'string' 'Preserve ICA weights of the first dataset ?' } ... + { 'style' 'checkbox' 'string' '' } }; + res = inputgui( 'uilist', uilist, 'geometry', { [3 1] [3 1] }, 'helpcom', 'pophelp(''pop_mergeset'')'); + + if isempty(res) + return; + end + INEEG2 = eval( [ '[' res{1} ']' ] ); + keepall = res{2}; + [EEG,LASTCOM]= pop_mergeset( observe_EEGDAT.ALLEEG,INEEG2,keepall); + if isempty(LASTCOM) + return; + end + + if ~isempty(LASTCOM) + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(observe_EEGDAT.ALLEEG) + OLDSET=1; + else + OLDSET = length(observe_EEGDAT.ALLEEG); + end + + Answer = f_EEG_save_single_file('Merged_datasets',EEG.filename,OLDSET); + if isempty(Answer) + return; + end + + if ~isempty(Answer) + EEGName = Answer{1}; + if ~isempty(EEGName) + EEG.setname = EEGName; + end + fileName_full = Answer{2}; + if isempty(fileName_full) + EEG.filename = ''; + EEG.saved = 'no'; + elseif ~isempty(fileName_full) + [pathstr, file_name, ext] = fileparts(fileName_full); + if strcmp(pathstr,'') + pathstr = cd; + end + EEG.filename = [file_name,ext]; + EEG.filepath = pathstr; + EEG.saved = 'yes'; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + end + end + + [observe_EEGDAT.ALLEEG, EEG,~,LASTCOM] = pop_newset(observe_EEGDAT.ALLEEG, EEG,OLDSET, 'gui', 'off'); + eegh(LASTCOM); + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + EStduio_eegtab_EEG_set.butttons_datasets.Value =observe_EEGDAT.CURRENTSET ; + EStduio_eegtab_EEG_set.butttons_datasets.Max =length(EEGlistName)+1; + EEGArray= EStduio_eegtab_EEG_set.butttons_datasets.Value; + estudioworkingmemory('EEGArray',EEGArray); + + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + observe_EEGDAT.eeg_panel_message=2; + end + end + +%%----------------------Clear the selected EEGsets------------------------- + function cleardata(source,~) + if isempty(observe_EEGDAT.EEG) + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Clear'); + observe_EEGDAT.eeg_panel_message =1; + EEGArray = EStduio_eegtab_EEG_set.butttons_datasets.Value; + if length(observe_EEGDAT.ALLEEG)==1 && numel(EEGArray) == length(observe_EEGDAT.ALLEEG) + ALLEEG = []; + LASTCOM = 'ALLEEG = []; EEG=[]; CURRENTSET=[];'; + else + [ALLEEG,LASTCOM] = pop_delset( observe_EEGDAT.ALLEEG , EEGArray); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + ERPset_remained = setdiff([1:length(observe_EEGDAT.ALLEEG)],EEGArray); + if isempty(ERPset_remained) + ALLEEG = []; + end + end + eegh(LASTCOM); + if isempty(ALLEEG) + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + Edit_label = 'off'; + CURRENTSET=1; + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'off'; + else + observe_EEGDAT.ALLEEG = observe_EEGDAT.ALLEEG(ERPset_remained); + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets();%%all EEGset + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + if EStduio_eegtab_EEG_set.eeg_contns.Value==0 + EStudio_gui_erp_totl.EEG_transf=1; + end + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 0; + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + EStudio_gui_erp_totl.EEG_transf=1; + end + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 1; + end + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + CURRENTSET = length(observe_EEGDAT.ALLEEG); + + %%contains the both continuous and epoched EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + if EStduio_eegtab_EEG_set.eeg_contns.Value==1%%continuous EEG + [~, ypos] = find(EEGtypeFlag==1); + else + [~, ypos] = find(EEGtypeFlag==0); + end + CURRENTSET = ypos(end); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + Edit_label = 'on'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'on'; + end + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + EStduio_eegtab_EEG_set.butttons_datasets.Value =CURRENTSET; + EStduio_eegtab_EEG_set.dupeselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.renameselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.suffix.Enable= Edit_label; + EStduio_eegtab_EEG_set.clearselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.savebutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.saveasbutton.Enable=Edit_label; + EStduio_eegtab_EEG_set.curr_folder.Enable='on'; + EStduio_eegtab_EEG_set.butttons_datasets.Min =1; + EStduio_eegtab_EEG_set.butttons_datasets.Max =length(EEGlistName)+1; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = Edit_label; + EStduio_eegtab_EEG_set.appendbutton.Enable = Edit_label; + EStduio_eegtab_EEG_set.refresh_eegset.Enable= 'on'; + EEGArray= EStduio_eegtab_EEG_set.butttons_datasets.Value; + estudioworkingmemory('EEGArray',EEGArray); + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(); + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets > Clear EEG'); + observe_EEGDAT.eeg_panel_message=2; + end + + +%-------------------------- Save selected EEGsets------------------------------------------- + function eegset_save(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEGsets > Save'); + observe_EEGDAT.eeg_panel_message =1; + pathNamedef = estudioworkingmemory('EEG_save_folder');%% the forlder to save the data. + if isempty(pathNamedef) + pathNamedef = [cd,filesep]; + end + + EEGArray= EStduio_eegtab_EEG_set.butttons_datasets.Value; + if isempty(EEGArray) || any(EEGArray>length(observe_EEGDAT.ALLEEG)) + EEGArray =observe_EEGDAT.CURRENTSET; + end + + for Numofeeg = 1:length(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Save EEG dataset*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + pathName = EEG.filepath; + if isempty(pathName) + pathName = pathNamedef; + end + FileName = EEG.filename; + if isempty(FileName) + FileName =EEG.setname; + end + [pathx, filename, ext] = fileparts(FileName); + filename = [filename '.set']; + checkfileindex = checkfilexists([pathName,filesep,filename]); + if checkfileindex==1 + [EEG, LASTCOM] = pop_saveset( EEG, 'filename',filename,'filepath',pathName); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg ==length(EEGArray) + eegh(LASTCOM); + end + disp(['Saved to',32,pathName,filesep,filename]); + fprintf(['\n',LASTCOM,'\n']); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg =1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%------------------------- Save as----------------------------------------- + function eegset_saveas(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGsets>Save a Copy'); + observe_EEGDAT.eeg_panel_message =1; + pathName = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName) + pathName = [cd,filesep]; + end + EEGArray= EStduio_eegtab_EEG_set.butttons_datasets.Value; + if isempty(EEGArray) || any(EEGArray>length(observe_EEGDAT.ALLEEG)) + EEGArray =observe_EEGDAT.CURRENTSET; + end + + Answer = f_EEG_saveas_multi_file(observe_EEGDAT.ALLEEG,EEGArray,'_copy',pathName); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + end + ALLEEG = observe_EEGDAT.ALLEEG; + for Numofeeg = 1:length(EEGArray) + EEG = ALLEEG_out(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Save EEG dataset as *',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + if ~isempty(EEG.filename) + filename= EEG.filename; + else + filename = [EEG.setname,'.set']; + end + [pathstr, filename, ext] = fileparts(filename); + filename = [filename '.set']; + checkfileindex = checkfilexists([EEG.filepath,filename]); + if checkfileindex==1 + [EEG, LASTCOM] = pop_saveset( EEG, 'filename',filename,'filepath',[EEG.filepath,filesep]); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg ==length(EEGArray) + eegh(LASTCOM); + end + disp(['Saved as to',32,EEG.filepath,filesep,filename]); + fprintf(['\n',LASTCOM,'\n']); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_ERP_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + catch + Selected_ERP_afd = length(observe_EEGDAT.ALLEEG); + end + EStduio_eegtab_EEG_set.butttons_datasets.Value = Selected_ERP_afd; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_ERP_afd); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + + observe_EEGDAT.count_current_eeg =1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%---------------- Enable/Disable dot structure----------------------------- + function curr_folder(~,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + pathName = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName) + pathName =cd; + end + title = 'Select one forlder for saving files in following procedures'; + select_path = uigetdir(pathName,title); + + if isequal(select_path,0) + select_path = cd; + end + + cd(select_path); + erpcom = sprintf('cd("%s',select_path); + erpcom = [erpcom,'");']; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*EEGsets>Current Folder*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf( [erpcom]); + fprintf( ['\n',repmat('-',1,100) '\n']); + + eegh(erpcom); + estudioworkingmemory('EEG_save_folder',select_path); + observe_EEGDAT.count_current_eeg=26; + end + + +%-----------------select the ERPset of interest-------------------------- + function selectdata(source,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=100 && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + EEGArraylabel = sort(source.Value); + [~,~,EEGtypeFlag] = getDatasets(); + EEGArraydef = estudioworkingmemory('EEGArray'); + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 %%continuous EEG + EEGtypeFlag1 = 1; + else%%epoched EEG + EEGtypeFlag1 = 0; + end + + [xpos, ypos] = find(EEGtypeFlag==EEGtypeFlag1); + Diffnum = setdiff(EEGArraylabel,ypos); + if ~isempty(Diffnum) + if isempty(EEGArraydef) + EStduio_eegtab_EEG_set.butttons_datasets.Value =ypos(end); + estudioworkingmemory('EEGArray',ypos(end)); + CURRENTSET = ypos(end); + else + %%insert Warning message to message panel + Diffnum1 = setdiff(EEGArraydef,ypos); + if ~isempty(Diffnum1) + EStduio_eegtab_EEG_set.butttons_datasets.Value =ypos(end); + estudioworkingmemory('EEGArray',ypos(end)); + CURRENTSET = ypos(end); + else + EStduio_eegtab_EEG_set.butttons_datasets.Value =EEGArraydef; + CURRENTSET = EEGArraydef(1); + end + end + else%%included in the continuous EEG + estudioworkingmemory('EEGArray',EEGArraylabel); + CURRENTSET = EEGArraylabel(1); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + %%save to workspace + estudioworkingmemory('Startimes',0); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + observe_EEGDAT.count_current_eeg =2; + if EStudio_gui_erp_totl.EEG_autoplot==1 + f_redrawEEG_Wave_Viewer(1); + end + end + + +%%%--------------Update this panel-------------------------------------- + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=1 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + Change2epocheeg= estudioworkingmemory('Change2epocheeg'); + if isempty(Change2epocheeg) || Change2epocheeg==0 + + elseif Change2epocheeg==1 + EStduio_eegtab_EEG_set.eeg_epoch.Value =1; + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + elseif Change2epocheeg==2 + EStduio_eegtab_EEG_set.eeg_epoch.Value =0; + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + end + estudioworkingmemory('Change2epocheeg',0); + if ~isempty(observe_EEGDAT.ALLEEG) && ~isempty(observe_EEGDAT.EEG) + ALLEEG = observe_EEGDAT.ALLEEG; + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:)>length(observe_EEGDAT.ALLEEG)) + EEGArray = length(observe_EEGDAT.ALLEEG);estudioworkingmemory('EEGArray',EEGArray); + observe_EEGDAT.CURRENTSET = EEGArray; + end + CURRENTSET = observe_EEGDAT.CURRENTSET; + ALLEEGArray = [1:length(ALLEEG)]; + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets();%%all EEGset + %%Only continuous EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 0; + end + %%Only epoched EEG + if EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + EStduio_eegtab_EEG_set.eeg_epoch.Value = 1; + end + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + if (EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==0) || (EEGConts_epoch_Flag(1)==0 && EEGConts_epoch_Flag(2)==1) + if isempty(setdiff(EEGArray,ALLEEGArray)) %% + if isempty(setdiff(CURRENTSET,EEGArray)) %% + CURRENTSET = EEGArray(1); + end + else + CURRENTSET = length(ALLEEG); + EEGArray = CURRENTSET; + estudioworkingmemory('EEGArray',CURRENTSET); + end + end + + %%contains the both continuous and epoched EEG + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + EStduio_eegtab_EEG_set.eeg_contns.Enable='on'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='on'; + if EStduio_eegtab_EEG_set.eeg_contns.Value==1%%continuous EEG + [~, ypos] = find(EEGtypeFlag==1); + else + [~, ypos] = find(EEGtypeFlag==0); + end + if isempty(setdiff(EEGArray,ypos)) %% + if isempty(setdiff(CURRENTSET,EEGArray)) %% + CURRENTSET = EEGArray(1); + end + else + CURRENTSET = ypos(end); + EEGArray = CURRENTSET; + estudioworkingmemory('EEGArray',CURRENTSET); + end + end + EStduio_eegtab_EEG_set.butttons_datasets.Min = 1; + EStduio_eegtab_EEG_set.butttons_datasets.Max = length(observe_EEGDAT.ALLEEG)+1; + EStduio_eegtab_EEG_set.butttons_datasets.Value = EEGArray; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(CURRENTSET); + observe_EEGDAT.CURRENTSET = CURRENTSET; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'off'; + Edit_label = 'on'; + else + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + Edit_label = 'off'; + CURRENTSET=1; + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'off'; + EStduio_eegtab_EEG_set.butttons_datasets.Value=1; + [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(); + EStduio_eegtab_EEG_set.butttons_datasets.String = EEGlistName; + end + %%save to workspace + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + if EEGUpdate==1 + Edit_label = 'off'; + EStduio_eegtab_EEG_set.eeg_contns.Enable='off'; + EStduio_eegtab_EEG_set.eeg_epoch.Enable='off'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = 'off'; + end + EStduio_eegtab_EEG_set.dupeselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.renameselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.suffix.Enable= Edit_label; + EStduio_eegtab_EEG_set.clearselected.Enable=Edit_label; + EStduio_eegtab_EEG_set.savebutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.saveasbutton.Enable=Edit_label; + EStduio_eegtab_EEG_set.curr_folder.Enable='on'; + EStduio_eegtab_EEG_set.butttons_datasets.Enable = Edit_label; + EStduio_eegtab_EEG_set.appendbutton.Enable= Edit_label; + EStduio_eegtab_EEG_set.refresh_eegset.Enable= 'on'; + observe_EEGDAT.count_current_eeg =2; + f_redrawEEG_Wave_Viewer(1); + end + +%----------------------Get the information of the updated EEGsets---------- + function [EEGlistName,EEGConts_epoch_Flag,EEGtypeFlag] = getDatasets(ALLEEG) + if nargin<1 + ALLEEG= observe_EEGDAT.ALLEEG; + end + EEGlistName = {}; + EEGConts_epoch_Flag = [0 0]; + if ~isempty(ALLEEG) + for ii = 1:length(ALLEEG) + EEGlistName{ii,1} = char(strcat(num2str(ii),'.',32, ALLEEG(ii).setname)); + if ALLEEG(ii).trials>1 + EEGtypeFlag(1,ii) = 0;%%epoched EEG + else + EEGtypeFlag(1,ii) = 1;%%Continuous EEG + end + end + [xpos,ypos1] = find(EEGtypeFlag==1); + if isempty(ypos1) + EEGConts_epoch_Flag(1) = 0; + else + EEGConts_epoch_Flag(1) = 1; + end + [~,ypos2] = find(EEGtypeFlag==0); + if isempty(ypos2) + EEGConts_epoch_Flag(2) = 0; + else + EEGConts_epoch_Flag(2) = 1; + end + + ERP_markdisable = []; + if EEGConts_epoch_Flag(1)==1 && EEGConts_epoch_Flag(2)==1 + if EStduio_eegtab_EEG_set.eeg_contns.Value==1 + ERP_markdisable = setdiff([1:length(ALLEEG)],ypos1); + else + ERP_markdisable = setdiff([1:length(ALLEEG)],ypos2); + end + if ~isempty(ERP_markdisable) + for ii = ERP_markdisable + EEGlistName{ii,1} = str2html( char(strcat(num2str(ii),'.',32, ALLEEG(ii).setname)),'italic', 1, 'colour', '#A0A0A0'); + end + end + end + else + EEGlistName{1} = 'No EEG is available' ; + EEGConts_epoch_Flag = [0,0];%%continuous EEG, epoch EEG + EEGtypeFlag = []; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=1 + return; + end + + if ~isempty(observe_EEGDAT.ALLEEG) + + CURRENTSET = length(observe_EEGDAT.ALLEEG); + EEGArray = CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(EEGArray); + if observe_EEGDAT.EEG.trials>1 + EStduio_eegtab_EEG_set.eeg_epoch.Value =1; + EStduio_eegtab_EEG_set.eeg_contns.Value=0; + else + EStduio_eegtab_EEG_set.eeg_epoch.Value =0; + EStduio_eegtab_EEG_set.eeg_contns.Value=1; + end + EStduio_eegtab_EEG_set.butttons_datasets.Value = CURRENTSET; + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',CURRENTSET); + end + observe_EEGDAT.Reset_eeg_paras_panel=2; + end + +end + +%%----Oct 2023---GH +%%---automatically close right panels if select continuous/epoched EEG----- +function EEGTab_close_open_Panels(whichpanel) +global EStudio_gui_erp_totl +if any(whichpanel(:)>24) || any(whichpanel(:)<1)%%check the labels for the right panels + return; +end + +for Numofpanel = 1:length(whichpanel) + minned = EStudio_gui_erp_totl.eegpanel{whichpanel(Numofpanel)}.IsMinimized; + if ~minned + szs = get( EStudio_gui_erp_totl.eegsettingLayout, 'Sizes'); + set( EStudio_gui_erp_totl.eegpanel{whichpanel(Numofpanel)}, 'IsMinimized', true); + szs(whichpanel(Numofpanel)) = 25; + set( EStudio_gui_erp_totl.eegsettingLayout, 'Sizes', szs ); + EStudio_gui_erp_totl.eegpanelscroll.Heights = sum(szs); + end +end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_eeglabica_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_eeglabica_GUI.m new file mode 100644 index 00000000..7671b346 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_eeglabica_GUI.m @@ -0,0 +1,1068 @@ +%%This function is to do the works about ICA in EGELAB + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + +function varargout = f_EEG_eeglabica_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +%---------------------------Initialize parameters------------------------------------ +EStduio_eegtab_eeglab_ica = struct(); + +%-----------------------------Name the title---------------------------------------------- +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_box_eeglab_ica = uiextras.BoxPanel('Parent', fig, 'Title', 'EEGLAB ICA (only for one selected dataset)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_box_eeglab_ica = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEGLAB ICA (only for one selected dataset)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + EStudio_box_eeglab_ica = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEGLAB ICA (only for one selected dataset)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%%, 'HelpFcn', @eeglabica_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_event2bin_eeg(FonsizeDefault) +varargout{1} = EStudio_box_eeglab_ica; + + function drawui_event2bin_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EStduio_eegtab_eeglab_ica.DataSelBox = uiextras.VBox('Parent', EStudio_box_eeglab_ica,'BackgroundColor',ColorB_def); + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + %%About this dataset and dataset information + EStduio_eegtab_eeglab_ica.decomp_labelic_title = uiextras.HBox('Parent', EStduio_eegtab_eeglab_ica.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + + EStduio_eegtab_eeglab_ica.icadecomp_eeg = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.decomp_labelic_title,... + 'String','Decompose data','callback',@icadecomp_eeg,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_ica.inslabel_ics = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.decomp_labelic_title,... + 'String','Inspect/label ICs','callback',@inslabel_ics,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + %%Edit eeg events and channel locations + EStduio_eegtab_eeglab_ica.event_chanlocs_title = uiextras.HBox('Parent', EStduio_eegtab_eeglab_ica.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_ica.classifyics_iclabel = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.event_chanlocs_title,... + 'String','Classify IC by ICLabel','callback',@classifyics_iclabel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_ica.remove_ics = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.event_chanlocs_title,... + 'String','Remove ICs','callback',@remove_ics,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + + %%transfter ICA weights + EStduio_eegtab_eeglab_ica.icaweigts_title1 = uiextras.HBox('Parent', EStduio_eegtab_eeglab_ica.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', EStduio_eegtab_eeglab_ica.icaweigts_title1,... + 'String','Transfer ICA weights:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_ica.DataSelGrid = uiextras.Grid('Parent', EStduio_eegtab_eeglab_ica.DataSelBox,... + 'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EStduio_eegtab_eeglab_ica.DataSelGrid); + uicontrol('Style','text','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','From','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + uicontrol('Style','text','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','Selected dataset','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1B + EStduio_eegtab_eeglab_ica.CurrentEEG_tras= uicontrol('Style','Edit','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 1B + + uiextras.Empty('Parent', EStduio_eegtab_eeglab_ica.DataSelGrid); % 1A + uicontrol('Style','text','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','to','FontSize',FonsizeDefault-1,'BackgroundColor',ColorB_def); % 1B + + uicontrol('Style','text','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','Target dataset','FontSize',FonsizeDefault-1,'BackgroundColor',ColorB_def); % 1B + EStduio_eegtab_eeglab_ica.targetEEG_tras= uicontrol('Style','Edit','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','',... + 'callback',@trans_weight_targeteeg,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 1B + + uiextras.Empty('Parent', EStduio_eegtab_eeglab_ica.DataSelGrid); % 1A + EStduio_eegtab_eeglab_ica.traICAweight= uicontrol('Style','pushbutton','Parent', EStduio_eegtab_eeglab_ica.DataSelGrid,'String','Transfer',... + 'callback',@trans_weight,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',EnableFlag); % 1B + set( EStduio_eegtab_eeglab_ica.DataSelGrid, 'ColumnSizes',[30 90 15 76 -1],'RowSizes',[20 30]); + + + %%Plot channel function + EStduio_eegtab_eeglab_ica.plotic_title1 = uiextras.HBox('Parent', EStduio_eegtab_eeglab_ica.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', EStduio_eegtab_eeglab_ica.plotic_title1,... + 'String','Plot independent components:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + EStduio_eegtab_eeglab_ica.plotic_title2 = uiextras.HBox('Parent', EStduio_eegtab_eeglab_ica.DataSelBox, 'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_ica.eeg_spcetra_map = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.plotic_title2,... + 'String','Spectra&maps','callback',@eeg_spcetra_map,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_ica.ic_maps_2d = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.plotic_title2,... + 'String','Maps (2-D)','callback',@maps_2d,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_ica.ic_maps_3d = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.plotic_title2,... + 'String','Maps (3-D)','callback',@maps_3d,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + EStduio_eegtab_eeglab_ica.plotic_title3 = uiextras.HBox('Parent', EStduio_eegtab_eeglab_ica.DataSelBox, 'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_ica.eeg_ic_prop = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.plotic_title3,... + 'String','IC Properties','callback',@eeg_ic_prop,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_ica.eeg_ic_tfr = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_ica.plotic_title3,... + 'String','IC Time-frequency','callback',@eeg_ic_tfr,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set(EStduio_eegtab_eeglab_ica.DataSelBox,'Sizes',[30 30 20 50 20 30 30]); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%-----------------Decompose the data by ICA------------------------------- + function icadecomp_eeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Decompose data'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > Decompose data: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + Save_file_label = 0; + + ALLEEG = observe_EEGDAT.ALLEEG; + EEG = ALLEEG(EEGArray); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray),'):',32,EEG.setname,'\n\n']); + %%Run ICA + [EEG, LASTCOM] =pop_runica( EEG); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + + fprintf(['\n',LASTCOM,'\n']); + Answer = f_EEG_save_multi_file(EEG,1, '_ica'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label==1 && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + eegh(LASTCOM); + + fprintf(['\n ICA was done for eeg dataset (No.',num2str(EEGArray),'):',32,EEG.setname,'\n']); + fprintf( ['\n',repmat('-',1,100) '\n']); + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------------------Inspect/label ICs------------------------------------ + function inslabel_ics(Source,~)%%Need to check again + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Inspect/label ICs'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > Inspect/label ICs:Only works for one selected dataset']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + estudioworkingmemory('EEGUpdate',1); + observe_EEGDAT.count_current_eeg=1; + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Inspect/label ICs*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + [~,LASTCOM] = pop_selectcomps(EEG);% + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Inspect/label ICs:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg=1; + return; + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + fprintf([LASTCOM,'\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + Output = f_EEG_update_gui; + if ~isempty(Output) && Output==1 + try EEG = evalin('base', 'EEG');catch EEG = []; end + if ~isempty(EEG) + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) =EEG ; + observe_EEGDAT.EEG = EEG; + end + end + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg=1; + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Inspect/label ICs'); + observe_EEGDAT.eeg_panel_message =2; + end + +%%-----------------Classify ICs by ICLabel--------------------------------- + function classifyics_iclabel(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Classify IC by ICLabel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > Classify IC by ICLabel: Only works for one selected dataset']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Classify IC by ICLabel*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + EEG = f_estudio_iclabel(EEG,EEGArray(Numofeeg)); + LASTCOM = sprintf('EEG = f_estudio_iclabel(EEG, %d);', EEGArray); + + EEG = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + if Numofeeg==1 + eegh(LASTCOM); + end + + if isempty(EEG) + observe_EEGDAT.eeg_panel_message =4; + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg=1; + return; + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) =EEG ; + observe_EEGDAT.EEG = EEG; + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + observe_EEGDAT.count_current_eeg=1; + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Classify IC by ICLabel'); + observe_EEGDAT.eeg_panel_message =2; + end + +%%-------------------Remove ICs-------------------------------------------- + function remove_ics(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Remove ICs'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > Remove ICs:Only works for one selected dataset']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + ALLEEG = observe_EEGDAT.ALLEEG; + + EEG = ALLEEG(EEGArray); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf( ['**Remove ICs**\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray),'):',32,EEG.setname,'\n\n']); + + if ~isempty(EEG.reject.gcompreject) + components = find(EEG.reject.gcompreject == 1); + components = components(:)'; + %promptstr = { ['Components to subtract from data' 10 '(default: pre-labeled components to reject):'] }; + else + components = []; + end + uilist = { { 'style' 'text' 'string' 'Note: for group level analysis, remove components in STUDY' } ... + { 'style' 'text' 'string' 'List of component(s) to remove from data' } ... + { 'style' 'edit' 'string' int2str(components) } ... + { 'style' 'text' 'string' 'Or list of component(s) to retain' } ... + { 'style' 'edit' 'string' '' } ... + }; + geom = { 1 [2 0.7] [2 0.7] }; + result = inputgui( 'uilist', uilist, 'geometry', geom, 'helpcom', 'pophelp(''pop_subcomp'')', ... + 'title', ['eegset',32,num2str(EEGArray),':Remove IC -- pop_subcomp()']); + if length(result) == 0 + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + components = eval( [ '[' result{1} ']' ] ); + if ~isempty(result{2}) + componentsOld = components; + components = eval( [ '[' result{2} ']' ] ); + if isequal(components, componentsOld) + components = []; + end + keepcomp = 1; %components = setdiff_bc([1:size(EEG.icaweights,1)], components); + else + keepcomp = 0; + end + plotag = 0; + [EEG, LASTCOM] = pop_subcomp( EEG, components, plotag, keepcomp); + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Remove ICs:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + try + EEG.setname = EEG.setname(1:end-16); + catch + end + fprintf(['\n',LASTCOM,'\n']); + Save_file_label = 0; + Answer = f_EEG_save_multi_file(EEG,1, '_rmic'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + if keepcomp==1 + components = setdiff_bc([1:size(EEG.icaweights,1)], components); + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + eegh(LASTCOM); + fprintf(['\n ICs [',32,num2str(components),32, '] have been removed from eeg dataset (No.',num2str(EEGArray),'):',32,EEG.setname,'\n']); + fprintf( ['\n',repmat('-',1,100) '\n']); + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end +%%----------------------------Target EEG for ICA weight transfer----------- + function trans_weight_targeteeg(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > Transfer ICA weights: Only works for one selected dataset']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + + return; + end + + TartgetEEG = str2num(Source.String); + if isempty(TartgetEEG) || numel(TartgetEEG)~=1 || any(TartgetEEG<=0) + msgboxText = ['EEGLAB ICA > Transfer ICA weights: The index of the Target EEG must be a single positive value']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if any(TartgetEEG>length(observe_EEGDAT.ALLEEG)) + msgboxText = ['EEGLAB ICA > Transfer ICA weights: The index of the Target EEG should be smaller than ',32,num2str(length(observe_EEGDAT.ALLEEG))]; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if any(TartgetEEG== observe_EEGDAT.CURRENTSET) + msgboxText = ['EEGLAB ICA > Transfer ICA weights: The current EEG cannot be used as target one because the selected set is the same to the target set']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if isempty(observe_EEGDAT.ALLEEG(EEGArray).icachansind) + msgboxText = ['EEGLAB ICA > Transfer ICA weights: Please run ICA for the current EEG first']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if any(observe_EEGDAT.ALLEEG(EEGArray).icachansind> observe_EEGDAT.ALLEEG(TartgetEEG).nbchan) || observe_EEGDAT.ALLEEG(TartgetEEG).nbchan~= observe_EEGDAT.EEG.nbchan + msgboxText = ['EEGLAB ICA > Transfer ICA weights: The channels for target set donot match with the current EEG']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%------------------------Transfer ICA weights----------------------------- + function trans_weight(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Transfer ICA weights> Transfer'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > Transfer ICA weights:Only works for one selected dataset']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + TartgetEEG = str2num(EStduio_eegtab_eeglab_ica.targetEEG_tras.String); + if isempty(TartgetEEG) || numel(TartgetEEG)~=1 || any(TartgetEEG<=0) + msgboxText = ['EEGLAB ICA > Transfer ICA weights > Transfer: The index of the Target EEG must be a single positive value']; + EStduio_eegtab_eeglab_ica.targetEEG_tras.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if any(TartgetEEG>length(observe_EEGDAT.ALLEEG)) + msgboxText = ['EEGLAB ICA > Transfer ICA weights > Transfer: The index of the Target EEG should be smaller than ',32,num2str(length(observe_EEGDAT.ALLEEG))]; + EStduio_eegtab_eeglab_ica.targetEEG_tras.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if any(TartgetEEG== observe_EEGDAT.CURRENTSET) + msgboxText = ['EEGLAB ICA > Transfer ICA weights > Transfer: The current EEG cannot be used as target one']; + EStduio_eegtab_eeglab_ica.targetEEG_tras.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if isempty(observe_EEGDAT.EEG.icachansind) + msgboxText = ['EEGLAB ICA > Transfer ICA weights > Transfer: Please run ICA for the current EEG']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if any(observe_EEGDAT.EEG.icachansind(:)> observe_EEGDAT.ALLEEG(TartgetEEG).nbchan) || observe_EEGDAT.ALLEEG(TartgetEEG).nbchan~= observe_EEGDAT.EEG.nbchan + msgboxText = ['EEGLAB ICA > Transfer ICA weights > Transfer: The channels for target set donot match with the current EEG']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + + ALLEEG = observe_EEGDAT.ALLEEG; + EEG = ALLEEG(TartgetEEG); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf( ['**Transfer ICA weights > Transfer**\n']); + fprintf(['Your current EEGset(No.',num2str(TartgetEEG),'):',32,EEG.setname,'\n\n']); + [EEG,LASTCOM]= pop_editset(EEG, 'icaweights', ['ALLEEG(',num2str(EEGArray),').icaweights'],... + 'icasphere', ['ALLEEG(',num2str(EEGArray),').icasphere'], 'icachansind', ['ALLEEG(',num2str(EEGArray),').icachansind']); + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > Remove ICs:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + fprintf(['\n',LASTCOM,'\n']); + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + + Save_file_label = 0; + Answer = f_EEG_save_multi_file(EEG,1, '_icaweights'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + fprintf(['\n',LASTCOM,'\n']); + eegh(LASTCOM); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + eegh(LASTCOM); + fprintf(['\n',LASTCOM,'\n']); + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%---------------------IC maps 2D------------------------------------------ + function maps_2d(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC maps in 2-D'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > IC maps in 2-D:Only works for one selected dataset']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.Enable = 'off'; + observe_EEGDAT.eeg_panel_message =2; + return; + end + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*IC maps in 2-D*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + + LASTCOM= pop_topoplot(EEG, 0); + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC maps in 2-D:User selected cancel'); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + set(gcf,'Name',['eegset',32,num2str(EEGArray(Numofeeg)),': IC maps in 2-D for',32,EEG.setname],'NumberTitle', 'off'); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + +%%---------------------IC maps 3D------------------------------------------ + function maps_3d(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC maps in 3-D'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG))|| any(EEGArray(:)<1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > IC maps in 3-D:Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*IC maps in 3-D*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + + [~, LASTCOM] = pop_headplot( EEG,0); + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC maps in 3-D:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + set(gcf,'Name',['eegset',32,num2str(EEGArray(Numofeeg)),': IC maps in 3-D for',32,EEG.setname],'NumberTitle', 'off'); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + + +%%----------------------Spectra and maps----------------------------------- + function eeg_spcetra_map(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC spectra and maps'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > IC spectra and maps:Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*IC spectra and maps*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + + LASTCOM= pop_spectopo(EEG,0); + if isempty(LASTCOM) + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC spectra and maps:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + set(gcf,'Name',['eegset',32,num2str(EEGArray(Numofeeg)),': IC spectra and maps for',32,EEG.setname],'NumberTitle', 'off'); + LASTCOM = LASTCOM(8:end); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + +%%---------------------Channel properties---------------------------------- + function eeg_ic_prop(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC properties'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB ICA > IC properties:Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = observe_EEGDAT.EEG; + typecomp = 0; % defaults + chanorcomp = 0; + commandchan = 'tmpchanlocs = EEG(1).chanlocs; [tmp tmpval] = pop_chansel({tmpchanlocs.labels}, ''withindex'', ''on'', ''selectionmode'', ''single''); set(findobj(gcbf, ''tag'', ''chan''), ''string'',tmpval); clear tmp tmpchanlocs tmpval'; + uitext = { { 'style' 'text' 'string' fastif(typecomp,'Channel index(ices) to plot:','Component index(ices) to plot:') } ... + { 'style' 'edit' 'string' '1', 'tag', 'chan' } ... + { 'style' 'pushbutton' 'string' '...', 'enable' fastif(~isempty(EEG(1).chanlocs) && typecomp, 'on', 'off') 'callback' commandchan } ... + { 'style' 'text' 'string' 'Spectral options (see spectopo() help):' } ... + { 'style' 'edit' 'string' '''freqrange'', [2 50]' } {} }; + uigeom = { [2 1 0.5 ] [2 1 0.5] }; + result = inputgui('geometry', uigeom, 'uilist', uitext, 'helpcom', 'pophelp(''pop_prop'');', ... + 'title', fastif( typecomp, 'IC properties - pop_prop()', 'Component properties - pop_prop()')); + if size( result, 1 ) == 0 + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC properties:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + + chanoristr = result{1}; + try + chanorcomp = eeg_decodechan(EEG.chanlocs, result{1} ); + catch + fprintf( 2,['\n EEGLAB Tools > IC properties: IC index out of range, we therefore set it to 1.\n']); + chanorcomp = 1; + end + + spec_opt = eval( [ '{' result{2} '}' ] ); + if isempty(chanorcomp) + msgboxText = 'EEGLAB Tools > IC properties:Please define IC index(ices)'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + if typecomp == 0 && isempty(EEG.icaweights) + msgboxText = ['EEGLAB Tools > IC properties > eegset',32,num2str(EEGArray(Numofeeg)),': No ICA weights recorded for this dataset -- first run ICA on it']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + return; + end + if min(chanorcomp(:)) > numel(EEG.icachansind) || max(chanorcomp(:)) > numel(EEG.icachansind) + fprintf( ['\n One or more defined IC index(ices) cannot be found, we therefore set it to 1\n']); + chanorcomp = 1; + end + + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*IC properties*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + for Numofchan = 1:numel(chanorcomp) + LASTCOM = pop_prop( EEG, 0, chanorcomp(Numofchan), NaN, spec_opt); + set(gcf,'Name',['eegset',32,num2str(EEGArray(Numofeeg)),': IC properties for',32,EEG.setname],'NumberTitle', 'off'); + end + LASTCOM = sprintf('pop_prop( EEG, %d, %s, NaN, %s);', typecomp, ['[',num2str(chanorcomp),']'], vararg2str( { spec_opt } ) ); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf(LASTCOM,'\n'); + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC properties'); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + +%%------------------------Time-frequency----------------------------------- + function eeg_ic_tfr(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC Time-frequency'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = 'EEGLAB ICA > IC Time-frequency:Only works on one selected dataset'; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*IC time-frequency*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + + LASTCOM = pop_newtimef(EEG,0); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + return; + end + set(gcf,'Name',['eegset',32,num2str(EEGArray(Numofeeg)),': IC Time-frequency for',32,EEG.setname],'NumberTitle', 'off'); + LASTCOM =LASTCOM(8:end); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + estudioworkingmemory('f_EEG_proces_messg','EEGLAB ICA > IC Time-frequency'); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=12 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.ALLEEG) || EEGUpdate==1 + EStduio_eegtab_eeglab_ica.icadecomp_eeg.Enable = 'off'; + EStduio_eegtab_eeglab_ica.inslabel_ics.Enable= 'off'; + EStduio_eegtab_eeglab_ica.classifyics_iclabel.Enable= 'off'; + EStduio_eegtab_eeglab_ica.remove_ics.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_spcetra_map.Enable= 'off'; + EStduio_eegtab_eeglab_ica.ic_maps_2d.Enable= 'off'; + EStduio_eegtab_eeglab_ica.ic_maps_3d.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_ic_prop.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_ic_tfr.Enable= 'off'; + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.targetEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.traICAweight.Enable= 'off'; + observe_EEGDAT.count_current_eeg=13; + return; + end + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray > length(observe_EEGDAT.ALLEEG)) || any(EEGArray <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + if numel(EEGArray)~=1 + EStduio_eegtab_eeglab_ica.icadecomp_eeg.Enable = 'off'; + EStduio_eegtab_eeglab_ica.inslabel_ics.Enable= 'off'; + EStduio_eegtab_eeglab_ica.classifyics_iclabel.Enable= 'off'; + EStduio_eegtab_eeglab_ica.remove_ics.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_spcetra_map.Enable= 'off'; + EStduio_eegtab_eeglab_ica.ic_maps_2d.Enable= 'off'; + EStduio_eegtab_eeglab_ica.ic_maps_3d.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_ic_prop.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_ic_tfr.Enable= 'off'; + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.targetEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.traICAweight.Enable= 'off'; + observe_EEGDAT.count_current_eeg=13; + return; + end + + if isempty(observe_EEGDAT.EEG.icachansind) + EStduio_eegtab_eeglab_ica.icadecomp_eeg.Enable = 'on'; + EStduio_eegtab_eeglab_ica.inslabel_ics.Enable= 'off'; + EStduio_eegtab_eeglab_ica.classifyics_iclabel.Enable= 'off'; + EStduio_eegtab_eeglab_ica.remove_ics.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_spcetra_map.Enable= 'off'; + EStduio_eegtab_eeglab_ica.ic_maps_2d.Enable= 'off'; + EStduio_eegtab_eeglab_ica.ic_maps_3d.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_ic_prop.Enable= 'off'; + EStduio_eegtab_eeglab_ica.eeg_ic_tfr.Enable= 'off'; + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.targetEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.traICAweight.Enable= 'off'; + else + EStduio_eegtab_eeglab_ica.icadecomp_eeg.Enable = 'on'; + EStduio_eegtab_eeglab_ica.inslabel_ics.Enable= 'on'; + EStduio_eegtab_eeglab_ica.classifyics_iclabel.Enable= 'on'; + EStduio_eegtab_eeglab_ica.remove_ics.Enable= 'on'; + EStduio_eegtab_eeglab_ica.eeg_spcetra_map.Enable= 'on'; + EStduio_eegtab_eeglab_ica.ic_maps_2d.Enable= 'on'; + EStduio_eegtab_eeglab_ica.ic_maps_3d.Enable= 'on'; + EStduio_eegtab_eeglab_ica.eeg_ic_prop.Enable= 'on'; + EStduio_eegtab_eeglab_ica.eeg_ic_tfr.Enable= 'on'; + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.Enable= 'off'; + EStduio_eegtab_eeglab_ica.targetEEG_tras.Enable= 'on'; + EStduio_eegtab_eeglab_ica.traICAweight.Enable= 'on'; + end + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.String = num2str(observe_EEGDAT.CURRENTSET); + %%CHECK IF ICLABEL EXISTS + if ~exist('ICLabel','dir') && ~exist('eegplugin_iclabel', 'file') + fprintf(2, 'Warning: ICLabel default plugin missing (probably due to downloading zip file from Github). Install manually.\n'); + EStduio_eegtab_eeglab_ica.classifyics_iclabel.Enable= 'off'; + end + observe_EEGDAT.count_current_eeg=13; + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=9 + return; + end + if ~isempty(observe_EEGDAT.EEG) + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.String = num2str(observe_EEGDAT.CURRENTSET); + else + EStduio_eegtab_eeglab_ica.CurrentEEG_tras.String = ''; + end + EStduio_eegtab_eeglab_ica.targetEEG_tras.String = ''; + observe_EEGDAT.Reset_eeg_paras_panel=10; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_eeglabtool_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_eeglabtool_GUI.m new file mode 100644 index 00000000..cd571056 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_eeglabtool_GUI.m @@ -0,0 +1,872 @@ +%%This function is to assin eventlist to one specific bin + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + +function varargout = f_EEG_eeglabtool_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); + +%---------------------------Initialize parameters------------------------------------ + +EStduio_eegtab_eeglab_tool = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_box_eeglab_tool; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_box_eeglab_tool = uiextras.BoxPanel('Parent', fig, 'Title',... + 'EEGLAB Tools (only for one selected dataset)', 'Padding', 5,'BackgroundColor',ColorB_def); % , 'HelpFcn', @eeglabtool_help +elseif nargin == 1 + EStudio_box_eeglab_tool = uiextras.BoxPanel('Parent', varargin{1}, 'Title',... + 'EEGLAB Tools (only for one selected dataset)', 'Padding ', 5,'BackgroundColor',ColorB_def); +else + EStudio_box_eeglab_tool = uiextras.BoxPanel('Parent', varargin{1}, 'Title',... + 'EEGLAB Tools (only for one selected dataset)', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_event2bin_eeg(FonsizeDefault) +varargout{1} = EStudio_box_eeglab_tool; + + function drawui_event2bin_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EStduio_eegtab_eeglab_tool.DataSelBox = uiextras.VBox('Parent', EStudio_box_eeglab_tool,'BackgroundColor',ColorB_def); + + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + %%About this dataset and Edit Dataset Info + EStduio_eegtab_eeglab_tool.datainfo_title = uiextras.HBox('Parent', EStduio_eegtab_eeglab_tool.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + + EStduio_eegtab_eeglab_tool.about_eegdata = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.datainfo_title,... + 'String','About this dataset','callback',@about_eegdata,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_tool.edit_eeginfor = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.datainfo_title,... + 'String','Edit Dataset Info','callback',@edit_eeginfor,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + + %%Edit eeg events and channel locations + EStduio_eegtab_eeglab_tool.event_chanlocs_title = uiextras.HBox('Parent', EStduio_eegtab_eeglab_tool.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_tool.edit_eegevent = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.event_chanlocs_title,... + 'String','Event values','callback',@edit_eegevent,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_tool.edit_eegchanlocs = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.event_chanlocs_title,... + 'String','Chan locations','callback',@edit_eegchanlocs,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + + %%Reject data using Clean Rawdata and ASR + EStduio_eegtab_eeglab_tool.eeg_ASR_title = uiextras.HBox('Parent', EStduio_eegtab_eeglab_tool.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_tool.eeg_asr = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.eeg_ASR_title,... + 'String','Reject data using clean rawdata and ASR','callback',@eeg_asr,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + %%adjust event latencies + EStduio_eegtab_eeglab_tool.eeg_adjustlatency_title = uiextras.HBox('Parent', EStduio_eegtab_eeglab_tool.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_tool.adjust_latency = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_eeglab_tool.eeg_adjustlatency_title,... + 'String','Adjust event latencies','callback',@adjust_latency,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent',EStduio_eegtab_eeglab_tool.eeg_adjustlatency_title); + set(EStduio_eegtab_eeglab_tool.eeg_adjustlatency_title,'Sizes',[130 -1]) + + + %%Plot channel function + EStduio_eegtab_eeglab_tool.plotchan_title1 = uiextras.HBox('Parent', EStduio_eegtab_eeglab_tool.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', EStduio_eegtab_eeglab_tool.plotchan_title1,... + 'String','Plot channel function:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_tool.plotchan_title2 = uiextras.HBox('Parent', EStduio_eegtab_eeglab_tool.DataSelBox, 'BackgroundColor',ColorB_def); + EStduio_eegtab_eeglab_tool.eeg_spcetra_map = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.plotchan_title2,... + 'String','Spectra & maps','callback',@eeg_spcetra_map,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_eeglab_tool.eeg_chanprop = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.plotchan_title2,... + 'String','Chan prop.','callback',@eeg_chanprop,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + EStduio_eegtab_eeglab_tool.eeg_tfr = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_eeglab_tool.plotchan_title2,... + 'String','Time-frequency','callback',@eeg_tfr,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set(EStduio_eegtab_eeglab_tool.DataSelBox,'Sizes',[30 30 30 30 20 30]) + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%-----------------------About the current EEG----------------------------- + function about_eegdata(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > About this dataset'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = 'EEGLAB Tools > About this dataset: Only works for one selected dataset'; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + + for Numofeeg = 1:numel(EEGArray)%%loop for subjects + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + if ~isempty(EEG.comments) + titleName = ['EEGset',32,num2str(EEGArray(Numofeeg)),':',EEG.setname]; + [EEG.comments,LASTCOM] = pop_comments(EEG.comments,titleName); + if Numofeeg==1 + eegh(LASTCOM); + end + else + msgboxText = ['EEGLAB Tools > EEG.comments is empty for',32,EEG.setname]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > About this dataset'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + end + + +%%---------------------EEG datasets information---------------------------- + function edit_eeginfor(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Edit Dataset Info'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Edit Dataset Info: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + EEG = observe_EEGDAT.ALLEEG(EEGArray); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(1)),'):',32,EEG.setname,'\n\n']); + + %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. + [EEG, LASTCOM] = pop_editset(EEG); + fprintf(LASTCOM,'\n'); + if isempty(LASTCOM) + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + Answer = f_EEG_save_multi_file(EEG,1,'_eeginfo'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + Save_file_label =0; + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + + checkfileindex = checkfilexists([EEG.filepath,filesep, EEG.filename]); + if Save_file_label==1 && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + fprintf(LASTCOM,'\n'); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + ALLEEG = observe_EEGDAT.ALLEEG; + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + fprintf(LASTCOM,'\n'); + fprintf( ['\n',repmat('-',1,100) '\n']); + eegh(LASTCOM); + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%--------------------Event values----------------------------------------- + function edit_eegevent(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Event values'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; estudioworkingmemory('EEGArray',EEGArray); + end + + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Event value: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + ALLEEG = observe_EEGDAT.ALLEEG; + + EEG = observe_EEGDAT.ALLEEG(EEGArray); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Event values*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray),':',EEG.setname,'\n']); + + %%Edit events contained in EEG dataset structure + [EEG, LASTCOM] = pop_editeventvals(EEG); + if isempty(LASTCOM) + fprintf( ['\n',repmat('-',1,100) '\n']); + return; + end + fprintf(LASTCOM,'\n'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + + Answer = f_EEG_save_multi_file(EEG,1,'_evetvalue'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + Save_file_label =0; + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + + checkfileindex = checkfilexists([EEG.filepath,filesep, EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + eegh(LASTCOM); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + fprintf(LASTCOM,'\n'); + fprintf( ['\n',repmat('-',1,100) '\n']); + eegh(LASTCOM); + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------------------Edit channel location-------------------------------- + function edit_eegchanlocs(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Chan locations'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Chan locations: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + ALLEEG = observe_EEGDAT.ALLEEG; + %%Edit the channel locations + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Edit the channel locations for eegset(s):',32,num2str(EEGArray),'\n']); + EEG= ALLEEG(EEGArray); + [EEG, chaninfo, urchans, LASTCOM] =pop_chanedit(EEG); + if isempty(LASTCOM) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + fprintf(LASTCOM,'\n'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + + Answer = f_EEG_save_multi_file(EEG,1,'_chanlos'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + Save_file_label =0; + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + if Save_file_label + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + checkfileindex = checkfilexists([EEG.filepath,filesep, EEG.filename]); + if checkfileindex==1 + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + fprintf( ['\n\n',repmat('-',1,100) '\n']); + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + fprintf(LASTCOM,'\n'); + fprintf( ['\n',repmat('-',1,100) '\n']); + eegh(LASTCOM); + observe_EEGDAT.ALLEEG = ALLEEG; + + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%----------------Reject data using clean rawdata and ASR------------------ + function eeg_asr(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Reject data using clean rawdata and ASR'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Reject data using clean rawdata and ASR: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + ALLEEG = observe_EEGDAT.ALLEEG; + %%Edit the channel locations + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['**Reject data using clean rawdata and ASR**\n']); + fprintf(['Your current eegset(s):',32,num2str(EEGArray),'\n']); + try + [EEG,LASTCOM] =pop_clean_rawdata(ALLEEG(EEGArray)); + catch + msgboxText = ['EEGLAB Tools > Reject data using clean rawdata and ASR: Clean Rawdata tool was not included in EEGLAB plugin']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if isempty(LASTCOM) + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + fprintf(LASTCOM,'\n'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + + Answer = f_EEG_save_multi_file(EEG,1,'_asr'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + Save_file_label =0; + if ~isempty(Answer{1}) + EEG = Answer{1}; + Save_file_label = Answer{2}; + end + checkfileindex = checkfilexists([EEG.filepath,filesep, EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + fprintf( ['\n',repmat('-',1,100) '\n']); + eegh(LASTCOM); + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%----------------adjust event latencies----------------------------------- + function adjust_latency(~,~) + BackERPLABcolor = [1 0.9 0.3]; % yellow + question = ["We do not support this EEGLAB function. We recommend that you instead use ERPLAB's function: Shift Event Codes for Continuous EEG.\nAlternatively, you can quite from ERPLAB Studio, launch EEGLAB, and run the EEGLAB function."]; + title = 'EEGLAB Tool > Adjust event latencies'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Yes','Yes'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor); + end + + +%%----------------------Spectra and maps----------------------------------- + function eeg_spcetra_map(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Spectra and maps'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Spectra and maps: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Channel spectra and maps*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray(Numofeeg)),':',EEG.setname,'\n']); + chanlocs_present = 0; + if ~isempty(EEG.chanlocs) + if isfield(EEG.chanlocs, 'theta') + tmpchanlocs = EEG.chanlocs; + if any(~cellfun(@isempty, { tmpchanlocs.theta })) + chanlocs_present = 1; + end + end + end + dataflag = 1; + geometry = { [2 1] [2 1] [2 1] [2 1] [2 1] [2 1]}; + scalp_freq = fastif(chanlocs_present, { '6 10 22' }, { '' 'enable' 'off' }); + promptstr = { { 'style' 'text' 'string' 'Epoch time range to analyze [min_ms max_ms]:' }, ... + { 'style' 'edit' 'string' [num2str( EEG.xmin*1000) ' ' num2str(EEG.xmax*1000)] }, ... + { 'style' 'text' 'string' 'Percent data to sample (1 to 100):'}, ... + { 'style' 'edit' 'string' '100' }, ... + { 'style' 'text' 'string' 'Frequencies to plot as scalp maps (Hz):'}, ... + { 'style' 'edit' 'string' scalp_freq{:} }, ... + { 'style' 'text' 'string' 'Apply to EEG|ERP|BOTH:'}, ... + { 'style' 'edit' 'string' 'EEG' }, ... + { 'style' 'text' 'string' 'Plotting frequency range [lo_Hz hi_Hz]:'}, ... + { 'style' 'edit' 'string' '2 25' }, ... + { 'style' 'text' 'string' 'Spectral and scalp map options (see topoplot):' } ... + { 'style' 'edit' 'string' '''electrodes'',''off''' } }; + if EEG.trials == 1 + geometry(3) = []; + promptstr(7:8) = []; + end + result = inputgui( geometry, promptstr, 'pophelp(''pop_spectopo'')', ['Channel spectra and maps for eegset:',num2str(EEGArray(Numofeeg))]); + if size(result,1) == 0 + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > EEGLAB Tools > Spectra and maps:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + timerange = eval( [ '[' result{1} ']' ] ); + options = []; + if isempty(EEG.chanlocs) + disp('Topographic plot options ignored. First import a channel location file'); + disp('To plot a single channel, use channel property menu or the following call'); + disp(' >> figure; chan = 1; spectopo(EEG.data(chan,:,:), EEG.pnts, EEG.srate);'); + end + if EEG.trials ~= 1 + Electrodelabel = result{6}; + frerange = str2num(result{5}); + else + Electrodelabel = result{5}; + frerange = str2num(result{4}); + end + Newfile = split(Electrodelabel,','); + toklinenoise1 = regexpi(Newfile{2}, 'on', 'match','ignorecase'); + toklinenoise3 = regexpi(Newfile{2}, 'labels', 'match','ignorecase'); + toklinenoise4 = regexpi(Newfile{2}, 'numbers', 'match','ignorecase'); + toklinenoise5 = regexpi(Newfile{2}, 'ptslabels', 'match','ignorecase'); + toklinenoise6 = regexpi(Newfile{2}, 'ptsnumbers', 'match','ignorecase'); + + if ~isempty(toklinenoise1) && strcmpi(toklinenoise1{1,1},'on') + Electrodelabel = 'on'; + elseif ~isempty(toklinenoise3) && strcmpi( toklinenoise3{1,1},'labels') + Electrodelabel = 'labels'; + elseif ~isempty(toklinenoise4) && strcmpi( toklinenoise4{1,1},'numbers') + Electrodelabel = 'numbers'; + elseif ~isempty(toklinenoise5) && strcmpi( toklinenoise5{1,1},'ptslabels') + Electrodelabel = 'ptslabels'; + elseif ~isempty(toklinenoise6) && strcmpi( toklinenoise6{1,1},'ptsnumbers') + Electrodelabel = 'ptsnumbers'; + else + Electrodelabel = 'off'; + end + figspec= figure('tag', 'spectopo'); + set(figspec,'Name',['eegset',32,num2str(EEGArray(Numofeeg)),': Channel spectra and maps for',32,EEG.setname],'NumberTitle', 'off'); + pop_spectopo(EEG, 1, str2num(result{1}), 'EEG' ,'percent',str2num(result{2}),... + 'freq', str2num(result{3}), 'freqrange',frerange,'electrodes',Electrodelabel); + if eval(result{2}) ~= 100, options = [ options ', ''percent'', ' result{2} ]; end + if ~isempty(result{3}) && ~isempty(EEG.chanlocs), options = [ options ', ''freq'', [' result{3} ']' ]; end + if EEG.trials ~= 1 + processflag = result{4}; + if ~isempty(result{5}), options = [ options ', ''freqrange'',[' result{5} ']' ]; end + if ~isempty(result{6}), options = [ options ',' result{6} ]; end + else + processflag = 'EEG'; + if ~isempty(result{4}), options = [ options ', ''freqrange'',[' result{4} ']' ]; end + if ~isempty(result{5}), options = [ options ',' result{5} ]; end + end + + %%History + LASTCOM = sprintf('pop_spectopo(EEG, %d, [%s], ''%s'' %s);', 1, num2str(timerange), processflag, options); + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + eegh(LASTCOM); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf(LASTCOM,'\n'); + fprintf( ['\n',repmat('-',1,100) '\n']); + end%%end loop for subject + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=26; + end + + +%%---------------------Channel properties---------------------------------- + function eeg_chanprop(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Chan properties'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Chan properties: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + EEG = observe_EEGDAT.EEG; + typecomp = 1; % defaults + chanorcomp = 1; + commandchan = 'tmpchanlocs = EEG(1).chanlocs; [tmp tmpval] = pop_chansel({tmpchanlocs.labels}, ''withindex'', ''on'', ''selectionmode'', ''single''); set(findobj(gcbf, ''tag'', ''chan''), ''string'',tmpval); clear tmp tmpchanlocs tmpval'; + uitext = { { 'style' 'text' 'string' fastif(typecomp,'Channel index(ices) to plot:','Component index(ices) to plot:') } ... + { 'style' 'edit' 'string' '1', 'tag', 'chan' } ... + { 'style' 'pushbutton' 'string' '...', 'enable' fastif(~isempty(EEG(1).chanlocs) && typecomp, 'on', 'off') 'callback' commandchan } ... + { 'style' 'text' 'string' 'Spectral options (see spectopo() help):' } ... + { 'style' 'edit' 'string' '''freqrange'', [2 50]' } {} }; + uigeom = { [2 1 0.5 ] [2 1 0.5] }; + result = inputgui('geometry', uigeom, 'uilist', uitext, 'helpcom', 'pophelp(''pop_prop'');', ... + 'title', fastif( typecomp, 'Channel properties - pop_prop()', 'Component properties - pop_prop()')); + if size( result, 1 ) == 0 + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Chan properties:User selected cancel'); + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + return; + end + + chanoristr = result{1}; + try + chanorcomp = eeg_decodechan(EEG.chanlocs, result{1} ); + catch + fprintf(2, ['\nEEGLAB Tools > Chan properties: Channel index out of range, we therefore set it to 1\n']); + titlNamerro = 'Warning for EEG Tab'; + msgboxText = ['EEGLAB Tools > Chan properties: Channel index out of range, we therefore set it to 1']; + estudio_warning(msgboxText,titlNamerro); + chanorcomp = 1; + end + spec_opt = eval( [ '{' result{2} '}' ] ); + if isempty(chanorcomp) + msgboxText = ['EEGLAB Tools > Chan properties:Please define Channel index(ices)']; + estudioworkingmemory('f_EEG_proces_messg',msgboxText); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =4; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + + EEG = observe_EEGDAT.ALLEEG(EEGArray); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Chan properties*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray),':',EEG.setname,'\n']); + for Numofchan = 1:numel(chanorcomp) + LASTCOM = pop_prop( EEG, 1, chanorcomp(Numofchan), NaN, spec_opt); + set(gcf,'Name',['eegset',32,num2str(EEGArray),': Channel properties for',32,EEG.setname],'NumberTitle', 'off'); + end + LASTCOM = sprintf('pop_prop( EEG, %d, %s, NaN, %s);', typecomp, ['[',num2str(chanorcomp),']'], vararg2str( { spec_opt } ) ); + observe_EEGDAT.ALLEEG(EEGArray) = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + eegh(LASTCOM); + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.EEG=observe_EEGDAT.ALLEEG(EEGArray); + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Chan properties'); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=26; + end + + +%%------------------------Time-frequency----------------------------------- + function eeg_tfr(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=0 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Time-frequency'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:)<1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + if numel(EEGArray)~=1 + msgboxText = ['EEGLAB Tools > Time-frequency: Only works for one selected dataset']; + Source.Enable = 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + EEG = observe_EEGDAT.ALLEEG(EEGArray); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Chan time-frequency*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current data',32,num2str(EEGArray),':',EEG.setname,'\n']); + LASTCOM = pop_newtimef(EEG,1); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + return; + end + set(gcf,'Name',['eegset',32,num2str(EEGArray),': Time-frequency for',32,EEG.setname],'NumberTitle', 'off'); + LASTCOM =LASTCOM(8:end); + observe_EEGDAT.ALLEEG(EEGArray) = eegh(LASTCOM, EEG); + fprintf(LASTCOM,'\n'); + eegh(LASTCOM); + fprintf( ['\n',repmat('-',1,100) '\n']); + estudioworkingmemory('f_EEG_proces_messg','EEGLAB Tools > Time-frequency'); + + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(EEGArray); + observe_EEGDAT.count_current_eeg=26; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=11 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || EEGUpdate==1 + EStduio_eegtab_eeglab_tool.about_eegdata.Enable = 'off'; + EStduio_eegtab_eeglab_tool.edit_eeginfor.Enable= 'off'; + EStduio_eegtab_eeglab_tool.edit_eegevent.Enable= 'off'; + EStduio_eegtab_eeglab_tool.edit_eegchanlocs.Enable= 'off'; + EStduio_eegtab_eeglab_tool.edit_samplerate.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_asr.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_spcetra_map.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_chanprop.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_tfr.Enable= 'off'; + EStduio_eegtab_eeglab_tool.adjust_latency.Enable= 'off'; + observe_EEGDAT.count_current_eeg=12; + return; + end + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + + if numel(EEGArray)~=1 + EStduio_eegtab_eeglab_tool.about_eegdata.Enable = 'off'; + EStduio_eegtab_eeglab_tool.edit_eeginfor.Enable= 'off'; + EStduio_eegtab_eeglab_tool.edit_eegevent.Enable= 'off'; + EStduio_eegtab_eeglab_tool.edit_eegchanlocs.Enable= 'off'; + EStduio_eegtab_eeglab_tool.edit_samplerate.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_asr.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_spcetra_map.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_chanprop.Enable= 'off'; + EStduio_eegtab_eeglab_tool.eeg_tfr.Enable= 'off'; + EStduio_eegtab_eeglab_tool.adjust_latency.Enable= 'off'; + observe_EEGDAT.count_current_eeg=12; + return; + end + EStduio_eegtab_eeglab_tool.about_eegdata.Enable = 'on'; + EStduio_eegtab_eeglab_tool.edit_eeginfor.Enable= 'on'; + EStduio_eegtab_eeglab_tool.edit_eegevent.Enable= 'on'; + EStduio_eegtab_eeglab_tool.edit_eegchanlocs.Enable= 'on'; + EStduio_eegtab_eeglab_tool.edit_samplerate.Enable= 'on'; + if observe_EEGDAT.EEG.trials~=1 + EStduio_eegtab_eeglab_tool.eeg_asr.Enable= 'off'; + else + EStduio_eegtab_eeglab_tool.eeg_asr.Enable= 'on'; + end + EStduio_eegtab_eeglab_tool.eeg_spcetra_map.Enable= 'on'; + EStduio_eegtab_eeglab_tool.eeg_chanprop.Enable= 'on'; + EStduio_eegtab_eeglab_tool.eeg_tfr.Enable= 'on'; + EStduio_eegtab_eeglab_tool.adjust_latency.Enable= 'on'; + observe_EEGDAT.count_current_eeg=12; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_event2bin_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_event2bin_GUI.m new file mode 100644 index 00000000..7dd1c957 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_event2bin_GUI.m @@ -0,0 +1,718 @@ +%%This function is to assin eventlist to one specific bin + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + +function varargout = f_EEG_event2bin_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +%---------------------------Initialize parameters------------------------------------ + +EStduio_eegtab_EEG_event2bin = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_box_EEG_event2bin; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_box_EEG_event2bin = uiextras.BoxPanel('Parent', fig, 'Title', 'Assign Events to Bins (BINLISTER)', ... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_box_EEG_event2bin = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Assign Events to Bins (BINLISTER)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + EStudio_box_EEG_event2bin = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Assign Events to Bins (BINLISTER)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @event2bin_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_event2bin_eeg(FonsizeDefault) +varargout{1} = EStudio_box_EEG_event2bin; + + function drawui_event2bin_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EStduio_eegtab_EEG_event2bin.DataSelBox = uiextras.VBox('Parent', EStudio_box_EEG_event2bin,'BackgroundColor',ColorB_def); + + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + %%display original data? + EStduio_eegtab_EEG_event2bin.BDF_title = uiextras.HBox('Parent', EStduio_eegtab_EEG_event2bin.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent',EStduio_eegtab_EEG_event2bin.BDF_title,... + 'String','Bin Descriptor File','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_event2bin.BDF_edit = uicontrol('Style', 'edit','Parent',EStduio_eegtab_EEG_event2bin.BDF_title,... + 'String','','callback',@BDF_edit,'FontSize',FonsizeDefault,'Enable',EnableFlag); + EStduio_eegtab_EEG_event2bin.BDF_edit.KeyPressFcn= @eeg_event2bin_presskey; + def = estudioworkingmemory('pop_binlister'); + if isempty(def) + def = {'' '' '' 0 [] [] 0 0 0 1 0}; + end + try bdfileName = def{1}; catch bdfileName = ''; end + if ~ischar(bdfileName) || isfile(bdfileName) + bdfileName = ''; + end + EStduio_eegtab_EEG_event2bin.BDF_edit.String = bdfileName; + EStduio_eegtab_EEG_event2bin.BDF_browse = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_event2bin.BDF_title,... + 'String','Browse','callback',@BDF_browse,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set( EStduio_eegtab_EEG_event2bin.BDF_title, 'Sizes',[100 -1 60]); + + %%---------------------Table--------------------------------------- + EStduio_eegtab_EEG_event2bin.table_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_event2bin.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + dsnames{ii,3} = ''; + end + EStduio_eegtab_EEG_event2bin.table_event = uitable( ... + 'Parent' , EStduio_eegtab_EEG_event2bin.table_title,... + 'Data' , dsnames, ... + 'ColumnWidth' , {50,100,100}, ... + 'ColumnName' , {'Bin','Description','#Occurrences'}, ... + 'RowName' , [],... + 'ColumnEditable',[false, false, false]); + + %%----------------cancel and Run--------------------------------- + EStduio_eegtab_EEG_event2bin.reset_Run = uiextras.HBox('Parent',EStduio_eegtab_EEG_event2bin.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_event2bin.bdf_cancel = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_event2bin.reset_Run,... + 'String','Cancel','callback',@BDF_eeg_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_event2bin.event2bin_advanced = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_event2bin.reset_Run,... + 'String','Advanced','callback',@event2bin_advanced,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_event2bin.event2bin_advanced.KeyPressFcn= @eeg_event2bin_presskey; + EStduio_eegtab_EEG_event2bin.bdf_Run = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_event2bin.reset_Run,... + 'String','Run','callback',@eeg_bdf_Run,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_event2bin.bdf_Run.KeyPressFcn= @eeg_event2bin_presskey; + + set(EStduio_eegtab_EEG_event2bin.DataSelBox,'Sizes',[30 100 30]); + estudioworkingmemory('EEGTab_event2bin',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%-------------------------Edit the Bin Descriptor File------------------------------- + function BDF_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + %%change color for cancel and Run + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [1 1 1]; + EStudio_box_EEG_event2bin.TitleColor= [0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [1 1 1]; + + BDFileName = EStduio_eegtab_EEG_event2bin.BDF_edit.String; + if ~ischar(BDFileName) || isempty(BDFileName) + msgboxText = ['Assign Events to Bins (BINLISTER) - bdfile should be a string.']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + EStduio_eegtab_EEG_event2bin.BDF_edit.String = ''; + end + estudioworkingmemory('EEGTab_event2bin',1); + end + +%%--------------------------------Browse the Bin Descriptor File---------------------- + function BDF_browse(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + %%change color for cancel and Run + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [1 1 1]; + EStudio_box_EEG_event2bin.TitleColor= [0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [1 1 1]; + try + pre_patha = EStduio_eegtab_EEG_event2bin.BDF_edit.String; + [pre_pathb, nameq, extq] = fileparts(pre_patha); + [bdfilename,bdfpathname] = uigetfile({'*.txt';'*.*'},'Select a Bin Descriptor File (BDF)', pre_pathb); + catch + [bdfilename,bdfpathname] = uigetfile({'*.txt';'*.*'},'Select a Bin Descriptor File (BDF)'); + end + if isequal(bdfilename,0) + return; + end + EStduio_eegtab_EEG_event2bin.BDF_edit.String = fullfile(bdfpathname, bdfilename); + estudioworkingmemory('EEGTab_event2bin',1); + end + +%%---------------------------Cancel---------------------------------------- + function BDF_eeg_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + def = estudioworkingmemory('pop_binlister'); + bdfilename = def{1}; + if isempty(def) + def = {'' '' '' 0 [] [] 0 0 0 1 0}; + end + try bdfileName = def{1}; catch bdfileName = ''; end + if ~ischar(bdfileName) || isfile(bdfileName) + bdfileName = ''; + end + EStduio_eegtab_EEG_event2bin.BDF_edit.String = bdfileName; + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || min(EEGArray(:)) <1 + EEGArray = observe_EEGDAT.CURRENTSET; + end + if ~isempty(EEGArray) && numel(EEGArray)>1 + EStduio_eegtab_EEG_event2bin.event2bin_advanced.Enable = 'off'; + else + EStduio_eegtab_EEG_event2bin.event2bin_advanced.Enable = 'on'; + end + estudioworkingmemory('EEGTab_event2bin',0); + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [0 0 0]; + EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [0 0 0]; + end + + +%%--------------------------Advanced options------------------------------- + function event2bin_advanced(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Assign Events to Bins (BINLISTER) > Advanced'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + estudioworkingmemory('EEGTab_event2bin',0); + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [0 0 0]; + EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [0 0 0]; + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + def = estudioworkingmemory('pop_binlister'); + if isempty(def) + def = {'' '' '' 0 [] [] 0 0 0 1 0}; + end + + %%get defined BDfile + bdfileName = EStduio_eegtab_EEG_event2bin.BDF_edit.String; + %%check is the file name is a string + if isempty(bdfileName) || ~ischar(bdfileName) + bdfileName = ''; + end + %%check if the specified file exists + if ~isfile(bdfileName) + bdfileName =''; + msgboxText = ['Assign Events to Bins (BINLISTER) > Advanced:Such bdfile doesnot exist']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + def{1} = bdfileName; + + packarray = menuBinListGUI(EEG, [], def); + + if isempty(packarray) + observe_EEGDAT.eeg_panel_message =2; + return + end + + file1 = packarray{1}; % bin descriptor file + file2 = packarray{2}; % external eventlist (read event list from) + file3 = packarray{3}; % text file containing the updated EVENTLIST (Write resulting eventlist to) + flagrst = packarray{4}; % 1 means reset flags + forbiddenCodeArray = packarray{5}; + ignoreCodeArray = packarray{6}; + updevent = packarray{7}; + option2do = packarray{8}; % See option2do below + reportable = packarray{9}; % 1 means create a report about binlister work. + iswarning = packarray{10}; % 1 means create a report about binlister work. + getfromerp = 0; + indexEL = packarray{12}; + EStduio_eegtab_EEG_event2bin.BDF_edit.String = file1; + if isempty(file2) || strcmpi(file2,'no') || strcmpi(file2,'none') + + if isfield(EEG, 'EVENTLIST') + if isfield(EEG.EVENTLIST, 'eventinfo') + if isempty(EEG.EVENTLIST(indexEL).eventinfo) + msgboxText = ['Assign Events to Bins (BINLISTER) > Advanced: EVENTLIST.eventinfo structure is empty!\n'... + 'Use Create EVENTLIST before BINLISTER']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return + end + else + msgboxText = ['Assign Events to Bins (BINLISTER) > Advanced: EVENTLIST.eventinfo structure was not found, please Create EVENTLIST before BINLISTER']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return + end + else + msgboxText = ['Assign Events to Bins (BINLISTER) > Advanced: EVENTLIST structure was not found, Please Create EVENTLIST before BINLISTER']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return + end + logfilename = 'no'; + logpathname = ''; + file2 = [logpathname logfilename]; + disp('For LOGFILE, user selected INTERNAL') + end + estudioworkingmemory('pop_binlister', {file1, file2, file3, flagrst, forbiddenCodeArray, ignoreCodeArray,... + updevent, option2do, reportable, iswarning, getfromerp, indexEL}); + + + if flagrst==1 + strflagrst = 'on'; + else + strflagrst = 'off'; + end + if updevent==1 + strupdevent = 'on'; + else + strupdevent = 'off'; + end + switch option2do + case 0 + msgboxText = 'Assign Events to Bins (BINLISTER) > Advanced: Where should I send the update EVENTLIST??? Pick an option.'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return + case 1 + stroption2do = 'Text'; + case 2 + stroption2do = 'EEG'; + case 3 + stroption2do = 'EEG&Text'; + case 4 + stroption2do = 'Workspace'; + case 5 + stroption2do = 'Workspace&Text'; + case 6 + stroption2do = 'Workspace&EEG'; + case 7 + stroption2do = 'All'; + end + if reportable==1 + strreportable = 'on'; + else + strreportable = 'off'; + end + if iswarning==1 + striswarning = 'on'; + else + striswarning = 'off'; + end + if ~getfromerp + EEG.setname = [EEG.setname '_bins']; %suggest a new name + end + + %% Run pop_ command again with the inputs from the GUI + [EEG, LASTCOM] = pop_binlister(EEG, 'BDF', file1, 'ImportEL', file2, 'ExportEL', file3, 'Resetflag', strflagrst, 'Forbidden', forbiddenCodeArray,... + 'Ignore', ignoreCodeArray, 'UpdateEEG', strupdevent, 'SendEL2', stroption2do,'Report', strreportable, 'Warning', striswarning,... + 'Saveas', 'off', 'IndexEL', indexEL, 'History', 'gui'); + if isempty(LASTCOM) + return; + end + if Numofeeg==1 + eegh(LASTCOM); + end + EEG = eegh(LASTCOM, EEG); + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + end + ALLEEG = observe_EEGDAT.ALLEEG; + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_bins'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%---------------------------Run----------------------------------------- + function eeg_bdf_Run(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Assign Events to Bins (BINLISTER) > Run'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + estudioworkingmemory('EEGTab_event2bin',0); + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [0 0 0]; + EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [0 0 0]; + + bdfileName = EStduio_eegtab_EEG_event2bin.BDF_edit.String; + %%check is the file name is a string + if isempty(bdfileName) || ~ischar(bdfileName) + msgboxText = ['Assign Events to Bins (BINLISTER) - bdfile should be a string']; + EStduio_eegtab_EEG_event2bin.BDF_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + %%check if the specified file exists + if ~isfile(bdfileName) + msgboxText = ['Assign Events to Bins (BINLISTER) - Cannot find the specified bdfile']; + EStduio_eegtab_EEG_event2bin.BDF_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || min(EEGArray(:)) <1 + EEGArray = observe_EEGDAT.CURRENTSET; + end + eventlistFlag = check_evetlist(observe_EEGDAT.ALLEEG,EEGArray); + if eventlistFlag==1 + msgboxText = ['Assign Events to Bins (BINLISTER) - No Eventlist or it is empty for some eegsets']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + ALLEEG = observe_EEGDAT.ALLEEG; + + def = estudioworkingmemory('pop_binlister'); + if isempty(def) + def = {'' '' '' 0 [] [] 0 0 0 1 0}; + end + def{1} = bdfileName; + estudioworkingmemory('pop_binlister',def); + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %% Run pop_ command again with the inputs from the GUI + [EEG, LASTCOM] = pop_binlister( EEG , 'BDF',bdfileName, 'IndexEL', 1, 'SendEL2', 'EEG', 'UpdateEEG', 'on', 'Voutput', 'EEG', 'History', 'gui' ); + if isempty(LASTCOM) + disp('Process failed. Please check your data or you selected cancel') + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_bins'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=13 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + for ii = 1:100 + dsnamesdef{ii,1} = ''; + dsnamesdef{ii,2} = ''; + dsnamesdef{ii,3} = ''; + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials~=1 || EEGUpdate==1 + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials~=1 + EStudio_box_EEG_event2bin.TitleColor= [0.7500 0.7500 0.75000]; + else + EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + end + EStduio_eegtab_EEG_event2bin.BDF_edit.Enable = 'off'; + EStduio_eegtab_EEG_event2bin.BDF_browse.Enable = 'off'; + EStduio_eegtab_EEG_event2bin.bdf_cancel.Enable = 'off'; + EStduio_eegtab_EEG_event2bin.event2bin_advanced.Enable = 'off'; + EStduio_eegtab_EEG_event2bin.bdf_Run.Enable = 'off'; + + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials~=1 && isfield(observe_EEGDAT.EEG,'EVENTLIST') && ~isempty(observe_EEGDAT.EEG.EVENTLIST) && ~isempty(observe_EEGDAT.EEG.EVENTLIST.trialsperbin) + EEG = observe_EEGDAT.EEG; + + for jjj = 1:length(EEG.EVENTLIST.eventinfo) + eventbini(jjj,1) = EEG.EVENTLIST.eventinfo(jjj).bini; + end + xpos = find(eventbini>0); + for ii = 1:length(observe_EEGDAT.EEG.EVENTLIST.trialsperbin) + try + dsnames{ii,1} = num2str(ii); + dsnames{ii,2} = EEG.EVENTLIST.bdf(ii).description; + dsnames{ii,3} = num2str(EEG.EVENTLIST.trialsperbin(ii)); + catch + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + dsnames{ii,3} =''; + end + end + else + dsnames = dsnamesdef; + end + EStduio_eegtab_EEG_event2bin.table_event.Data = dsnames; + + observe_EEGDAT.count_current_eeg=14; + return; + end + + if ~isempty(observe_EEGDAT.EEG) && isfield(observe_EEGDAT.EEG,'EVENTLIST') && ~isempty(observe_EEGDAT.EEG.EVENTLIST) && (~isempty(observe_EEGDAT.EEG.EVENTLIST.trialsperbin)) + EEG = observe_EEGDAT.EEG; + for jjj = 1:length(EEG.EVENTLIST.eventinfo) + eventbini(jjj,1) = EEG.EVENTLIST.eventinfo(jjj).bini; + end + xpos = find(eventbini>0); + if ~isempty(xpos) + for ii = 1:length(observe_EEGDAT.EEG.EVENTLIST.trialsperbin) + try + dsnames{ii,1} = num2str(ii); + dsnames{ii,2} = EEG.EVENTLIST.bdf(ii).description; + dsnames{ii,3} = num2str(EEG.EVENTLIST.trialsperbin(ii)); + catch + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + dsnames{ii,3} =''; + end + end + else + dsnames = dsnamesdef; + end + else + dsnames = dsnamesdef; + end + try + EStduio_eegtab_EEG_event2bin.table_event.Data = dsnames; + catch + EStduio_eegtab_EEG_event2bin.table_event.Data = dsnamesdef; + end + EStduio_eegtab_EEG_event2bin.BDF_edit.Enable = 'on'; + EStduio_eegtab_EEG_event2bin.BDF_browse.Enable = 'on'; + EStduio_eegtab_EEG_event2bin.bdf_cancel.Enable = 'on'; + EStduio_eegtab_EEG_event2bin.event2bin_advanced.Enable = 'on'; + EStduio_eegtab_EEG_event2bin.bdf_Run.Enable = 'on'; + EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + observe_EEGDAT.count_current_eeg=14; + end + + +%%--------------press return to execute "Run"---------------------------- + function eeg_event2bin_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_event2bin'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + eeg_bdf_Run(); + estudioworkingmemory('EEGTab_event2bin',0); + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [0 0 0]; + EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%----check if eventlist can be found for each of the selected eegsets----- + function eventlistFlag = check_evetlist(ALLEEG,EEGArray) + eventlistFlag = 0; + count = 0; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + if ~isfield(EEG, 'EVENTLIST') || isempty(EEG.EVENTLIST) + count = count+1; + eventlistFlag = 1; + if count==1 + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf('For following eegset(s), we didnot find eventlist or found the eventlist is empty,please create one.\n') + fprintf(2,['\n',EEG.setname,'\n']); + end + end + end + if count~=0 + fprintf(['\n',repmat('-',1,100) '\n\n\n']); + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=10 + return; + end + estudioworkingmemory('EEGTab_event2bin',0); + EStduio_eegtab_EEG_event2bin.bdf_Run.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_Run.ForegroundColor = [0 0 0]; + % EStudio_box_EEG_event2bin.TitleColor= [0.0500 0.2500 0.5000]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.BackgroundColor = [1 1 1]; + EStduio_eegtab_EEG_event2bin.bdf_cancel.ForegroundColor = [0 0 0]; + EStduio_eegtab_EEG_event2bin.BDF_edit.String= ''; + def = {'' '' '' 0 [] [] 0 0 0 1 0}; + estudioworkingmemory('pop_binlister',def); + observe_EEGDAT.Reset_eeg_paras_panel=11; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_events_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_events_GUI.m new file mode 100644 index 00000000..b3f6e9d4 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_events_GUI.m @@ -0,0 +1,1356 @@ +%%This function is operation for EventList + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2023 + + +function varargout = f_EEG_events_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +%---------------------------Initialize parameters------------------------------------ + +EStduio_eegtab_EEG_events = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_eeg_events_box; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_eeg_events_box = uiextras.BoxPanel('Parent', fig, 'Title', 'EventList', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_eeg_events_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EventList', 'Padding', 5,... + 'BackgroundColor',ColorB_def); +else + EStudio_eeg_events_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EventList', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @event_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_eeg_events(FonsizeDefault) +varargout{1} = EStudio_eeg_events_box; + + function drawui_eeg_events(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EStduio_eegtab_EEG_events.DataSelBox = uiextras.VBox('Parent', EStudio_eeg_events_box,'BackgroundColor',ColorB_def); + if isempty(observe_EEGDAT.EEG) + EnableFlag= 'off'; + else + EnableFlag= 'on'; + end + + %%----------------title "EventList Operations"--------------------- + EStduio_eegtab_EEG_events.eventop_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', EStduio_eegtab_EEG_events.eventop_title,'FontWeight','bold',... + 'String','EventList Operations:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + %%Create Eventlist and Import + EStduio_eegtab_EEG_events.create_rt_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_events.create_eventlist = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.create_rt_title ,... + 'String','Create','callback',@create_eventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_events.imp_eventlist = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.create_rt_title ,... + 'String','Import .txt','callback',@imp_eventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_events.exp_eventlist = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.create_rt_title,... + 'String','Export .txt','callback',@exp_eventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + %%export eventlist + EStduio_eegtab_EEG_events.imp_exp_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + + EStduio_eegtab_EEG_events.vieweventlist = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.imp_exp_title,... + 'String','View ','callback',@vieweventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + EStduio_eegtab_EEG_events.imp_eventlist_exc = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.imp_exp_title ,... + 'String','Import .xls','callback',@imp_eventlist_exc,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + EStduio_eegtab_EEG_events.exp_eventlist_exc = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.imp_exp_title,... + 'String','Export .xls','callback',@exp_eventlist_exc,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + + EStduio_eegtab_EEG_events.imp_exp_title1 = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + + EStduio_eegtab_EEG_events.transfer_event = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_events.imp_exp_title1 ,... + 'String','Transfer event info to EEG.event','callback',@transfer_event,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EStduio_eegtab_EEG_events.imp_exp_title1); + set(EStduio_eegtab_EEG_events.imp_exp_title1,'Sizes',[200 -1]); + + %%------------title for "Other Operations"------------------------- + EStduio_eegtab_EEG_events.eventotherop_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', EStduio_eegtab_EEG_events.eventotherop_title,'FontWeight','bold',... + 'String','Other Operations:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + %%Summarize EEG event codes + EStduio_eegtab_EEG_events.summarize_code_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_events.summarize_code = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.summarize_code_title,... + 'String','Summarize event codes/bins in cmd window','callback',@summarize_code,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EStduio_eegtab_EEG_events.summarize_code_title); + set( EStduio_eegtab_EEG_events.summarize_code_title,'Sizes',[265 -1]); + + %%Shuffle events/bins/samples/ + EStduio_eegtab_EEG_events.shuffle_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_events.eeg_shuffle = uicontrol('Style', 'pushbutton','Parent',EStduio_eegtab_EEG_events.shuffle_title ,... + 'String','Shuffle events/bins/samples','callback',@eeg_shuffle,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + %%export reaction times + EStduio_eegtab_EEG_events.exp_rt = uicontrol('Style', 'pushbutton','Parent', EStduio_eegtab_EEG_events.shuffle_title ,... + 'String','Export RTs','callback',@exp_rt,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set(EStduio_eegtab_EEG_events.shuffle_title,'Sizes',[170 -1]); + + EStduio_eegtab_EEG_events.sumevent_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + EStduio_eegtab_EEG_events.sumevent_name = uicontrol('Style', 'text','Parent', EStduio_eegtab_EEG_events.sumevent_title,'FontWeight','bold',... + 'String','Event Code Summary','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + %%---------------------Table--------------------------------------- + EStduio_eegtab_EEG_events.table_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + end + EStduio_eegtab_EEG_events.table_event = uitable( ... + 'Parent' , EStduio_eegtab_EEG_events.table_title,... + 'Data' , dsnames, ... + 'ColumnWidth' , {100,100}, ... + 'ColumnName' , {'Event Code','#Occurrences'}, ... + 'RowName' , [],... + 'ColumnEditable',[false, false]); + + %%EEG setname and file name + EStduio_eegtab_EEG_events.setfilename_title = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', EStduio_eegtab_EEG_events.setfilename_title,'String','Current EEG setname & file name',... + 'FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorB_def); + + + EStduio_eegtab_EEG_events.setfilename_title2 = uiextras.HBox('Parent',EStduio_eegtab_EEG_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + end + EStduio_eegtab_EEG_events.table_setfilenames = uitable( ... + 'Parent' , EStduio_eegtab_EEG_events.setfilename_title2,... + 'Data' , dsnames, ... + 'ColumnWidth' , {500}, ... + 'ColumnName' , {''}, ... + 'RowName' , {'Set name','File name'},... + 'ColumnEditable',[false]); + set(EStduio_eegtab_EEG_events.DataSelBox,'Sizes',[20 30 30 30 20 30 30 20 100 20 70]); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------Summarize the event codes for the selected EEG----------------- + function summarize_code(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + if isempty(observe_EEGDAT.EEG.event) + Source.Enable= 'off'; + msgboxText = ['EventList > Summarize event code:EEG.event is empty for the current EEG']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EventList > Summarize event code'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + if isempty(EEG.event) + CheckFlag = 0; + msgboxText = ['EventList > Summarize event code:EEG.event is empty for',32,EEG.setname]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + elseif isempty([EEG(1).event.type]) + CheckFlag = 0; + msgboxText = ['EventList > Summarize event code:EEG.event.type is empty for',32,EEG.setname]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + else + CheckFlag=1; + end + if CheckFlag==1 + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + [EEG, LASTCOM] = pop_squeezevents(EEG,'History','gui'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = EEG; + end + end + estudioworkingmemory('f_EEG_proces_messg','EventList > Summarize event code'); + observe_EEGDAT.eeg_panel_message =2; + end + +%%------------------------Create EEG eventlist----------------------------- + function create_eventlist(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + if observe_EEGDAT.EEG.trials>1 + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + if isempty(observe_EEGDAT.EEG.event) + Source.Enable= 'off'; + msgboxText = ['EventList > Create Eventlist: EEG.event is empty for the current EEG']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + estudioworkingmemory('f_EEG_proces_messg','EventList > Create Eventlist'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + + %% Get previous input parameters + def = estudioworkingmemory('pop_creabasiceventlist'); + if isempty(def) + def = {'' 'boundary' -99 1 1}; + end + if numel(EEGArray)>1 + multieeg =1; + else + multieeg=0; + end + %% Call GUI + inputstrMat = creabasiceventlistGUI(def, multieeg); % GUI + + if isempty(inputstrMat) && ~strcmp(inputstrMat,'') + observe_EEGDAT.eeg_panel_message =2; + return + elseif strcmp(inputstrMat,'advanced') + EEG = ALLEEG(EEGArray); + [EEG, LASTCOM ] = pop_editeventlist(EEG); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + [ALLEEG_out, EEG, ~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end + + + if ~strcmp(inputstrMat,'advanced') + elname = inputstrMat{1}; + boundarystrcode = inputstrMat{2}; + newboundarynumcode = inputstrMat{3}; + rwwarn = inputstrMat{4}; + alphanum = inputstrMat{5}; + + estudioworkingmemory('pop_creabasiceventlist', {elname, boundarystrcode, newboundarynumcode, rwwarn, alphanum}); + if rwwarn==1 + striswarning = 'on'; + else + striswarning = 'off'; + end + if alphanum==1 + stralphanum = 'on'; + else + stralphanum = 'off'; + end + + [pathx, filename, ext] = fileparts(elname); + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + filename1 = strcat(filename,'.txt'); + filename1 = fullfile(pathx, filename1); + if multieeg==1 + filename1 =''; + end + %% Run pop_ command again with the inputs from the GUI + [EEG, LASTCOM] = pop_creabasiceventlist(EEG, 'Eventlist', filename1, 'BoundaryString', boundarystrcode,... + 'BoundaryNumeric', newboundarynumcode,'Warning', striswarning, 'AlphanumericCleaning', stralphanum, 'History', 'gui'); + if isempty(LASTCOM) + fprintf( ['\n',repmat('-',1,100) '\n\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out, EEG, ~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + + end + + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_elist'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG, EEG, ~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%----------------Export reaction times to text file----------------------- + function exp_rt(Source,~) + if isempty(observe_EEGDAT.EEG)|| observe_EEGDAT.EEG.trials>1 + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EventList > Export RTs'); + observe_EEGDAT.eeg_panel_message =1; + + if ~isfield(observe_EEGDAT.EEG,'EVENTLIST') || isempty(observe_EEGDAT.EEG.EVENTLIST) + msgboxText = ['EventList > Export RTs: No EVETLIST, please create one first']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + def = estudioworkingmemory('pop_rt2text'); + + if isempty(def) + def = {'' 'basic' 'on' 'off' 1}; + end + + e2 = length(observe_EEGDAT.EEG.EVENTLIST); + + % + % Call Gui + % + param = saveRTGUI(def, e2); + + if isempty(param) + observe_EEGDAT.eeg_panel_message =2; + return + end + filenamei = param{1}; + listformat = param{2}; + header = param{3}; % 1 means include header (name of variables) + arfilt = param{4}; % 1 means filter out RTs with marked flags + indexel = param{5}; % index for eventlist + [pathx, filename, ext] = fileparts(filenamei); + if header==1 + headstr = 'on'; + else + headstr = 'off'; + end + if arfilt==1 + arfilter = 'on'; + else + arfilter = 'off'; + end + estudioworkingmemory('pop_rt2text', {fullfile(pathx, filename), listformat, headstr, arfilter, indexel}); + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || min(EEGArray(:)) <1 + EEGArray = observe_EEGDAT.CURRENTSET; + end + for Numofeeg = 1:numel(EEGArray) + + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + if ~isfield(EEG, 'EVENTLIST') + estudioworkingmemory('f_EEG_proces_messg','EventList > Export RTs:EVENTLIST structure is empty'); + observe_EEGDAT.eeg_panel_message =4; + else + filenameeeg = EEG.filename; + [pathxeeg, filenameeeg, ext] = fileparts(filenameeeg); + if isempty(filenameeeg) + filename = [num2str(EEGArray(Numofeeg)),'_',filename,'.txt']; + else + filename = strcat(filenameeeg,'_',filename,'.txt'); + end + filename = fullfile(pathx, filename); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + fprintf(['The exported file name:',32,filename,'\n\n']); + + [EEG,values, LASTCOM] = pop_rt2text(EEG, 'filename', filename, 'listformat', listformat, 'header', headstr,... + 'arfilter', arfilter, 'eventlist', indexel, 'History', 'gui'); + if ~isempty( values) + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) =EEG; + else + fprintf(2,['Cannot export reaction times for:',32,EEG.setname,'\n']); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + end + end + end + estudioworkingmemory('f_EEG_proces_messg','EventList > Export RTs'); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=1; + end + + +%%-------------------View eventlist---------------------------------------- + function vieweventlist(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + estudioworkingmemory('f_EEG_proces_messg','EventList > View EventList'); + observe_EEGDAT.eeg_panel_message =1; + + ALLEEG = observe_EEGDAT.ALLEEG; + [ALLEEG, LASTCOM] = pop_eeg_eventlist_view( ALLEEG, 'EEGArray',EEGArray,... + 'Saveas', 'off', 'History', 'script'); + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['*EEG Tab>Eventlist>View*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf( [LASTCOM]); + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.ALLEEG = ALLEEG; + eegh(LASTCOM); + observe_EEGDAT.EEG=observe_EEGDAT.ALLEEG(EEGArray); + observe_EEGDAT.count_current_eeg=26; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------------------import EEG eventlist from text file-------------------- + function imp_eventlist(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + if observe_EEGDAT.EEG.trials>1 + msgboxText = 'Eventlist>Import:pop_importeegeventlist() has been tested for continuous data only'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + estudioworkingmemory('f_EEG_proces_messg','EventList > Import'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + ALLEEG_out = []; + ALLEEG = observe_EEGDAT.ALLEEG; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %% Run pop_ command again with the inputs from the GUI + [filename,pathname] = uigetfile({'*.txt*'},['Select a EVENTLIST file for eegset:',32,num2str(EEGArray(Numofeeg))]); + ELfullname = fullfile(pathname, filename); + + if isequal(filename,0) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return + else + disp(['For read an EVENTLIST, user selected ', ELfullname]) + end + + [EEG, LASTCOM] = pop_importeegeventlist( EEG, ELfullname , 'ReplaceEventList', 'on','History','gui'); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n\n']); + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out, ~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_impel'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG, EEG, ~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------------------export EEG eventlist to text file-------------------- + function exp_eventlist(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EventList > Export eventlist'); + observe_EEGDAT.eeg_panel_message =1; + + if ~isfield(observe_EEGDAT.EEG,'EVENTLIST') || isempty(observe_EEGDAT.EEG.EVENTLIST) + msgboxText = ['EventList >Export eventlist: Please check the current EEG.EVENTLIST']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + [fname, pathname] = uiputfile({'*.txt*'},'Save EVENTLIST file as (This will be suffix when using EStudio)'); + + if isequal(fname,0) + observe_EEGDAT.eeg_panel_message =2; + return + end + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + [xpath, suffixstr, ext] = fileparts(fname); + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + msgboxText = ''; + if isfield(EEG, 'EVENTLIST') + if isempty(EEG.EVENTLIST) + msgboxText = ['EEG.EVENTLIST structure is empty']; + end + if isfield(EEG.EVENTLIST, 'eventinfo') + if isempty(EEG.EVENTLIST.eventinfo) + msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['EEG.EVENTLIST structure is empty']; + end + + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + if isempty(msgboxText) + if numel(EEGArray) >1 + filenameeg = EEG.filename; + [xpatheeg, filenameeg, exteeg] = fileparts(filenameeg); + if isempty(filenameeg) + filenameeg = strcat(num2str(EEGArray(Numofeeg)),'_',suffixstr,'.txt'); + else + filenameeg = strcat(filenameeg,'_',suffixstr,'.txt'); + end + else + filenameeg = [suffixstr,'.txt']; + end + filenameeg = fullfile(pathname, filenameeg); + + disp(['For EVENTLIST output user selected ', filenameeg]) + [EEG, LASTCOM] = pop_exporteegeventlist( EEG , 'Filename', filenameeg,'History','gui'); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) =EEG; + else + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf(2,['Cannot export eventlist for:',32,EEG.setname,'\n']); + fprintf( [repmat('-',1,100) '\n']); + end + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('f_EEG_proces_messg','EventList > Export eventlist'); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=1; + end + + +%%--------------------import EEG eventlist from .xls file-------------------- + function imp_eventlist_exc(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + if observe_EEGDAT.EEG.trials>1 + msgboxText = 'Eventlist>Import .xls:pop_importeegeventlist() has been tested for continuous data only'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + estudioworkingmemory('f_EEG_proces_messg','EventList > Import'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + ALLEEG_out = []; + ALLEEG = observe_EEGDAT.ALLEEG; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %% Run pop_ command again with the inputs from the GUI + [filename,pathname] = uigetfile({'*.xls*';'*.xlsx*'},['Select a EVENTLIST file for eegset:',32,num2str(EEGArray(Numofeeg))]); + ELfullname = fullfile(pathname, filename); + + if isequal(filename,0) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return + else + disp(['For read an EVENTLIST, user selected ', ELfullname]) + end + + [EEG, LASTCOM] = pop_importeegeventlist( EEG, ELfullname , 'ReplaceEventList', 'on','History','gui' ); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( ['\n',repmat('-',1,100) '\n\n']); + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out, ~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_impel'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG, EEG, ~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + + end + + function exp_eventlist_exc(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EventList > Export eventlist to .xls file'); + observe_EEGDAT.eeg_panel_message =1; + + if ~isfield(observe_EEGDAT.EEG,'EVENTLIST') || isempty(observe_EEGDAT.EEG.EVENTLIST) + msgboxText = ['EventList >Export eventlist: Please check the current EEG.EVENTLIST']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + [fname, pathname] = uiputfile({'*.xls*,*xlsx*'},'Save EVENTLIST file as (This will be suffix when using EStudio)'); + + if isequal(fname,0) + observe_EEGDAT.eeg_panel_message =2; + return + end + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + [xpath, suffixstr, ext] = fileparts(fname); + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + msgboxText = ''; + if isfield(EEG, 'EVENTLIST') + if isempty(EEG.EVENTLIST) + msgboxText = ['EEG.EVENTLIST structure is empty']; + end + if isfield(EEG.EVENTLIST, 'eventinfo') + if isempty(EEG.EVENTLIST.eventinfo) + msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['EEG.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['EEG.EVENTLIST structure is empty']; + end + + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + if isempty(msgboxText) + if numel(EEGArray)>1 + filenameeg = EEG.filename; + [xpatheeg, filenameeg, exteeg] = fileparts(filenameeg); + if isempty(filenameeg) + filenameeg = strcat(num2str(EEGArray(Numofeeg)),'_',suffixstr,'.xls'); + else + filenameeg = strcat(filenameeg,'_',suffixstr,'.xls'); + end + else + filenameeg = [suffixstr,'.xls']; + end + + filenameeg = fullfile(pathname, filenameeg); + + disp(['For EVENTLIST output user selected ', filenameeg]) + [EEG, LASTCOM] = pop_exporteegeventlist( EEG , 'Filename', filenameeg,'History','gui'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) =EEG; + else + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf(2,['Cannot export eventlist for:',32,EEG.setname,'\n']); + fprintf( [repmat('-',1,100) '\n']); + end + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('f_EEG_proces_messg','EventList > Export eventlist to .xls file'); + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg=1; + end + + + +%%-----------------Shuffle events/bins/samples----------------------------- + function eeg_shuffle(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + if observe_EEGDAT.EEG.trials>1 + Source.Enable= 'off'; + return; + end + + estudioworkingmemory('f_EEG_proces_messg','EventList > Shuffle events/bins/samples'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG))|| any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + + %% Get previous input parameters + def = estudioworkingmemory('pop_eventshuffler'); + + if isempty(def) + def = {[] 0}; + end + %% Call GUI + answer = shuffleGUI(def); + if isempty(answer) + observe_EEGDAT.eeg_panel_message =2; + return + end + valueatfield = answer{1}; + specfield = answer{2}; + + if specfield==0 + specfieldstr = 'code'; + elseif specfield==1 + specfieldstr = 'bini'; + elseif specfield==2 + specfieldstr = 'data'; + valueatfield = 'off'; + else + msgboxText = ['EventList > Shuffle events/bins/samples: invalid field']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if ~isnumeric(valueatfield) && ~strcmpi(valueatfield, 'all') && ~strcmpi(valueatfield, 'off') + valueatfield = str2num(valueatfield); + if isempty(valueatfield) + msgboxText = 'EventList > Shuffle events/bins/samples:Invalid value for "codes to shuffle"'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + estudioworkingmemory('pop_eventshuffler', {valueatfield specfield}); + ALLEEG_out = []; + ALLEEG = observe_EEGDAT.ALLEEG; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset:',32,EEG.setname,'\n\n']); + + if ~isnumeric(valueatfield) && strcmpi(valueatfield, 'all') + fprintf('User selected all %s\n', specfieldstr ) + elseif isnumeric(valueatfield) + fprintf('User specified %s = %s \n', specfieldstr, vect2colon(valueatfield)) + end + %%check current eeg data + msgboxText =''; + if ~isfield(EEG, 'event') + msgboxText = ['pop_eventshuffler did not find EEG.event field at dataset',32,num2str(EEGArray(Numofeeg))]; + end + if ~isfield(EEG.event, 'type') + msgboxText = ['pop_eventshuffler did not find EEG.event.type field at dataset',32,num2str(EEGArray(Numofeeg))]; + end + if ~isfield(EEG.event, 'latency') + msgboxText = ['pop_eventshuffler did not find EEG.event.latency field at dataset',32,num2str(EEGArray(Numofeeg))]; + end + if ischar(EEG.event(1).type) && ~isfield(EEG, 'EVENTLIST') + msgboxText = ['pop_eventshuffler found alphanumeric codes at dataset',32,num2str(EEGArray(Numofeeg)),... + 'We recommend to use Create EEG Eventlist to convert them into numeric ones.']; + elseif ischar(EEG.event(1).type) && isfield(EEG, 'EVENTLIST') + msgboxText = ['pop_eventshuffler found alphanumeric codes at dataset',32,num2str(EEGArray(Numofeeg)),... + 'We recommend to use Create EEG Eventlist Advance first.']; + end + if isempty(msgboxText) + %% Run pop_ command again with the inputs from the GUI + [EEG, LASTCOM] = pop_eventshuffler(EEG, 'Values', valueatfield, 'Field', specfieldstr, 'History', 'gui'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + msgboxText = ['EventList > Shuffle events/bins/samples:', msgboxText]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf( ['\n',repmat('-',1,100) '\n\n']); + observe_EEGDAT.eeg_panel_message =2; + break; + end + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_shuffled'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------------Transfer event info to EEG.event--------------------------- + function transfer_event(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + if isempty(observe_EEGDAT.EEG.event) + Source.Enable= 'off'; + msgboxText = ['EventList > Transfer event to EEG.event: EEG.event is empty for the current EEG']; + Source.Enable= 'off'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if observe_EEGDAT.EEG.trials>1 + Source.Enable= 'off'; + return; + end + estudioworkingmemory('f_EEG_proces_messg','EventList > Transfer event to EEG.event'); + observe_EEGDAT.eeg_panel_message =1; + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + %% Call GUI + answer = overwriteventGUI; + + if isempty(answer) + observe_EEGDAT.eeg_panel_message =2; + return + end + mainfield = answer{1}; + removenctype = answer{2}; % remove remaining event codes + if removenctype==1 + rrcstr = 'on'; + else + rrcstr = 'off'; + end + iserrorf = 0; + + ALLEEG_out = []; + ALLEEG = observe_EEGDAT.ALLEEG; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset:',32,EEG.setname,'\n\n']); + serror = erplab_eegscanner(EEG, 'pop_overwritevent', 0, 0, 0, 2, 1); + msgboxText =''; + if serror + fprintf( ['\n',repmat('-',1,100) '\n\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + %%check current eeg data + if ~serror + testfield1 = unique_bc2([EEG.EVENTLIST.eventinfo.(mainfield)]); + if isempty(testfield1) + iserrorf = 1; + end + if isnumeric(testfield1) + testfield1 = num2str(testfield1); + end + if strcmp(testfield1,'"') + iserrorf = 1; + end + if iserrorf + msgboxText = ['Sorry, EEG.EVENTLIST.eventinfo.' mainfield ' field is empty!\n\n'... + 'You should assign values to this field before overwriting EEG.event']; + end + + if isempty(msgboxText) + [EEG, LASTCOM] = pop_overwritevent(EEG, mainfield, 'RemoveRemCodes', rrcstr,'History', 'gui'); + if isempty(LASTCOM) + fprintf( ['\n',repmat('-',1,100) '\n\n']); + observe_EEGDAT.eeg_panel_message =2; + break; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + msgboxText = ['EventList > Transfer event to EEG.event:', msgboxText]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf( ['\n',repmat('-',1,100) '\n\n']); + break; + end + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray), '_transf'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=9 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.EEG.event) ||EEGUpdate==1 + EnableFlag = 'off'; + EStduio_eegtab_EEG_events.summarize_code.Enable=EnableFlag; + %%Create and RTs + EStduio_eegtab_EEG_events.create_eventlist.Enable=EnableFlag; + %%export reaction times + EStduio_eegtab_EEG_events.exp_rt.Enable=EnableFlag; + %%Import and export eventlist + EStduio_eegtab_EEG_events.imp_eventlist.Enable=EnableFlag; + %%export evetnlist to text file + EStduio_eegtab_EEG_events.exp_eventlist.Enable='off'; + EStduio_eegtab_EEG_events.eeg_shuffle.Enable=EnableFlag; + EStduio_eegtab_EEG_events.transfer_event.Enable=EnableFlag; + EStduio_eegtab_EEG_events.vieweventlist.Enable=EnableFlag; + EStduio_eegtab_EEG_events.imp_eventlist_exc.Enable=EnableFlag; + EStduio_eegtab_EEG_events.exp_eventlist_exc.Enable='off'; + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + end + if isempty(observe_EEGDAT.EEG) + EStduio_eegtab_EEG_events.sumevent_name.String = 'Event Code Summary'; + EStduio_eegtab_EEG_events.table_event.Data = dsnames; + end + observe_EEGDAT.count_current_eeg=10; + return; + end + + EStudio_eeg_events_box.Title = 'EventList'; + EStudio_eeg_events_box.ForegroundColor= [1 1 1]; + for ii = 1:100 + dsnamesdef{ii,1} = ''; + dsnamesdef{ii,2} = ''; + end + if ~isempty(observe_EEGDAT.EEG) + if ndims(observe_EEGDAT.EEG.data) ==3%%Epoched EEG + EnableFlag ='off'; + else %%Continuous EEG + EnableFlag ='on'; + end + eventArray = observe_EEGDAT.EEG.event; + if ~isempty(eventArray) + if ischar(eventArray(1).type) + allevents = { eventArray.type }'; + formateve = 'STRINGS'; + else + allevents = cellstr(num2str([eventArray.type]')); + formateve = 'NUMERICS'; + end + eventtypes = unique_bc2( allevents ); + % Summary + sortevent = sort(allevents); + [tf, indx] = ismember_bc2(eventtypes, sortevent); + histo = diff([0 indx'])'; + for ii = 1:length(histo) + dsnames{ii,1} = eventtypes{ii}; + dsnames{ii,2} = num2str(histo(ii)); + end + else + dsnames = dsnamesdef; + end + else + dsnames = dsnamesdef; + end + EStduio_eegtab_EEG_events.table_event.Data = dsnames; + %%Summarize EEG event codes + EStduio_eegtab_EEG_events.summarize_code.Enable=EnableFlag; + %%Shift EEG event codes + %%Create and RTs + EStduio_eegtab_EEG_events.create_eventlist.Enable=EnableFlag; + %%export reaction times + EStduio_eegtab_EEG_events.exp_rt.Enable=EnableFlag; + %%Import and export eventlist + EStduio_eegtab_EEG_events.imp_eventlist.Enable=EnableFlag; + EStduio_eegtab_EEG_events.imp_eventlist_exc.Enable=EnableFlag; + %%export evetnlist to text file + if ~isempty(observe_EEGDAT.EEG) + EStduio_eegtab_EEG_events.exp_eventlist.Enable='on'; + EStduio_eegtab_EEG_events.exp_eventlist_exc.Enable='on'; + EStduio_eegtab_EEG_events.sumevent_name.String = ['Event Code Summary for EEGset:',32,num2str(observe_EEGDAT.CURRENTSET)]; + else + EStduio_eegtab_EEG_events.exp_eventlist.Enable='off'; + EStduio_eegtab_EEG_events.exp_eventlist_exc.Enable='off'; + EStduio_eegtab_EEG_events.sumevent_name.String = ['Event Code Summary']; + end + EStduio_eegtab_EEG_events.eeg_shuffle.Enable=EnableFlag; + EStduio_eegtab_EEG_events.transfer_event.Enable=EnableFlag; + if isfield(observe_EEGDAT.EEG,'EVENTLIST') && ~isempty(observe_EEGDAT.EEG.EVENTLIST) + EStduio_eegtab_EEG_events.vieweventlist.Enable='on'; + EStduio_eegtab_EEG_events.exp_eventlist.Enable='on'; + EStduio_eegtab_EEG_events.exp_eventlist_exc.Enable='on'; + else + EStduio_eegtab_EEG_events.vieweventlist.Enable='off'; + EStduio_eegtab_EEG_events.exp_eventlist.Enable='off'; + EStduio_eegtab_EEG_events.exp_eventlist_exc.Enable='off'; + end + + try + filesetname{1,1} = observe_EEGDAT.EEG.setname; + filesetname{2,1} = observe_EEGDAT.EEG.filename; + catch + filesetname{1,1} = ''; + filesetname{2,1} = ''; + end + EStduio_eegtab_EEG_events.table_setfilenames.Data= filesetname; + + observe_EEGDAT.count_current_eeg=10; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_filtering_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_filtering_GUI.m new file mode 100755 index 00000000..0629967c --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_filtering_GUI.m @@ -0,0 +1,1503 @@ +%Author: Guanghui ZHANG & Steve LUCK +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +%Sep. 2023 && 2024 + +% ERPLAB Studio + +function varargout = f_EEG_filtering_GUI(varargin) + +global observe_EEGDAT; +global EStudio_gui_erp_totl; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +gui_eegtab_filtering = struct(); +%%---------------------------gui------------------------------------------- +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end +if nargin == 0 + fig = figure(); % Parent figure + EEG_filtering_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Filtering', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % , 'HelpFcn', @filter_help +elseif nargin == 1 + EEG_filtering_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Filtering', 'Padding', 5,... + 'BackgroundColor',ColorB_def); +else + EEG_filtering_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Filtering', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + + +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +eeg_filtering_gui(FonsizeDefault); + +varargout{1} = EEG_filtering_box; +%%********************Draw the GUI for ERP measurement tool***************** + function eeg_filtering_gui(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + if isempty(observe_EEGDAT.EEG) + Enable_label = 'off'; + fs = 256; + nchan=1; + else + Enable_label = 'on'; + + try + nchan = observe_EEGDAT.EEG.nbchan; + fs = observe_EEGDAT.EEG.srate; + catch + nchan =1; + end + end + + defx = {0 30 2 1:nchan 1 'butter' 0 []}; + def = estudioworkingmemory('pop_basicfilter'); + if isempty(def) + def = defx; + end + if fs <=0 + fs =256; + end + locutoff = def{1}; % for high pass filter + hicutoff = def{2}; % for low pass filter + filterorder = def{3}; + chanArray = def{4}; + filterallch = def{5}; + fdesign = def{6}; + remove_dc = def{7}; + + typef = 0; + + filterorder = 2; + if locutoff >= fs/2 || locutoff<=0 + locutoff = floor(fs/2)-1; + end + + if hicutoff>=fs/2 || hicutoff<=0 + hicutoff = floor(fs/2)-1; + end + if isempty(locutoff) + locutoff = 0; + end + + if isempty(hicutoff) + hicutoff = 0; + end + + locutoff = 0; + hicutoff = 20; + highpass_toggle_value = 1; + lowpass_toggle_value =1; + hp_halfamp_enable = 'on'; + lp_halfamp_Enable = 'on'; + hp_halfpow_string = '---'; + lp_halfpow_string = '---'; + Apply_ERP_filter_enable = 'on'; + Advance_ERP_filter_enable = 'on'; + hp_tog_enable = 'on'; + lp_tog_enable = 'on'; + + if ~isempty(observe_EEGDAT.EEG) + %%High-pass filtering + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); + if locutoff > 0 && hicutoff ==0 + highpass_toggle_value = 1; + hp_halfamp_enable = 'on'; + lowpass_toggle_value = 0; + lp_halfamp_Enable = 'off'; + hp_halfpow_string =num2str(roundn(frec3dB(1),-2)); + lp_halfpow_string ='---'; + end + %%Low pass filtering + if hicutoff > 0 && locutoff ==0 + highpass_toggle_value = 0; + hp_halfamp_enable = 'off'; + lowpass_toggle_value = 1; + lp_halfamp_Enable = 'on'; + lp_halfpow_string =num2str(roundn(frec3dB,-2)); + hp_halfpow_string ='---'; + end + %%Band pass filtering or notch filtering + if locutoff >0 && hicutoff>0 + highpass_toggle_value = 1; + hp_halfamp_enable = 'on'; + hp_halfpow_string =num2str(roundn(frec3dB(2),-2)); + lowpass_toggle_value = 1; + lp_halfamp_Enable = 'on'; + lp_halfpow_string =num2str(roundn(frec3dB(1),-2)); + end + else + hp_halfamp_enable = 'off'; + lp_halfamp_Enable = 'off'; + Apply_ERP_filter_enable = 'off'; + Advance_ERP_filter_enable = 'off'; + + lp_tog_enable = 'off'; + hp_tog_enable = 'off'; + hp_halfpow_string ='--'; + lp_halfpow_string ='---'; + end + gui_eegtab_filtering.filtering = uiextras.VBox('Parent',EEG_filtering_box,'BackgroundColor',ColorB_def); + + %%-----------------------------Setting for bin and chan-------------------- + gui_eegtab_filtering.bin_chan_title = uiextras.HBox('Parent',gui_eegtab_filtering.filtering,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',gui_eegtab_filtering.bin_chan_title,'String','Channel Selection:','FontWeight','bold',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + gui_eegtab_filtering.filter_bin_chan_option = uiextras.HBox('Parent', gui_eegtab_filtering.filtering,'Spacing',1,'BackgroundColor',ColorB_def); + + gui_eegtab_filtering.all_chan = uicontrol('Style', 'radiobutton','Parent', gui_eegtab_filtering.filter_bin_chan_option,... + 'String','All (Recommended)','callback',@All_chan,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eegtab_filtering.all_chan.KeyPressFcn =@eeg_filter_presskey; + gui_eegtab_filtering.Selected_chan = uicontrol('Style', 'radiobutton','Parent', gui_eegtab_filtering.filter_bin_chan_option,... + 'String','Selected channels','callback',@Selected_chan,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eegtab_filtering.all_chan.KeyPressFcn =@eeg_filter_presskey; + set(gui_eegtab_filtering.filter_bin_chan_option, 'Sizes',[130 170]); + + %%--------------------------Setting for IIR filter------------------------------ + gui_eegtab_filtering.IIR_title = uiextras.HBox('Parent',gui_eegtab_filtering.filtering,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',gui_eegtab_filtering.IIR_title,'String','Setting for IIR Butterworth:',... + 'FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + gui_eegtab_filtering.filt_grid = uiextras.Grid('Parent',gui_eegtab_filtering.filtering,'BackgroundColor',ColorB_def); + % first column + uiextras.Empty('Parent',gui_eegtab_filtering.filt_grid); % 1A + gui_eegtab_filtering.hp_tog = uicontrol('Style','checkbox','Parent',gui_eegtab_filtering.filt_grid,'String','High Pass',... + 'callback',@highpass_toggle,'Value',0,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1B + gui_eegtab_filtering.hp_tog.KeyPressFcn =@eeg_filter_presskey; + gui_eegtab_filtering.lp_tog = uicontrol('Style','checkbox','Parent',gui_eegtab_filtering.filt_grid,'String','Low Pass',... + 'callback',@lowpass_toggle,'Value',1,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1C + gui_eegtab_filtering.lp_tog.KeyPressFcn =@eeg_filter_presskey; + + % second column + uicontrol('Style','text','Parent',gui_eegtab_filtering.filt_grid,'String','Half Amp.','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2A + gui_eegtab_filtering.hp_halfamp = uicontrol('Style','edit','Parent',gui_eegtab_filtering.filt_grid,... + 'callback',@hp_halfamp,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 2B + gui_eegtab_filtering.hp_halfamp.KeyPressFcn =@eeg_filter_presskey; + if strcmp(hp_halfamp_enable,'off') + if typef<2 + gui_eegtab_filtering.hp_halfamp.String = '0'; + else + gui_eegtab_filtering.hp_halfamp.String = '60'; + end + else + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + end + gui_eegtab_filtering.lp_halfamp = uicontrol('Style','edit','Parent',gui_eegtab_filtering.filt_grid,... + 'callback',@lp_halfamp,'Enable',lp_halfamp_Enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 2C + gui_eegtab_filtering.lp_halfamp.KeyPressFcn =@eeg_filter_presskey; + if strcmp(lp_halfamp_Enable,'off') + gui_eegtab_filtering.lp_halfamp.String = '20'; + else + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + end + % third column + uicontrol('Style','text','Parent',gui_eegtab_filtering.filt_grid,'String','Half Power','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 3A + gui_eegtab_filtering.hp_halfpow = uicontrol('Style','text','Parent',gui_eegtab_filtering.filt_grid,... + 'String',hp_halfpow_string,'Enable','off','BackgroundColor','y','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 3B + + gui_eegtab_filtering.lp_halfpow = uicontrol('Style','text','Parent',gui_eegtab_filtering.filt_grid,... + 'String',lp_halfpow_string,'Enable','off','BackgroundColor','y','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 3C + + % fourth column + uiextras.Empty('Parent',gui_eegtab_filtering.filt_grid); % 4A + uicontrol('Style','text','Parent',gui_eegtab_filtering.filt_grid,'String','Hz','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 4B + uicontrol('Style','text','Parent',gui_eegtab_filtering.filt_grid,'String','Hz','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 4C + set(gui_eegtab_filtering.filt_grid, 'ColumnSizes',[90 70 70 40],'RowSizes',[20 -1 -1]); + + + gui_eegtab_filtering.rolloff_row = uiextras.HBox('Parent', gui_eegtab_filtering.filtering,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',gui_eegtab_filtering.rolloff_row,'String','Roll-Off','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1D + Roll_off = {'12','24','36','48'}; + gui_eegtab_filtering.roll_off = uicontrol('Style','popupmenu','Parent',gui_eegtab_filtering.rolloff_row,'String',Roll_off,... + 'callback',@EEG_filtering_rolloff,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 2D + gui_eegtab_filtering.roll_off.KeyPressFcn =@eeg_filter_presskey; + if filterorder ==2 + gui_eegtab_filtering.roll_off.Value = 1; + elseif filterorder ==4 + gui_eegtab_filtering.roll_off.Value = 2; + + elseif filterorder ==6 + gui_eegtab_filtering.roll_off.Value = 3; + + elseif filterorder ==8 + gui_eegtab_filtering.roll_off.Value = 4; + end + uicontrol('Style','text','Parent',gui_eegtab_filtering.rolloff_row,'String','dB/Octave','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 3D + + + gui_eegtab_filtering.REMOVE_DC = uiextras.HBox('Parent', gui_eegtab_filtering.filtering,'BackgroundColor',ColorB_def); + gui_eegtab_filtering.DC_remove = uicontrol('Style','checkbox','Parent', gui_eegtab_filtering.REMOVE_DC,'Enable',Enable_label,... + 'String','Remove DC Offset (Strongly recommended)','Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def);%,'callback',@remove_dc + gui_eegtab_filtering.DC_remove.KeyPressFcn =@eeg_filter_presskey; + gui_eegtab_filtering.filt_buttons = uiextras.HBox('Parent', gui_eegtab_filtering.filtering,'BackgroundColor',ColorB_def); + gui_eegtab_filtering.cancel = uicontrol('Style','pushbutton','Parent',gui_eegtab_filtering.filt_buttons,'String','Cancel',... + 'callback',@EEG_filter_Cancel,'Enable',Apply_ERP_filter_enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_eegtab_filtering.advanced = uicontrol('Style','pushbutton','Parent',gui_eegtab_filtering.filt_buttons,'String','Advanced',... + 'callback',@advanced_EEG_filter,'Enable',Advance_ERP_filter_enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_eegtab_filtering.apply = uicontrol('Style','pushbutton','Parent',gui_eegtab_filtering.filt_buttons,'String','Run',... + 'callback',@EEG_filter_apply,'Enable',Apply_ERP_filter_enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + set( gui_eegtab_filtering.filtering,'Sizes',[20 20 20 80 20 20 30]); + + + defx = {0 30 2 1:nchan 1 'butter' 0 []}; + def = estudioworkingmemory('pop_basicfilter'); + if isempty(def) + def = defx; + end + if gui_eegtab_filtering.all_chan.Value ==1 + def{5} = 1; + else + def{5} = 0; + end + remove_dc = gui_eegtab_filtering.DC_remove.Value; + def{7} = remove_dc; + + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + def{3} = filterorder; + locutoff = str2num(gui_eegtab_filtering.hp_halfamp.String);%% + hicutoff = str2num(gui_eegtab_filtering.lp_halfamp.String); + + if isempty(locutoff) + locutoff =0; + end + if isempty(hicutoff) + hicutoff =0; + end + def{1} = locutoff; + def{2} = hicutoff; + estudioworkingmemory('pop_basicfilter',def); + end + +%%************************************************************************* +%%******************* Subfunctions ************************************ +%%************************************************************************* + +%%----------------------all bin and all chan------------------------------- + function All_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + gui_eegtab_filtering.all_chan.Value = 1; + gui_eegtab_filtering.Selected_chan.Value = 0; + estudioworkingmemory('EEGTab_filter',1); + end + +%%----------------------selected bin and all chan------------------------------- + function Selected_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + gui_eegtab_filtering.all_chan.Value = 0; + gui_eegtab_filtering.Selected_chan.Value = 1; + estudioworkingmemory('EEGTab_filter',1); + end + +%%--------------------------------High-pass filtering toggle------------------ + function highpass_toggle(source,~) + if isempty(observe_EEGDAT.EEG) + source.Enable = 'off'; + gui_eegtab_filtering.hp_halfamp.Enable ='off'; + gui_eegtab_filtering.hp_halfpow.Enable ='off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + try + fs = observe_EEGDAT.EEG.srate; + catch + return; + end + locutoff = 0.1; + try + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + catch + filterorder =2; + gui_eegtab_filtering.roll_off.Value=1; + end + typef = 0; + + if source.Value == 0 + gui_eegtab_filtering.hp_halfamp.Enable ='off'; + gui_eegtab_filtering.hp_halfpow.Enable ='off'; + gui_eegtab_filtering.hp_halfamp.String = '0'; + gui_eegtab_filtering.hp_halfpow.String = '---'; + if gui_eegtab_filtering.lp_tog.Value ==0 + gui_eegtab_filtering.roll_off.Enable = 'off'; + end + else + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder,0,locutoff,fs); + gui_eegtab_filtering.hp_tog.Value =1; + gui_eegtab_filtering.hp_halfamp.Enable ='on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfpow.String = num2str(frec3dB(1)); + gui_eegtab_filtering.hp_halfpow.Enable ='off'; + gui_eegtab_filtering.hp_halfpow.String = num2str(frec3dB); + gui_eegtab_filtering.roll_off.Enable = 'on'; + end + estudioworkingmemory('EEGTab_filter',1); + end + + +%%--------------------------------Low-pass filtering toggle------------------ + function lowpass_toggle(source,~) + if isempty(observe_EEGDAT.EEG) + source.Enable = 'off'; + gui_eegtab_filtering.lp_halfamp.Enable ='off'; + gui_eegtab_filtering.lp_halfpow.Enable ='off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + try + fs = observe_EEGDAT.EEG.srate; + catch + return; + end + typef = 0; + try + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + catch + filterorder =2; + gui_eegtab_filtering.roll_off.Value=1; + end + hicutoff = floor((fs/2-1)*5/10); + if source.Value == 0 + gui_eegtab_filtering.lp_halfamp.Enable ='off'; + gui_eegtab_filtering.lp_halfpow.Enable ='off'; + gui_eegtab_filtering.lp_halfamp.String = '0'; + gui_eegtab_filtering.lp_halfpow.String = '---'; + if gui_eegtab_filtering.hp_tog.Value ==0 + gui_eegtab_filtering.roll_off.Enable = 'off'; + end + else + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,0, fs); + gui_eegtab_filtering.lp_tog.Value =1; + gui_eegtab_filtering.lp_halfamp.Enable ='on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfpow.String = num2str(frec3dB); + gui_eegtab_filtering.lp_halfpow.Enable ='off'; + gui_eegtab_filtering.roll_off.Enable = 'on'; + end + estudioworkingmemory('EEGTab_filter',1); + end + + + +%%---------------------Half amplitude for high pass filtering-------------- + function hp_halfamp(Source,~) + if isempty(observe_EEGDAT.EEG) + gui_eegtab_filtering.hp_tog.Enable = 'off'; + gui_eegtab_filtering.hp_halfamp.Enable ='off'; + gui_eegtab_filtering.hp_halfpow.Enable ='off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + + try + fs = observe_EEGDAT.EEG.srate; + catch + return; + end + + typef = 0; + try + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + catch + filterorder =2; + gui_eegtab_filtering.roll_off.Value=1; + end + + valueh = str2num(Source.String); + if length(valueh)~=1 + MessageViewer = ['Filtering - Invalid input for high-pass filter cutoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(MessageViewer,titlNamerro); + return; + end + if valueh>=fs/2 + MessageViewer = ['Filtering - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(MessageViewer,titlNamerro); + return; + end + if valueh<0.001 + msgboxText = ['Filtering - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + valuel = 0; + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, valuel, valueh, fs); + gui_eegtab_filtering.hp_halfamp.Enable ='on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(valueh); + gui_eegtab_filtering.hp_halfpow.String = num2str(frec3dB); + gui_eegtab_filtering.hp_halfpow.Enable ='off'; + estudioworkingmemory('EEGTab_filter',1); + end + + + +%%---------------------Half amplitude for low pass filtering--------------- + function lp_halfamp(Source,~) + if isempty(observe_EEGDAT.EEG) + gui_eegtab_filtering.lp_tog.Enable = 'off'; + gui_eegtab_filtering.lp_halfamp.Enable ='off'; + gui_eegtab_filtering.lp_halfpow.Enable ='off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + + try + fs = observe_EEGDAT.EEG.srate; + catch + return; + end + try + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + catch + filterorder =2; + gui_eegtab_filtering.roll_off.Value=1; + end + valuel = str2num(Source.String); + if length(valuel)~=1 || isempty(valuel) + msgboxText = ['Filtering - Invalid input for low-pass filter cutoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if valuel>=fs/2 + msgboxText = ['Filtering - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if valuel<0.001 + msgboxText = ['Filtering - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + %if the valueh is between 0.1 and fs/2 Hz + typef = 0; + valueh = 0; + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, valuel, valueh, fs); + gui_eegtab_filtering.lp_halfamp.Enable ='on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(valuel); + gui_eegtab_filtering.lp_halfpow.String = num2str(frec3dB(1)); + gui_eegtab_filtering.lp_halfpow.Enable ='off'; + estudioworkingmemory('EEGTab_filter',1); + end + + +%%----------------------------Setting for roll-off------------------------- + function EEG_filtering_rolloff(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable = 'off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + gui_eegtab_filtering.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.apply.ForegroundColor = [1 1 1]; + EEG_filtering_box.TitleColor= [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_eegtab_filtering.cancel.ForegroundColor = [1 1 1]; + + Source_value = Source.Value; + filterorder = 2*Source_value; + typef = 0; + fs = observe_EEGDAT.EEG.srate; + valuel = str2num(gui_eegtab_filtering.lp_halfamp.String);%% for low-pass filter + valueh = str2num(gui_eegtab_filtering.hp_halfamp.String);%%for high-pass filter + if gui_eegtab_filtering.lp_tog.Value ==1 + if isempty(valuel)|| length(valuel)~=1 + msgboxText = ['Filtering - Invalid input for low-pass filter cutoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if valuel>=fs/2 + msgboxText = ['Filtering - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if gui_eegtab_filtering.hp_tog.Value ==0 + if valuel<0.001 + msgboxText = ['Filtering - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + end + + if gui_eegtab_filtering.hp_tog.Value ==1 + if length(valueh)~=1 + msgboxText = ['Filtering - Invalid input for high-pass filter cutoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if valueh>=fs/2 + msgboxText = ['Filtering - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if gui_eegtab_filtering.lp_tog.Value ==0 + if valueh<0.001 + msgboxText = ['Filtering - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + end + + if gui_eegtab_filtering.hp_tog.Value ==1 && gui_eegtab_filtering.lp_tog.Value ==1 + if valueh >0 && valueh >0 && valueh >=valuel + msgboxText = ['Filtering - The lowest bandpass cuttoff is the highest bandpass cuttoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if valueh==0 && valuel==0 + msgboxText = ['Filtering - Either Lowest bandpass cuttoff or the highest bandpass cuttoff or both is larger than 0.01Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + + if valuel> 0 && valueh ==0 + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, valuel, 0, fs); + gui_eegtab_filtering.lp_halfpow.String = num2str(frec3dB); + elseif valuel== 0 && valueh > 0 + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder,0, valueh,fs); + gui_eegtab_filtering.hp_halfpow.String = num2str(frec3dB); + elseif valuel> 0 && valueh > 0 + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder,valuel, valueh,fs); + gui_eegtab_filtering.lp_halfpow.String = num2str(frec3dB(1)); + gui_eegtab_filtering.hp_halfpow.String = num2str(frec3dB(2)); + end + estudioworkingmemory('EEGTab_filter',1); + EStudio_gui_erp_totl.EEG_transf = 0; + end + + +%%------------------Setting for apply option-------------------------------- + function EEG_filter_apply(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable = 'off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + gui_eegtab_filtering.apply.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.apply.ForegroundColor = [0 0 0]; + EEG_filtering_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_filtering.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_filter',0); + try + nchan = observe_EEGDAT.EEG.nbchan; + fs = observe_EEGDAT.EEG.srate; + catch + return; + end + defx = {0 30 2 1:nchan 1 'butter' 0 []}; + def = estudioworkingmemory('pop_basicfilter'); + if isempty(def) + def = defx; + end + if gui_eegtab_filtering.all_chan.Value ==1 + def{5} = 1; + else + def{5} = 0; + end + remove_dc = gui_eegtab_filtering.DC_remove.Value; + def{7} = remove_dc; + + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + def{3} = filterorder; + locutoff = str2num(gui_eegtab_filtering.hp_halfamp.String);%% + hicutoff = str2num(gui_eegtab_filtering.lp_halfamp.String); + + if isempty(locutoff) + locutoff =0; + end + if isempty(hicutoff) + hicutoff =0; + end + def{1} = locutoff; + def{2} = hicutoff; + estudioworkingmemory('pop_basicfilter',def); + + if gui_eegtab_filtering.lp_tog.Value ==1 + if length(hicutoff)~=1 || isempty(hicutoff) + msgboxText = ['Filtering - Invalid input for low-pass filter cutoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if hicutoff>=fs/2 + msgboxText = ['Filtering - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if gui_eegtab_filtering.hp_tog.Value ==0 + if hicutoff<0.001 + msgboxText = ['Filtering - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + end + + if gui_eegtab_filtering.hp_tog.Value ==1 + if length(locutoff)~=1 + msgboxText = ['Filtering - Invalid input for high-pass filter cutoff']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if locutoff>=fs/2 + msgboxText = ['Filtering - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if gui_eegtab_filtering.lp_tog.Value ==0 + if locutoff<0.001 + msgboxText = ['Filtering - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + end + + if gui_eegtab_filtering.hp_tog.Value ==1 && gui_eegtab_filtering.lp_tog.Value ==1 + if locutoff==0 && hicutoff==0 + msgboxText = ['Filtering - Either Lowest bandpass cuttoff or the highest bandpass cuttoff or both is larger than 0.01Hz']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + + if remove_dc==1 + rdc = 'on'; + else + rdc = 'off'; + end + filterallch = def{5}; + + if filterallch + chanArray = 1:nchan; + else + chanArray= estudioworkingmemory('EEG_ChanArray'); + end + + fdesign = 'butter'; + if ~strcmpi(fdesign, 'notch') && locutoff==0 && hicutoff>0 % Butter (IIR) and FIR%% low-pass filter + ftype = 'lowpass'; + cutoff = hicutoff; + elseif ~strcmpi(fdesign, 'notch') && locutoff>0 && hicutoff==0 % Butter (IIR) and FIR + ftype = 'highpass'; + cutoff = locutoff; + elseif ~strcmpi(fdesign, 'notch') && locutoff>0 && hicutoff>0 && locutoff0 && hicutoff>0 && locutoff>hicutoff% Butter (IIR) and FIR + ftype = 'simplenotch'; + cutoff = [locutoff hicutoff]; + elseif ~strcmpi(fdesign, 'notch') && locutoff==0 && hicutoff==0 % Butter (IIR) and FIR + msgboxText = 'Filtering - I beg your pardon?'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + else + msgboxText = ['Filtering - Invalid type of filter']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + %%save changed parameters to the memory file + estudioworkingmemory('pop_basicfilter', {locutoff,hicutoff,filterorder,chanArray,filterallch,fdesign,remove_dc,[]}); + + %%-------------loop start for filtering the selected ERPsets----------------------------------- + estudioworkingmemory('f_EEG_proces_messg','Filtering>Apply'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + if gui_eegtab_filtering.all_chan.Value == 1 + chanArray = [1:EEG.nbchan]; + else + if isempty(chanArray) || any(chanArray(:) > EEG.nbchan) || any(chanArray(:) <=0) + chanArray = [1:EEG.nbchan]; + end + end + %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. + [EEG, LASTCOM] = pop_basicfilter(EEG, chanArray, 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... + 'History', 'gui'); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end + + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_filt'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%-------------------Setting for advance option--------------------------- + function advanced_EEG_filter(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable = 'off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) %%&& eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + gui_eegtab_filtering.apply.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.apply.ForegroundColor = [0 0 0]; + EEG_filtering_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_filtering.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_filter',0); + try + nchan = observe_EEGDAT.EEG.nbchan; + fs = observe_EEGDAT.EEG.srate; + catch + fs = 256; + nchan = 30; + end + defx = {0 30 2 1:nchan 1 'butter' 0 []}; + def = estudioworkingmemory('pop_basicfilter'); + + if isempty(def) + def = defx; + else + def{4} = def{4}(ismember_bc2(def{4},1:nchan)); + end + + def{1} = str2num(gui_eegtab_filtering.hp_halfamp.String); + def{2} = str2num(gui_eegtab_filtering.lp_halfamp.String); + if gui_eegtab_filtering.hp_tog.Value ==1 + if isempty(def{1}) || def{1} ==0 + def{1} = 0.01; + end + end + if gui_eegtab_filtering.lp_tog.Value ==1 + if isempty(def{2}) || def{2} ==0 + def{2} = floor((fs/2-1)*5/10); + end + end + + def{7} = gui_eegtab_filtering.DC_remove.Value; + def{8} = []; + fdesign = 'butter'; + def{3} = 2*gui_eegtab_filtering.roll_off.Value; + def{6} = fdesign; + + EEGArray = estudioworkingmemory('EEGArray'); + if gui_eegtab_filtering.all_chan.Value == 1 + chanArray = 1:nchan; + def{5} =1; + else + chanArray= estudioworkingmemory('EEG_ChanArray'); + def{5} =0; + end + def{4} = chanArray; + + %%call the GUI for advance option + answer = basicfilterGUI2(observe_EEGDAT.EEG, def); + if isempty(answer) + return; + end + + defx = {answer{1},answer{2},answer{3},answer{4},answer{5},answer{6},answer{7},answer{8}}; + estudioworkingmemory('pop_basicfilter',defx); + + locutoff = answer{1}; % for high pass filter + hicutoff = answer{2}; % for low pass filter + filterorder = answer{3}; + chanArray = answer{4}; + filterallch = answer{5}; + fdesign = answer{6}; + remove_dc = answer{7}; + Boundaryflag = answer{8}; + if locutoff >= fs/2 || locutoff< 0 + locutoff = floor(fs/2)-1; + end + if hicutoff>=fs/2 || hicutoff< 0 + hicutoff = floor(fs/2)-1; + end + if isempty(locutoff) + locutoff = 0; + end + if isempty(hicutoff) + hicutoff = 0; + end + %%-----------setting for IIR butter---------------------- + if strcmpi(fdesign,'butter') + typef = 0; + gui_eegtab_filtering.roll_off.Value = filterorder/2; + gui_eegtab_filtering.roll_off.String = {'12','24','36','48'}'; + gui_eegtab_filtering.roll_off.Enable = 'on'; + gui_eegtab_filtering.DC_remove.Value = remove_dc; + %%High-pass filtering + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); + if locutoff > 0 && (isempty(hicutoff) || hicutoff ==0 ) + gui_eegtab_filtering.hp_tog.Value = 1; + gui_eegtab_filtering.hp_tog.Enable ='on'; + gui_eegtab_filtering.lp_tog.Value = 0; + gui_eegtab_filtering.lp_tog.Enable ='on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfamp.Enable = 'on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfamp.Enable = 'off'; + gui_eegtab_filtering.hp_halfpow.String = num2str(roundn(frec3dB(1),-2)); + gui_eegtab_filtering.lp_halfpow.String = '---'; + end + %%Low pass filtering + if hicutoff > 0 && (isempty(locutoff) || locutoff ==0) + gui_eegtab_filtering.lp_tog.Value = 1; + gui_eegtab_filtering.lp_tog.Enable ='on'; + gui_eegtab_filtering.hp_tog.Value = 0; + gui_eegtab_filtering.hp_tog.Enable ='on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfamp.Enable = 'on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfamp.Enable = 'off'; + gui_eegtab_filtering.lp_halfpow.String = num2str(roundn(frec3dB(1),-2)); + gui_eegtab_filtering.hp_halfpow.String = '---'; + end + %%Band pass filtering or notch filtering + if locutoff >0 && hicutoff>0 + gui_eegtab_filtering.hp_tog.Value = 1; + gui_eegtab_filtering.hp_tog.Enable ='on'; + gui_eegtab_filtering.lp_tog.Value = 1; + gui_eegtab_filtering.lp_tog.Enable ='on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfamp.Enable = 'on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfamp.Enable = 'on'; + gui_eegtab_filtering.hp_halfpow.String = num2str(roundn(frec3dB(2),-2)); + gui_eegtab_filtering.lp_halfpow.String = num2str(roundn(frec3dB(1),-2)); + end + end%%setting end for IIR butter filter + %%*************Filter the selected ERPsets*************************** + if remove_dc==1 + rdc = 'on'; + else + rdc = 'off'; + end + filterallch = def{5}; + if ~strcmpi(fdesign, 'notch') && locutoff==0 && hicutoff>0 % Butter (IIR) and FIR%% low-pass filter + ftype = 'lowpass'; + cutoff = hicutoff; + elseif ~strcmpi(fdesign, 'notch') && locutoff>0 && hicutoff==0 % Butter (IIR) and FIR + ftype = 'highpass'; + cutoff = locutoff; + elseif ~strcmpi(fdesign, 'notch') && locutoff>0 && hicutoff>0 && locutoff0 && hicutoff>0 && locutoff>hicutoff% Butter (IIR) and FIR + ftype = 'simplenotch'; + cutoff = [locutoff hicutoff]; + elseif strcmpi(fdesign, 'notch') && locutoff==hicutoff % Parks-McClellan Notch + ftype = 'PMnotch'; + cutoff = hicutoff; + elseif ~strcmpi(fdesign, 'notch') && locutoff==0 && hicutoff==0 % Butter (IIR) and FIR + msgboxText = 'Filtering - I beg your pardon?'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + else + msgboxText = ['Filtering - Invalid type of filter']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if strcmpi(fdesign, 'notch') && locutoff==hicutoff + if 3*filterorder>=length(observe_EEGDAT.EEG.times) + msgboxText = ['Filtering -The length of the data must be more than three times the filter order']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + + %%-------------loop start for filtering the selected ERPsets----------------------------------- + estudioworkingmemory('f_EEG_proces_messg','Filtering>Advanced'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. + [EEG, LASTCOM] = pop_basicfilter(EEG, chanArray, 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... + 'History', 'gui','Boundary', Boundaryflag); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + return; + end + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out, ~, ~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end + + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_filt'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + EEG.saved = 'yes'; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG, ~, ~] = pop_newset(ALLEEG, EEG, length(ALLEEG_out), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------------------------------------Cancel----------------------------- +%%this function is to cancel the changed parameters + function EEG_filter_Cancel(~,~) + if isempty(observe_EEGDAT.EEG) + gui_eegtab_filtering.cancel.Enable = 'off'; + gui_eegtab_filtering.apply.Enable = 'off'; + gui_eegtab_filtering.advanced.Enable = 'off'; + gui_eegtab_filtering.roll_off.Enable = 'off'; + gui_eegtab_filtering.hp_halfamp.Enable = 'off'; + gui_eegtab_filtering.lp_halfamp.Enable = 'off'; + gui_eegtab_filtering.hp_tog.Enable = 'off'; + gui_eegtab_filtering.lp_tog.Enable = 'off'; + gui_eegtab_filtering.all_chan.Enable = 'off'; + gui_eegtab_filtering.Selected_chan.Enable = 'off'; + return; + end + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + nchan=observe_EEGDAT.EEG.nbchan; + defx= estudioworkingmemory('pop_basicfilter'); + if isempty(defx) + defx = {0 30 2 1:nchan 1 'butter' 0 []}; + end + locutoff = defx{1}; % for high pass filter + hicutoff = defx{2}; % for low pass filter + filterorder = defx{3}; + filterallch = defx{5}; + remove_dc = defx{7}; + fs = observe_EEGDAT.EEG.srate; + if locutoff >= fs/2 || locutoff< 0 + locutoff = floor(fs/2)-1; + end + if hicutoff>=fs/2 || hicutoff< 0 + hicutoff = floor(fs/2)-1; + end + if isempty(locutoff) + locutoff = 0; + end + if isempty(hicutoff) + hicutoff = 0; + end + if filterallch==1 + gui_eegtab_filtering.all_chan.Value = 1; + gui_eegtab_filtering.Selected_chan.Value = 0; + else + gui_eegtab_filtering.all_chan.Value = 0; + gui_eegtab_filtering.Selected_chan.Value = 1; + end + typef = 0; + gui_eegtab_filtering.roll_off.Value = filterorder/2; + gui_eegtab_filtering.roll_off.String = {'12','24','36','48'}'; + gui_eegtab_filtering.roll_off.Enable = 'on'; + gui_eegtab_filtering.DC_remove.Value = remove_dc; + %%High-pass filtering + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); + if locutoff > 0 && (isempty(hicutoff) || hicutoff ==0 ) + gui_eegtab_filtering.hp_tog.Value = 1; + gui_eegtab_filtering.hp_tog.Enable ='on'; + gui_eegtab_filtering.lp_tog.Value = 0; + gui_eegtab_filtering.lp_tog.Enable ='on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfamp.Enable = 'on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfamp.Enable = 'off'; + gui_eegtab_filtering.hp_halfpow.String = num2str(roundn(frec3dB(1),-2)); + gui_eegtab_filtering.lp_halfpow.String = '---'; + end + %%Low pass filtering + if hicutoff > 0 && (isempty(locutoff) || locutoff ==0) + gui_eegtab_filtering.lp_tog.Value = 1; + gui_eegtab_filtering.lp_tog.Enable ='on'; + gui_eegtab_filtering.hp_tog.Value = 0; + gui_eegtab_filtering.hp_tog.Enable ='on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfamp.Enable = 'on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfamp.Enable = 'off'; + gui_eegtab_filtering.lp_halfpow.String = num2str(roundn(frec3dB(1),-2)); + gui_eegtab_filtering.hp_halfpow.String = '---'; + end + %%Band pass filtering or notch filtering + if locutoff >0 && hicutoff>0 + gui_eegtab_filtering.hp_tog.Value = 1; + gui_eegtab_filtering.hp_tog.Enable ='on'; + gui_eegtab_filtering.lp_tog.Value = 1; + gui_eegtab_filtering.lp_tog.Enable ='on'; + gui_eegtab_filtering.hp_halfamp.String = num2str(locutoff); + gui_eegtab_filtering.hp_halfamp.Enable = 'on'; + gui_eegtab_filtering.lp_halfamp.String = num2str(hicutoff); + gui_eegtab_filtering.lp_halfamp.Enable = 'on'; + gui_eegtab_filtering.hp_halfpow.String = num2str(roundn(frec3dB(2),-2)); + gui_eegtab_filtering.lp_halfpow.String = num2str(roundn(frec3dB(1),-2)); + end + gui_eegtab_filtering.apply.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.apply.ForegroundColor = [0 0 0]; + EEG_filtering_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_filtering.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('EEGTab_filter',0); + + if ndims(observe_EEGDAT.EEG.data)==3 + gui_eegtab_filtering.DC_remove.Enable = 'off'; + gui_eegtab_filtering.DC_remove.Value = 0; + else + gui_eegtab_filtering.DC_remove.Enable = 'on'; + gui_eegtab_filtering.DC_remove.Value = 1; + end + + defx = {0 30 2 1:nchan 1 'butter' 0 []}; + def = estudioworkingmemory('pop_basicfilter'); + if isempty(def) + def = defx; + end + if gui_eegtab_filtering.all_chan.Value ==1 + def{5} = 1; + else + def{5} = 0; + end + remove_dc = gui_eegtab_filtering.DC_remove.Value; + def{7} = remove_dc; + + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + def{3} = filterorder; + locutoff = str2num(gui_eegtab_filtering.hp_halfamp.String);%% + hicutoff = str2num(gui_eegtab_filtering.lp_halfamp.String); + + if isempty(locutoff) + locutoff =0; + end + if isempty(hicutoff) + hicutoff =0; + end + def{1} = locutoff; + def{2} = hicutoff; + estudioworkingmemory('pop_basicfilter',def); + + end + +%%-------------------Setting for the whole panel of fitering based on ALLERP and CURRENTERP-------------- + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=10 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) ||EEGUpdate==1 + gui_eegtab_filtering.apply.Enable = 'off'; + gui_eegtab_filtering.advanced.Enable = 'off'; + gui_eegtab_filtering.roll_off.Enable = 'off'; + gui_eegtab_filtering.hp_halfamp.Enable = 'off'; + gui_eegtab_filtering.lp_halfamp.Enable = 'off'; + gui_eegtab_filtering.hp_tog.Enable = 'off'; + gui_eegtab_filtering.lp_tog.Enable = 'off'; + gui_eegtab_filtering.all_chan.Enable = 'off'; + gui_eegtab_filtering.Selected_chan.Enable = 'off'; + gui_eegtab_filtering.cancel.Enable = 'off'; + gui_eegtab_filtering.DC_remove.Enable = 'off'; + observe_EEGDAT.count_current_eeg=11; + return; + else + gui_eegtab_filtering.all_chan.Enable = 'on'; + gui_eegtab_filtering.Selected_chan.Enable = 'on'; + locutoff = str2num(gui_eegtab_filtering.hp_halfamp.String);%%for high pass filter + hicutoff = str2num(gui_eegtab_filtering.lp_halfamp.String);%% for low pass filter + if isempty(locutoff) + locutoff =0; + gui_eegtab_filtering.hp_halfamp.String = '0'; + end + if isempty(hicutoff) + hicutoff = 0; + gui_eegtab_filtering.lp_halfamp.String = '0'; + end + fs = observe_EEGDAT.EEG.srate; + if fs <=0 + fs = 256; + end + typef = 0; + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); + if locutoff > 0 && hicutoff ==0 + highpass_toggle_value = 1; + hp_halfamp_enable = 'on'; + lowpass_toggle_value = 0; + lp_halfamp_Enable = 'off'; + hp_halfpow_string =num2str(roundn(frec3dB(1),-2)); + lp_halfpow_string ='---'; + end + %%Low pass filtering + if hicutoff > 0 && locutoff ==0 + highpass_toggle_value = 0; + hp_halfamp_enable = 'off'; + lowpass_toggle_value = 1; + lp_halfamp_Enable = 'on'; + lp_halfpow_string =num2str(roundn(frec3dB,-2)); + hp_halfpow_string ='---'; + end + %%Band pass filtering or notch filtering + if locutoff >0 && hicutoff>0 + highpass_toggle_value = 1; + hp_halfamp_enable = 'on'; + hp_halfpow_string =num2str(roundn(frec3dB(2),-2)); + lowpass_toggle_value = 1; + lp_halfamp_Enable = 'on'; + lp_halfpow_string =num2str(roundn(frec3dB(1),-2)); + end + + if locutoff==0 && hicutoff==0 + highpass_toggle_value = 0; + hp_halfamp_enable = 'off'; + hp_halfpow_string ='0'; + lowpass_toggle_value = 0; + lp_halfamp_Enable = 'off'; + lp_halfpow_string ='0'; + end + gui_eegtab_filtering.apply.Enable = 'on'; + gui_eegtab_filtering.advanced.Enable = 'on'; + gui_eegtab_filtering.roll_off.Enable = 'on'; + gui_eegtab_filtering.hp_halfpow.String = hp_halfpow_string; + gui_eegtab_filtering.lp_halfpow.String = lp_halfpow_string; + gui_eegtab_filtering.hp_halfamp.Enable = hp_halfamp_enable; + gui_eegtab_filtering.lp_halfamp.Enable = lp_halfamp_Enable; + gui_eegtab_filtering.hp_tog.Value = highpass_toggle_value; + gui_eegtab_filtering.lp_tog.Value = lowpass_toggle_value; + gui_eegtab_filtering.hp_tog.Enable = 'on'; + gui_eegtab_filtering.lp_tog.Enable = 'on'; + gui_eegtab_filtering.cancel.Enable = 'on'; + if ndims(observe_EEGDAT.EEG.data)==3 + gui_eegtab_filtering.DC_remove.Enable = 'off'; + gui_eegtab_filtering.DC_remove.Value = 0; + else + gui_eegtab_filtering.DC_remove.Enable = 'on'; + end + if EStudio_gui_erp_totl.EEG_transf ==1 + gui_eegtab_filtering.roll_off.Value=1; + if observe_EEGDAT.EEG.trials==1 + gui_eegtab_filtering.DC_remove.Value =1; + end + EStudio_gui_erp_totl.EEG_transf =0; + end + end + EStudio_gui_erp_totl.EEG_transf=0; + observe_EEGDAT.count_current_eeg=11; + end + +%%--------------press return to execute "Apply"---------------------------- + function eeg_filter_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_filter'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + EEG_filter_apply(); + estudioworkingmemory('EEGTab_filter',0); + gui_eegtab_filtering.apply.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.apply.ForegroundColor = [0 0 0]; + EEG_filtering_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_filtering.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=8 + return; + end + estudioworkingmemory('EEGTab_filter',0); + gui_eegtab_filtering.apply.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.apply.ForegroundColor = [0 0 0]; + % EEG_filtering_box.TitleColor= [0.0500 0.2500 0.5000]; + gui_eegtab_filtering.cancel.BackgroundColor = [1 1 1]; + gui_eegtab_filtering.cancel.ForegroundColor = [0 0 0]; + + %%----------------------channel selection-------------------------- + gui_eegtab_filtering.all_chan.Value = 1; + gui_eegtab_filtering.Selected_chan.Value = 0; + + %%-------------------setting for IIR Butterworth------------------- + gui_eegtab_filtering.hp_halfpow.String = '---'; + gui_eegtab_filtering.hp_halfamp.Enable = 'off'; + gui_eegtab_filtering.lp_halfamp.Enable = 'on'; + gui_eegtab_filtering.hp_tog.Value = 0; + gui_eegtab_filtering.lp_tog.Value = 1; + if ~isempty(observe_EEGDAT.EEG) + if observe_EEGDAT.EEG.trials>1 + gui_eegtab_filtering.DC_remove.Enable = 'off'; + else + gui_eegtab_filtering.DC_remove.Enable = 'on'; + end + end + gui_eegtab_filtering.DC_remove.Value = 0; + gui_eegtab_filtering.hp_halfamp.String = '0'; + gui_eegtab_filtering.lp_halfamp.String = '30'; + gui_eegtab_filtering.roll_off.Value=1; + try + fs = observe_EEGDAT.EEG.srate; + catch + fs = 256; + end + typef = 0; + if EStudio_gui_erp_totl.EEG_transf ==1 + gui_eegtab_filtering.roll_off.Value=1; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials==1 + gui_eegtab_filtering.DC_remove.Value =1; + end + EStudio_gui_erp_totl.EEG_transf =0; + end + remove_dc = gui_eegtab_filtering.DC_remove.Value; + filterorder = 2*gui_eegtab_filtering.roll_off.Value; + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, 0,30,fs); + hp_halfpow_string =num2str(roundn(frec3dB(1),-2)); + gui_eegtab_filtering.lp_halfpow.String = hp_halfpow_string; + try nchan=observe_EEGDAT.EEG.nbchan;catch nchan=1;end + defx = {0, 30, 2, 1:nchan, 1 ,'butter', remove_dc, []}; + estudioworkingmemory('pop_basicfilter',defx); + observe_EEGDAT.Reset_eeg_paras_panel=9; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +% if exist(filenamex, 'file')~=0 +% msgboxText = ['This EEG Data already exist.\n'...; +% 'Would you like to overwrite it?']; +% title = 'Estudio: WARNING!'; +% button = askquest(sprintf(msgboxText), title); +% if strcmpi(button,'no') +% checkfileindex=0; +% else +% checkfileindex=1; +% end +% end +end + +%Progem end: ERP Measurement tool \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_history_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_history_GUI.m new file mode 100644 index 00000000..ddd7a0ad --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_history_GUI.m @@ -0,0 +1,326 @@ +%%This script is to save history for either current EEGset or current session. + + + +%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +%Oct. 2023 + +% ERPLAB Studio + +function varargout = f_EEG_history_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +gui_eeg_history = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global box_eeg_history; + +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end + +if nargin == 0 + fig = figure(); % Parent figure + box_eeg_history = uiextras.BoxPanel('Parent', fig, 'Title', 'History', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + box_eeg_history = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'History', 'Padding', 5,'BackgroundColor',ColorB_def); +else + box_eeg_history = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'History', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_eeg_history(FonsizeDefault); +varargout{1} = box_eeg_history; + + function drawui_eeg_history(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + FontSize_defualt = FonsizeDefault; + %%--------------------channel and bin setting---------------------- + gui_eeg_history.DataSelBox = uiextras.VBox('Parent', box_eeg_history,'BackgroundColor',ColorB_def); + + gui_eeg_history.eeg_history_title = uiextras.HBox('Parent', gui_eeg_history.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_history.eeg_h_all = uicontrol('Style','radiobutton','Parent',gui_eeg_history.eeg_history_title,'String','Current EEGset',... + 'callback',@eeg_H_ALL,'Value',1,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on'); % 2F + gui_eeg_history.eeg_h_EEG = uicontrol('Style','radiobutton','Parent', gui_eeg_history.eeg_history_title,'String','Current session',... + 'callback',@eeg_H_EEG,'Value',0,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on'); % 2F + + try + eeg_history = observe_EEGDAT.EEG.history; + catch + eeg_history = []; + end + if isempty(eeg_history) + eeg_history = char('No history was found for the current eegset'); + end + [~, total_len] = size(eeg_history); + if total_len <500 + total_len =1000; + end + gui_eeg_history.eeg_history_table = uiextras.HBox('Parent', gui_eeg_history.DataSelBox); + gui_eeg_history.uitable = uitable( ... + 'Parent' , gui_eeg_history.eeg_history_table,... + 'Data' , strsplit(eeg_history(1,:), '\n')', ... + 'ColumnWidth' , {total_len+2}, ... + 'ColumnName' , {'Function call'}, ... + 'RowName' , [],'Enable',EnableFlag); + + %%save the scripts + gui_eeg_history.save_history_title = uiextras.HBox('Parent', gui_eeg_history.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_history.save_script = uicontrol('Style','pushbutton','Parent',gui_eeg_history.save_history_title,... + 'String','Save history script','callback',@savescript,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + gui_eeg_history.show_cmd = uicontrol('Style','pushbutton','Parent',gui_eeg_history.save_history_title,... + 'String','Show in cmd window','callback',@show_cmd,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + set( gui_eeg_history.DataSelBox,'Sizes',[35 -1 30]); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + + +%--------History for both EEG and eeg data processing procedure------------ + function eeg_H_ALL(~,~) + Source_value = 1; + set(gui_eeg_history.eeg_h_all,'Value',Source_value); + set(gui_eeg_history.eeg_h_EEG,'Value',~Source_value); + + %adding the relared history in dispaly panel + hiscp_empty =0; + try + eeg_history = observe_EEGDAT.EEG.history; + catch + eeg_history = []; + end + + if isempty(eeg_history) + eeg_history = char('No history exist in the current eegset'); + else + gui_eeg_history.save_script.Enable = 'on'; + end + eeg_history_display = {}; + for Numofrow = 1:size(eeg_history,1) + eeg_history_display = [eeg_history_display,strsplit(eeg_history(Numofrow,:), '\n')]; + end + set(gui_eeg_history.uitable,'Data', eeg_history_display'); + end + +%%------------------------ALLCOM------------------------------------------- + function eeg_H_EEG(~,~) + Source_value = 1; + set(gui_eeg_history.eeg_h_all,'Value',~Source_value); + set(gui_eeg_history.eeg_h_EEG,'Value',Source_value); + %adding the relared history in dispaly panel + try + eeg_history = evalin('base','ALLCOM'); + eeg_history = eeg_history'; + catch + eeg_history = []; + end + if isempty(eeg_history) + eeg_history = {'No command history was found in the current session'}; + else + end + gui_eeg_history.save_script.Enable = 'on'; + count = 0; + for ii = length(eeg_history):-1:1 + count = count+1; + His_Data{count,1} = eeg_history{ii}; + end + set(gui_eeg_history.uitable,'Data',His_Data); + end + +%%--------------------------------Save scripts----------------------------- + function savescript(Source,~) + if gui_eeg_history.eeg_h_all.Value==1 + MessageViewer= char(strcat('Save history script for the current EEGset')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=1; + if ~isempty(observe_EEGDAT.EEG) + LASTCOM = pop_saveh(observe_EEGDAT.EEG.history); + else + return; + end + else + MessageViewer= char(strcat('Save history script for the current session')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=1; + try + eeg_history = evalin('base','ALLCOM'); + eeg_history = eeg_history'; + catch + return; + end + LASTCOM = pop_saveh(eeg_history); + end + fprintf(['\n',LASTCOM,'\n']); + observe_EEGDAT.eeg_panel_message=2; + end + +%%--------Setting current eegset/session history based on the current updated eegset------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=26 + return; + end + if ~isempty(observe_EEGDAT.EEG) + gui_eeg_history.eeg_h_all.String = ['Current EEGset (',num2str(observe_EEGDAT.CURRENTSET),')']; + else + gui_eeg_history.eeg_h_all.String = 'Current EEGset'; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + gui_eeg_history.save_script.Enable = 'on'; + gui_eeg_history.eeg_h_all.Enable = 'on'; + gui_eeg_history.eeg_h_EEG.Enable = 'on'; + gui_eeg_history.uitable.Enable = 'on'; + gui_eeg_history.show_cmd.Enable = 'on'; + if gui_eeg_history.eeg_h_all.Value ==1 + try + eeg_history = observe_EEGDAT.EEG.history; + catch + eeg_history = []; + end + if isempty(eeg_history) + eeg_history = char('No command history was found for the current eegset'); + gui_eeg_history.save_script.Enable = 'off'; + end + eeg_history_display = {}; + for Numofrow = 1:size(eeg_history,1) + eeg_history_display = [eeg_history_display,strsplit(eeg_history(Numofrow,:), '\n')]; + end + set(gui_eeg_history.uitable,'Data', eeg_history_display'); + set(gui_eeg_history.DataSelBox,'Heights',[40 -1]); + else%% ALLeegCOM for current session + try + eeg_history = evalin('base','ALLCOM'); + eeg_history = eeg_history'; + count = 0; + for ii = length(eeg_history):-1:1 + count = count+1; + His_Data{count,1} = eeg_history{ii}; + end + set(gui_eeg_history.uitable,'Data',His_Data); + + catch + eeg_history = {'No command history was found in the current session'}; + set(gui_eeg_history.uitable,'Data',eeg_history); + end + if isempty(eeg_history) + eeg_history = {'No command history was found in the current session'}; + set(gui_eeg_history.uitable,'Data',eeg_history); + end + end + + end + +%%-------------show history to command window------------------------------ + function show_cmd(~,~) + MessageViewer='History > Show in cmd window'; + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_EEGDAT.eeg_panel_message=1; + + if gui_eeg_history.eeg_h_all.Value ==1 + try + eeg_history = observe_EEGDAT.EEG.history; + catch + eeg_history = []; + end + if isempty(eeg_history) + try disp(['No command history for',32,observe_EEGDAT.EEG.setname]);catch; end; + observe_EEGDAT.eeg_panel_message=2; + return; + end + eeg_history_display = {}; + for Numofrow = 1:size(eeg_history,1) + eeg_history_display = [eeg_history_display,strsplit(eeg_history(Numofrow,:), '\n')]; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['**Command history**',32,datestr(datetime('now')),'\n']); + fprintf(['EEG name:',32,observe_EEGDAT.EEG.setname,'\n\n']); + for ii = 1:length(eeg_history_display) + disp([eeg_history_display{ii}]); + end + fprintf( [repmat('-',1,100) '\n\n']); + else + try + eeg_history = evalin('base','ALLCOM'); + catch + eeg_history = []; + end + if isempty(eeg_history) + disp(['No command history for current session']); + observe_EEGDAT.eeg_panel_message=2; + return; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['**Command history for current session**',32,datestr(datetime('now')),'\n\n']); + for ii = length(eeg_history):-1:1 + disp([eeg_history{ii}]); + end + fprintf( [repmat('-',1,100) '\n\n']); + end + observe_EEGDAT.eeg_panel_message=2; + end + + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=22 + return; + end + set(gui_eeg_history.eeg_h_all,'Value',1); + set(gui_eeg_history.eeg_h_EEG,'Value',0); + + %adding the relared history in dispaly panel + hiscp_empty =0; + try + eeg_history = observe_EEGDAT.EEG.history; + catch + eeg_history = []; + end + + if isempty(eeg_history) + eeg_history = char('No history exist in the current eegset'); + else + gui_eeg_history.save_script.Enable = 'on'; + end + eeg_history_display = {}; + for Numofrow = 1:size(eeg_history,1) + eeg_history_display = [eeg_history_display,strsplit(eeg_history(Numofrow,:), '\n')]; + end + set(gui_eeg_history.uitable,'Data', eeg_history_display'); + if ~isempty(observe_EEGDAT.EEG) + gui_eeg_history.eeg_h_all.String = ['Current EEGset (',num2str(observe_EEGDAT.CURRENTSET),')']; + else + gui_eeg_history.eeg_h_all.String = 'Current EEGset'; + end + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_import_GUI.fig b/studio_functions/GUIs/EEG Tab/f_EEG_import_GUI.fig new file mode 100755 index 00000000..c2a262de Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_import_GUI.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_import_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_import_GUI.m new file mode 100755 index 00000000..f319a431 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_import_GUI.m @@ -0,0 +1,845 @@ +function varargout = f_EEG_import_GUI(varargin) +% F_EEG_IMPORT_GUI MATLAB code for f_EEG_import_GUI.fig +% F_EEG_IMPORT_GUI, by itself, creates a new F_EEG_IMPORT_GUI or raises the existing +% singleton*. +% +% H = F_EEG_IMPORT_GUI returns the handle to a new F_EEG_IMPORT_GUI or the handle to +% the existing singleton*. +% +% F_EEG_IMPORT_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_IMPORT_GUI.M with the given input arguments. +% +% F_EEG_IMPORT_GUI('Property','Value',...) creates a new F_EEG_IMPORT_GUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_EEG_import_GUI_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_EEG_import_GUI_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 f_EEG_import_GUI + +% Last Modified by GUIDE v2.5 16-Oct-2023 21:04:26 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_EEG_import_GUI_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_import_GUI_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 f_EEG_import_GUI is made visible. +function f_EEG_import_GUI_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_import_GUI + +try + ALLEEG = varargin{1}; +catch + ALLEEG = []; +end + +% handles.erpnameor = ERP.erpname; +handles.output = []; +handles.ALLEEG = ALLEEG; + + +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Import EEG data GUI']) + + +% Color GUI +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +try + p1 = which('eegplugin_bva_io','-all'); + p1 = p1{1}; + p1 = p1(1:findstr(p1,'eegplugin_bva_io.m')-1); + addpath(genpath([p1])); +catch +end + +handles = setfonterplabestudio(handles); + +handles.checkbox_func_plugs.Value = 1; +handles.listbox_plugins.Enable = 'on'; +Plugin_fuName = {'';'ASCII/float file or Matlab array';'Biosemi BDF file (BIOSIG toolbox)';... + 'EDF/EDF+/GDF files (BIOSIG toolbox)';'Biosemi BDF and EDF files (BDF plugin)';... + 'Brain Vis. Rec. .vhdr or .ahdr file';'Brain Vis. Anal. Matlab file';'Magstim/EGI .mff file';... + 'Neuroscan .CNT file';'Neuroscan .EEG file'}; +handles.listbox_plugins.String = Plugin_fuName; +handles.listbox_plugins.Value=1; + +% Update handles structure +guidata(hObject, handles); + + +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_EEG_import_GUI_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +% try +% set(handles.menuerp.Children, 'Enable','on'); +% catch +% disp('EEGset menu was not found...') +% end +varargout{1} = handles.output; +delete(handles.gui_chassis); +pause(0.1) + + + + + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = []; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) + +handles.output = handles.ALLEEG; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + +% --- Executes on button press in checkbox_func_plugs. +function checkbox_func_plugs_Callback(hObject, eventdata, handles) + +if handles.checkbox_func_plugs.Value == 0; + handles.listbox_plugins.Enable = 'off'; + handles.listbox_plugins.Value=1; +else + handles.listbox_plugins.Enable = 'on'; +end + + + +% --- Executes on button press in pushbutton_fileio. +function pushbutton_fileio_Callback(hObject, eventdata, handles) +handles.text_message.String = ''; +%%check if the function exist? +fileName = which('pop_fileio'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Filio Vxxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end + +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile('*.*', 'Choose files or header files -- pop_fileio()',... + 'MultiSelect', 'on'); + +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_fileio([filepath,filename], 'dataformat','auto'); + [~, myFilename, ~] = fileparts(filename); + else + [EEG,LASTCOM] = pop_fileio([filepath,filename{Numofile}], 'dataformat','auto'); + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end +guidata(hObject, handles); + + +% --- Executes on button press in pushbutton_biosiginter. +function pushbutton_biosiginter_Callback(hObject, eventdata, handles) +% handles.text_message.String = ''; +fileName = which('pop_biosig'); +% fileName = which('biosig_installer'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile({'*.BDF;*.bdf';'*.EDF+;*.edf+';'*.GDF;*.gdf'}, 'Choose BDF/EDF+/GDF files -- pop_biosig()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + try + [EEG,LASTCOM] = pop_biosig([filepath,filename]); + catch + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; + end + [~, myFilename, ~] = fileparts(filename); + else + try + [EEG,LASTCOM] = pop_biosig([filepath,filename{Numofile}]); + catch + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; + end + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end +guidata(hObject, handles); + + + + +% --- Executes on button press in pushbutton_troubleformat. +function pushbutton_troubleformat_Callback(hObject, eventdata, handles) +pophelp('troubleshooting_data_formats'); +guidata(hObject, handles); + + +% --- Executes on importing ASCII/float file or Matlab array +function handles = pushbutton_asii(hObject, eventdata, handles) +% handles.text_message.String = ''; + +fileName = which('pop_importdata'); +if isempty(fileName) + handles.text_message.String = 'There is no function "ASCII/float file or Matlab array".'; + return; +end + +[EEG LASTCOM] = pop_importdata; +if isempty(EEG) + return; +end +EEG = eegh(LASTCOM, EEG); +eegh(LASTCOM); +ALLEEG = handles.ALLEEG; +if isempty(ALLEEG) + OLDSET=1; +else + OLDSET = length(ALLEEG); +end +[ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); +eegh(LASTCOM); +handles.ALLEEG = ALLEEG; +guidata(hObject, handles); + + + + +% --- Executes on importing Biosemi BDF file (BIOSIG toolbox) +function handles = pushbutton_biosemibdf(hObject, eventdata, handles) +% handles.text_message.String = ''; + +fileName = which('pop_biosig'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end + +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile({'*.BDF;*.bdf';'*.EDF+;*.edf+';'*.GDF;*.gdf'}, 'Choose BDF/EDF+/GDF files -- pop_biosig()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + try + [EEG,LASTCOM] = pop_biosig([filepath,filename]); + catch + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; + end + [~, myFilename, ~] = fileparts(filename); + else + try + [EEG,LASTCOM] = pop_biosig([filepath,filename{Numofile}]); + catch + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; + end + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end +% guidata(hObject, handles); + + + +% --- Executes on imporing EDF/EDF+/GDF files (BIOSIG toolbox) +function handles = pushbutton_bio_edf(hObject, eventdata, handles) +% handles.text_message.String = ''; + +fileName = which('pop_biosig'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end + +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile({'*.BDF;*.bdf';'*.EDF+;*.edf+';'*.GDF;*.gdf'}, 'Choose BDF/EDF+/GDF files -- pop_biosig()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + try + [EEG,LASTCOM] = pop_biosig([filepath,filename]); + catch + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; + end + [~, myFilename, ~] = fileparts(filename); + else + try + [EEG,LASTCOM] = pop_biosig([filepath,filename{Numofile}]); + catch + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > Biosig Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; + end + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end + + + + +% --- Executes on importing Brain Vis. Rec. .vhdr file +function handles = pushbutton_visrec(hObject, eventdata, handles) +% handles.text_message.String = ''; +fileName = which('pop_loadbva'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > bva-io Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end +% [EEG,LASTCOM] = pop_loadbv(); +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile({'*.vhdr' '*.ahdr'}, 'Select Brain Vision vhdr-file - pop_loadbv()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_loadbv(filepath,filename); + [~, myFilename, ~] = fileparts(filename); + else + [EEG,LASTCOM] = pop_loadbv(filepath,filename{Numofile}); + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=0; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end + + + +% --- Executes on importing Brain Vis. Anal. Matlab file +function handles = pushbutton_visanal(hObject, eventdata, handles) +% handles.text_message.String = ''; + +fileName = which('pop_loadbva'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > bva-io Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile('*.mat;*.MAT', 'Choose a Matlab file from Brain Vision Analyser -- pop_loadbva',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_loadbva([filepath,filename]); + [~, myFilename, ~] = fileparts(filename); + else + [EEG,LASTCOM] = pop_loadbva([filepath,filename{Numofile}]); + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=0; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end +% guidata(hObject, handles); + + + + +% --- Executes on button press in pushbutton_mff. +%%[EEG, LASTCOM] = pop_mffimport +function handles = pushbutton_mff(hObject, eventdata, handles) +% handles.text_message.String = ''; +fileName = which('pop_mffimport'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > MFFMaltabIO Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end + +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile('*.MFF;*.mff', 'Select an EGI .mff file(s)--pop_mffimport',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_mffimport([filepath,filename]); + [~, myFilename, ~] = fileparts(filename); + else + [EEG,LASTCOM] = pop_mffimport([filepath,filename{Numofile}]); + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end + + + + + +% --- Executes on importing Neuroscan .CNT file +function handles = pushbutton_cnt(hObject, eventdata, handles) +% handles.text_message.String = ''; +fileName = which('pop_loadcnt'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > neuroscanio Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end + +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile('*.CNT;*.cnt', 'Load CNT files -- pop_loadcnt()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_loadcnt([filepath,filename]); + [~, myFilename, ~] = fileparts(filename); + else + [EEG,LASTCOM] = pop_loadcnt([filepath,filename{Numofile}]); + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end + + + + +% --- Executes on importing Neuroscan .EEG file +function handles = pushbutton_eeg(hObject, eventdata, handles) +% handles.text_message.String = ''; +fileName = which('pop_loadeeg'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > neuroscanio Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end +% [EEG,LASTCOM] = pop_loadeeg(); +ALLEEG = handles.ALLEEG; +[filename, filepath,filterindex] = uigetfile('*.eeg;*.EEG', 'Load EEG files -- pop_loadeeg()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +if iscell(filename) + filterindex = length(filename); +else + filterindex =1; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_loadeeg(filename,filepath); + [~, myFilename, ~] = fileparts(filename); + else + [EEG,LASTCOM] = pop_loadeeg(filename{Numofile},filepath); + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end + +%%pop_readbdf + + +% --- Executes on button press in pushbutton_bdf_plugin. +function handles = pushbutton_bdf_plugin(hObject, eventdata, handles) +% handles.text_message.String = ''; +fileName = which('pop_readbdf'); +if isempty(fileName) + handles.text_message.String = 'Please use EEGLAB menu: "File > Manage EEGLAB extension > BDFimport Vxx" to download it'; + handles.listbox_plugins.Value=1; + return; +end +ALLEEG = handles.ALLEEG; +% [EEG,LASTCOM] = pop_readbdf(); +[filename, filepath,filterindex] = uigetfile('*.BDF;*.bdf', 'Load BDF files -- pop_loadcnt()',... + 'MultiSelect', 'on'); +if filterindex==0 + handles.text_message.String = 'User selected Cancel'; + handles.listbox_plugins.Value=1; + return; +end + +for Numofile = 1:filterindex %%loop for subjects which is allow to load the mutiple datasets + handles.text_message.String = ['Loading data (',num2str(Numofile),'/',num2str(filterindex),')']; + if filterindex==1 + [EEG,LASTCOM] = pop_readbdf([filepath,filename]); + else + [EEG,LASTCOM] = pop_readbdf([filepath,filename{Numofile}]); + end + if isempty(EEG) + return; + end + EEG = eegh(LASTCOM, EEG); + eegh(LASTCOM); + if isempty(ALLEEG) + OLDSET=1; + else + OLDSET = length(ALLEEG); + end + if filterindex==1 + [~, myFilename, ~] = fileparts(filename); + else + [~, myFilename, ~] = fileparts(filename{Numofile}); + end + if ~isempty(myFilename) + EEG.setname = myFilename; + end + [ALLEEG, EEG,~,LASTCOM] = pop_newset( ALLEEG, EEG,OLDSET); + eegh(LASTCOM); + handles.ALLEEG = ALLEEG; +end + + +% --- Executes on selection change in listbox_plugins. +function listbox_plugins_Callback(hObject, eventdata, handles) +Value = handles.listbox_plugins.Value; +handles.text_message.String = 'Loading data'; +handles.text_message.ForegroundColor = [0 0 0]; +handles.text_message.FontSize= handles.text_message.FontSize+2; +switch Value + case 1 + case 2 + handles = pushbutton_asii(hObject, eventdata, handles); + case 3 + handles = pushbutton_biosemibdf(hObject, eventdata, handles); + case 4 + handles = pushbutton_bio_edf(hObject, eventdata, handles); + case 5 + handles = pushbutton_bdf_plugin(hObject, eventdata, handles); + case 6 + handles = pushbutton_visrec(hObject, eventdata, handles); + case 7 + handles = pushbutton_visanal(hObject, eventdata, handles); + case 8 + handles = pushbutton_mff(hObject, eventdata, handles); + case 9 + handles = pushbutton_cnt(hObject, eventdata, handles); + case 10 + handles = pushbutton_eeg(hObject, eventdata, handles); +end +handles.listbox_plugins.Value =1; +handles.text_message.String = 'Loading was done!'; +pause(0.1); +handles.text_message.String = ''; +guidata(hObject, handles); + + + +% --- Executes during object creation, after setting all properties. +function listbox_plugins_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in pushbutton_eeglab_extension. +function pushbutton_eeglab_extension_Callback(hObject, eventdata, handles) +handles.text_message.String = 'We recommended you restart "Import EEG data GUI" after you updated the functions using "EEGLAB manage extensions".'; +plugin_menu([]); + + +% --- Executes on button press in pushbutton_otherformat. +function pushbutton_otherformat_Callback(hObject, eventdata, handles) +BackERPLABcolor = [1 0.9 0.3]; % yellow +titleName = ['Import the other data formats:\n']; +question = ['(1) Please use EEGLAB to import the datasets with other formats,\n(2) Save them as “.set†files after imported them by EEGLAB,\n(3) Restart EStudio and load the “.set†files by "EEGsets" panel > "load".']; +title = 'EEGsets>Import>Other data formats'; +oldcolor = get(0,'DefaultUicontrolBackgroundColor'); +set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) +button = questdlg(sprintf([titleName,question]), title,'Okay','Yes'); +set(0,'DefaultUicontrolBackgroundColor',oldcolor); +guidata(hObject, handles); diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_informtion_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_informtion_GUI.m new file mode 100755 index 00000000..5ab2246d --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_informtion_GUI.m @@ -0,0 +1,292 @@ + +%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +%Feb. 20234 + + + +function varargout = f_EEG_informtion_GUI(varargin) +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end +if nargin == 0 + fig = figure(); % Parent figure + EEG_info = uiextras.BoxPanel('Parent', fig, 'Title', 'EEG & Bin Information', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EEG_info = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEG & Bin Information', 'Padding', 5,'BackgroundColor',ColorB_def); +else + EEG_info = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEG & Bin Information', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +varargout{1} = EEG_info; +gui_EEG_info = struct; +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_EEG_info(FonsizeDefault); + + + function drawui_EEG_info(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + gui_EEG_info.DataSelBox = uiextras.VBox('Parent', EEG_info, 'Spacing',1,'BackgroundColor',ColorB_def); + + %%EEG setname and file name + gui_EEG_info.setfilename_title = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', gui_EEG_info.setfilename_title,'String','Current EEG setname & file name',... + 'FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorB_def); + + + gui_EEG_info.setfilename_title2 = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + end + gui_EEG_info.table_setfilenames = uitable( ... + 'Parent' , gui_EEG_info.setfilename_title2,... + 'Data' , dsnames, ... + 'ColumnWidth' , {500}, ... + 'ColumnName' , {''}, ... + 'RowName' , {'Set name','File name'},... + 'ColumnEditable',[false]); + + %%----------------------------Setting sampling rate--------------------- + gui_EEG_info.samplingrate = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.samplingrate = uicontrol('Style','text','Parent', gui_EEG_info.samplingrate,'String','Sampling:','FontSize',FonsizeDefault); + + EEG_time_resolution = strcat('Sampling:'); + set(gui_EEG_info.samplingrate,'HorizontalAlignment','left','BackgroundColor',ColorB_def,'String',EEG_time_resolution); + + %%----------------------------Number of Channels--------------------- + gui_EEG_info.chan_num = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.numofchan = uicontrol('Style','text','Parent', gui_EEG_info.chan_num,'String','Number of channels: ','FontSize',FonsizeDefault); + set(gui_EEG_info.numofchan,'HorizontalAlignment','left','BackgroundColor',ColorB_def); + + %%----------------------------Setting epoch--------------------- + gui_EEG_info.epoch = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.epoch_name = uicontrol('Style','text','Parent', gui_EEG_info.epoch,'String','Time range: ','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_EEG_info.epoch_name,'HorizontalAlignment','left'); + + %%----------------------------Setting chanlocation--------------------- + gui_EEG_info.chanlocs_title = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.chanlocs = uicontrol('Style','text','Parent', gui_EEG_info.chanlocs_title,'String','Channel locations: ','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_EEG_info.chanlocs,'HorizontalAlignment','left'); + + %%----------------------------Setting ICA weights--------------------- + gui_EEG_info.icweights_title = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.icweights = uicontrol('Style','text','Parent', gui_EEG_info.icweights_title ,'String','ICA weights: ','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_EEG_info.icweights,'HorizontalAlignment','left'); + + + %%----------------------------Number of bins--------------------- + gui_EEG_info.bin_num = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.numofbin = uicontrol('Style','text','Parent', gui_EEG_info.bin_num,'String','Number of bins:','FontSize',FonsizeDefault); + set(gui_EEG_info.numofbin,'HorizontalAlignment','left','BackgroundColor',ColorB_def); + + %%----------------------------Number of epoch--------------------- + gui_EEG_info.epoch_num_title = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'BackgroundColor',ColorB_def); + gui_EEG_info.numofepoch = uicontrol('Style','text','Parent', gui_EEG_info.epoch_num_title,'String','Number of epochs:','FontSize',FonsizeDefault); + set(gui_EEG_info.numofepoch,'HorizontalAlignment','left','BackgroundColor',ColorB_def); + + %%----------------------------Total accepted--------------------- + N_trials = 0; + N_trial_total = 0; + N_trial_rejected = 0; + if N_trial_total ==0 + Total_rejected_trials = strcat('0'); + else + Total_rejected_trials = strcat('0%'); + end + gui_EEG_info.total_rejected = uiextras.HBox('Parent',gui_EEG_info.DataSelBox); + gui_EEG_info.total_rejected_percentage = uicontrol('Style','text','Parent', gui_EEG_info.total_rejected,'String',['Total rejected trials:',32,Total_rejected_trials],'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_EEG_info.total_rejected_percentage,'HorizontalAlignment','left'); + + + %%---------------------Table--------------------------------------- + gui_EEG_info.table_title = uiextras.HBox('Parent',gui_EEG_info.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + dsnames{ii,3} = ''; + end + gui_EEG_info.table_event = uitable( ... + 'Parent' , gui_EEG_info.table_title,... + 'Data' , dsnames, ... + 'ColumnWidth' , {50,100,100}, ... + 'ColumnName' , {'Bin','Description','#Occurrences'}, ... + 'RowName' , [],... + 'ColumnEditable',[false, false, false]); + + set(gui_EEG_info.DataSelBox,'Sizes',[20 70 20 20 20 20 20 20 20 30 100]);% 20 100 + end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%-----------------------------Subfunction---------------------------------- +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg~=7 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + EEG = observe_EEGDAT.EEG; + if ~isempty(EEG) + EEG_time_resolution = strcat(num2str(EEG.srate),32,'Hz',32,'(',num2str(roundn(1000/EEG.srate,-2)),32,'ms /sample)'); + else + EEG_time_resolution = strcat(''); + end + gui_EEG_info.samplingrate.String = ['Sampling: ',EEG_time_resolution]; + %%channel + try + gui_EEG_info.numofchan.String=['Number of channels: ',32,num2str(EEG.nbchan)]; + catch + gui_EEG_info.numofchan.String=['Number of channels: 0']; + end + + %%------------------------time------------------------ + try + if EEG.trials==1 + gui_EEG_info.epoch_name.String=['Time range: ',32,num2str(EEG.xmin),32,'to',32,num2str(EEG.xmax),'s']; + else + gui_EEG_info.epoch_name.String=['Epoch: ',32,num2str(EEG.times(1)),32,'to',32,num2str(EEG.times(end)),32,'ms',32,'(',num2str(EEG.pnts),32,'pnts)']; + end + catch + gui_EEG_info.epoch_name.String='Time range: '; + end + %%channel locations? + try + count = 0; + if ~isempty(EEG.chanlocs) + for Numofchan = 1:EEG.nbchan + if ~isempty(EEG.chanlocs(Numofchan).X) + count =1; + end + end + end + if count==1 + gui_EEG_info.chanlocs.String = 'Channel locations: set'; + else + gui_EEG_info.chanlocs.String = 'Channel locations: not set'; + end + catch + gui_EEG_info.chanlocs.String = 'Channel locations: not set'; + end + + try + if ~isempty(EEG) + if ~isempty(EEG.icachansind) && ~isempty(EEG.icaweights) && ~isempty(EEG.icasphere) && ~isempty(EEG.icawinv) + gui_EEG_info.icweights.String = 'ICA Weights: present'; + else + gui_EEG_info.icweights.String = 'ICA Weights: absent'; + end + end + catch + gui_EEG_info.icweights.String = 'ICA Weights: '; + end + + try + gui_EEG_info.numofbin.String=['Number of bins: ',32,num2str(numel(EEG.EVENTLIST.trialsperbin))]; + gui_EEG_info.numofbin.Enable = 'on'; + catch + gui_EEG_info.numofbin.String='Number of bins: '; + gui_EEG_info.numofbin.Enable = 'off'; + end + %%Numof rejection + for ii = 1:100 + dsnamesdef{ii,1} = []; + dsnamesdef{ii,2} = []; + dsnamesdef{ii,3} = []; + dsnamesdef{ii,4} = []; + dsnamesdef{ii,5} = []; + end + if ~isempty(EEG) && EEG.trials>1 + gui_EEG_info.numofepoch.String = ['Number of epochs:',32,num2str(EEG.trials)]; + gui_EEG_info.numofepoch.Enable = 'on'; + [ERP, EVENTLISTi, countbiORI, countbinINV, countbinOK, countflags, workfname] = averager(EEG, 1, 1, 1, 1, [], [],0); + ERP.ntrials.accepted = countbinOK; + ERP.ntrials.rejected = countbiORI-countbinINV-countbinOK; + ERP.ntrials.invalid = countbinINV; + N_trials = ERP.ntrials; + N_trial_total = sum(N_trials.accepted(:))+sum(N_trials.rejected(:))+sum(N_trials.invalid(:)); + N_trial_rejected = sum(N_trials.rejected(:)); + if N_trial_total ==0 + Total_rejected_trials = ['Total rejected trials:',32,'0 (0%)']; + else + Total_rejected_trials = strcat([num2str(N_trial_rejected),32,'(',num2str(roundn(N_trial_rejected/N_trial_total,-3)*100),'%)']); + end + gui_EEG_info.total_rejected_percentage.String = ['Total rejected trials:',32,Total_rejected_trials]; + Enable_label = 'on'; + else + gui_EEG_info.total_rejected_percentage.String = ['Total rejected trials:',32,'0 (0%)']; + gui_EEG_info.numofepoch.Enable = 'off'; + Enable_label = 'off'; + dsnames = dsnamesdef; + gui_EEG_info.numofepoch.String = ['Number of epochs:']; + end + % gui_EEG_info.table_event.Data = dsnames; + if EEGUpdate==1 + Enable_label = 'off'; + end + gui_EEG_info.total_rejected_percentage.Enable = Enable_label; + + try + filesetname{1,1} = EEG.setname; + filesetname{2,1} = EEG.filename; + catch + filesetname{1,1} = ''; + filesetname{2,1} = ''; + end + gui_EEG_info.table_setfilenames.Data= filesetname; + + for ii = 1:100 + dsnamesdef{ii,1} = ''; + dsnamesdef{ii,2} = ''; + dsnamesdef{ii,3} = ''; + end + if ~isempty(observe_EEGDAT.EEG) && isfield(observe_EEGDAT.EEG,'EVENTLIST') && ~isempty(observe_EEGDAT.EEG.EVENTLIST) && (~isempty(observe_EEGDAT.EEG.EVENTLIST.trialsperbin)) + EEG = observe_EEGDAT.EEG; + for jjj = 1:length(EEG.EVENTLIST.eventinfo) + eventbini(jjj,1) = EEG.EVENTLIST.eventinfo(jjj).bini; + end + if any(eventbini(:)>0) + for ii = 1:length(observe_EEGDAT.EEG.EVENTLIST.trialsperbin) + try + dsnames{ii,1} = num2str(ii); + dsnames{ii,2} = EEG.EVENTLIST.bdf(ii).description; + dsnames{ii,3} = num2str(EEG.EVENTLIST.trialsperbin(ii)); + catch + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; + dsnames{ii,3} =''; + end + end + else + dsnames = dsnamesdef; + end + else + dsnames = dsnamesdef; + end + gui_EEG_info.table_event.Data = dsnames; + + observe_EEGDAT.count_current_eeg=8; + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_interpolate_chan_epoch_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_interpolate_chan_epoch_GUI.m new file mode 100644 index 00000000..1be0713d --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_interpolate_chan_epoch_GUI.m @@ -0,0 +1,1576 @@ +%%This function is to interpolate channels for epoched EEG + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct.2023 + + +function varargout = f_EEG_interpolate_chan_epoch_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ + +Eegtab_EEG_interpolate_chan_epoch = struct(); + +%-----------------------------Name the title---------------------------------------------- + +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + box_interpolate_chan_epoch = uiextras.BoxPanel('Parent', fig, 'Title', 'Interpolate Channels',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + box_interpolate_chan_epoch = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Interpolate Channels',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + box_interpolate_chan_epoch = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Interpolate Channels',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @intpchan_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_ic_chan_eeg(FonsizeDefault) +varargout{1} = box_interpolate_chan_epoch; + + function drawui_ic_chan_eeg(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + Enable_label = 'off'; + %%--------------------channel and bin setting---------------------- + Eegtab_EEG_interpolate_chan_epoch.DataSelBox = uiextras.VBox('Parent', box_interpolate_chan_epoch,'BackgroundColor',ColorB_def); + + %%%----------------Mode----------------------------------- + Eegtab_EEG_interpolate_chan_epoch.mode_1 = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_interpolate_chan_epoch.mode_modify_title = uicontrol('Style','text','Parent',Eegtab_EEG_interpolate_chan_epoch.mode_1 ,... + 'String','Mode:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_interpolate_chan_epoch.mode_modify = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.mode_1 ,... + 'String','Modify existing dataset','callback',@mode_modify,'Value',1,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_interpolate_chan_epoch.mode_modify.KeyPressFcn = @eeg_interpolatechan_presskey; + set(Eegtab_EEG_interpolate_chan_epoch.mode_1,'Sizes',[55 -1]); + %%--------------For create a new ERPset---------------------------- + Eegtab_EEG_interpolate_chan_epoch.mode_2 = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_interpolate_chan_epoch.mode_2,'BackgroundColor',ColorB_def); + Eegtab_EEG_interpolate_chan_epoch.mode_create = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.mode_2 ,... + 'String','Create new dataset','callback',@mode_create,'Value',0,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_interpolate_chan_epoch.mode_create.KeyPressFcn = @eeg_interpolatechan_presskey; + set(Eegtab_EEG_interpolate_chan_epoch.mode_2,'Sizes',[55 -1]); + Eegtab_EEG_interpolate_chan_epoch.Parameters{1} = Eegtab_EEG_interpolate_chan_epoch.mode_modify.Value; + + erplabInterpolateElectrodes= estudioworkingmemory('pop_erplabInterpolateElectrodes'); + try + ignoreChannels = erplabInterpolateElectrodes{2}; + interpolationMethod = erplabInterpolateElectrodes{3}; + catch + ignoreChannels = []; + interpolationMethod = []; + end + if strcmpi(interpolationMethod,'spherical') + InterpValue = 1; + else + InterpValue = 0; + end + + %%Interpolate Channelsnels + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + + uicontrol('Style','text','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title,... + 'String','Interpolated chan','FontSize',FontSize_defualt,'Enable','on','BackgroundColor',ColorB_def); % 2F + + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title,... + 'String','','FontSize',FontSize_defualt,'callback',@interpolate_chan_edit,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.KeyPressFcn = @eeg_interpolatechan_presskey; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_browse = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title,... + 'String','Browse','FontSize',FontSize_defualt,'callback',@interpolate_chan_browse,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + set( Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title,'Sizes',[100 -1 60]); + Eegtab_EEG_interpolate_chan_epoch.Parameters{2} = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + + + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add1 = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_interpolate_chan_epoch.interpolate_methods= uicontrol('Style','text','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add1,... + 'String','Interpolation methods:','FontSize',FontSize_defualt,'Enable','on','BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add1 ,... + 'String','Inverse distance','callback',@interpolate_inverse,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',~InterpValue); % 2F + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.String = ' Inverse
                            distances'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.KeyPressFcn = @eeg_interpolatechan_presskey; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add1,... + 'String','Spherical ','callback',@interpolate_spherical,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',InterpValue); % 2F + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.KeyPressFcn = @eeg_interpolatechan_presskey; + set(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add1,'Sizes',[100 80 -1]); + Eegtab_EEG_interpolate_chan_epoch.Parameters{3} = Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value; + + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add2 = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + + Eegtab_EEG_interpolate_chan_epoch.ignore_chan = uicontrol('Style','checkbox','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add2,... + 'String','Ignored chans','callback',@ignore_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.KeyPressFcn = @eeg_interpolatechan_presskey; + Eegtab_EEG_interpolate_chan_epoch.Parameters{4} = Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value; + if isempty(ignoreChannels) + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value = 0; + else + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value = 1; + end + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit = uicontrol('Style','edit','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add2 ,... + 'String',' ','callback',@ignore_chan_edit,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.KeyPressFcn = @eeg_interpolatechan_presskey; + try + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = num2str(ignoreChannels); + catch + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + end + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add2 ,... + 'String','Browse','callback',@ignore_chan_browse,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + set(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_title_add2,'Sizes',[110 -1 60]); + Eegtab_EEG_interpolate_chan_epoch.Parameters{5} = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + + + %%interpoate all time points + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch_title = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch_title,... + 'String','Interpolate all time points','callback',@interpolate_op_all_epoch,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.KeyPressFcn = @eeg_interpolatechan_presskey; + uiextras.Empty('Parent', Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch_title); + set(Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch_title,'Sizes',[160 -1]); + Eegtab_EEG_interpolate_chan_epoch.Parameters{6} =Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value; + + + %%interpoate marked epochs and its advanced options + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_title = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_title,... + 'String','Interpolate epochs with this flag:','callback',@interpolate_marked_epoch_op,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',1); % 2F + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.KeyPressFcn = @eeg_interpolatechan_presskey; + uiextras.Empty('Parent', Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_title); + set(Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_title,'Sizes',[250 -1]); + + Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + + Eegtab_EEG_interpolate_chan_epoch.mflag1 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag1,'String','1','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',1); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag2 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag2,'String','2','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag3 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag3,'String','3','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag4 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag4,'String','4','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag5 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag5,'String','5','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag6 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag6,'String','6','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag7 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag7,'String','7','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag8 = uicontrol('Style','radiobutton','Parent',Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,... + 'callback',@mflag8,'String','8','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',Enable_label,'BackgroundColor',ColorB_def,'Value',0); % 2F + Eegtab_EEG_interpolate_chan_epoch.mflag = [1,0,0,0,0,0,0,0]; + set( Eegtab_EEG_interpolate_chan_epoch.interpolate_mflags_title,'Sizes',[33 33 33 33 33 33 33 33]); + Eegtab_EEG_interpolate_chan_epoch.Parameters{7}= Eegtab_EEG_interpolate_chan_epoch.mflag; + + %%-----------------------Cancel and Run---------------------------- + Eegtab_EEG_interpolate_chan_epoch.advanced_run_title = uiextras.HBox('Parent', Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_EEG_interpolate_chan_epoch.advanced_run_title); + Eegtab_EEG_interpolate_chan_epoch.cancel = uicontrol('Style', 'pushbutton','Parent',Eegtab_EEG_interpolate_chan_epoch.advanced_run_title,... + 'String','Cancel','callback',@interpolated_chan_cancel,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_interpolate_chan_epoch.advanced_run_title); + Eegtab_EEG_interpolate_chan_epoch.interpolate_run = uicontrol('Style','pushbutton','Parent',Eegtab_EEG_interpolate_chan_epoch.advanced_run_title,... + 'String','Run','callback',@interpolate_run,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_EEG_interpolate_chan_epoch.advanced_run_title); + set(Eegtab_EEG_interpolate_chan_epoch.advanced_run_title,'Sizes',[10,-1,30,-1,10]); + + %%resize each row + set(Eegtab_EEG_interpolate_chan_epoch.DataSelBox,'sizes',[30 30 25 30 25 30 30 20 30]) + estudioworkingmemory('EEGTab_interpolated_chan_epoch',0); + end +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%---------------------Modify Existing dataset----------------------------- + function mode_modify(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mode_modify.Value =1; + Eegtab_EEG_interpolate_chan_epoch.mode_create.Value = 0; + end + + +%%---------------------Create new dataset---------------------------------- + function mode_create(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mode_modify.Value =0; + Eegtab_EEG_interpolate_chan_epoch.mode_create.Value = 1; + end + + +%%---------------Edit channels that will be interpolated------------------- + function interpolate_chan_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + + Newchan = round(str2num(Source.String)); + if isempty(Newchan) || any(Newchan(:) <=0) + msgboxText = ['Interpolate Channels > Indexes of interpolated chans should be positive values']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + ChanNum = observe_EEGDAT.EEG.nbchan; + if any(Newchan(:) > ChanNum) + msgboxText =['Interpolate Channels > Any indexes of interpolated chans should be between 1 and ',32,num2str(ChanNum)]; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + ChanignoreArray = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + overlap_elec = intersect(Newchan,ChanignoreArray); + if ~isempty(overlap_elec) + msgboxText = ['Interpolate Channels: There is overlap between the interpolated chans and the ignore chans']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + Newchan = vect2colon(Newchan); + Newchan = erase(Newchan,{'[',']'}); + Source.String= Newchan; + end + + +%%------------Browse channels that will be interpolated-------------------- + function interpolate_chan_browse(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + + %%-------Browse and select chans that will be interpolated--------- + EEG = observe_EEGDAT.EEG; + for Numofchan = 1:EEG.nbchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',EEG.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + chaninterpolated = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + if isempty(chaninterpolated) + indxlistb = EEG.nbchan; + else + if min(chaninterpolated(:)) >0 && max(chaninterpolated(:)) <= EEG.nbchan + indxlistb = chaninterpolated; + else + indxlistb = EEG.nbchan; + end + end + titlename = 'Select interpolated Channel(s):'; + + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + chan_label_select = vect2colon(chan_label_select); + chan_label_select = erase(chan_label_select,{'[',']'}); + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String = chan_label_select; + else + return + end + end + +%%-----------------Interpolate channel method:inverse---------------------- + function interpolate_inverse(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value= 1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value=0; + end + +%%------------------ignore chan when interpolate chan---------------------- + function ignore_chan(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + ignoreValue = Source.Value; + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + if ignoreValue==1 + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse.Enable='on'; + else + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse.Enable='off'; + end + end + + +%%-------------------methods for interpolate chan-------------------------- + function interpolate_spherical(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value= 0; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value=1; + end + +%%-------------------edit ignore chan-------------------------------------- + function ignore_chan_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + ChanArray = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + + ChanArrayNew = str2num(Source.String); + if isempty(ChanArrayNew) || any(ChanArrayNew(:)<=0) + msgboxText = ['Interpolate Channels: Any index(es) of the ignored channels should be positive value']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if any(ChanArrayNew(:) > observe_EEGDAT.EEG.nbchan) + msgboxText = ['Interpolate Channels: Any index(es) of the ignored channels should be below ',32,num2str(observe_EEGDAT.EEG.nbchan)]; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + overlap_elec = intersect(ChanArray, ChanArrayNew); + if ~isempty(overlap_elec) + msgboxText = ['Interpolate Channels: There is overlap in the replace electrodes and the ignore electrodes']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + Source.String= vect2colon(ChanArrayNew); + + end + +%%---------------------browse chan for ignore chan------------------------- + function ignore_chan_browse(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + ChanArray = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + EEG = observe_EEGDAT.EEG; + for Numofchan = 1:EEG.nbchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',EEG.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + chanIgnore = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + if isempty(chanIgnore) + indxlistb = EEG.nbchan; + else + if any(chanIgnore(:) >0) && any(chanIgnore(:) <= EEG.nbchan) + indxlistb = chanIgnore; + else + indxlistb = EEG.nbchan; + end + end + titlename = 'Select Ignored Channel(s):'; + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = vect2colon(chan_label_select); + else + return + end + + ChanArrayNew = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + overlap_elec = intersect(ChanArray, ChanArrayNew); + if ~isempty(overlap_elec) + msgboxText = ['Interpolate Channels > There is overlap in the replace electrodes and the ignore electrodes']; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + +%%------------------interpolate all epochs option ------------------------- + function interpolate_op_all_epoch(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value=1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value=0; + Enable_flag = 'off'; + Eegtab_EEG_interpolate_chan_epoch.mflag1.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Enable = Enable_flag; + + end + + +%%----------------------Interpolate marked epochs option------------------- + function interpolate_marked_epoch_op(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value=0; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value=1; + Enable_flag = 'on'; + Eegtab_EEG_interpolate_chan_epoch.mflag1.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Enable = Enable_flag; + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + flagx= (flagcheck>1); + [~,ypos] = find(Eegtab_EEG_interpolate_chan_epoch.mflag==1); + [~,ypos1] = find(flagx==1); + AA = intersect(ypos1,ypos); + count =0; + for f = 1:length(flagx) + if flagx(f)>0 && flagx(f)<9 + if isempty(AA) + count = count+1; + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable','on'); + if count==1 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',1); + else + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + else + %turn off/invisible all not-active-flag choices + if f < 9 %no flags over 8 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable','off'); + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + end + end + +%%-------------------------------Flag one---------------------------------- + function mflag1(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + + +%%-------------------------------Flag one---------------------------------- + function mflag2(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + + +%%-------------------------------Flag one---------------------------------- + function mflag3(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + + + +%%-------------------------------Flag one---------------------------------- + function mflag4(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + + +%%-------------------------------Flag one---------------------------------- + function mflag5(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + +%%-------------------------------Flag one---------------------------------- + function mflag6(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + +%%-------------------------------Flag one---------------------------------- + function mflag7(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=1; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=0; + end + + +%%-------------------------------Flag one---------------------------------- + function mflag8(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',1); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value=0; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value=1; + end + + +%%------------------run for interpolation---------------------------------- + function interpolate_run(Source,~) + if isempty(observe_EEGDAT.EEG) %%|| observe_EEGDAT.EEG.trials ==1 + Source.Enable= 'off'; + return; + end + + if Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value==1 + interpolate_allchan();%%for all epochs + else + interpolate_marked_epoch() ; %% for marked epochs + end + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_interpolate_chan_epoch.Parameters{1} = Eegtab_EEG_interpolate_chan_epoch.mode_modify.Value; + Eegtab_EEG_interpolate_chan_epoch.Parameters{2} = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + Eegtab_EEG_interpolate_chan_epoch.Parameters{3} = Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value; + Eegtab_EEG_interpolate_chan_epoch.Parameters{4} = Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value; + Eegtab_EEG_interpolate_chan_epoch.Parameters{5} = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + Eegtab_EEG_interpolate_chan_epoch.Parameters{6} =Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value; + + end + +%%------------------Interpolate all time points---------------------------- + function interpolate_allchan(~,~) + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',0); + + estudioworkingmemory('f_EEG_proces_messg','Interpolate Channels > Run'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + if Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value==1 + interpolationMethod = 'spherical'; + else + interpolationMethod = 'invdist'; + end + + ChanArray = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + if isempty(ChanArray) || any(ChanArray(:)<=0) + msgboxText = ['Interpolate Channels > Run: The index(es) of the interpolated chans should be positive numbers']; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value==0 + ChanArrayig = []; + else + ChanArrayig = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + end + if ~isempty(ChanArrayig) + overlap_elec = intersect(ChanArray, ChanArrayig); + if ~isempty(overlap_elec) + msgboxText = ['Interpolate Channels > Run: There is overlap in the replace electrodes and the ignore electrodes']; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if any(ChanArrayig(:)<=0) + msgboxText = ['Interpolate Channels > Run: Index(es) of the ignored channels should be positive values']; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if any(ChanArrayig(:) > observe_EEGDAT.EEG.nbchan) + msgboxText = ['Interpolate Channels > Run: Index(es) of the ignored channels should be smaller than',32,num2str(observe_EEGDAT.EEG.nbchan)]; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + if numel(ChanArrayig) + numel(ChanArray) ==observe_EEGDAT.EEG.nbchan + msgboxText = ['Interpolate Channels > Run: Too many channels will be interpolated or ignored, please left enough channels that are to interpolate others']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + CreateeegFlag = Eegtab_EEG_interpolate_chan_epoch.mode_create.Value; %%create new eeg dataset + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Interpolate selected chan*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %%check the selected chans + if any(ChanArray(:) > EEG.nbchan) + msgboxText = ['Interpolate Channels > Run: Selected channel should be between 1 and ',32, num2str(EEG.nbchan)]; + fprintf( ['\n',repmat('-',1,100) '\n']); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + if numel(ChanArray) == EEG.nbchan + msgboxText = ['Interpolate Channels > Run: We strongly recommend you donot need to interpolate all channels']; + fprintf( ['\n',repmat('-',1,100) '\n']); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + [EEG,LASTCOM] = pop_erplabInterpolateElectrodes( EEG , 'displayEEG', 0, 'ignoreChannels', ChanArrayig,... + 'interpolationMethod', interpolationMethod, 'replaceChannels',ChanArray,'history', 'implicit'); + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~, ~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + ALLEEG_out(end).filename = EEG.filename; + ALLEEG_out(end).filepath = EEG.filepath; + end + Save_file_label=0; + if CreateeegFlag==1 + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_interp'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + + if CreateeegFlag==0 + ALLEEG(EEGArray) = ALLEEG_out; + else + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~, ~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + end + end + + observe_EEGDAT.ALLEEG = ALLEEG; + if CreateeegFlag==1 + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%------------------Inerpolate the marked epochs--------------------------- + function interpolate_marked_epoch(~,~) + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + box_interpolate_chan_epoch.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('EEGTab_interpolated_chan_epoch',0); + + estudioworkingmemory('f_EEG_proces_messg','Interpolate Channels > Run'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + replaceChannelIndes = str2num(Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String); + if isempty(replaceChannelIndes) || min(replaceChannelIndes(:))<=0 + msgboxText = ['Interpolate Channels > Run: Index(es) of interpolated chans should be positive numbers']; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + def = estudioworkingmemory('pop_artinterp'); + defx = {0, 'spherical',[],[],[],0,10}; + if isempty(def) + def = defx; + end + try threshold_perc = def{7}; catch threshold_perc = 10;end + if isempty(threshold_perc) || numel(threshold_perc)~=1 || any(threshold_perc(:)<0) || any(threshold_perc(:)>100) + threshold_perc = 10; + end + def{7} = 10; + try many_electrodes = def{6}; catch many_electrodes = 0;end + if isempty(many_electrodes) || numel(many_electrodes)~=1 || (many_electrodes~=0 && many_electrodes~=1) + many_electrodes=0; + end + def{6}=0; + + try replaceFlag = def{1}; catch replaceFlag =[]; end + + + if Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value==0 + ignoreChannels = []; + else + ignoreChannels = str2num(Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String); + end + if ~isempty(ignoreChannels) + overlap_elec = intersect(replaceChannelIndes, ignoreChannels); + if ~isempty(overlap_elec) + msgboxText = ['Interpolate Channels > Run: There is overlap in the replace electrodes and the ignore electrodes']; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if any(ignoreChannels(:)<=0) + msgboxText = ['Interpolate Channels > Run: Index(es) of the ignored channels should be positive values']; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if any(ignoreChannels(:) > observe_EEGDAT.EEG.nbchan) + msgboxText = ['Interpolate Channels > Run: Index(es) of the ignored channels should be smaller than',32,num2str(observe_EEGDAT.EEG.nbchan)]; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + + if Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value==1 + interpolationMethod = 'spherical'; + else + interpolationMethod = 'invdist'; + end + + CreateeegFlag = Eegtab_EEG_interpolate_chan_epoch.mode_create.Value; %%create new eeg dataset + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + end + + Eegtab_EEG_interpolate_chan_epoch.mflag = [ Eegtab_EEG_interpolate_chan_epoch.mflag1.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value]; + [~,active_flags] = find(Eegtab_EEG_interpolate_chan_epoch.mflag==1); + if isempty(active_flags) + msgboxText = ['Interpolate Channels > Run: No epochs were actually flagged, so no epochswere needed to interpolate']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + + Eegtab_EEG_interpolate_chan_epoch.Parameters{7}= Eegtab_EEG_interpolate_chan_epoch.mflag; + %%loop for the selected EEGsets + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Interpolate marked epochs*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + + %%check interpolated chans and ignored chans + if any(replaceChannelIndes(:) > EEG.nbchan ) + msgboxText = ['Interpolate Channels > Run: Interpolated chans should be smaller than',32,num2str( EEG.nbchan)]; + estudioworkingmemory('f_EEG_proces_messg',msgboxText); + observe_EEGDAT.eeg_panel_message =4; %%Marking for the procedure has been started. + fprintf( ['\n',repmat('-',1,100) '\n']); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if any(ignoreChannels(:) > EEG.nbchan) + msgboxText = ['Interpolate Channels > Run: Ignored chans should be smaller than',32,num2str( EEG.nbchan)]; + fprintf( ['\n',repmat('-',1,100) '\n']); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + for Numofchan = 1:numel(replaceChannelIndes)%%loop for each chan + replaceChannelInd = replaceChannelIndes(Numofchan); + fprintf( ['\n Interpolating chan',32, num2str(replaceChannelInd),'...\n']); + %%Run ICA + [EEG, LASTCOM] = pop_artinterp(EEG, 'FlagToUse', active_flags, 'InterpMethod', interpolationMethod, ... + 'ChanToInterp', replaceChannelInd, 'ChansToIgnore', ignoreChannels, ... + 'InterpAnyChan', many_electrodes, ...%'Threshold',threshold_perc, + 'Review', 'off', 'History', 'implicit'); + % if isempty(LASTCOM) + % estudioworkingmemory('f_EEG_proces_messg','Interpolate Channels > Run: Please check you data or you selected cancel'); + % observe_EEGDAT.eeg_panel_message =4; + % return; + % end + if Numofchan==1 && ~isempty(LASTCOM) + EEG = eegh(LASTCOM, EEG); + fprintf(['\n',LASTCOM,'\n']); + end + end + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( ['\n',repmat('-',1,100) '\n']); + ALLEEG_out(end).filename = EEG.filename; + ALLEEG_out(end).filepath = EEG.filepath; + end + Save_file_label=0; + if CreateeegFlag==1 + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_arInterp'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + + if CreateeegFlag==0 + ALLEEG(EEGArray) = ALLEEG_out; + else + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + end + end + + observe_EEGDAT.ALLEEG = ALLEEG; + if CreateeegFlag==1 + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=5 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || EEGUpdate==1 + Eegtab_EEG_interpolate_chan_epoch.mode_modify.Enable ='off'; + Eegtab_EEG_interpolate_chan_epoch.mode_create.Enable = 'off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.Enable= 'off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_browse.Enable= 'off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Enable= 'off'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.Enable='off'; + + Eegtab_EEG_interpolate_chan_epoch.cancel.Enable='off'; + observe_EEGDAT.count_current_eeg=6; + return; + end + Eegtab_EEG_interpolate_chan_epoch.mode_modify.Enable ='on'; + Eegtab_EEG_interpolate_chan_epoch.mode_create.Enable = 'on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.Enable= 'on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_browse.Enable= 'on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Enable= 'on'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='on'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.Enable='on'; + + Eegtab_EEG_interpolate_chan_epoch.cancel.Enable='on'; + if Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value==0 + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse.Enable='off'; + end + if observe_EEGDAT.EEG.trials ==1 + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value = 1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value = 0; + Eegtab_EEG_interpolate_chan_epoch.Parameters{6} = Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value ; + end + + if ~isempty(observe_EEGDAT.EEG) + if observe_EEGDAT.EEG.trials ==1%%Force the "interpolate marked epochs" to be grayed out. + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='off'; + Enable_flag = 'off'; + else + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='on'; + if Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value==0 + Enable_flag = 'off'; + else + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + flagcheck(1) = 0; + [~, active_flags] = find(flagcheck>=1); + if isempty(active_flags) + Enable_flag = 'off'; + else + Enable_flag = 'on'; + end + end + end + Eegtab_EEG_interpolate_chan_epoch.mflag1.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Enable = Enable_flag; + if observe_EEGDAT.EEG.trials>1 + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + flagx= (flagcheck>1); + [~,ypos] = find(Eegtab_EEG_interpolate_chan_epoch.mflag==1); + [~,ypos1] = find(flagx==1); + AA = intersect(ypos1,ypos); + count =0; + for f = 1:length(flagx) + if flagx(f)>0 && flagx(f)<9 + if isempty(AA) + count = count+1; + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable',Enable_flag); + if count==1 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',1); + else + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + else + %turn off/invisible all not-active-flag choices + if f < 9 %no flags over 8 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable','off'); + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + end + + end + end + Eegtab_EEG_interpolate_chan_epoch.mflag = [ Eegtab_EEG_interpolate_chan_epoch.mflag1.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value]; + observe_EEGDAT.count_current_eeg=6; + end + +%%-----------------------------cancel-------------------------------------- + function interpolated_chan_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable = 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_interpolated_chan_epoch',0); + box_interpolate_chan_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [0 0 0]; + try + Eegtab_EEG_interpolate_chan_epoch.mode_modify.Value=Eegtab_EEG_interpolate_chan_epoch.Parameters{1}; + Eegtab_EEG_interpolate_chan_epoch.mode_create.Value=~Eegtab_EEG_interpolate_chan_epoch.Parameters{1}; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String = num2str( Eegtab_EEG_interpolate_chan_epoch.Parameters{2}); + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value = Eegtab_EEG_interpolate_chan_epoch.Parameters{3} ; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value = ~Eegtab_EEG_interpolate_chan_epoch.Parameters{3} ; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value=Eegtab_EEG_interpolate_chan_epoch.Parameters{4}; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = num2str(Eegtab_EEG_interpolate_chan_epoch.Parameters{5}); + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value = Eegtab_EEG_interpolate_chan_epoch.Parameters{6}; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value = ~Eegtab_EEG_interpolate_chan_epoch.Parameters{6}; + if Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value==0%%if inactive ignored chans + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_browse.Enable='off'; + end + if observe_EEGDAT.EEG.trials ==1%%Force the "interpolate marked epochs" to be grayed out. + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='off'; + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value = 1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value = 0; + Eegtab_EEG_interpolate_chan_epoch.Parameters{6} = Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value ; + end + if Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value == 0 + Enable_flag = 'off'; + else + if ~isempty(observe_EEGDAT.EEG) + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + [~, active_flags] = find(flagcheck>=1); + if isempty(active_flags) + Enable_flag = 'off'; + else + Enable_flag = 'on'; + end + else + Enable_flag = 'off'; + end + end + [~,active_flags] = find(Eegtab_EEG_interpolate_chan_epoch.mflag==1); + if isempty(active_flags) || numel(active_flags)~=1 || any(active_flags(:)<1) || any(active_flags(:)>8) + active_flags=1;Eegtab_EEG_interpolate_chan_epoch.mflag = [1 0 0 0 0 0 0 0]; + end + Indexflag = zeros(1,8); + Indexflag(active_flags) = 1; + Eegtab_EEG_interpolate_chan_epoch.mflag1.Value = Indexflag(1); + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value = Indexflag(2); + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value = Indexflag(3); + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value = Indexflag(4); + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value = Indexflag(5); + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value = Indexflag(6); + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value = Indexflag(7); + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value = Indexflag(8); + Eegtab_EEG_interpolate_chan_epoch.mflag1.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Enable = Enable_flag; + if ~isempty(observe_EEGDAT.EEG) + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + flagx= (flagcheck>1); + [~,ypos] = find(Eegtab_EEG_interpolate_chan_epoch.mflag==1); + [~,ypos1] = find(flagx==1); + AA = intersect(ypos1,ypos); + count =0; + for f = 1:length(flagx) + if flagx(f)>0 && flagx(f)<9 + if isempty(AA) + count = count+1; + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable',Enable_flag); + if count==1 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',1); + else + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + else + if f < 9 %no flags over 8 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable','off'); + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + end + end + Eegtab_EEG_interpolate_chan_epoch.mflag = [ Eegtab_EEG_interpolate_chan_epoch.mflag1.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag2.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag3.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag4.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag5.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag6.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag7.Value,... + Eegtab_EEG_interpolate_chan_epoch.mflag8.Value]; + catch + end + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_interpolatechan_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_plotset'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + interpolate_run(); + estudioworkingmemory('EEGTab_interpolated_chan_epoch',0); + box_interpolate_chan_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=5 + return; + end + estudioworkingmemory('EEGTab_interpolated_chan_epoch',0); + box_interpolate_chan_epoch.TitleColor= [0.0500 0.2500 0.5000]; + Eegtab_EEG_interpolate_chan_epoch.cancel.BackgroundColor = [ 1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.cancel.ForegroundColor = [0 0 0]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.BackgroundColor = [1 1 1]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_run.ForegroundColor = [0 0 0]; + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value= 1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value=0; + Eegtab_EEG_interpolate_chan_epoch.interpolate_chan_edit.String = ''; + Eegtab_EEG_interpolate_chan_epoch.interpolate_inverse.Value= 1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_spherical.Value=0; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan.Value=0; + Eegtab_EEG_interpolate_chan_epoch.ignore_chan_edit.String = ''; + Eegtab_EEG_interpolate_chan_epoch.interpolate_op_all_epoch.Value= 1; + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Value=0; + if ~isempty(observe_EEGDAT.EEG) + if observe_EEGDAT.EEG.trials ==1%%Force the "interpolate marked epochs" to be grayed out. + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='off'; + Enable_flag = 'off'; + else + Eegtab_EEG_interpolate_chan_epoch.interpolate_marked_epoch_op.Enable='on'; + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + flagcheck(1) = 0; + [~, active_flags] = find(flagcheck>1); + if isempty(active_flags) + Enable_flag = 'off'; + else + Enable_flag = 'on'; + end + end + Eegtab_EEG_interpolate_chan_epoch.mflag1.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag2.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag3.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag4.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag5.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag6.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag7.Enable = Enable_flag; + Eegtab_EEG_interpolate_chan_epoch.mflag8.Enable = Enable_flag; + if ~isempty(observe_EEGDAT.EEG) + histoflags = summary_rejectflags(observe_EEGDAT.EEG); + %check currently activated flags + flagcheck = sum(histoflags); + flagx= (flagcheck>1); + count =0; + for f = 1:length(flagx) + if flagx(f)>0 && flagx(f)<9 + count = count+1; + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable',Enable_flag); + if count==1 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',1); + else + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + else + %turn off/invisible all not-active-flag choices + if f < 9 %no flags over 8 + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Enable','off'); + set(Eegtab_EEG_interpolate_chan_epoch.(['mflag' num2str(f)]), 'Value',0); + end + end + end + end + end + observe_EEGDAT.Reset_eeg_paras_panel=6; + end + +end + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_resample_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_resample_GUI.m new file mode 100644 index 00000000..a793dc83 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_resample_GUI.m @@ -0,0 +1,895 @@ +%Author: Guanghui ZHANG +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +% Mar. 2024 + +% EEGLAB Studio + +function varargout = f_EEG_resample_GUI(varargin) +global observe_EEGDAT; + +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +gui_eeg_resample = struct(); + +%-----------------------------Name the title---------------------------------------------- +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end + +if nargin == 0 + fig = figure(); % Parent figure + box_eeg_resample = uiextras.BoxPanel('Parent', fig, 'Title', 'Sampling Rate & Epoch', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + box_eeg_resample = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Sampling Rate & Epoch', 'Padding', 5,... + 'BackgroundColor',ColorB_def); +else + box_eeg_resample = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Sampling Rate & Epoch', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @resample_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_eeg_resample(FonsizeDefault); +varargout{1} = box_eeg_resample; + + function drawui_eeg_resample(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + + gui_eeg_resample.DataSelBox = uiextras.VBox('Parent', box_eeg_resample,'BackgroundColor',ColorB_def); + + %%------------------current sampling rate-------------------------- + gui_eeg_resample.csrate_title = uiextras.HBox('Parent', gui_eeg_resample.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', gui_eeg_resample.csrate_title,'String','Current sampling rate:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_resample.csrate_edit = uicontrol('Style','edit','Parent', gui_eeg_resample.csrate_title,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + uicontrol('Style','text','Parent', gui_eeg_resample.csrate_title,'String','Hz',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_eeg_resample.csrate_title,'Sizes',[130 110 30]); + + %%---------------------new sampling rate--------------------------- + gui_eeg_resample.nwsrate_title = uiextras.HBox('Parent', gui_eeg_resample.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_resample.nwsrate_checkbox = uicontrol('Style','checkbox','Parent', gui_eeg_resample.nwsrate_title,'String','New sampling rate:',... + 'callback',@nwsrate_checkbox,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); + gui_eeg_resample.nwsrate_checkbox.KeyPressFcn = @EEG_resample_presskey; + gui_eeg_resample.Paras{1} = gui_eeg_resample.nwsrate_checkbox.Value; + gui_eeg_resample.nwsrate_edit = uicontrol('Style','edit','Parent', gui_eeg_resample.nwsrate_title,'String','',... + 'callback',@nwsrate_edit,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_eeg_resample.Paras{2} = str2num(gui_eeg_resample.nwsrate_edit.String); + gui_eeg_resample.nwsrate_edit.KeyPressFcn = @EEG_resample_presskey; + uicontrol('Style','text','Parent', gui_eeg_resample.nwsrate_title,'String','Hz',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_eeg_resample.nwsrate_title,'Sizes',[130 110 30]); + + %%----------------current time-window------------------------------ + gui_eeg_resample.ctimewindow_title = uiextras.HBox('Parent', gui_eeg_resample.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent',gui_eeg_resample.ctimewindow_title,... + 'String','Current epoch','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_resample.ctimewindow_editleft = uicontrol('Style','edit','Parent', gui_eeg_resample.ctimewindow_title,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_eeg_resample.currentunitleft = uicontrol('Style', 'text','Parent',gui_eeg_resample.ctimewindow_title,... + 'String','ms, to','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_resample.ctimewindow_editright = uicontrol('Style','edit','Parent', gui_eeg_resample.ctimewindow_title,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_eeg_resample.currentunitright = uicontrol('Style', 'text','Parent',gui_eeg_resample.ctimewindow_title,... + 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_eeg_resample.ctimewindow_title,'Sizes',[90 55 40 55 25]); + + %%--------------------new time window-------------------------------- + gui_eeg_resample.nwtimewindow_title = uiextras.HBox('Parent', gui_eeg_resample.DataSelBox,'BackgroundColor',ColorB_def); + gui_eeg_resample.nwtimewindow_checkbox= uicontrol('Style', 'checkbox','Parent',gui_eeg_resample.nwtimewindow_title,... + 'callback',@nwtimewindow_checkbox,'String','New epoch','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); + gui_eeg_resample.Paras{3} = gui_eeg_resample.nwtimewindow_checkbox.Value; + gui_eeg_resample.nwtimewindow_checkbox.KeyPressFcn = @EEG_resample_presskey; + gui_eeg_resample.nwtimewindow_editleft = uicontrol('Style','edit','Parent', gui_eeg_resample.nwtimewindow_title,'String','',... + 'callback',@nwtimewindow_editleft,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_eeg_resample.Paras{4} = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + gui_eeg_resample.nwtimewindow_editleft.KeyPressFcn = @EEG_resample_presskey; + gui_eeg_resample.nwwd_unitleft = uicontrol('Style', 'text','Parent',gui_eeg_resample.nwtimewindow_title,... + 'String','ms, to','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_eeg_resample.nwtimewindow_editright = uicontrol('Style','edit','Parent', gui_eeg_resample.nwtimewindow_title,'String','',... + 'callback',@nwtimewindow_editright,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_eeg_resample.Paras{5} = str2num(gui_eeg_resample.nwtimewindow_editright.String); + gui_eeg_resample.nwtimewindow_editright.KeyPressFcn = @EEG_resample_presskey; + gui_eeg_resample.nwwd_unitright = uicontrol('Style', 'text','Parent',gui_eeg_resample.nwtimewindow_title,... + 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_eeg_resample.nwtimewindow_title,'Sizes',[90 55 40 55 25]); + + %%------------------------Trim Continuous data----------------------------- + gui_eeg_resample.Trimcont_title = uiextras.HBox('Parent',gui_eeg_resample.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + gui_eeg_resample.Trimcont= uicontrol('Style', 'pushbutton','Parent',gui_eeg_resample.Trimcont_title,... + 'String','Trim relative to first & last event','callback',@Trimcont,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_eeg_resample.Trimcont_title); + set(gui_eeg_resample.Trimcont_title,'Sizes',[-1 20]); + + %%------------------------cancel & apply----------------------------- + gui_eeg_resample.advance_help_title = uiextras.HBox('Parent',gui_eeg_resample.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', gui_eeg_resample.advance_help_title); + gui_eeg_resample.resample_cancel= uicontrol('Style', 'pushbutton','Parent',gui_eeg_resample.advance_help_title,... + 'String','Cancel','callback',@resample_cancel,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_eeg_resample.advance_help_title); + + gui_eeg_resample.resample_run = uicontrol('Style', 'pushbutton','Parent',gui_eeg_resample.advance_help_title,'String','Apply',... + 'callback',@resample_run,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_eeg_resample.advance_help_title); + set(gui_eeg_resample.advance_help_title,'Sizes',[15 105 30 105 15]); + set(gui_eeg_resample.DataSelBox,'Sizes',[30 30 30 30 30 30]); + + estudioworkingmemory('EEGTab_resample',0); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + + +%%-------------------checkbox for new sampling rate------------------------ + function nwsrate_checkbox(Source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + gui_eeg_resample.nwsrate_edit.BackgroundColor = [1 1 1]; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_resample',1); + gui_eeg_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_run.ForegroundColor = [1 1 1]; + box_eeg_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_cancel.ForegroundColor = [1 1 1]; + + if Source.Value==1 + gui_eeg_resample.nwsrate_edit.Enable = 'on'; + Newsrate = str2num(gui_eeg_resample.nwsrate_edit.String); + if isempty(Newsrate) || numel(Newsrate)~=1 || any(Newsrate<=0) + try gui_eeg_resample.nwsrate_edit.String = str2num(observe_EEGDAT.EEG.srate); catch end + end + else + gui_eeg_resample.nwsrate_edit.Enable = 'off'; + end + end + + +%%-------------------------edit new sampling rate-------------------------- + function nwsrate_edit(Source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_resample',1); + gui_eeg_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_run.ForegroundColor = [1 1 1]; + box_eeg_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_cancel.ForegroundColor = [1 1 1]; + + Newsrate = str2num(gui_eeg_resample.nwsrate_edit.String); + if isempty(Newsrate) || numel(Newsrate)~=1 ||any(Newsrate<=0) + msgboxText='Sampling Rate & Epoch: New sampling rate must be a positive value'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + end + end + +%%-------------------checkbox for new time window-------------------------- + function nwtimewindow_checkbox(Source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + gui_eeg_resample.nwtimewindow_editleft.BackgroundColor = [1 1 1]; + gui_eeg_resample.nwtimewindow_editright.BackgroundColor = [1 1 1]; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_resample',1); + gui_eeg_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_run.ForegroundColor = [1 1 1]; + box_eeg_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_cancel.ForegroundColor = [1 1 1]; + if Source.Value==1 + gui_eeg_resample.nwtimewindow_editleft.Enable ='on'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'on'; + NewStart = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.nwtimewindow_editleft.String = num2str(observe_EEGDAT.EEG.times(1)); + else + gui_eeg_resample.nwtimewindow_editleft.String = num2str(observe_EEGDAT.EEG.xmin); + end + end + Newend = str2num(gui_eeg_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.nwtimewindow_editright.String = num2str(observe_EEGDAT.EEG.times(end)); + else + gui_eeg_resample.nwtimewindow_editright.String = num2str(observe_EEGDAT.EEG.xmax); + end + end + else + gui_eeg_resample.nwtimewindow_editleft.Enable ='off'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'off'; + end + end + +%%--------------------------new epoch start-------------------------------- + function nwtimewindow_editleft(Source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_resample',1); + gui_eeg_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_run.ForegroundColor = [1 1 1]; + box_eeg_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_cancel.ForegroundColor = [1 1 1]; + NewStart = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 + msgboxText='Sampling Rate & Epoch: the left edge for the new time window must be a single value'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if NewStart>= observe_EEGDAT.EEG.times(end) + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than',32,num2str(observe_EEGDAT.EEG.times(end)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + + if observe_EEGDAT.EEG.trials==1 + if NewStart< 0 + msgboxText=['Sampling Rate & Epoch: Left edge for the new time window cannot smaller than 0 ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = '0'; + end + + end + + if observe_EEGDAT.EEG.trials>1 + if NewStart< observe_EEGDAT.EEG.times(1) + msgboxText=['Sampling Rate & Epoch: we will set 0 for the additional time range because the left edge for the new time window is smaller than',32,num2str(observe_EEGDAT.EEG.times(1)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + if NewStart>= 0 + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than 0 ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + end + + end + + +%%---------------------------new epoch stop-------------------------------- + function nwtimewindow_editright(Source,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_resample',1); + gui_eeg_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_run.ForegroundColor = [1 1 1]; + box_eeg_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_eeg_resample.resample_cancel.ForegroundColor = [1 1 1]; + Newend = str2num(gui_eeg_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 + msgboxText='Sampling Rate & Epoch: the right edge for the new time window must be a single value'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if Newend<= observe_EEGDAT.EEG.times(1) + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than',32,num2str(observe_EEGDAT.EEG.times(1)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if observe_EEGDAT.EEG.trials==1 + if Newend> observe_EEGDAT.EEG.times(end) + msgboxText=['Sampling Rate & Epoch: Right edge for the new time window is smaller than',32,num2str(observe_EEGDAT.EEG.times(end)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + if observe_EEGDAT.EEG.trials>1 + if Newend> observe_EEGDAT.EEG.times(end) + msgboxText=['Sampling Rate & Epoch: we will set 0 for the additional time range because the right edge for the new time window is larger than',32,num2str(observe_EEGDAT.EEG.times(end)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end + + if Newend<=0 + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than 0 ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + + end +%%--------------------------Trim continuous data--------------------------- + function Trimcont(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + estudioworkingmemory('f_EEG_proces_messg','Sampling Rate & Epoch>Trim continuous data'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + def = estudioworkingmemory('pop_eegtrim'); + + % + % Call GUI + % + answer = gui_eegtrim(def); + if isempty(answer) + observe_EEGDAT.eeg_panel_message =2; + return + end + + presti = answer{1}; + poststi = answer{2}; + estudioworkingmemory('pop_eegtrim', {answer{1} answer{2}}); + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Sampling Rate & Epoch>Trim continuous data *',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + %% Run the pop_ command with the user input from the GUI + [EEG, LASTCOM] = pop_eegtrim(EEG, presti, poststi, 'History', 'implicit'); + + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_trim'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + % checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%--------------------------cancel----------------------------------------- + function resample_cancel(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + estudioworkingmemory('EEGTab_resample',0); + gui_eeg_resample.resample_run.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_run.ForegroundColor = [0 0 0]; + box_eeg_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_cancel.ForegroundColor = [0 0 0]; + + gui_eeg_resample.csrate_edit.String = num2str(observe_EEGDAT.EEG.srate); + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.ctimewindow_editleft.String = num2str(observe_EEGDAT.EEG.times(1)); + gui_eeg_resample.ctimewindow_editright.String = num2str(observe_EEGDAT.EEG.times(end)); + else + gui_eeg_resample.ctimewindow_editleft.String = num2str(observe_EEGDAT.EEG.xmin); + gui_eeg_resample.ctimewindow_editright.String = num2str(observe_EEGDAT.EEG.xmax); + end + %%------------------new sampling rate-------------------------- + nwsrate_checkboxValue = gui_eeg_resample.Paras{1}; + if isempty(nwsrate_checkboxValue) || numel(nwsrate_checkboxValue)~=1 || (nwsrate_checkboxValue~=0 && nwsrate_checkboxValue~=1) + gui_eeg_resample.Paras{1}=0; + nwsrate_checkboxValue=0; + end + gui_eeg_resample.nwsrate_checkbox.Value=nwsrate_checkboxValue; + if nwsrate_checkboxValue==1 + gui_eeg_resample.nwsrate_edit.Enable = 'on'; + else + gui_eeg_resample.nwsrate_edit.Enable = 'off'; + end + gui_eeg_resample.nwsrate_edit.String = num2str(gui_eeg_resample.Paras{2}); + %%------------------------new-time window------------------------- + newtwcheckboxValue = gui_eeg_resample.Paras{3}; + if isempty(newtwcheckboxValue) || numel(newtwcheckboxValue)~=1 || (newtwcheckboxValue~=0 && newtwcheckboxValue~=1) + gui_eeg_resample.Paras{3}=0; + newtwcheckboxValue=0; + end + gui_eeg_resample.nwtimewindow_checkbox.Value=newtwcheckboxValue; + if newtwcheckboxValue==1 + gui_eeg_resample.nwtimewindow_editleft.Enable ='on'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'on'; + else + gui_eeg_resample.nwtimewindow_editleft.Enable ='off'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'off'; + end + gui_eeg_resample.nwtimewindow_editleft.String = num2str(gui_eeg_resample.Paras{4}); + gui_eeg_resample.nwtimewindow_editright.String = num2str(gui_eeg_resample.Paras{5}); + end + +%%--------------------------Run-------------------------------------------- + function resample_run(~,~) + if isempty(observe_EEGDAT.EEG) + observe_EEGDAT.count_current_eeg=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=18 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels +1;%%call the functions from the other panel + end + if gui_eeg_resample.nwsrate_checkbox.Value==0 && gui_eeg_resample.nwtimewindow_checkbox.Value==0 + msgboxText='Sampling Rate & Epoch: Please select "New sampling rate" or "New epoch"'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + %%Send message to Message panel + estudioworkingmemory('f_EEG_proces_messg','Sampling Rate & Epoch'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + %%--------------------check new sampling rate---------------------- + Freq2resamp = str2num(gui_eeg_resample.nwsrate_edit.String); + if gui_eeg_resample.nwsrate_checkbox.Value==1 + if isempty(Freq2resamp) || numel(Freq2resamp)~=1 ||any(Freq2resamp<=0) + msgboxText='Sampling Rate & Epoch: New sampling rate must be a positive value'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + else + Freq2resamp = []; + end + + %%----------------------------check new time window---------------- + if gui_eeg_resample.nwtimewindow_checkbox.Value==1 + NewStart = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 + msgboxText='Sampling Rate & Epoch: the left edge for the new time window must be a single value'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if NewStart>= observe_EEGDAT.EEG.times(end) + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than',32,num2str(observe_EEGDAT.times(end)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if observe_EEGDAT.EEG.trials>1 + if NewStart>=0 + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than 0 ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + end + + Newend = str2num(gui_eeg_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 + msgboxText='Sampling Rate & Epoch: the right edge for the new time window must be a single value'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + if Newend<= observe_EEGDAT.EEG.times(1) + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than',32,num2str(observe_EEGDAT.times(1)),'ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if Newend<= 0 + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than 0 ms']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + else + NewStart = []; + Newend = []; + end + + estudioworkingmemory('EEGTab_resample',0); + gui_eeg_resample.resample_run.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_run.ForegroundColor = [0 0 0]; + box_eeg_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_cancel.ForegroundColor = [0 0 0]; + gui_eeg_resample.Paras{1} = gui_eeg_resample.nwsrate_checkbox.Value; + gui_eeg_resample.Paras{2} = str2num(gui_eeg_resample.nwsrate_edit.String); + gui_eeg_resample.Paras{3} = gui_eeg_resample.nwtimewindow_checkbox.Value; + gui_eeg_resample.Paras{4} = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + gui_eeg_resample.Paras{5} = str2num(gui_eeg_resample.nwtimewindow_editright.String); + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(end); + observe_EEGDAT.CURRENTSET = EEGArray; + estudioworkingmemory('EEGArray',EEGArray); + end + + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + if gui_eeg_resample.nwsrate_checkbox.Value==0 + Freq2resamp = EEG.srate; + end + if gui_eeg_resample.nwtimewindow_checkbox.Value==0 + TimeRange = [EEG.times(1),EEG.times(end)]; + else + TimeRange = [NewStart,Newend]; + end + if EEG.trials>1 + [EEG, LASTCOM] = pop_resampleeg(EEG, 'Freq2resamp',Freq2resamp, 'TimeRange',TimeRange,... + 'Saveas', 'off', 'History', 'gui'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + [EEG,LASTCOM ]= pop_select( EEG, 'time',TimeRange); + EEG = eeg_checkset(EEG); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + if Freq2resamp~=EEG.srate + setnameold = EEG.setname; + [EEG, LASTCOM]= pop_resample( EEG, Freq2resamp); + EEG.setname = setnameold; + EEG = eeg_checkset(EEG); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + end + end + [ALLEEG_out,~,~] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + end + suffixname = '_resampled'; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),suffixname); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + if Save_file_label + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + + try + EEGArray = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + EEGArray = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',EEGArray); + + observe_EEGDAT.eeg_panel_message =2; + observe_EEGDAT.count_current_eeg = 1; + end + + +%%--------Setting current EEGset/session history based on the current updated EEGset------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg~=8 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || isempty(observe_EEGDAT.ALLEEG) ||EEGUpdate==1 + Enableflag = 'off'; + else + Enableflag = 'on'; + end + if ~isempty(observe_EEGDAT.EEG) + gui_eeg_resample.csrate_edit.String = num2str(observe_EEGDAT.EEG.srate); + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.ctimewindow_editleft.String = num2str(observe_EEGDAT.EEG.times(1)); + gui_eeg_resample.ctimewindow_editright.String = num2str(observe_EEGDAT.EEG.times(end)); + gui_eeg_resample.currentunitleft.String = 'ms, to'; + gui_eeg_resample.currentunitright.String = 'ms'; + + gui_eeg_resample.nwwd_unitleft.String = 'ms, to'; + gui_eeg_resample.nwwd_unitright.String = 'ms'; + else + gui_eeg_resample.ctimewindow_editleft.String = num2str(observe_EEGDAT.EEG.xmin); + gui_eeg_resample.ctimewindow_editright.String = num2str(observe_EEGDAT.EEG.xmax); + gui_eeg_resample.currentunitleft.String = 's, to'; + gui_eeg_resample.currentunitright.String = 's'; + + gui_eeg_resample.nwwd_unitleft.String = 's, to'; + gui_eeg_resample.nwwd_unitright.String = 's'; + end + else + gui_eeg_resample.csrate_edit.String = ''; + gui_eeg_resample.ctimewindow_editleft.String = ''; + gui_eeg_resample.ctimewindow_editright.String = ''; + end + %%----------------------new sampling rate-------------------------- + gui_eeg_resample.nwsrate_checkbox.Enable = Enableflag; + gui_eeg_resample.nwsrate_edit.Enable = Enableflag; + if strcmp(Enableflag,'on') && gui_eeg_resample.nwsrate_checkbox.Value==1 + gui_eeg_resample.nwsrate_edit.Enable = 'on'; + Newsrate = str2num(gui_eeg_resample.nwsrate_edit.String); + if isempty(Newsrate) || numel(Newsrate)~=1 || any(Newsrate<=0) + try gui_eeg_resample.nwsrate_edit.String = str2num(observe_EEGDAT.EEG.srate); catch end + end + else + gui_eeg_resample.nwsrate_edit.Enable = 'off'; + end + + %%--------------------new tiem window------------------------------ + gui_eeg_resample.nwtimewindow_checkbox.Enable = Enableflag; + gui_eeg_resample.nwtimewindow_editleft.Enable = Enableflag; + gui_eeg_resample.nwtimewindow_editright.Enable = Enableflag; + + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials==1 + gui_eeg_resample.Trimcont.Enable = 'on'; + else + gui_eeg_resample.Trimcont.Enable = 'off'; + end + gui_eeg_resample.resample_run.Enable = Enableflag; + gui_eeg_resample.resample_cancel.Enable = Enableflag; + if strcmp(Enableflag,'on') && gui_eeg_resample.nwtimewindow_checkbox.Value==1 + gui_eeg_resample.nwtimewindow_editleft.Enable ='on'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'on'; + NewStart = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 || any(NewStart>=observe_EEGDAT.EEG.times(end)) + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.nwtimewindow_editleft.String = num2str(observe_EEGDAT.EEG.times(1)); + else + gui_eeg_resample.nwtimewindow_editleft.String = num2str(observe_EEGDAT.EEG.xmin); + end + end + Newend = str2num(gui_eeg_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 || any(Newend<=observe_EEGDAT.EEG.times(1)) + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.nwtimewindow_editright.String = num2str(observe_EEGDAT.EEG.times(end)); + else + gui_eeg_resample.nwtimewindow_editright.String = num2str(observe_EEGDAT.EEG.xmax); + end + end + else + gui_eeg_resample.nwtimewindow_editleft.Enable ='off'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'off'; + end + gui_eeg_resample.Trimcont.Enable = Enableflag; + gui_eeg_resample.Paras{1} = gui_eeg_resample.nwsrate_checkbox.Value; + gui_eeg_resample.Paras{2} = str2num(gui_eeg_resample.nwsrate_edit.String); + gui_eeg_resample.Paras{3} = gui_eeg_resample.nwtimewindow_checkbox.Value; + gui_eeg_resample.Paras{4} = str2num(gui_eeg_resample.nwtimewindow_editleft.String); + gui_eeg_resample.Paras{5} = str2num(gui_eeg_resample.nwtimewindow_editright.String); + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials==1 + gui_eeg_resample.Trimcont.Enable = 'on'; + else + gui_eeg_resample.Trimcont.Enable = 'off'; + end + observe_EEGDAT.count_current_eeg=9; + end + + + +%%--------------press return to execute "Apply"---------------------------- + function EEG_resample_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_resample'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + resample_run(); + estudioworkingmemory('EEGTab_resample',0); + gui_eeg_resample.resample_run.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_run.ForegroundColor = [0 0 0]; + box_eeg_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_EEG_paras_panel~=7 + return; + end + estudioworkingmemory('EEGTab_resample',0); + gui_eeg_resample.resample_run.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_run.ForegroundColor = [0 0 0]; + box_eeg_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_eeg_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_eeg_resample.resample_cancel.ForegroundColor = [0 0 0]; + if ~isempty(observe_EEGDAT.EEG) + gui_eeg_resample.csrate_edit.String = num2str(observe_EEGDAT.EEG.srate); + if observe_EEGDAT.EEG.trials>1 + gui_eeg_resample.ctimewindow_editleft.String = num2str(observe_EEGDAT.EEG.times(1)); + gui_eeg_resample.ctimewindow_editright.String = num2str(observe_EEGDAT.EEG.times(end)); + gui_eeg_resample.currentunitleft.String = 'ms, to'; + gui_eeg_resample.currentunitright.String = 'ms'; + + gui_eeg_resample.nwwd_unitleft.String = 'ms, to'; + gui_eeg_resample.nwwd_unitright.String = 'ms'; + else + gui_eeg_resample.ctimewindow_editleft.String = num2str(observe_EEGDAT.EEG.xmin); + gui_eeg_resample.ctimewindow_editright.String = num2str(observe_EEGDAT.EEG.xmax); + gui_eeg_resample.currentunitleft.String = 's, to'; + gui_eeg_resample.currentunitright.String = 's'; + + gui_eeg_resample.nwwd_unitleft.String = 's, to'; + gui_eeg_resample.nwwd_unitright.String = 's'; + end + else + gui_eeg_resample.csrate_edit.String = ''; + gui_eeg_resample.ctimewindow_editleft.String = ''; + gui_eeg_resample.ctimewindow_editright.String = ''; + end + gui_eeg_resample.nwsrate_checkbox.Value=0; + gui_eeg_resample.nwsrate_edit.Enable = 'off'; + gui_eeg_resample.nwsrate_edit.String=''; + gui_eeg_resample.nwtimewindow_editleft.Enable ='off'; + gui_eeg_resample.nwtimewindow_editright.Enable = 'off'; + gui_eeg_resample.nwtimewindow_checkbox.Value=0; + gui_eeg_resample.nwtimewindow_editleft.String =''; + gui_eeg_resample.nwtimewindow_editright.String = ''; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials==1 + gui_eeg_resample.Trimcont.Enable = 'on'; + else + gui_eeg_resample.Trimcont.Enable = 'off'; + end + observe_EEGDAT.Reset_EEG_paras_panel=8; + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_save_multi_file.fig b/studio_functions/GUIs/EEG Tab/f_EEG_save_multi_file.fig new file mode 100644 index 00000000..7249fbdb Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_save_multi_file.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_save_multi_file.m b/studio_functions/GUIs/EEG Tab/f_EEG_save_multi_file.m new file mode 100644 index 00000000..f6baf0b6 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_save_multi_file.m @@ -0,0 +1,435 @@ +function varargout = f_EEG_save_multi_file(varargin) +% F_EEG_SAVE_MULTI_FILE MATLAB code for f_EEG_save_multi_file.fig +% F_EEG_SAVE_MULTI_FILE, by itself, creates a new F_EEG_SAVE_MULTI_FILE or raises the existing +% singleton*. +% +% H = F_EEG_SAVE_MULTI_FILE returns the handle to a new F_EEG_SAVE_MULTI_FILE or the handle to +% the existing singleton*. +% +% F_EEG_SAVE_MULTI_FILE('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_SAVE_MULTI_FILE.M with the given input arguments. +% +% F_EEG_SAVE_MULTI_FILE('Property','Value',...) creates a new F_EEG_SAVE_MULTI_FILE or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_EEG_save_multi_file_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_EEG_save_multi_file_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 f_EEG_save_multi_file + +% Last Modified by GUIDE v2.5 12-Feb-2024 08:54:05 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_EEG_save_multi_file_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_save_multi_file_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 f_EEG_save_multi_file is made visible. +function f_EEG_save_multi_file_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_save_multi_file + +try + ALLEEG = varargin{1}; + EEGArray = varargin{2}; + suffix = varargin{3}; +catch + suffix = ''; + EEGLAB = []; + EEGLAB.setname = 'No eegset was selected'; + EEGLAB.filename ='No eegset was selected.set'; + EEGLAB.event = []; + EEGLAB.chanlocs = []; + EEGLAB.nbchan = 0; + ALLEEG(1) = EEGLAB; + EEGArray = 1; +end + +% handles.setnameor = setname; +handles.output = []; +handles.suffix = suffix; + +handles.ALLEEG = ALLEEG; +handles.EEGArray =EEGArray; + +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save multiple eegsets GUI']) + + +% set(handles.checkbox1_suffix,'Value',1); +set(handles.edit_suffix_name,'String',suffix); +set(handles.checkbox2_save_label,'Value',0); + +ColumnName_table = {'EEG name','File name'}; + +set(handles.uitable1_erpset_table,'ColumnName',cellstr(ColumnName_table)); +set(handles.uitable1_erpset_table,'RowName',cellstr(num2str(EEGArray'))); +handles.uitable1_erpset_table.ColumnEditable(1) = true; +handles.uitable1_erpset_table.ColumnEditable(2) = false; +for Numoferpset = 1:numel(EEGArray) + DataString{Numoferpset,1} = strcat(ALLEEG(EEGArray(Numoferpset)).setname,suffix); + DataString{Numoferpset,2} = ''; +end + +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); +set(handles.uitable1_erpset_table,'Enable','on'); +set(handles.checkbox3_filename_setname,'Enable','off'); +set(handles.edit_path,'Enable','off','String',''); +set(handles.pushbutton_path_browse,'Enable','off'); + + +% handles.uitable1_erpset_table.DisplayDataChangedFcn = {@tableDisplayDataChangedFcn,hObject,handles}; +% +% % Color GUI +% % +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + +% Update handles structure +guidata(hObject, handles); +handles.uitable1_erpset_table.BackgroundColor = [1 1 1]; +handles.checkbox1_suffix.BackgroundColor = [1 1 1]; +% handles.checkbox3_filename_setname.BackgroundColor = [1 1 1]; +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_EEG_save_multi_file_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +try + varargout{1} = handles.output; +catch + varargout{1} = []; +end + +delete(handles.gui_chassis); +pause(0.1) + + + +% --- Executes on button press in checkbox1_suffix. +function checkbox1_suffix_Callback(hObject, eventdata, handles) +ALLEEG = handles.ALLEEG; +EEGArray = handles.EEGArray; +suffix_edit = handles.edit_suffix_name.String; + +DataString_before = handles.uitable1_erpset_table.Data; +for Numoferpset = 1:numel(EEGArray) + DataString{Numoferpset,1} = strcat(ALLEEG(EEGArray(Numoferpset)).setname,suffix_edit); + if handles.checkbox3_filename_setname.Value==0 + DataString{Numoferpset,2} = DataString_before{Numoferpset,2}; + else + DataString{Numoferpset,2} = [DataString{Numoferpset,1},'.set']; + end +end +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); + +set(handles.uitable1_erpset_table,'Enable','on'); + + + + + +function edit_suffix_name_Callback(hObject, eventdata, handles) + + + + +% --- Executes during object creation, after setting all properties. +function edit_suffix_name_CreateFcn(hObject, eventdata, handles) + +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + + + +% --- Executes on button press in checkbox2_save_label. +function checkbox2_save_label_Callback(hObject, eventdata, handles) + +Values = handles.checkbox2_save_label.Value; + +if Values + set(handles.checkbox3_filename_setname,'Enable','on'); + ALLEEG = handles.ALLEEG; + EEGArray = handles.EEGArray; + DataString_before = handles.uitable1_erpset_table.Data; + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + DataString{Numoferpset,2} = char(ALLEEG(EEGArray(Numoferpset)).filename); + end + set(handles.uitable1_erpset_table,'Data',DataString); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; +else + set(handles.checkbox3_filename_setname,'Enable','off'); + DataString_before = handles.uitable1_erpset_table.Data; + for Numoferpset = 1:size(DataString_before,1) + DataString_before{Numoferpset,2} = ''; + end + set(handles.uitable1_erpset_table,'Data',DataString_before); + set(handles.uitable1_erpset_table,'Enable','on'); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = false; +end +if handles.checkbox2_save_label.Value + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','on'); + set(handles.pushbutton_path_browse,'Enable','on'); +else + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','off'); + set(handles.pushbutton_path_browse,'Enable','off'); +end + + + +% --- Executes on button press in checkbox3_filename_setname. +function checkbox3_filename_setname_Callback(hObject, eventdata, handles) +Value_filename_setname = handles.checkbox3_filename_setname.Value; + +% set(handles.uitable1_erpset_table,'Enable','off'); +DataString_before = handles.uitable1_erpset_table.Data; + +for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.set'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.set']; + else + file_name = [file_name,'.set']; + end + DataString{Numoferpset,2} = file_name; +end + +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +% set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); +if handles.checkbox3_filename_setname.Value==0 + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = false; +else + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; +end + + + + + +% --- Executes when entered data in editable cell(s) in uitable1_erpset_table. +function uitable1_erpset_table_CellEditCallback(hObject, eventdata, handles) + +DataString = handles.uitable1_erpset_table.Data; +EEGArray = handles.EEGArray; +if size(DataString,1) < numel(EEGArray) + msgboxText = 'EEG name and filename for one of erpsets are empty at least! Please give name to eegname and filename'; + title = 'EStudio: f_EEG_save_multi_file empty setname'; + errorfound(msgboxText, title); + return +end + +for Numofselected = 1:numel(EEGArray) + if isempty(DataString{Numofselected,1}) + msgboxText = 'EEG setname for one of erpsets is empty at least! Please give name to that eegset'; + title = 'EStudio: f_EEG_save_multi_file empty eegname'; + errorfound(msgboxText, title); + return + end +end + +if handles.checkbox3_filename_setname.Value==1 + DataString_before = handles.uitable1_erpset_table.Data; + + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.set'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.set']; + else + file_name = [file_name,'.set']; + end + DataString{Numoferpset,2} = file_name; + end + + set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +end +guidata(hObject, handles); + + + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = []; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) + +Data_String =handles.uitable1_erpset_table.Data; +ALLEEG = handles.ALLEEG; +EEGArray = handles.EEGArray; + +if size(Data_String,1)< numel(EEGArray)% + msgboxText = 'ERP name for one of erpsets is empty at least! Please give a name'; + title = 'EStudio: f_EEG_save_multi_file empty eegname'; + errorfound(msgboxText, title); + return +end + + +if size(Data_String,1)> numel(EEGArray)% + msgboxText = 'More eegname is given. Please delect it!!!'; + title = 'EStudio: f_EEG_save_multi_file empty setname'; + errorfound(msgboxText, title); + return +end + +for Numofselected = 1:numel(EEGArray) + if isempty(Data_String{Numofselected,1}) + msgboxText = 'EEG setname for one of erpsets is empty at least! Please give name to that erpset'; + title = 'EStudio: f_EEG_save_multi_file empty setname'; + errorfound(msgboxText, title); + return + end + +end + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end + +for Numoferpset = 1:numel(EEGArray) + ALLEEG(EEGArray(Numoferpset)).setname = Data_String{Numoferpset,1}; + fileName = char(Data_String{Numoferpset,2}); + if isempty(fileName) + fileName = Data_String{Numoferpset,1}; + end + + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.set']; + else + file_name = [file_name,'.set']; + end + + ALLEEG(EEGArray(Numoferpset)).filename = file_name; + if handles.checkbox2_save_label.Value + ALLEEG(EEGArray(Numoferpset)).filepath = pathName; + end + + if handles.checkbox2_save_label.Value + ALLEEG(EEGArray(Numoferpset)).saved = 'yes'; + else + ALLEEG(EEGArray(Numoferpset)).saved = 'no'; + end + +end + +FilePath = handles.checkbox2_save_label.Value; + +handles.output = {ALLEEG, FilePath}; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + + +function edit_path_Callback(hObject, eventdata, handles) + + +PathName = handles.edit_path.String; + + + + + +% --- Executes during object creation, after setting all properties. +function edit_path_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_path (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 + + +% --- Executes on button press in pushbutton_path_browse. +function pushbutton_path_browse_Callback(hObject, eventdata, handles) + + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end +title = 'Select one forlder for saving files in following procedures'; +select_path = uigetdir(pathName,title); + +if isequal(select_path,0) + select_path = cd; +end +handles.edit_path.String = select_path; diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_save_single_file.fig b/studio_functions/GUIs/EEG Tab/f_EEG_save_single_file.fig new file mode 100644 index 00000000..b794f596 Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_save_single_file.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_save_single_file.m b/studio_functions/GUIs/EEG Tab/f_EEG_save_single_file.m new file mode 100644 index 00000000..c43dc955 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_save_single_file.m @@ -0,0 +1,305 @@ +function varargout = f_EEG_save_single_file(varargin) +% F_EEG_SAVE_SINGLE_FILE MATLAB code for f_EEG_save_single_file.fig +% F_EEG_SAVE_SINGLE_FILE, by itself, creates a new F_EEG_SAVE_SINGLE_FILE or raises the existing +% singleton*. +% +% H = F_EEG_SAVE_SINGLE_FILE returns the handle to a new F_EEG_SAVE_SINGLE_FILE or the handle to +% the existing singleton*. +% +% F_EEG_SAVE_SINGLE_FILE('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_SAVE_SINGLE_FILE.M with the given input arguments. +% +% F_EEG_SAVE_SINGLE_FILE('Property','Value',...) creates a new F_EEG_SAVE_SINGLE_FILE or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_EEG_save_single_file_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_EEG_save_single_file_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 f_EEG_save_single_file + +% Last Modified by GUIDE v2.5 06-Sep-2023 13:17:11 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_EEG_save_single_file_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_save_single_file_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 f_EEG_save_single_file is made visible. +function f_EEG_save_single_file_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_save_single_file + +try + erpname = varargin{1}; + filename = varargin{2}; + CURRENTSET = varargin{3}; + [pathstr, file_name, ext] = fileparts(erpname); + erpname =file_name; +catch + erpname = ''; + filename = ''; + CURRENTSET = ''; +end + +handles.erpnameor = erpname; +handles.output = []; +erpmenu = findobj('tag', 'eegsets'); + +if ~isempty(erpmenu) + handles.menuerp = get(erpmenu); + set(handles.menuerp.Children, 'Enable','off'); +end + +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save single EEGset GUI']) +set(handles.edit_erpname, 'String', erpname); +set(handles.radio_erpname,'Value',1); +if isempty(CURRENTSET) + set(handles.current_erp_label,'String', ['No active EEGset was found'],... + 'FontWeight','Bold', 'FontSize', 16); +else + + set(handles.current_erp_label,'String', ['Your active EEGset is # ' num2str(CURRENTSET)],... + 'FontWeight','Bold', 'FontSize', 16) +end +if ~isempty(filename) + set(handles.edit_filename, 'Enable', 'off'); + set(handles.edit_filename, 'String', ''); + set(handles.radiobutton_saveas, 'Value', 0); + set(handles.filename_erpname, 'Enable', 'off'); + % set(handles.erpname_filename, 'Enable', 'off'); + set(handles.pushbutton_browse, 'Enable', 'off'); +else + set(handles.edit_filename, 'String', ''); + set(handles.radiobutton_saveas, 'Value', 0); + set(handles.edit_filename, 'Enable', 'off'); + set(handles.filename_erpname, 'Enable', 'off'); + % set(handles.erpname_filename, 'Enable', 'off'); + set(handles.pushbutton_browse, 'Enable', 'off'); +end +% +% % Color GUI +% % +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + +% Update handles structure +guidata(hObject, handles); +set(handles.filename_erpname,'BackgroundColor','white') + +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_EEG_save_single_file_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +% try +% set(handles.menuerp.Children, 'Enable','on'); +% catch +% disp('ERPset menu was not found...') +% end +varargout{1} = handles.output; +delete(handles.gui_chassis); +pause(0.1) + + + + +% --- Executes on button press in radio_erpname. +function radio_erpname_Callback(hObject, eventdata, handles) +% hObject handle to radio_erpname (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 radio_erpname +Value_radio_erpname = get(hObject,'Value'); +set(handles.radio_erpname, 'Value', 1); + + + +function edit_erpname_Callback(hObject, eventdata, handles) + + +% --- Executes during object creation, after setting all properties. +function edit_erpname_CreateFcn(hObject, eventdata, handles) + +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +% --- Executes on button press in radiobutton_saveas. +function radiobutton_saveas_Callback(hObject, eventdata, handles) + +if get(hObject, 'Value') + set(handles.edit_filename, 'Enable', 'on'); + set(handles.filename_erpname, 'Enable', 'on'); + set(handles.pushbutton_browse, 'Enable', 'on'); +else + set(handles.edit_filename, 'Enable', 'off'); + set(handles.filename_erpname, 'Enable', 'off'); + set(handles.pushbutton_browse, 'Enable', 'off'); + set(handles.edit_filename, 'String', ''); +end + + +function edit_filename_Callback(hObject, eventdata, handles) +% hObject handle to edit_filename (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 edit_filename as text +% str2double(get(hObject,'String')) returns contents of edit_filename as a double + + +% --- Executes during object creation, after setting all properties. +function edit_filename_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_filename (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 + + +% --- Executes on button press in filename_erpname. +function filename_erpname_Callback(hObject, eventdata, handles) +% hObject handle to filename_erpname (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +fname = get(handles.edit_erpname, 'String'); +% +if strcmp(fname,'') || isempty(fname) + msgboxText = 'You must enter a filename first!'; + title = 'ERPLAB: f_EEG_save_single GUI empty filename'; + errorfound(msgboxText, title); + return +end +[pathstr, fname, ext] = fileparts(fname); +erpname = [fname,'.set']; +filenames = handles.edit_filename.String; +[pathstr, ~, ~] = fileparts(filenames); +set(handles.edit_filename, 'String', fullfile(pathstr,erpname)); + + + + +% --- Executes on button press in pushbutton_browse. +function pushbutton_browse_Callback(hObject, eventdata, handles) +fndefault = get(handles.edit_filename,'String'); +[fname, pathname] = uiputfile({'*.set', 'EEGset (*.set)';... + '*.mat', 'MAT-files (*.mat)';... + '*.*' , 'All Files (*.*)'},'Save Output file as',... + fndefault); + +if isequal(fname,0) + disp('User selected Cancel') + guidata(hObject, handles); + handles.owfp = 0; % over write file permission + guidata(hObject, handles); +else + set(handles.edit_filename,'String', fullfile(pathname, fname)); + % disp(['To save ERP, user selected ', fullfile(pathname, fname)]) + handles.owfp = 1; % over write file permission + guidata(hObject, handles); +end + + + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = []; +beep; +disp('User selected Cancel') +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) +erpname = strtrim(get(handles.edit_erpname, 'String')); + +if isempty(erpname) + msgboxText = 'You must enter an erpname at least!'; + title = 'EStudio: f_EEG_save_single_file empty erpname'; + errorfound(msgboxText, title); + return +end + +fname = strtrim(get(handles.edit_filename, 'String')); +if ~isempty(fname) && get(handles.radiobutton_saveas, 'Value') + + [pathstr, name, ext] = fileparts(fname); + + if ~strcmp(ext,'.set') && ~strcmp(ext,'.mat') + ext = '.set'; + end + if strcmp(pathstr,'') + pathstr = cd; + end + + fullname = fullfile(pathstr, [name ext]); +elseif isempty(fname) && get(handles.radiobutton_saveas, 'Value') + msgboxText = 'You must enter a filename!'; + title = 'EStudio: f_EEG_save_single_file empty filename'; + errorfound(msgboxText, title); + return; +else + fullname = []; +end + +handles.output = {erpname, fullname}; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_saveas_multi_file.fig b/studio_functions/GUIs/EEG Tab/f_EEG_saveas_multi_file.fig new file mode 100644 index 00000000..93c56f55 Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_saveas_multi_file.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_saveas_multi_file.m b/studio_functions/GUIs/EEG Tab/f_EEG_saveas_multi_file.m new file mode 100644 index 00000000..fa2f1a99 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_saveas_multi_file.m @@ -0,0 +1,455 @@ +function varargout = f_EEG_saveas_multi_file(varargin) +% F_EEG_SAVEAS_MULTI_FILE MATLAB code for f_EEG_saveas_multi_file.fig +% F_EEG_SAVEAS_MULTI_FILE, by itself, creates a new F_EEG_SAVEAS_MULTI_FILE or raises the existing +% singleton*. +% +% H = F_EEG_SAVEAS_MULTI_FILE returns the handle to a new F_EEG_SAVEAS_MULTI_FILE or the handle to +% the existing singleton*. +% +% F_EEG_SAVEAS_MULTI_FILE('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_SAVEAS_MULTI_FILE.M with the given input arguments. +% +% F_EEG_SAVEAS_MULTI_FILE('Property','Value',...) creates a new F_EEG_SAVEAS_MULTI_FILE or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_EEG_saveas_multi_file_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_EEG_saveas_multi_file_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 f_EEG_saveas_multi_file + +% Last Modified by GUIDE v2.5 17-Mar-2024 14:12:25 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_EEG_saveas_multi_file_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_saveas_multi_file_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 f_EEG_saveas_multi_file is made visible. +function f_EEG_saveas_multi_file_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_saveas_multi_file + +try + ALLEEG = varargin{1}; + EEGArray = varargin{2}; + suffix = varargin{3}; +catch + suffix = ''; + EEGLAB = []; + EEGLAB.setname = 'No eegset was selected'; + EEGLAB.filename ='No eegset was selected.set'; + EEGLAB.event = []; + EEGLAB.chanlocs = []; + EEGLAB.nbchan = 0; + ALLEEG(1) = EEGLAB; + EEGArray = 1; +end +try + pathName = varargin{4}; +catch + pathName = [cd,filesep]; +end +% handles.setnameor = setname; +handles.output = []; +handles.suffix = suffix; + +handles.ALLEEG = ALLEEG; +handles.EEGArray =EEGArray; +handles.pathName= pathName; +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save eegsets as GUI']) + +handles.edit_path.String = pathName; + +% set(handles.checkbox1_suffix,'Value',1); +set(handles.edit_suffix_name,'String',suffix); +set(handles.checkbox2_save_label,'Value',1,'Enable','off'); + +ColumnName_table = {'EEG name','File name'}; + +set(handles.uitable1_erpset_table,'ColumnName',cellstr(ColumnName_table)); +set(handles.uitable1_erpset_table,'RowName',cellstr(num2str(EEGArray'))); +handles.uitable1_erpset_table.ColumnEditable(1) = true; +handles.uitable1_erpset_table.ColumnEditable(2) = true; +for Numoferpset = 1:numel(EEGArray) + DataString{Numoferpset,1} = strcat(ALLEEG(EEGArray(Numoferpset)).setname,suffix); + DataString{Numoferpset,2} = [strcat(ALLEEG(EEGArray(Numoferpset)).setname,suffix),'.set']; +end + +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); +set(handles.uitable1_erpset_table,'Enable','on'); +set(handles.checkbox3_filename_setname,'Enable','on','Value',1); +set(handles.pushbutton_path_browse,'Enable','on'); + + +% handles.uitable1_erpset_table.DisplayDataChangedFcn = {@tableDisplayDataChangedFcn,hObject,handles}; +% +% % Color GUI +% % +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + +% Update handles structure +guidata(hObject, handles); +handles.uitable1_erpset_table.BackgroundColor = [1 1 1]; +handles.checkbox1_suffix.BackgroundColor = [1 1 1]; +% handles.checkbox3_filename_setname.BackgroundColor = [1 1 1]; +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_EEG_saveas_multi_file_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +try + varargout{1} = handles.output; +catch + varargout{1} = []; +end + +delete(handles.gui_chassis); +pause(0.1) + + + +% --- Executes on button press in checkbox1_suffix. +function checkbox1_suffix_Callback(hObject, eventdata, handles) +ALLEEG = handles.ALLEEG; +EEGArray = handles.EEGArray; +suffix_edit = handles.edit_suffix_name.String; + + +DataString_before = handles.uitable1_erpset_table.Data; +for Numoferpset = 1:numel(EEGArray) + + DataString{Numoferpset,1} = strcat(DataString_before{Numoferpset,1},suffix_edit); + if handles.checkbox3_filename_setname.Value==1 + DataString{Numoferpset,2} = [DataString{Numoferpset,1},'.set']; + else + DataString{Numoferpset,2} = DataString_before{Numoferpset,2}; + end +end +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +set(handles.uitable1_erpset_table,'Enable','on'); + + + + + + +function edit_suffix_name_Callback(hObject, eventdata, handles) + + + + +% --- Executes during object creation, after setting all properties. +function edit_suffix_name_CreateFcn(hObject, eventdata, handles) + +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + + + +% --- Executes on button press in checkbox2_save_label. +function checkbox2_save_label_Callback(hObject, eventdata, handles) + +Values = handles.checkbox2_save_label.Value; + +if Values + set(handles.checkbox3_filename_setname,'Enable','on'); + ALLEEG = handles.ALLEEG; + EEGArray = handles.EEGArray; + DataString_before = handles.uitable1_erpset_table.Data; + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + DataString{Numoferpset,2} = char(ALLEEG(EEGArray(Numoferpset)).filename); + end + set(handles.uitable1_erpset_table,'Data',DataString); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; +else + set(handles.checkbox3_filename_setname,'Enable','off'); + DataString_before = handles.uitable1_erpset_table.Data; + for Numoferpset = 1:size(DataString_before,1) + DataString_before{Numoferpset,2} = ''; + end + set(handles.uitable1_erpset_table,'Data',DataString_before); + set(handles.uitable1_erpset_table,'Enable','on'); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = false; +end +if handles.checkbox2_save_label.Value + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','on'); + set(handles.pushbutton_path_browse,'Enable','on'); +else + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','off'); + set(handles.pushbutton_path_browse,'Enable','off'); +end + + + +% --- Executes on button press in checkbox3_filename_setname. +function checkbox3_filename_setname_Callback(hObject, eventdata, handles) +Value_filename_setname = handles.checkbox3_filename_setname.Value; + +% set(handles.uitable1_erpset_table,'Enable','off'); +DataString_before = handles.uitable1_erpset_table.Data; +if Value_filename_setname==1 + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.set'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.set']; + else + file_name = [file_name,'.set']; + end + DataString{Numoferpset,2} = file_name; + end + + set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); + % set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); + + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; +end + + + + + +% --- Executes when entered data in editable cell(s) in uitable1_erpset_table. +function uitable1_erpset_table_CellEditCallback(hObject, eventdata, handles) + +DataString = handles.uitable1_erpset_table.Data; +EEGArray = handles.EEGArray; +if size(DataString,1) < numel(EEGArray) + msgboxText = 'EEG name and filename for one of erpsets are empty at least! Please give name to eegname and filename'; + title = 'EStudio: f_EEG_save_multi_file empty setname'; + errorfound(msgboxText, title); + return +end + +for Numofselected = 1:numel(EEGArray) + if isempty(DataString{Numofselected,1}) + msgboxText = 'EEG setname for one of erpsets is empty at least! Please give name to that eegset'; + title = 'EStudio: f_EEG_save_multi_file empty eegname'; + errorfound(msgboxText, title); + return + end +end + +if handles.checkbox3_filename_setname.Value==1 + DataString_before = handles.uitable1_erpset_table.Data; + + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.set'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.set']; + else + file_name = [file_name,'.set']; + end + DataString{Numoferpset,2} = file_name; + end + + set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +end +guidata(hObject, handles); + + + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = []; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) + +Data_String =handles.uitable1_erpset_table.Data; +ALLEEG = handles.ALLEEG; +EEGArray = handles.EEGArray; + +if size(Data_String,1)< numel(EEGArray)% + msgboxText = 'ERP name for one of erpsets is empty at least! Please give a name'; + title = 'EStudio: f_EEG_save_multi_file empty eegname'; + errorfound(msgboxText, title); + return +end + + +if size(Data_String,1)> numel(EEGArray)% + msgboxText = 'More eegname is given. Please delect it!!!'; + title = 'EStudio: f_EEG_save_multi_file empty setname'; + errorfound(msgboxText, title); + return +end + +for Numofselected = 1:numel(EEGArray) + if isempty(Data_String{Numofselected,1}) + msgboxText = 'EEG setname for one of erpsets is empty at least! Please give name to that erpset'; + title = 'EStudio: f_EEG_save_multi_file empty setname'; + errorfound(msgboxText, title); + return + end + +end + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end + +for Numoferpset = 1:numel(EEGArray) + ALLEEG(EEGArray(Numoferpset)).setname = Data_String{Numoferpset,1}; + fileName = char(Data_String{Numoferpset,2}); + if isempty(fileName) + fileName = Data_String{Numoferpset,1}; + end + + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.set']; + else + file_name = [file_name,'.set']; + end + ALLEEG(EEGArray(Numoferpset)).filename = file_name; + if handles.checkbox2_save_label.Value + ALLEEG(EEGArray(Numoferpset)).filepath = pathName; + end + + if handles.checkbox2_save_label.Value + ALLEEG(EEGArray(Numoferpset)).saved = 'yes'; + else + ALLEEG(EEGArray(Numoferpset)).saved = 'no'; + end + +end + +FilePath = handles.checkbox2_save_label.Value; + +handles.output = {ALLEEG, FilePath}; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + + +function edit_path_Callback(hObject, eventdata, handles) + + +PathName = handles.edit_path.String; +handles.pathName= PathName; + + + + +% --- Executes during object creation, after setting all properties. +function edit_path_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_path (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 + + +% --- Executes on button press in pushbutton_path_browse. +function pushbutton_path_browse_Callback(hObject, eventdata, handles) + + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end +title = 'Select one forlder for saving files in following procedures'; +select_path = uigetdir(pathName,title); + +if isequal(select_path,0) + select_path = cd; +end +handles.pathName= select_path; +handles.edit_path.String = select_path; + + +% --- Executes on button press in pushbutton_reset. +function pushbutton_reset_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton_reset (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(handles.checkbox3_filename_setname,'Enable','on','Value',1); +suffix = handles.suffix; +ALLEEG = handles.ALLEEG; +EEGArray = handles.EEGArray; +for Numoferpset = 1:numel(EEGArray) + DataString{Numoferpset,1} = strcat(ALLEEG(EEGArray(Numoferpset)).setname,suffix); + DataString{Numoferpset,2} = [strcat(ALLEEG(EEGArray(Numoferpset)).setname,suffix),'.set']; +end + +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_shift_eventcode_conus_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_shift_eventcode_conus_GUI.m new file mode 100644 index 00000000..344e44cb --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_shift_eventcode_conus_GUI.m @@ -0,0 +1,715 @@ +%%This function is to Shift Event Codes (Continuous EEG). + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Oct. 2023 + + +function varargout = f_EEG_shift_eventcode_conus_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); +%---------------------------Initialize parameters------------------------------------ +EEG_shift_eventcode_conus = struct(); +%-----------------------------Name the title---------------------------------------------- + +% global Eegtab_box_shift_eventcodes_conus; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_shift_eventcodes_conus = uiextras.BoxPanel('Parent', fig, 'Title', 'Shift Event Codes (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_shift_eventcodes_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Shift Event Codes (Continuous EEG)',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_shift_eventcodes_conus = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Shift Event Codes (Continuous EEG)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @shift_help; +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_shift_eventcode_conus_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_shift_eventcodes_conus; + + function drawui_shift_eventcode_conus_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + EEG_shift_eventcode_conus.DataSelBox = uiextras.VBox('Parent', Eegtab_box_shift_eventcodes_conus,'BackgroundColor',ColorB_def); + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + def = estudioworkingmemory('pop_erplabShiftEventCodes'); + if isempty(def) + def = {}; + end + try + eventcodes = def{1}; + catch + eventcodes = ''; + end + %%Event codes + EEG_shift_eventcode_conus.chan_title = uiextras.HBox('Parent', EEG_shift_eventcode_conus.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',EEG_shift_eventcode_conus.chan_title,'HorizontalAlignment','left',... + 'String','Event codes:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + EEG_shift_eventcode_conus.event_codes_edit = uicontrol('Style','edit','Parent',EEG_shift_eventcode_conus.chan_title,... + 'String','','FontSize',FontSize_defualt,'callback',@event_codes_edit,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_shift_eventcode_conus.event_codes_edit.KeyPressFcn= @eeg_shiftcodes_presskey; + EEG_shift_eventcode_conus.event_codes_browse = uicontrol('Style','pushbutton','Parent',EEG_shift_eventcode_conus.chan_title,... + 'String','Browse','FontSize',FontSize_defualt,'callback',@event_codes_browse,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + set( EEG_shift_eventcode_conus.chan_title,'Sizes',[90 -1,60]); + if iscell(eventcodes) + EEG_shift_eventcode_conus.event_codes_edit.String = num2str(strjoin(eventcodes, ',')); + else + EEG_shift_eventcode_conus.event_codes_edit.String = num2str(eventcodes); + end + + %%buffer before eventcode in ms + try + timeshift= def{2}; + catch + timeshift = []; + end + EEG_shift_eventcode_conus.voltage_title = uiextras.HBox('Parent', EEG_shift_eventcode_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_shift_eventcode_conus.voltage_text = uicontrol('Style','text','Parent',EEG_shift_eventcode_conus.voltage_title,'HorizontalAlignment','left',... + 'String',['Timeshift (ms):'],'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 2F + EEG_shift_eventcode_conus.timeshift_edit = uicontrol('Style','edit','Parent',EEG_shift_eventcode_conus.voltage_title,... + 'callback',@timeshift_edit,'String',num2str(timeshift),'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); % 2F + EEG_shift_eventcode_conus.timeshift_edit.KeyPressFcn= @eeg_shiftcodes_presskey; + EEG_shift_eventcode_conus.timeshift_qestion = uicontrol('Style','pushbutton','Parent',EEG_shift_eventcode_conus.voltage_title,... + 'callback',@timeshift_question,'String','?','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','on','BackgroundColor',[1 1 1]); % 2F + set(EEG_shift_eventcode_conus.voltage_title,'Sizes',[90,-1,60]); + try + sample_rounding= def{3}; + catch + sample_rounding = 'earlier'; + end + if strcmp(sample_rounding,'earlier') + Valueround1 = 1; + Valueround2 = 0; + Valueround3 = 0; + elseif strcmp(sample_rounding,'nearest') + Valueround1 = 0; + Valueround2 = 1; + Valueround3 = 0; + elseif strcmp(sample_rounding,'later') + Valueround1 = 0; + Valueround2 = 0; + Valueround3 = 1; + else + Valueround1 = 1; + Valueround2 = 0; + Valueround3 = 0; + end + %%Round to arlier time sample (recommended) + EEG_shift_eventcode_conus.movewindow_title = uiextras.HBox('Parent', EEG_shift_eventcode_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_shift_eventcode_conus.roundearlier = uicontrol('Style','radiobutton','Parent',EEG_shift_eventcode_conus.movewindow_title,'HorizontalAlignment','left',... + 'callback',@roundearlier,'String','Round to earlier time sample (recommended)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_shift_eventcode_conus.roundearlier.KeyPressFcn= @eeg_shiftcodes_presskey; + uiextras.Empty('Parent', EEG_shift_eventcode_conus.movewindow_title ,'BackgroundColor',ColorB_def); + set(EEG_shift_eventcode_conus.movewindow_title,'Sizes',[270,-1]); + + %%Round to nearest time sample + EEG_shift_eventcode_conus.windowstep_title = uiextras.HBox('Parent', EEG_shift_eventcode_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_shift_eventcode_conus.roundnearest = uicontrol('Style','radiobutton','Parent',EEG_shift_eventcode_conus.windowstep_title,'HorizontalAlignment','left',... + 'callback',@roundnearest,'String','Round to nearest time sample','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + EEG_shift_eventcode_conus.roundnearest.KeyPressFcn= @eeg_shiftcodes_presskey; + uiextras.Empty('Parent',EEG_shift_eventcode_conus.windowstep_title ,'BackgroundColor',ColorB_def); + set(EEG_shift_eventcode_conus.windowstep_title,'Sizes',[260,-1]); + + %%Round to later time sample + EEG_shift_eventcode_conus.eventcode_title = uiextras.HBox('Parent', EEG_shift_eventcode_conus.DataSelBox,'BackgroundColor',ColorB_def); + EEG_shift_eventcode_conus.roundlater = uicontrol('Style','radiobutton','Parent',EEG_shift_eventcode_conus.eventcode_title,'HorizontalAlignment','left',... + 'callback',@roundlater,'String','Round to later time sample','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable',EnableFlag,'BackgroundColor',ColorB_def); % 2F + uiextras.Empty('Parent', EEG_shift_eventcode_conus.eventcode_title ); + set(EEG_shift_eventcode_conus.eventcode_title,'Sizes',[260,-1]); + EEG_shift_eventcode_conus.roundearlier.Value = Valueround1; + EEG_shift_eventcode_conus.roundnearest.Value = Valueround2; + EEG_shift_eventcode_conus.roundlater.Value = Valueround3; + + %%-----------------------Cancel and Run---------------------------- + EEG_shift_eventcode_conus.detar_run_title = uiextras.HBox('Parent', EEG_shift_eventcode_conus.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EEG_shift_eventcode_conus.detar_run_title,'BackgroundColor',ColorB_def); + EEG_shift_eventcode_conus.shiftcodes_cancel = uicontrol('Style', 'pushbutton','Parent',EEG_shift_eventcode_conus.detar_run_title,... + 'String','Cancel','callback',@shiftcodes_cancel,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_shift_eventcode_conus.detar_run_title,'BackgroundColor',ColorB_def); + EEG_shift_eventcode_conus.shiftcodes_run = uicontrol('Style','pushbutton','Parent',EEG_shift_eventcode_conus.detar_run_title,... + 'String','Shift Events','callback',@shiftcodes_run,'FontSize',FontSize_defualt,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', EEG_shift_eventcode_conus.detar_run_title,'BackgroundColor',ColorB_def); + set(EEG_shift_eventcode_conus.detar_run_title,'Sizes',[15 105 30 105 15]); + + set(EEG_shift_eventcode_conus.DataSelBox,'Sizes',[30 30 25 25 25 30]); + estudioworkingmemory('EEGTab_shiftcodes_conus',0); + end + + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------------------edit chans----------------------------------------- + function event_codes_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_shiftcodes_conus',1); + end + +%%--------------------------Browse event codes----------------------------- + function event_codes_browse(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [1 1 1]; + EEG = observe_EEGDAT.EEG; + msgboxText = ''; + if isempty(EEG(1).event) + msgboxText = 'Event for current EEG is empty'; + end + if isempty([EEG(1).event.type]) + msgboxText = 'Event for current EEG is empty'; + end + if ~isempty(msgboxText) + msgboxText = ['Shift Event Codes (Continuous EEG) > Browse event codes:',32,msgboxText]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + [eventtypes histo] = squeezevents(EEG.event); + titlename = 'Select event codes:'; + + Eventcodeold = EEG_shift_eventcode_conus.event_codes_edit.String; + try + Eventcodeold = eval(num2str(Eventcodeold)); %if numeric + catch + Eventcodeold = regexp(Eventcodeold,'(?<=\d)\s(?=\d)|,\s*','split'); %remove commas if exist + Eventcodeold = Eventcodeold(~cellfun('isempty',Eventcodeold)); + end + + try + [C,IA] = ismember_bc2(Eventcodeold,eventtypes); + indxlistb = IA; + if any(IA==0) + indxlistb=1; + else + indxlistb=IA; + end + catch + indxlistb=1; + end + evnetcodes_select = browsechanbinGUI(eventtypes, indxlistb, titlename); + if ~isempty(evnetcodes_select) + if numel(evnetcodes_select)==1 + EventcodeNew = eventtypes{evnetcodes_select}; + else + for ii = 1:numel(evnetcodes_select) + EventcodeNew{ii} = eventtypes{evnetcodes_select(ii)}; + end + end + try + EEG_shift_eventcode_conus.event_codes_edit.String =strjoin(EventcodeNew,','); + catch + EEG_shift_eventcode_conus.event_codes_edit.String = num2str(EventcodeNew); + end + else + return + end + end + +%%-----------------------------volatge------------------------------------- + function timeshift_edit(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [1 1 1]; + + estudioworkingmemory('EEGTab_shiftcodes_conus',1); + timeshiftnew= str2num(Source.String); + if isempty(timeshiftnew) || numel(timeshiftnew)~=1 + msgboxText = ['Shift Event Codes (Continuous EEG) > Time shift meust be one number']; + Source.String = ''; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + end + +%%----------------------Qestion for time shift----------------------------- + function timeshift_question(~,~) + BackERPLABcolor = [1 0.9 0.3]; % yellow + question = ['Positive timeshift shifts right/forward in time\nNegative timeshift shifts left/backward in time']; + title = 'Shift Event Codes (Continuous EEG)'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Yes','Yes'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor); + end + + + + +%%------------------------moving window------------------------------------ + function roundearlier(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [1 1 1]; + + estudioworkingmemory('EEGTab_shiftcodes_conus',1); + EEG_shift_eventcode_conus.roundearlier.Value = 1; + EEG_shift_eventcode_conus.roundnearest.Value = 0; + EEG_shift_eventcode_conus.roundlater.Value = 0; + end + + +%%-------------------------moving step------------------------------------- + function roundnearest(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_shiftcodes_conus',1); + EEG_shift_eventcode_conus.roundearlier.Value = 0; + EEG_shift_eventcode_conus.roundnearest.Value = 1; + EEG_shift_eventcode_conus.roundlater.Value = 0; + end + + +%%------------------Ignore/use--------------------------------------------- + function roundlater(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [1 1 1]; + estudioworkingmemory('EEGTab_shiftcodes_conus',1); + EEG_shift_eventcode_conus.roundearlier.Value = 0; + EEG_shift_eventcode_conus.roundnearest.Value = 0; + EEG_shift_eventcode_conus.roundlater.Value = 1; + end + + +%%%----------------------Preview------------------------------------------- + function shiftcodes_cancel(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Shift Event Codes (Continuous EEG) > Cancel'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [0 0 0]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_shiftcodes_conus',0); + def = estudioworkingmemory('pop_erplabShiftEventCodes'); + if isempty(def) + def = {}; + end + try + eventcodes = def{1}; + catch + eventcodes = ''; + end + + if iscell(eventcodes) + EEG_shift_eventcode_conus.event_codes_edit.String = num2str(strjoin(eventcodes, ',')); + else + EEG_shift_eventcode_conus.event_codes_edit.String = num2str(eventcodes); + end + try + timeshift= def{2}; + catch + timeshift = []; + end + EEG_shift_eventcode_conus.timeshift_edit.String = num2str(timeshift); + try + sample_rounding= def{3}; + catch + sample_rounding = 'earlier'; + end + if strcmp(sample_rounding,'earlier') + Valueround1 = 1; + Valueround2 = 0; + Valueround3 = 0; + elseif strcmp(sample_rounding,'nearest') + Valueround1 = 0; + Valueround2 = 1; + Valueround3 = 0; + elseif strcmp(sample_rounding,'later') + Valueround1 = 0; + Valueround2 = 0; + Valueround3 = 1; + else + Valueround1 = 1; + Valueround2 = 0; + Valueround3 = 0; + end + EEG_shift_eventcode_conus.roundearlier.Value = Valueround1; + EEG_shift_eventcode_conus.roundnearest.Value = Valueround2; + EEG_shift_eventcode_conus.roundlater.Value = Valueround3; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------------Shift events-------------------------------------- + function shiftcodes_run(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 + Source.Enable= 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && eegpanelIndex~=12 + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','Shift Event Codes (Continuous EEG) > Shift events'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [0 0 0]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [0 0 0]; + + estudioworkingmemory('EEGTab_shiftcodes_conus',0); + %%--------Selected EEGsets----------- + EEGArray= estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || min(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) || max(EEGArray(:)) > length(observe_EEGDAT.ALLEEG) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + Eventcodes = EEG_shift_eventcode_conus.event_codes_edit.String; + try + Eventcodes = eval(num2str(Eventcodes)); %if numeric + catch + Eventcodes = regexp(Eventcodes,'(?<=\d)\s(?=\d)|,\s*','split'); %remove commas if exist + Eventcodes = Eventcodes(~cellfun('isempty',Eventcodes)); + end + need_to_flat = 0; + for ec = 1:length(Eventcodes) + try + temp_nums = num2cell(eval(num2str(Eventcodes{ec}))); %evaluate & flatten any numeric expression + Eventcodes{ec} = cellfun(@num2str,temp_nums,'UniformOutput',false); %change to string + need_to_flat = 1; + catch + end + end + if need_to_flat == 1 + Eventcodes =[Eventcodes{:}]; + end + Eventcodes = (Eventcodes); + if isempty(Eventcodes) + msgboxText = ['Shift Event Codes (Continuous EEG) > Shift events: Please define one or more event codes']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + %%timeshift + timeshift = str2num(EEG_shift_eventcode_conus.timeshift_edit.String); + if isempty(timeshift) || numel(timeshift)~=1 + msgboxText = ['Shift Event Codes (Continuous EEG) > Shift events: Timeshift must be one number']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + %% + if EEG_shift_eventcode_conus.roundearlier.Value==1 + rounding = 'earlier'; + elseif EEG_shift_eventcode_conus.roundnearest.Value==1 + rounding = 'nearest'; + elseif EEG_shift_eventcode_conus.roundlater.Value ==1 + rounding = 'later'; + else + rounding = 'earlier'; + end + displayFeedback = 'both'; + displayEEG = 0; + + estudioworkingmemory('pop_erplabShiftEventCodes', ... + {Eventcodes, timeshift, rounding, displayEEG, displayFeedback}); + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Shift Event Codes (Continuous EEG) > Shift events*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n\n']); + %% Run the pop_ command with the user input from the GUI + [EEG, LASTCOM] = pop_erplabShiftEventCodes(EEG, ... + 'Eventcodes' , Eventcodes, ... + 'Timeshift' , timeshift, ... + 'Rounding' , rounding, ... + 'DisplayEEG' , displayEEG, ... + 'DisplayFeedback', displayFeedback, ... + 'History' , 'implicit'); + + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_shift'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=17 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ~=1 || isempty(observe_EEGDAT.EEG.event) || EEGUpdate==1 + EEG_shift_eventcode_conus.event_codes_edit.Enable= 'off'; + EEG_shift_eventcode_conus.event_codes_browse.Enable= 'off'; + EEG_shift_eventcode_conus.timeshift_edit.Enable= 'off'; + EEG_shift_eventcode_conus.roundearlier.Enable= 'off'; + EEG_shift_eventcode_conus.roundnearest.Enable= 'off'; + EEG_shift_eventcode_conus.roundlater.Enable= 'off'; + EEG_shift_eventcode_conus.shiftcodes_run.Enable= 'off'; + EEG_shift_eventcode_conus.shiftcodes_cancel.Enable= 'off'; + if ~isempty(observe_EEGDAT.EEG) && observe_EEGDAT.EEG.trials ~=1 + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.7500 0.7500 0.75000]; + else + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.0500 0.2500 0.5000]; + end + observe_EEGDAT.count_current_eeg=18; + return; + end + + Eegtab_box_shift_eventcodes_conus.Title = 'Shift Event Codes (Continuous EEG)'; + Eegtab_box_shift_eventcodes_conus.ForegroundColor= [1 1 1]; + + EEG_shift_eventcode_conus.event_codes_edit.Enable= 'on'; + EEG_shift_eventcode_conus.event_codes_browse.Enable= 'on'; + EEG_shift_eventcode_conus.timeshift_edit.Enable= 'on'; + EEG_shift_eventcode_conus.roundearlier.Enable= 'on'; + EEG_shift_eventcode_conus.roundnearest.Enable= 'on'; + EEG_shift_eventcode_conus.roundlater.Enable= 'on'; + EEG_shift_eventcode_conus.shiftcodes_run.Enable= 'on'; + EEG_shift_eventcode_conus.shiftcodes_cancel.Enable= 'on'; + EEG_shift_eventcode_conus.shiftcodes_cancel.String = 'Cancel'; + EEG = observe_EEGDAT.EEG; + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.0500 0.2500 0.5000]; + if ~isempty(EEG(1).event) && ~isempty([EEG(1).event.type]) + % [eventtypes histo] = squeezevents(EEG.event); + % Check numeric or string type + if ischar(EEG.event(1).type) + ec_type_is_str = 0; + else + ec_type_is_str = 1; + end + evT = struct2table(EEG.event); + if ec_type_is_str + all_ev = str2double(evT.type); + else + all_ev = evT.type; + end + else + fprintf(['Shift Event Codes (Continuous EEG) > Event for current EEG is empty',32,32,32,32,datestr(datetime('now')),'\n']); + EEG_shift_eventcode_conus.event_codes_edit.Enable= 'off'; + EEG_shift_eventcode_conus.event_codes_browse.Enable= 'off'; + EEG_shift_eventcode_conus.event_codes_edit.String = ''; + EEG_shift_eventcode_conus.shiftcodes_run.Enable= 'off'; + EEG_shift_eventcode_conus.shiftcodes_cancel.Enable= 'off'; + end + observe_EEGDAT.count_current_eeg=18; + end + + +%%--------------press return to execute "Apply"---------------------------- + function eeg_shiftcodes_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('EEGTab_shiftcodes_conus'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + shiftcodes_run(); + estudioworkingmemory('EEGTab_shiftcodes_conus',0); + Eegtab_box_shift_eventcodes_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [0 0 0]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_eeg_panel_change(~,~) + if observe_EEGDAT.Reset_eeg_paras_panel~=14 + return; + end + estudioworkingmemory('EEGTab_shiftcodes_conus',0); + % Eegtab_box_shift_eventcodes_conus.TitleColor= [0.0500 0.2500 0.5000]; + EEG_shift_eventcode_conus.shiftcodes_cancel.BackgroundColor = [1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_cancel.ForegroundColor = [0 0 0]; + EEG_shift_eventcode_conus.shiftcodes_run.BackgroundColor = [ 1 1 1]; + EEG_shift_eventcode_conus.shiftcodes_run.ForegroundColor = [0 0 0]; + EEG_shift_eventcode_conus.event_codes_edit.String =''; + EEG_shift_eventcode_conus.roundearlier.Value = 1; + EEG_shift_eventcode_conus.roundnearest.Value = 0; + EEG_shift_eventcode_conus.roundlater.Value = 0; + EEG_shift_eventcode_conus.timeshift_edit.String = '0'; + observe_EEGDAT.Reset_eeg_paras_panel=15; + end +end + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_suffix_gui.fig b/studio_functions/GUIs/EEG Tab/f_EEG_suffix_gui.fig new file mode 100755 index 00000000..eb908cb2 Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_suffix_gui.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_rename_gui.m b/studio_functions/GUIs/EEG Tab/f_EEG_suffix_gui.m similarity index 65% rename from studio_functions/GUIs/ERP Tab/f_ERP_rename_gui.m rename to studio_functions/GUIs/EEG Tab/f_EEG_suffix_gui.m index ae76509a..f2260852 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_rename_gui.m +++ b/studio_functions/GUIs/EEG Tab/f_EEG_suffix_gui.m @@ -1,35 +1,35 @@ -function varargout = f_ERP_rename_gui(varargin) -% F_ERP_RENAME_GUI MATLAB code for f_ERP_rename_gui.fig -% F_ERP_RENAME_GUI, by itself, creates a new F_ERP_RENAME_GUI or raises the existing +function varargout = f_EEG_suffix_gui(varargin) +% F_EEG_SUFFIX_GUI MATLAB code for f_EEG_suffix_gui.fig +% F_EEG_SUFFIX_GUI, by itself, creates a new F_EEG_SUFFIX_GUI or raises the existing % singleton*. % -% H = F_ERP_RENAME_GUI returns the handle to a new F_ERP_RENAME_GUI or the handle to +% H = F_EEG_SUFFIX_GUI returns the handle to a new F_EEG_SUFFIX_GUI or the handle to % the existing singleton*. % -% F_ERP_RENAME_GUI('CALLBACK',hObject,eventData,handles,...) calls the local -% function named CALLBACK in F_ERP_RENAME_GUI.M with the given input arguments. +% F_EEG_SUFFIX_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_SUFFIX_GUI.M with the given input arguments. % -% F_ERP_RENAME_GUI('Property','Value',...) creates a new F_ERP_RENAME_GUI or raises the +% F_EEG_SUFFIX_GUI('Property','Value',...) creates a new F_EEG_SUFFIX_GUI or raises the % existing singleton*. Starting from the left, property value pairs are -% applied to the GUI before f_ERP_rename_gui_OpeningFcn gets called. An +% applied to the GUI before f_EEG_suffix_gui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application -% stop. All inputs are passed to f_ERP_rename_gui_OpeningFcn via varargin. +% stop. All inputs are passed to f_EEG_suffix_gui_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 f_ERP_rename_gui +% Edit the above text to modify the response to help f_EEG_suffix_gui -% Last Modified by GUIDE v2.5 02-Aug-2022 16:46:06 +% Last Modified by GUIDE v2.5 11-Aug-2023 15:36:09 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... - 'gui_OpeningFcn', @f_ERP_rename_gui_OpeningFcn, ... - 'gui_OutputFcn', @f_ERP_rename_gui_OutputFcn, ... + 'gui_OpeningFcn', @f_EEG_suffix_gui_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_suffix_gui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) @@ -44,16 +44,16 @@ % End initialization code - DO NOT EDIT -% --- Executes just before f_ERP_rename_gui is made visible. -function f_ERP_rename_gui_OpeningFcn(hObject, eventdata, handles, varargin) -% Choose default command line output for f_ERP_rename_gui +% --- Executes just before f_EEG_suffix_gui is made visible. +function f_EEG_suffix_gui_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_suffix_gui try erpname = varargin{1}; - currenterp = varargin{2}; + catch erpname = ''; - currenterp = ''; + end handles.erpnameor = erpname; @@ -65,20 +65,15 @@ function f_ERP_rename_gui_OpeningFcn(hObject, eventdata, handles, varargin) set(handles.menuerp.Children, 'Enable','off'); end -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; -set(handles.gui_chassis,'Name', ['EStudio ' version ' - Rename current ERPset GUI']) +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Add Suffix to EEG GUI']) set(handles.edit_erpname, 'String', erpname); -if isempty(currenterp) - set(handles.current_erp_label,'String', ['No active erpset was found'],... - 'FontWeight','Bold', 'FontSize', 16); -else - ERPNAME = char(strcat('ERPset # ', num2str(currenterp),': (',erpname,')')); - set(handles.current_erp_label,'String',ERPNAME ,... - 'FontWeight','Bold', 'FontSize', 16) -end +set(handles.current_erp_label,'String', ['Enter suffix, which will be added onto the name of each selected EEGset'],... + 'FontWeight','Bold', 'FontSize', 16); + % % % Color GUI % % @@ -100,7 +95,7 @@ function f_ERP_rename_gui_OpeningFcn(hObject, eventdata, handles, varargin) % --- Outputs from this function are returned to the command line. -function varargout = f_ERP_rename_gui_OutputFcn(hObject, eventdata, handles) +function varargout = f_EEG_suffix_gui_OutputFcn(hObject, eventdata, handles) % Get default command line output from handles structure % try @@ -108,8 +103,12 @@ function f_ERP_rename_gui_OpeningFcn(hObject, eventdata, handles, varargin) % catch % disp('ERPset menu was not found...') % end -varargout{1} = handles.output; -delete(handles.gui_chassis); +try + varargout{1} = handles.output; +catch + varargout{1} =''; +end +% delete(handles.gui_chassis); pause(0.1) @@ -138,8 +137,6 @@ function edit_erpname_CreateFcn(hObject, eventdata, handles) % --- Executes on button press in pushbutton_Cancel. function pushbutton_Cancel_Callback(hObject, eventdata, handles) handles.output = []; -beep; -disp('User selected Cancel') % Update handles structure guidata(hObject, handles); uiresume(handles.gui_chassis); @@ -150,14 +147,14 @@ function pushbutton4_okay_Callback(hObject, eventdata, handles) erpname = strtrim(get(handles.edit_erpname, 'String')); if isempty(erpname) - msgboxText = 'You must enter an erpname at least!'; - title = 'EStudio: f_ERP_save_single_file empty erpname'; + msgboxText = 'You must enter a suffix at least!'; + title = 'EStudio: f_ERP_suffix_gui empty suffix.'; errorfound(msgboxText, title); return end -handles.output = {erpname}; +handles.output = erpname; % Update handles structure guidata(hObject, handles); diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_update_gui.fig b/studio_functions/GUIs/EEG Tab/f_EEG_update_gui.fig new file mode 100644 index 00000000..e4ab9ddf Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_EEG_update_gui.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_update_gui.m b/studio_functions/GUIs/EEG Tab/f_EEG_update_gui.m new file mode 100644 index 00000000..3e6f1625 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_update_gui.m @@ -0,0 +1,157 @@ +function varargout = f_EEG_update_gui(varargin) +% F_EEG_UPDATE_GUI MATLAB code for f_EEG_update_gui.fig +% F_EEG_UPDATE_GUI, by itself, creates a new F_EEG_UPDATE_GUI or raises the existing +% singleton*. +% +% H = F_EEG_UPDATE_GUI returns the handle to a new F_EEG_UPDATE_GUI or the handle to +% the existing singleton*. +% +% F_EEG_UPDATE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_EEG_UPDATE_GUI.M with the given input arguments. +% +% F_EEG_UPDATE_GUI('Property','Value',...) creates a new F_EEG_UPDATE_GUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_EEG_update_gui_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_EEG_update_gui_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 f_EEG_update_gui + +% Last Modified by GUIDE v2.5 17-Mar-2024 18:26:39 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_EEG_update_gui_OpeningFcn, ... + 'gui_OutputFcn', @f_EEG_update_gui_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 f_EEG_update_gui is made visible. +function f_EEG_update_gui_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_EEG_update_gui + +try + erpname = varargin{1}; + +catch + erpname = ''; + +end + +handles.erpnameor = erpname; +handles.output = []; +erpmenu = findobj('tag', 'erpsets'); + +if ~isempty(erpmenu) + handles.menuerp = get(erpmenu); + set(handles.menuerp.Children, 'Enable','off'); +end + +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['Estudio ' version ' - Inspect/Label ICs tool GUI']) +% set(handles.edit_erpname, 'String', '_processed'); +handles.current_erp_label.String = 'While you are using the Inspect/Label ICs tool, the main ERPLAB Studio window will be frozen. Click "Okay" when you have closed the Inspect/Label ICs tool.'; + +handles.pushbutton4_okay.String = 'Okay'; + +% +% % Color GUI +% % +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + +% Update handles structure +guidata(hObject, handles); + + +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_EEG_update_gui_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +% try +% set(handles.menuerp.Children, 'Enable','on'); +% catch +% disp('ERPset menu was not found...') +% end +try + varargout{1} = handles.output; +catch + varargout{1} =0; +end +pause(0.1) + + + + + +% --- Executes during object creation, after setting all properties. +function edit_erpname_CreateFcn(hObject, eventdata, handles) + +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = 0; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) + + +handles.output =1; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end diff --git a/studio_functions/GUIs/EEG Tab/f_EEG_utilities_GUI.m b/studio_functions/GUIs/EEG Tab/f_EEG_utilities_GUI.m new file mode 100644 index 00000000..cad19094 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_EEG_utilities_GUI.m @@ -0,0 +1,888 @@ +%%This function is for Utilities. + + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Mar. 2024 + + +function varargout = f_EEG_utilities_GUI(varargin) + +global observe_EEGDAT; +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); + +%---------------------------Initialize parameters------------------------------------ + +Eegtab_utilities = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global Eegtab_box_art_sumop; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + Eegtab_box_art_sumop = uiextras.BoxPanel('Parent', fig, 'Title', 'EEG Utilities',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + Eegtab_box_art_sumop = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEG Utilities',... + 'Padding', 5,'BackgroundColor',ColorB_def); +else + Eegtab_box_art_sumop = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EEG Utilities',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @sumart_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_art_sumop_eeg(FonsizeDefault) +varargout{1} = Eegtab_box_art_sumop; + + function drawui_art_sumop_eeg(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + Eegtab_utilities.DataSelBox = uiextras.VBox('Parent', Eegtab_box_art_sumop,'BackgroundColor',ColorB_def); + + if isempty(observe_EEGDAT.EEG) + EnableFlag = 'off'; + else + EnableFlag = 'on'; + end + + %%Convert to Continuous EEG + Eegtab_utilities.epoch2continuous_title = uiextras.HBox('Parent', Eegtab_utilities.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_utilities.epoch2continuous_title,'BackgroundColor',ColorB_def); + Eegtab_utilities.epoch2continuous = uicontrol('Style', 'pushbutton','Parent',Eegtab_utilities.epoch2continuous_title,... + 'String','Convert to Continuous EEG','callback',@epoch2continuous,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_utilities.epoch2continuous_title,'BackgroundColor',ColorB_def); + set(Eegtab_utilities.epoch2continuous_title, 'Sizes',[15 -1 15]); + + + %%Erase undesired event codes + Eegtab_utilities.rm_eventcodes_title = uiextras.HBox('Parent', Eegtab_utilities.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_utilities.rm_eventcodes_title,'BackgroundColor',ColorB_def); + Eegtab_utilities.rm_eventcodes = uicontrol('Style', 'pushbutton','Parent',Eegtab_utilities.rm_eventcodes_title,... + 'String','Erase Undesired Event Codes','callback',@rm_eventcodes,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_utilities.rm_eventcodes_title,'BackgroundColor',ColorB_def); + set(Eegtab_utilities.rm_eventcodes_title, 'Sizes',[15 -1 15]); + + %%Recover bin descriptor file from EEG + Eegtab_utilities.rc_bdf_title = uiextras.HBox('Parent', Eegtab_utilities.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_utilities.rc_bdf_title,'BackgroundColor',ColorB_def); + Eegtab_utilities.rc_bdf = uicontrol('Style', 'pushbutton','Parent',Eegtab_utilities.rc_bdf_title,... + 'String','Recover Bin Descriptor File from EEG','callback',@rc_bdf,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_utilities.rc_bdf_title,'BackgroundColor',ColorB_def); + set(Eegtab_utilities.rc_bdf_title, 'Sizes',[15 -1 15]); + + %%Reset Event Code Bytes + Eegtab_utilities.event_byte_title = uiextras.HBox('Parent', Eegtab_utilities.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_utilities.event_byte_title,'BackgroundColor',ColorB_def); + Eegtab_utilities.event_byte = uicontrol('Style', 'pushbutton','Parent',Eegtab_utilities.event_byte_title,... + 'String','Reset Event Code Bytes','callback',@event_byte,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_utilities.event_byte_title,'BackgroundColor',ColorB_def); + set(Eegtab_utilities.event_byte_title, 'Sizes',[15 -1 15]); + + %%Delete Spurious Additional Responses + Eegtab_utilities.rmerrors_title = uiextras.HBox('Parent', Eegtab_utilities.DataSelBox, 'Spacing', 5,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', Eegtab_utilities.rmerrors_title,'BackgroundColor',ColorB_def); + Eegtab_utilities.rmerrors = uicontrol('Style', 'pushbutton','Parent',Eegtab_utilities.rmerrors_title,... + 'String','Delete Spurious Additional Responses','callback',@rmerrors,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', Eegtab_utilities.rmerrors_title,'BackgroundColor',ColorB_def); + set(Eegtab_utilities.rmerrors_title, 'Sizes',[15 -1 15]); + set(Eegtab_utilities.DataSelBox,'Sizes',[30 30 30 30 30]); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%------------Convert to Continuous EEG---------------------- + function epoch2continuous(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials ==1 + Source.Enable = 'off'; + return; + end + + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Convert to Continuous EEG'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG) ) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; + estudioworkingmemory('EEGArray',EEGArray); + end + + app = feval('estudio_epoch2contn_gui',[1]); + waitfor(app,'Finishbutton',1); + try + RestoreEvent = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + observe_EEGDAT.eeg_panel_message =2; + return; + end + if isempty(RestoreEvent) + observe_EEGDAT.eeg_panel_message =2; + return; + end + + if isempty(RestoreEvent) || numel(RestoreEvent)~=1 || (RestoreEvent~=0 && RestoreEvent~=1) + RestoreEvent=1; + end + if RestoreEvent==1 + RestoreEventStr = 'on'; + else + RestoreEventStr = 'off'; + end + + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Convert to Continuous EEG*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + if EEG.trials==1 + erroMessage= 'EEG Utilities > Convert to Continuous EEG: cannot work on a continuous EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + setname = EEG.setname; + [EEG, LASTCOM] = pop_epoch2continuous(EEG, 'RestoreEvent',RestoreEventStr, 'History', 'implicit'); + if isempty(LASTCOM) + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + EEG.setname = setname; + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_ep2con'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + estudioworkingmemory('Change2epocheeg',2); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + + +%%-----------------Erase undesired event codes--------------------- + function rm_eventcodes(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials >1 + Source.Enable = 'off'; + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Erase undesired event codes: it has been tested for continuous data only'); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Erase undesired event codes'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET; estudioworkingmemory('EEGArray',EEGArray); + end + + prompt = {'expression (>, <, ==, ~=):'}; + dlg_title = 'Input event-code condition to delete'; + num_lines = 1; + def = estudioworkingmemory('pop_eraseventcodes'); + if isempty(def) + def = {'>255'}; + end + answer = inputvalue(prompt,dlg_title,num_lines,def); + if isempty(answer) + observe_EEGDAT.eeg_panel_message =2; + return + end + expression = answer{1}; + estudioworkingmemory('pop_eraseventcodes', {expression}); + + + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Erase undesired event codes*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + if EEG.trials>1 + erroMessage= 'EEG Utilities > Erase undesired event codes: cannot work on an epoched EEG'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + + if ~isfield(EEG(1), 'event') + erroMessage= 'EEG Utilities > Erase undesired event codes: did not find EEG.event field'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + + if ~isfield(EEG(1).event, 'type') + erroMessage= 'EEG Utilities > Erase undesired event codes: did not find EEG.event.type field'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + + if~isfield(EEG(1).event, 'latency') + erroMessage= 'EEG Utilities > Erase undesired event codes: did not find EEG.event.latency field'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + + if ischar(EEG(1).event(1).type) + erroMessage= 'EEG Utilities > Erase undesired event codes: only works with numeric event codes. We recommend to use Create EEG Eventlist - Basic first'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + + [EEG, LASTCOM] = pop_eraseventcodes( EEG, expression, 'History', 'implicit'); + + fprintf([LASTCOM]); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( [repmat('-',1,100) '\n']); + end + + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_delevents'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Erase undesired event codes'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + +%%-------------------Recover bin descriptor file from EEG--------------------- + function rc_bdf(Source,~) + if isempty(observe_EEGDAT.EEG) || ~isfield(observe_EEGDAT.EEG,'EVENTLIST') || isempty(observe_EEGDAT.EEG.EVENTLIST) + Source.Enable = 'off'; + msgboxText = ['EEG Utilities > Recover bin descriptor file from EEG: Your EVENTLIST is empty or does not exist']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Recover bin descriptor file from EEG'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + + for Numofeeg = 1:numel(EEGArray) + EEG = observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Recover bin descriptor file from EEG*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + [EEG, LASTCOM] = pop_bdfrecovery(EEG); + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + observe_EEGDAT.ALLEEG(EEGArray(Numofeeg)) = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + fprintf( [repmat('-',1,100) '\n']); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + observe_EEGDAT.count_current_eeg=26; + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Recover bin descriptor file from EEG'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + +%%-------------------Reset Event Code Bytes------------------- + function event_byte(Source,~) + if isempty(observe_EEGDAT.EEG) || observe_EEGDAT.EEG.trials >1 + Source.Enable = 'off'; + erroMessage= 'EEG Utilities > Reset Event Code Bytes: only works for continuous dataset'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Reset Event Code Bytes'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + %%call GUI to set parameters + answer = setcodebitGUI; + if isempty(answer) + return + end + newvalue2 = 0; + todo = answer{1}; + + + ALLEEG_out = []; + ALLEEG = observe_EEGDAT.ALLEEG; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Reset Event Code Bytes*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + if EEG.trials>1 + erroMessage= 'EEG Utilities > Reset Event Code Bytes: only works for continuous dataset'; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return; + end + + if ischar(EEG.event(1).type) + erroMessage= ['EEG Utilities > Reset Event Code Bytes: Your event codes are not numeric for',32,EEG.setname]; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(erroMessage,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + fprintf( [repmat('-',1,100) '\n']); + return + end + if strcmpi(todo, 'all') + bitindex = 1:16; + newvalue = 0; + [EEG, LASTCOM ] = pop_setcodebit(EEG, bitindex, newvalue, 'History', 'gui'); + elseif strcmpi(todo, 'lower') + bitindex = 1:8; + newvalue = 0; + [EEG, LASTCOM ] = pop_setcodebit(EEG, bitindex, newvalue, 'History', 'gui'); + elseif strcmpi(todo, 'upper') + bitindex = 9:16; + newvalue = 0; + [EEG, LASTCOM ] = pop_setcodebit(EEG, bitindex, newvalue, 'History', 'gui'); + else + if ~isempty(answer{2}) + bitindex = answer{2}; + newvalue = 0; + [EEG, LASTCOM ] = pop_setcodebit(EEG, bitindex, newvalue, 'History', 'gui'); + if Numofeeg==1 + eegh(LASTCOM); + end + end + if ~isempty(answer{3}) + bitindex = answer{3}; + newvalue = 1; + [EEG, LASTCOM ] = pop_setcodebit(EEG, bitindex, newvalue, 'History', 'gui'); + if Numofeeg==1 + eegh(LASTCOM); + end + end + end + if strcmpi(todo, 'all') || strcmpi(todo, 'lower') || strcmpi(todo, 'upper') + if Numofeeg==1 + eegh(LASTCOM); + end + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + end + + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_resetbyte'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Reset Event Code Bytes'); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + end + +%%------------------Delete Spurious Additional Responses------------------- + function rmerrors(Source,~) + if isempty(observe_EEGDAT.EEG) + Source.Enable = 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_EEG_proces_messg','EEG Utilities > Delete Spurious Additional Responses'); + observe_EEGDAT.eeg_panel_message =1; %%Marking for the procedure has been started. + + EEGArray = estudioworkingmemory('EEGArray'); + if isempty(EEGArray) || any(EEGArray(:) > length(observe_EEGDAT.ALLEEG)) || any(EEGArray(:) <1) + EEGArray = observe_EEGDAT.CURRENTSET;estudioworkingmemory('EEGArray',EEGArray); + end + [stim_codes, resp_codes] = gui_remove_response_mistakes(observe_EEGDAT.EEG); + if isempty(stim_codes) || isempty(resp_codes) || ~isnumeric(stim_codes) || ~isnumeric(resp_codes) + msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Please enter valid "Stimulus" and "Response" events (i.e., numeric array)']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; %%Marking for the procedure has been started. + return; + end + + % try + % stim_codes = num2str(stim_codes); %if numeric eval(num2str(stim_codes)); + % catch + % stim_codes = regexp(stim_codes,'(?<=\d)\s(?=\d)|,\s*','split'); %remove commas if exist + % stim_codes = stim_codes(~cellfun('isempty',stim_codes)); + % end + % need_to_flat = 0; + % for ec = 1:length(stim_codes) + % try + % temp_nums = num2cell(eval(num2str(stim_codes{ec}))); %evaluate & flatten any numeric expression + % stim_codes{ec} = cellfun(@num2str,temp_nums,'UniformOutput',false); %change to string + % need_to_flat = 1; + % catch + % end + % end + % if need_to_flat == 1 + % stim_codes =[stim_codes{:}]; + % for ii = 1:length(stim_codes) + % stim_codes1(ii) = str2num(stim_codes{ii}); + % end + % stim_codes = unique(stim_codes1); + % end + % stim_codes = (stim_codes); + % + % + % if isempty(stim_codes) + % msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Some of Stimulus event types are invalid']; + % titlNamerro = 'Warning for EEG Tab'; + % estudio_warning(msgboxText,titlNamerro); + % observe_EEGDAT.eeg_panel_message =2; + % return; + % end + % + % evT = struct2table(observe_EEGDAT.EEG.event); + % all_ev = evT.type; + % all_ev_unique = unique(all_ev); + % try + % all_ev_unique(isnan(all_ev_unique)) = []; + % catch + % end + % + % try + % [IA1,stim_codes] = f_check_eventcodes(stim_codes,all_ev_unique); + % catch + % IA1 = 0; + % end + % if IA1==0 + % msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Some of Stimulus event types are invalid']; + % titlNamerro = 'Warning for EEG Tab'; + % estudio_warning(msgboxText,titlNamerro); + % observe_EEGDAT.eeg_panel_message =2; + % return; + % end + % + % %%Response event types + % try + % resp_codes = eval(num2str(resp_codes)); %if numeric + % catch + % resp_codes = regexp(resp_codes,'(?<=\d)\s(?=\d)|,\s*','split'); %remove commas if exist + % resp_codes = resp_codes(~cellfun('isempty',resp_codes)); + % end + % need_to_flat = 0; + % for ec = 1:length(resp_codes) + % try + % temp_nums = num2cell(eval(num2str(resp_codes{ec}))); %evaluate & flatten any numeric expression + % resp_codes{ec} = cellfun(@num2str,temp_nums,'UniformOutput',false); %change to string + % need_to_flat = 1; + % catch + % end + % end + % if need_to_flat == 1 + % resp_codes =[resp_codes{:}]; + % for ii = 1:length(resp_codes) + % resp_codes1(ii) = str2num(resp_codes{ii}); + % end + % resp_codes = unique(resp_codes1); + % end + % resp_codes = (resp_codes); + % + % if isempty(resp_codes) + % msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Some of Response event types are invalid']; + % titlNamerro = 'Warning for EEG Tab'; + % estudio_warning(msgboxText,titlNamerro); + % observe_EEGDAT.eeg_panel_message =2; + % return; + % end + % try + % [IA2,resp_codes] = f_check_eventcodes(resp_codes,all_ev_unique); + % catch + % IA2 = 0; + % end + % + % if IA2==0 + % msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Some of Response event types are invalid']; + % titlNamerro = 'Warning for EEG Tab'; + % estudio_warning(msgboxText,titlNamerro); + % observe_EEGDAT.eeg_panel_message =2; + % return; + % end + ALLEEG = observe_EEGDAT.ALLEEG; + ALLEEG_out = []; + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG(EEGArray(Numofeeg)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Delete Spurious Additional Responses (Continuous EEG) > Run*',32,32,32,32,datestr(datetime('now')),'\n']); + + fprintf(['Your current EEGset(No.',num2str(EEGArray(Numofeeg)),'):',32,EEG.setname,'\n']); + if ischar(EEG.event(1).type) + ec_type_is_str = 0; + else + ec_type_is_str = 1; + end + evT = struct2table(EEG.event); + + all_ev = evT.type; + all_ev_unique = unique(all_ev); + try + all_ev_unique(isnan(all_ev_unique)) = []; + catch + end + try + [IA1,stim_codes] = f_check_eventcodes(stim_codes,all_ev_unique); + catch + IA1 = 0; + end + if IA1==0 + msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Some of Stimulus event types are invalid']; + estudioworkingmemory('f_EEG_proces_messg',msgboxText); + observe_EEGDAT.eeg_panel_message =4; %%Marking for the procedure has been started. + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + try + [IA2,resp_codes] = f_check_eventcodes(resp_codes,all_ev_unique); + catch + IA2 = 0; + end + + if IA2==0 + msgboxText = ['EEG Utilities > Delete Spurious Additional Responses: Some of Response event types are invalid']; + fprintf( [repmat('-',1,100) '\n']); + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_EEGDAT.eeg_panel_message =2; + return; + end + + [~,EEG, LASTCOM] = pop_remove_response_mistakes(ALLEEG,EEG,EEGArray(Numofeeg),stim_codes,resp_codes); + if isempty(LASTCOM) + fprintf( [repmat('-',1,100) '\n']); + observe_EEGDAT.eeg_panel_message =2; + return; + end + fprintf([LASTCOM,'\n']); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + [ALLEEG_out,~,~,LASTCOM] = pop_newset(ALLEEG_out, EEG, length(ALLEEG_out), 'gui', 'off'); + fprintf( [repmat('-',1,100) '\n']); + if Numofeeg==1 + eegh(LASTCOM); + end + end%%end for loop of subjects + Save_file_label = 0; + Answer = f_EEG_save_multi_file(ALLEEG_out,1:numel(EEGArray),'_rmerr'); + if isempty(Answer) + observe_EEGDAT.eeg_panel_message =2; + return; + end + if ~isempty(Answer{1}) + ALLEEG_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numofeeg = 1:numel(EEGArray) + EEG = ALLEEG_out(Numofeeg); + checkfileindex = checkfilexists([EEG.filepath,filesep,EEG.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(EEG.filename); + EEG.filename = [file_name,'.set']; + [EEG, LASTCOM] = pop_saveset(EEG,'filename', EEG.filename, 'filepath',EEG.filepath,'check','on'); + EEG = eegh(LASTCOM, EEG); + if Numofeeg==1 + eegh(LASTCOM); + end + else + EEG.filename = ''; + EEG.saved = 'no'; + EEG.filepath = ''; + end + [ALLEEG,~,~,LASTCOM] = pop_newset(ALLEEG, EEG, length(ALLEEG), 'gui', 'off'); + end + + observe_EEGDAT.ALLEEG = ALLEEG; + try + Selected_EEG_afd = [length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1:length(observe_EEGDAT.ALLEEG)]; + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG)-numel(EEGArray)+1; + catch + Selected_EEG_afd = length(observe_EEGDAT.ALLEEG); + observe_EEGDAT.CURRENTSET = length(observe_EEGDAT.ALLEEG); + end + observe_EEGDAT.EEG = observe_EEGDAT.ALLEEG(observe_EEGDAT.CURRENTSET); + estudioworkingmemory('EEGArray',Selected_EEG_afd); + assignin('base','EEG',observe_EEGDAT.EEG); + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + observe_EEGDAT.count_current_eeg=1; + observe_EEGDAT.eeg_panel_message =2; + end + +%%--------Settting will be modified if the selected was changed------------ + function count_current_eeg_change(~,~) + if observe_EEGDAT.count_current_eeg ~=25 + return; + end + EEGUpdate = estudioworkingmemory('EEGUpdate'); + if isempty(EEGUpdate) || numel(EEGUpdate)~=1 || (EEGUpdate~=0 && EEGUpdate~=1) + EEGUpdate = 0; estudioworkingmemory('EEGUpdate',0); + end + if isempty(observe_EEGDAT.EEG) || EEGUpdate==1 + Eegtab_utilities.epoch2continuous.Enable = 'off'; + Eegtab_utilities.event_byte.Enable = 'off'; + Eegtab_utilities.rm_eventcodes.Enable = 'off'; + Eegtab_utilities.rc_bdf.Enable = 'off'; + Eegtab_utilities.rmerrors.Enable = 'off'; + observe_EEGDAT.count_current_eeg=26; + return; + end + if observe_EEGDAT.EEG.trials>1 + Eegtab_utilities.epoch2continuous.Enable = 'on'; + Eegtab_utilities.rmerrors.Enable = 'off'; + else + Eegtab_utilities.epoch2continuous.Enable = 'off'; + Eegtab_utilities.rmerrors.Enable = 'on'; + end + + if observe_EEGDAT.EEG.trials==1 + Eegtab_utilities.rm_eventcodes.Enable = 'on'; + Eegtab_utilities.event_byte.Enable = 'on'; + else + Eegtab_utilities.rm_eventcodes.Enable = 'off'; + Eegtab_utilities.event_byte.Enable = 'off'; + end + Eegtab_utilities.rc_bdf.Enable = 'on'; + observe_EEGDAT.count_current_eeg=26; + end + + +%%--------------------------------check event codes------------------------ + function [IA,resp_codes]= f_check_eventcodes(resp_codes,all_ev_unique) + IA = 0; + for ii = 1:length(resp_codes) + for kk = 1:length(all_ev_unique) + if isnumeric(resp_codes(ii)) && isnumeric(all_ev_unique(kk)) + if resp_codes(ii) == all_ev_unique(kk) + IA = IA +1; + end + elseif (ischar(resp_codes(ii)) || iscell(resp_codes(ii)) )&& (ischar(all_ev_unique(kk)) || iscell(all_ev_unique(kk)) ) + try + stim_codesstr=erase(resp_codes{ii}," "); + all_ev_uniquestr= erase(all_ev_unique{kk}, " "); + catch + stim_codesstr=resp_codes{ii}; + all_ev_uniquestr= all_ev_unique{kk}; + end + if strcmpi(stim_codesstr,all_ev_uniquestr) + resp_codes{ii} = all_ev_unique{kk}; + IA = IA +1; + end + end + end + end + end + +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/f_change_chan_name_GUI.fig b/studio_functions/GUIs/EEG Tab/f_change_chan_name_GUI.fig new file mode 100644 index 00000000..349ca5f7 Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_change_chan_name_GUI.fig differ diff --git a/studio_functions/GUIs/EEG Tab/f_change_chan_name_GUI.m b/studio_functions/GUIs/EEG Tab/f_change_chan_name_GUI.m new file mode 100644 index 00000000..fb66f816 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_change_chan_name_GUI.m @@ -0,0 +1,174 @@ +function varargout = f_change_chan_name_GUI(varargin) +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_change_chan_name_GUI_OpeningFcn, ... + 'gui_OutputFcn', @f_change_chan_name_GUI_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 + +%----------------------------------------------------------------------------------- +function f_change_chan_name_GUI_OpeningFcn(hObject, eventdata, handles, varargin) +handles.output = []; + +try + listname = varargin{1}; +catch + for ii = 1:100 + listname{ii,1} = num2str(ii); + end +end +for ii = 1:numel(listname) + listname1{ii,1}= listname{ii}; +end +listname = listname1; + +try + listnameOlder = varargin{2}; +catch + listnameOlder = listname; +end + +for ii = 1:numel(listnameOlder) + listnameOlder1{ii,1}= listnameOlder{ii}; +end +listnameOlder = listnameOlder1; + +try + titlename = varargin{3}; +catch + erplab_default_values; + version = erplabver; + titlename = ['Estudio',32,version,32,'Change Channel Name']; +end + +[Numrows,Numcolumns] = size(listname); +for Numofrows = 1:Numrows + for Numofcolumns = 1:2 + try + if Numofcolumns==2 + GridinforData{Numofrows,Numofcolumns} = char(listnameOlder{Numofrows,1}); + else + GridinforData{Numofrows,Numofcolumns} = char(listname{Numofrows}); + end + catch + GridinforData{Numofrows,Numofcolumns} = 'None'; + end + end +end + + + +ColumnEditable =[0,1]; +ColumnWidth = {300 300}; +ColumnName{1,1} = char(['Current Name']); +ColumnName{1,2} = char(['New Name']); +columFormat = {'char','char'}; + +for Numofrow = 1:Numrows + RowsName{Numofrow} = char(['Ch',num2str(Numofrow)]); +end + +% +% Color GUI +% +handles = painterplab(handles); +% [version reldate,ColorBdef,ColorF_def,errorColorF_def,ColorBviewer_def] = geterplabstudiodef; +% set(handles.gui_chassis, 'Color', ColorBviewer_def); +% +% Set font size +% +handles = setfonterplab(handles); + +% Update handles structure +handles = setfonterplabestudio(handles); + + + +guidata(hObject, handles); +set(handles.uitable1_layout,'Data',GridinforData); +handles.uitable1_layout.ColumnEditable = logical(ColumnEditable); +handles.uitable1_layout.ColumnWidth = ColumnWidth; +handles.uitable1_layout.ColumnName = ColumnName; +handles.uitable1_layout.RowName = RowsName; +handles.uitable1_layout.ColumnFormat = columFormat; +set(handles.gui_chassis, 'Name', titlename, 'WindowStyle','modal'); +handles.uitable1_layout.BackgroundColor = [1 1 1]; +% UIWAIT makes f_change_chan_name_GUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + +%----------------------------------------------------------------------------------- +function varargout = f_change_chan_name_GUI_OutputFcn(hObject, eventdata, handles) +try + varargout{1} = handles.output; +catch + varargout{1} = []; +end +% The figure can be deleted now +delete(handles.gui_chassis); +pause(0.1) + +%---------------------------------------------------------------------------------- +% function listbox_list_Callback(hObject, eventdata, handles) +% +% %---------------------------------------------------------------------------------- +% function listbox_list_CreateFcn(hObject, eventdata, handles) +% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) +% set(hObject,'BackgroundColor','white'); +% end + +%---------------------------------------------------------------------------------- +function pushbutton_cancel_Callback(hObject, eventdata, handles) +handles.output = []; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); +%---------------------------------------------------------------------------------- +function pushbutton_ok_Callback(hObject, eventdata, handles) + +Data = get(handles.uitable1_layout, 'Data'); + +for ii = 1:size(Data,1) + if isempty(Data{ii,2}) + Chanlabels{ii,1} = 'None'; + else + Chanlabels{ii,1} = Data{ii,2} ; + end +end + +handles.output = Chanlabels; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.gui_chassis); + +%---------------------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + % The GUI is still in UIWAIT, us UIRESUME + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + +% --- Executes on button press in pushbutton_default. +function pushbutton_default_Callback(hObject, eventdata, handles) +Data = handles.uitable1_layout.Data; +for ii = 1:size(Data,1) + Data{ii,2}=Data{ii,1}; +end +set(handles.uitable1_layout,'Data',Data); + diff --git a/studio_functions/GUIs/EEG Tab/f_editchan_gui.mlapp b/studio_functions/GUIs/EEG Tab/f_editchan_gui.mlapp new file mode 100644 index 00000000..c19e8e3d Binary files /dev/null and b/studio_functions/GUIs/EEG Tab/f_editchan_gui.mlapp differ diff --git a/studio_functions/GUIs/EEG Tab/f_estudio_chan_frontback_left_right.m b/studio_functions/GUIs/EEG Tab/f_estudio_chan_frontback_left_right.m new file mode 100644 index 00000000..944521e4 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_estudio_chan_frontback_left_right.m @@ -0,0 +1,166 @@ +%%This function is to reorder the channel orders acrodding to +%%front-back/left-right + + + + +function [chanindexnew,errormessg] = f_estudio_chan_frontback_left_right(chanlocs) +chanindexnew = []; + +if nargin < 1 + help f_estudio_chan_frontback_left_right; + return; +end +errormessg = ''; +if isempty(chanlocs) + errormessg = 'The input is empty'; + return; +end +invalidchan = []; +[eloc, labels, theta, radius, indices] = readlocs( chanlocs); +[checkindex,invalidchan] = checktheta(theta); +checkindex1 = checktheta(radius); +if checkindex || checkindex1 + msgboxText = ['Please do channel location first before display the wave with front-back/left-right ']; + title = 'Estudio: f_estudio_chan_frontback_left_right() inputs'; + errorfound(sprintf(msgboxText), title); + return +end + +namesfield = fieldnames(chanlocs); +[C,IA] = ismember_bc2('X',namesfield); +if IA==0 + errormessg = 'Please check the chanlocs for the current EEG'; + return; +end + + +validechan = setdiff([1:length(chanlocs)],invalidchan); + +labelsvalid = labels(validechan); + +[Simplabels,simplabelIndex,SamAll] = Simplelabels(labelsvalid); + +[xchanpos,ychanpos] = get_chanxylocs(chanlocs(validechan)); + + +[Bxpos,Ixpos] = sort(xchanpos,'descend'); +ychanpos = ychanpos(Ixpos); +simplabelIndexNew = simplabelIndex(Ixpos); +chanindexnew = Ixpos; +simplabelIndexNew_uq = unique(simplabelIndexNew,'stable'); +% if numel(unique(simplabelIndexNew))~=1 +oldindex = 0; +count = 0; +validechanNew = []; +for jj = 1:length(simplabelIndexNew_uq) + if jj>length(simplabelIndexNew_uq) + break; + end + if oldindex~=simplabelIndexNew_uq(jj) + oldindex=simplabelIndexNew_uq(jj); + [xpos,ypos]= find(simplabelIndexNew == simplabelIndexNew_uq(jj)); + if ~isempty(ypos) + count = count+1; + [x_ychanposcell,y_ychanposcell] = sort(ychanpos(ypos),'descend'); + Ixpos(ypos) = Ixpos(ypos(y_ychanposcell)); + labelscell = labelsvalid(Ixpos(ypos)); + validechanNew = [validechanNew validechan(Ixpos(ypos))]; + end + end +end + +%%--------------------------check HEOG & VEOG------------------------------ +chanindexnew=[invalidchan,validechanNew]; +[C,IA] = ismember_bc2('HEOG',labels); +if IA~=0 + [xpos,ypos] = find(chanindexnew==IA); + chanindexnew(ypos) = []; + chanindexnew = [IA,chanindexnew]; +end + +[C,IA] = ismember_bc2('VEOG',labels); +if IA~=0 + [xpos,ypos] = find(chanindexnew==IA); + chanindexnew(ypos) = []; + chanindexnew = [IA,chanindexnew]; +end + +% else +% msgboxText = ['There is only one type for channel label and we cannot do for front-back/left-right']; +% title = 'Estudio: f_estudio_chan_frontback_left_right() inputs'; +% errorfound(sprintf(msgboxText), title); +% chanindexnew = [1:length(chanlocs)]; +% end + + +end + + + + +%%check if there are channel locations +function [checkindex,invalidchan ]= checktheta(theta) +checkindex = 0; +count = 0; +invalidchan = []; +for ii = 1:length(theta) + if isnan(theta(ii)) + count = count+1; + invalidchan(count) = ii; + end +end +if count == length(theta) + checkindex = 1; +end +end + + +function [Simplabels,simplabelIndex,SamAll] = Simplelabels(labels) +labelsrm = ['[']; +for ii=1:1000 + labelsrm = char([labelsrm,',',num2str(ii)]); +end +labelsrm = char([labelsrm,',z,Z]']); + +SamAll = 0; +for ii = 1:length(labels) + labelcell = labels{ii}; + labelcell(regexp(labelcell,labelsrm))=[]; + labelsNew{ii} = labelcell; +end + +%%get the simple +[~,X,Z] = unique(labelsNew,'stable'); +Simplabels = labelsNew(X); +if length(Simplabels)==1 + SamAll = 1; +end + +simplabelIndex = zeros(1,length(labels)); +count = 0; +for jj = 1:length(Simplabels) + for kk = 1:length(labelsNew) + if strcmp(Simplabels{jj},labelsNew{kk}) + count = count+1; + simplabelIndex(kk) = jj; + end + end +end +end + + +%%getx, and y positions +function [xposchan,yposchan] = get_chanxylocs(chanlocs) + +namesfield = fieldnames(chanlocs); +[C,IAx] = ismember_bc2('X',namesfield); +[C,IAy] = ismember_bc2('Y',namesfield); + +xposchan = nan(1,length(chanlocs)); +yposchan = nan(1,length(chanlocs)); +for ii = 1:length(chanlocs) + xposchan(ii) = getfield(chanlocs(ii),'X'); + yposchan(ii) = getfield(chanlocs(ii),'Y'); +end +end diff --git a/studio_functions/GUIs/EEG Tab/f_estudio_iclabel.m b/studio_functions/GUIs/EEG Tab/f_estudio_iclabel.m new file mode 100644 index 00000000..b84ccace --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/f_estudio_iclabel.m @@ -0,0 +1,174 @@ +%%This function is to change the title of inputdlg3 so that the users are +%%easy to know which eegset that they are seeing when using ICLabel + + +%%Thanks for EEGLAB developers + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Sep. 2023 + + +function EEG = f_estudio_iclabel(EEG,CURRENTEEGSET) + +if nargin < 1 + help f_estudio_iclabel; + return; +end; + +if nargin < 2 + CURRENTEEGSET = 1; % default +end; + +%%Label independent components using ICLabel + +try + icversion=inputdlg3('prompt', {'Select which icversion of ICLabel to use:', 'Default (recommended)|Lite|Beta'}, ... + 'style', {'text', 'popupmenu'}, ... + 'default', {[], 1}, ... + 'title', ['eegset',32,num2str(CURRENTEEGSET),': ICLabel']); + icversion = icversion{2}; +catch + icversion = 0; +end +switch icversion + case 0 + icversion = 'default'; + case 1 + icversion = 'default'; + case 2 + icversion = 'lite'; + case 3 + icversion = 'beta'; +end +EEG = iclabel(EEG, icversion);%%somthing goes wrong +LASTCOM1 = ['EEG = pop_iclabel(EEG, ''' icversion ''');']; +EEG = eegh(LASTCOM1, EEG); +fprintf([LASTCOM1,'\n']); + + +%%----------------See common properties of many ICs----------------------- +typecomp = 0; +PLOTPERFIG = 35; +promptstr = { fastif(typecomp,'Channel indices to plot:','Component indices to plot:') ... + 'Spectral options (see spectopo() help):','Erpimage options (see erpimage() help):' ... + [' Draw events over scrolling ' fastif(typecomp,'channel','component') ' activity']}; +if typecomp + inistr = { ['1:' int2str(length(EEG.chanlocs))] ['''freqrange'', [2 ' num2str(min(80, EEG.srate/2)) ']'] '' 1}; +else + inistr = { ['1:' int2str(size(EEG.icawinv, 2))] ['''freqrange'', [2 ' num2str(min(80, EEG.srate/2)) ']'] '' 1}; +end +stylestr = {'edit', 'edit', 'edit', 'checkbox'}; + +% labels when available +if ~typecomp && isfield(EEG.etc, 'ic_classification') + classifiers = fieldnames(EEG.etc.ic_classification); + if ~isempty(classifiers) + iclabel_ind = find(strcmpi(classifiers, 'ICLabel')); + promptstr = [promptstr {classifiers}]; + inistr = [inistr {fastif(isempty(iclabel_ind), 1, iclabel_ind)}]; + stylestr = [stylestr {'popupmenu'}]; + end +end + +try + result = inputdlg3( 'prompt', promptstr,'style', stylestr, ... + 'default', inistr, 'title', ['eegset',32,num2str(CURRENTEEGSET),': View comp. properties -- pop_viewprops']); +catch + result = []; +end +if size( result, 1 ) == 0 + return; end + +chanorcomp = eval( [ '[' result{1} ']' ] ); +spec_opt = eval( [ '{' result{2} '}' ] ); +erp_opt = eval( [ '{' result{3} '}' ] ); + +scroll_event = result{4}; +if ~typecomp && isfield(EEG.etc, 'ic_classification') && ~isempty(classifiers) + classifiers = fieldnames(EEG.etc.ic_classification); + classifier_name = classifiers{result{5}}; +end + +if length(chanorcomp) > PLOTPERFIG + ButtonName=questdlg2(strvcat(['More than ' int2str(PLOTPERFIG) fastif(typecomp,' channels',' components') ' so'],... + 'this function will pop-up several windows'), 'Confirmation', 'Cancel', 'OK','OK'); + if ~isempty( strmatch(lower(ButtonName), 'cancel')), return; end; +end; +if ~exist('ICLabel','dir') && ~exist('eegplugin_iclabel', 'file') + fprintf(2, 'Warning: ICLabel default plugin missing (probably due to downloading zip file from Github). Install manually.\n'); + EEG = []; + return; +end +try + LASTCOM1 = pop_viewprops( EEG, 0, chanorcomp, spec_opt, erp_opt, scroll_event, classifier_name); +catch + pathName = which ('eegplugin_iclabel'); + pathName = pathName(1:findstr(pathName,'eegplugin_iclabel.m')-1); + % add all ERPLAB subfolders + addpath(genpath(pathName)); + try + LASTCOM1 = pop_viewprops( EEG, 0, chanorcomp, spec_opt, erp_opt, scroll_event, classifier_name); + catch + EEG = []; + end +end +EEG = eegh(LASTCOM1, EEG); +fprintf([LASTCOM1,'\n']); +eegh(LASTCOM1); +end + + + + +%%---------This subfunction is copied from the function "pop_iclabel"------ +%%---------in eeglab. Please update this if there is any changes in-------- +%%---------the original function------------------------------------------- + +function [result, userdat, strhalt, resstruct] = inputdlg3( varargin) + +if nargin < 2 + help inputdlg3; + return; +end; + +% check input values +% ------------------ +[opt addopts] = finputcheck(varargin, { 'prompt' 'cell' [] {}; + 'style' 'cell' [] {}; + 'default' 'cell' [] {}; + 'tag' 'cell' [] {}; + 'tooltip','cell' [] {}}, 'inputdlg3', 'ignore'); +if isempty(opt.prompt), error('The ''prompt'' parameter must be non empty'); end; +if isempty(opt.style), opt.style = cell(1,length(opt.prompt)); opt.style(:) = {'edit'}; end; +if isempty(opt.default), opt.default = cell(1,length(opt.prompt)); opt.default(:) = {0}; end; +if isempty(opt.tag), opt.tag = cell(1,length(opt.prompt)); opt.tag(:) = {''}; end; + +% creating GUI list input +% ----------------------- +uilist = {}; +uigeometry = {}; +outputind = ones(1,length(opt.prompt)); +for index = 1:length(opt.prompt) + if strcmpi(opt.style{index}, 'edit') + uilist{end+1} = { 'style' 'text' 'string' opt.prompt{index} }; + uilist{end+1} = { 'style' 'edit' 'string' opt.default{index} 'tag' opt.tag{index} 'tooltip' opt.tag{index}}; + uigeometry{index} = [2 1]; + else + uilist{end+1} = { 'style' opt.style{index} 'string' opt.prompt{index} 'value' opt.default{index} 'tag' opt.tag{index} 'tooltip' opt.tag{index}}; + uigeometry{index} = [1]; + end; + if strcmpi(opt.style{index}, 'text') + outputind(index) = 0; + end; +end; + +w = warning('off', 'MATLAB:namelengthmaxexceeded'); +[tmpresult, userdat, strhalt, resstruct] = inputgui('uilist', uilist,'geometry', uigeometry, addopts{:}); +warning(w.state, 'MATLAB:namelengthmaxexceeded') % warning suppression added by luca +result = cell(1,length(opt.prompt)); +result(find(outputind)) = tmpresult; +end diff --git a/studio_functions/GUIs/EEG Tab/pop_ERP_save_trial_information.m b/studio_functions/GUIs/EEG Tab/pop_ERP_save_trial_information.m new file mode 100644 index 00000000..f383a9b5 --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/pop_ERP_save_trial_information.m @@ -0,0 +1,292 @@ +%write trial information to .text or .xls file + + + +function erpcom = pop_ERP_save_trial_information(ALLERP, varargin) + +erpcom = ''; +if nargin<1 + help pop_ERP_save_trial_information + return +end + +if nargin==1 + if isempty(ALLERP) + msgboxText = ['pop_ERP_save_trial_information: ALLERP is empty!']; + titlNamerro = 'Error for pop_ERP_save_trial_information'; + estudio_warning(msgboxText,titlNamerro); + return; + end + ERPArray = [1:length(ALLERP)]; + binArray = [1:ALLERP(1).nbin]; + + erpcom = pop_ERP_save_trial_information(ALLERP, 'ERPArray',ERPArray,'binArray',binArray,'History', 'gui'); + pause(0.01); + return +end + +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('ALLERP'); + +p.addParamValue('ERPArray', [], @isnumeric); % +p.addParamValue('binArray', [], @isnumeric); +p.addParamValue('History', 'gui', @ischar); % history from scripting + +p.parse(ALLERP, varargin{:}); +p_Results = p.Results; + +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end + + +BackERPLABcolor = [1 0.9 0.3]; % ERPLAB main window background +question = 'In order to see your summary, What would you like to do?'; +title = 'Artifact detection summary'; +oldcolor = get(0,'DefaultUicontrolBackgroundColor'); +set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) +button = questdlg(question, title,'Save in a .txt file','Save in a .xls file', 'Cancel','Cancel'); +set(0,'DefaultUicontrolBackgroundColor',oldcolor); + +if strcmpi(button,'Save in a .txt file') + write_spreadsheet=1; + formatname = {'*.txt'}; +elseif strcmpi(button,'Save in a .xls file') + write_spreadsheet=2; + formatname = {'*.xls';'*.xlsx'}; +else + return; +end + +ERPtooltype = erpgettoolversion('tooltype'); +if strcmpi(ERPtooltype,'EStudio') + pathstr= estudioworkingmemory('EEG_save_folder'); + if isempty(pathstr) + pathstr = pwd; + end +else + pathstr = pwd; +end + +namedef ='ERP_Trial_information'; +[erpfilename, erppathname, indxs] = uiputfile(formatname, ... + ['Export trial information'],... + fullfile(pathstr,namedef)); +if isequal(erpfilename,0) + return +end +if isequal(erpfilename,0) + return +end + +[pathstr, erpfilename, ext] = fileparts(erpfilename) ; +if write_spreadsheet==1 + ext = '.txt'; +else + if indxs==1 + ext = '.xls'; + elseif indxs==2 + ext = '.xlsx'; + else + ext = '.xls'; + end +end + +erpFilename = char(strcat(erppathname,erpfilename,ext)); +delete(erpFilename); + +qERParray = p_Results.ERPArray; +ERPArray = qERParray; +if isempty(qERParray) || any(qERParray(:)>length(ALLERP)) || any(qERParray(:)<1) + qERParray = 1:length(ALLERP); +end + +qbinArray = p_Results.binArray; +binArray = qbinArray; + +for Numoferp = 1:numel(qERParray) + + ERP = ALLERP(qERParray(Numoferp)); + if isempty(qbinArray) || any(qbinArray(:)>ERP.nbin) || any(qbinArray(:)<1) + qbinArray = [1:ERP.nbin]; + end + histoflags = fliplr(ERP.ntrials.arflags); + %%txt file + if write_spreadsheet==1 + if Numoferp==1 + fileID = fopen(erpFilename,'w+'); + end + fprintf(fileID,'%s\n','*'); + fprintf(fileID,'%s\n','**'); + columName1{1,1} = ['Name:',32,ERP.erpname]; + fprintf(fileID,'%s\n\n\n',columName1{1,:}); + + %%Table title + formatSpec2 =['%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\n']; + columName2 = {'Bin', 'Total trials','Included trials', 'Rejected trials', 'Invalid trials','F2','F3','F4','F5','F6','F7','F8'}; + fprintf(fileID,formatSpec2,columName2{1,:}); + for ii = 1:length(qbinArray) + data = []; + try + data{1,1} = [num2str(qbinArray(ii)),'.',ERP.bindescr{qbinArray(ii)}]; + data{1,2} = [num2str(ERP.ntrials.accepted(qbinArray(ii))+ERP.ntrials.rejected(qbinArray(ii))+ERP.ntrials.invalid(qbinArray(ii)))]; + data{1,3} = [num2str(ERP.ntrials.accepted(qbinArray(ii)))]; + data{1,4} = [num2str(ERP.ntrials.rejected(qbinArray(ii)))]; + data{1,5} = [num2str(ERP.ntrials.invalid(qbinArray(ii)))]; + data{1,6} = num2str(histoflags(ii,2)); + data{1,7} = num2str(histoflags(ii,3)); + data{1,8} = num2str(histoflags(ii,4)); + data{1,9} = num2str(histoflags(ii,5)); + data{1,10} = num2str(histoflags(ii,6)); + data{1,11} = num2str(histoflags(ii,7)); + data{1,12} = num2str(histoflags(ii,8)); + catch + data{1,1} = ''; + data{1,2} = ''; + data{1,3} = ''; + data{1,4} = ''; + data{1,5} = ''; + data{1,6} = ''; + data{1,7} = ''; + data{1,8} = ''; + data{1,9} = ''; + data{1,10} = ''; + data{1,11} = ''; + data{1,12} = ''; + end + fprintf(fileID,formatSpec2,data{1,:}); + end + + if Numoferp~=length(qERParray) + data1{1,1} = ''; + data1{1,2} = ''; + data1{1,3} = ''; + data1{1,4} = ''; + data1{1,5} = ''; + data1{1,6} = '';%%F2 + data1{1,7} = '';%%F3 + data1{1,8} = ''; + data1{1,9} = ''; + data1{1,10} = ''; + data1{1,11} = ''; + data1{1,12} = ''; + formatSpec3 =['%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t',32,'%s\t','%s\n\n\n\n\n\n']; + fprintf(fileID,formatSpec3,data1{1,:}); + + end + end + + %%xls file + if write_spreadsheet==2 + data = []; + binname = ''; + columName2 = {ERP.erpname,'Total trials','Included trials', 'Rejected trials', 'Invalid trials','F2','F3','F4','F5','F6','F7','F8'}; + for ii = 1:length(qbinArray) + try + data(ii,1) = [ERP.ntrials.accepted(qbinArray(ii))+ERP.ntrials.rejected(qbinArray(ii))+ERP.ntrials.invalid(qbinArray(ii))]; + data(ii,2) = [ERP.ntrials.accepted(qbinArray(ii))]; + data(ii,3) = [ERP.ntrials.rejected(qbinArray(ii))]; + data(ii,4) = [ERP.ntrials.invalid(qbinArray(ii))]; + data(ii,5) = histoflags(ii,2);%%F2 + data(ii,6) = histoflags(ii,3);%%F3 + data(ii,7) = histoflags(ii,4); + data(ii,8) = histoflags(ii,5); + data(ii,9) = histoflags(ii,6); + data(ii,10) = histoflags(ii,7); + data(ii,11) = histoflags(ii,8); + catch + data(ii,1) = []; + data(ii,2) = []; + data(ii,3) = []; + data(ii,4) = []; + data(ii,5) = [];%%F2 + data(ii,6) = [];%%F3 + data(ii,7) = []; + data(ii,8) = []; + data(ii,9) = []; + data(ii,10) = []; + data(ii,11) = []; + end + try + binname{ii,1} = ERP.bindescr{qbinArray(ii)}; + catch + binname{ii,1} = 'none'; + end + end + if Numoferp==1 + end + sheet_label_T = table(columName2); + sheetname = char(ERP.erpname); + if length(sheetname)>31 + sheetname = sheetname(1:31); + end + writetable(sheet_label_T,erpFilename,'Sheet',Numoferp,'Range','A1','WriteVariableNames',false,'Sheet',sheetname,"AutoFitWidth",false); + xls_d = table(binname,data); + writetable(xls_d,erpFilename,'Sheet',Numoferp,'Range','A2','WriteVariableNames',false,'Sheet',sheetname,"AutoFitWidth",false); % write data + end +end + +if write_spreadsheet==1 + fclose(fileID); +end +disp(['A new file for trial information was created at ' erpFilename '']) + + + +skipfields = {'ALLERP', 'History'}; + +if isempty(ERPArray) + skipfields = [skipfields,{'ERPArray'}]; +end + +if isempty(binArray) + skipfields = [skipfields,{'binArray'}]; +end + +fn = fieldnames(p.Results); +erpcom = sprintf( 'erpcom = pop_ERP_save_trial_information( %s', 'ALLERP'); +for q=1:length(fn) + fn2com = fn{q}; + if ~ismember_bc2(fn2com, skipfields) + fn2res = p.Results.(fn2com); + if ~isempty(fn2res) + if ischar(fn2res) + if ~strcmpi(fn2res,'off') && ~strcmpi(fn2res,'no') + erpcom = sprintf( '%s, ''%s'', ''%s''', erpcom, fn2com, fn2res); + end + else + erpcom = sprintf( '%s, ''%s'', %s', erpcom, fn2com, vect2colon(fn2res,'Repeat','on')); + end + end + end +end +erpcom = sprintf( '%s );', erpcom); + +% get history from script. ERP +switch shist + case 1 % from GUI + displayEquiComERP(erpcom); + case 2 % from script + for i=1:length(ALLERP) + ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); + end + case 3 + % implicit + %for i=1:length(ALLERP) + % ALLERP(i) = erphistory(ALLERP(i), [], erpcom, 1); + %end + %fprintf('%%Equivalent command:\n%s\n\n', erpcom); + otherwise %off or none + erpcom = ''; + return +end + +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/pop_blceeg.m b/studio_functions/GUIs/EEG Tab/pop_blceeg.m new file mode 100644 index 00000000..07e8200e --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/pop_blceeg.m @@ -0,0 +1,285 @@ +% PURPOSE : Removes epoched EEG baseline +% +% FORMAT : +% +% EEG = pop_blceeg(EEG, blc) +% +% EEG - EEGLAB structure +% blc - window for baseline correction in msec or either a string like 'pre', 'post', or 'all' +% (strings with the baseline interval also works. e.g. '-300 100') +% +% Example : +% >> EEG = pop_blceeg( EEG , [-200 800], [-100 0]); +% >> EEG = pop_blceeg( EEG , [-200 800], '-100 0'); +% >> EEG = pop_blceeg( EEG , [-400 2000], 'post'); +% +% INPUTS : +% +% EEG - EEGLAB structure +% blc - window for baseline correction in msec or either a string like +% 'none', 'pre', 'post', or 'whole' +% +% OUTPUTS : +% +% - updated (output) EEGset +% +% *** This function is part of EStudio Toolbox *** +% Author: Guanghui Zhang +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + +%b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b +% +% EStudio Toolbox +% Created by Guanghui Zhang and Steven Luck +% Center for Mind and Brain, University of California, Davis, +% ghzhang@ucdavis.edu, sjluck@ucdavis.edu + + +function [EEG, LATCOM] = pop_blceeg(EEG, varargin) +LATCOM = ''; +if nargin < 1 + help pop_blceeg + return +end +% +% Gui is working... +% +if nargin==1 + title_msg = 'EStudio: pop_blceeg() error:'; + if isempty(EEG) + if isempty(EEG) + msgboxText = 'No EEGset was found!'; + errorfound(msgboxText, title_msg); + return + end + end + if isempty(EEG.data) + msgboxText = 'cannot work with an empty EEGset!'; + errorfound(msgboxText, title_msg); + return + end + + if EEG.trials ==1 + msgboxText = 'cannot work with a continous EEGset!'; + errorfound(msgboxText, title_msg); + end + + titlegui = 'Baseline Correction for EEGset'; + answer = blcerpGUI(EEG, titlegui ); % open GUI + + if isempty(answer) + return + end + blcorr = answer{1}; + + ChanArray = answer{2}; + + % + % Somersault + % + [EEG, LATCOM] = pop_blceeg(EEG, 'Baseline', blcorr,'ChanArray',ChanArray,... + 'Saveas', 'off', 'History', 'gui'); + return +end + +% +% Parsing inputs +% +p = inputParser; +p.FunctionName = mfilename; +p.CaseSensitive = false; +p.addRequired('EEG'); +% option(s) +p.addParamValue('Baseline', 'pre'); % EEGset index or input file +p.addParamValue('ChanArray', [], @isnumeric); % 'on', 'off' +p.addParamValue('Saveas', 'off', @ischar); % 'on', 'off' +p.addParamValue('History', 'script', @ischar); % history from scripting +p.parse(EEG, varargin{:}); + +ChanArray = p.Results.ChanArray; +if isempty(ChanArray) || any(ChanArray(:)>EEG.nbchan) || any(ChanArray(:)<1) + ChanArray = [1:EEG.nbchan]; +end + + +kktime = 1000; + +blcorr = p.Results.Baseline; +if strcmpi(p.Results.History,'implicit') + shist = 3; % implicit +elseif strcmpi(p.Results.History,'script') + shist = 2; % script +elseif strcmpi(p.Results.History,'gui') + shist = 1; % gui +else + shist = 0; % off +end +if ismember_bc2({p.Results.Saveas}, {'on','yes'}) + issaveas = 1; +else + issaveas = 0; +end + + +title_msg = 'EStudio: pop_blceeg() error:'; + +if isempty(EEG.data) + msgboxText = 'cannot work with an empty EEGset!'; + errorfound(msgboxText, title_msg); + return +end + +if EEG.trials ==1 + msgboxText = 'cannot work with a continous EEGset!'; + errorfound(msgboxText, title_msg); +end + + + +if ischar(blcorr) + if ~ismember_bc2(lower(blcorr),{'all' 'pre' 'post' 'none'}) + internum = str2double(blcorr); + if length(internum) ~=2 + msgboxText = ['pop_blceeg will not be performed.\n'... + 'Check out your baseline correction values']; + title = 'EStudio: pop_blceeg() base line'; + errorfound(sprintf(msgboxText), title); + return + end + if internum(1)>=internum(2)|| internum(1)>EEG.xmax || internum(2)=blcorr(2)|| blcorr(1)>EEG.xmax*kktime || blcorr(2)> pop_eegplot( EEG ) % Scroll EEG channel data. Allow marking for rejection via +% % button 'Update Marks' but perform no actual data rejection. +% % Do not show or use marks from previous visual inspections +% % or from semi-auotmatic rejection. +% >> pop_eegplot( EEG, icacomp, superpose, reject ); +% +% Graphic interface: +% "Add to previously marked rejections" - [edit box] Either YES or NO. +% Command line equivalent: 'superpose'. +% "Reject marked trials" - [edit box] Either YES or NO. Command line +% equivalent 'reject'. +% Inputs: +% EEG - input EEG dataset +% icacomp - type of rejection 0 = independent components; +% 1 = data channels. {Default: 1 = data channels} +% superpose - 0 = Show new marks only: Do not color the background of data portions +% previously marked for rejection by visual inspection. Mark new data +% portions for rejection by first coloring them (by dragging the left +% mouse button), finally pressing the 'Update Marks' or 'Reject' +% buttons (see 'reject' below). Previous markings from visual inspection +% will be lost. +% 1 = Show data portions previously marked by visual inspection plus +% data portions selected in this window for rejection (by dragging +% the left mouse button in this window). These are differentiated +% using a lighter and darker hue, respectively). Pressing the +% 'Update Marks' or 'Reject' buttons (see 'reject' below) +% will then mark or reject all the colored data portions. +% {Default: 0, show and act on new marks only} +% reject - 0 = Mark for rejection. Mark data portions by dragging the left mouse +% button on the data windows (producing a background coloring indicating +% the extent of the marked data portion). Then press the screen button +% 'Update Marks' to store the data portions marked for rejection +% (stretches of continuous data or whole data epochs). No 'Reject' button +% is present, so data marked for rejection cannot be actually rejected +% from this EEGPLOT window. +% 1 = Reject marked trials. After inspecting/selecting data portions for +% rejection, press button 'Reject' to reject (remove) them from the EEG +% dataset (i.e., those portions plottted on a colored background. +% {default: 1, mark for rejection only} +% +% topcommand - Input deprecated. Kept for compatibility with other function calls +% Outputs: +% Modifications are applied to the current EEG dataset at the end of the +% EEGPLOT call, when the user presses the 'Update Marks' or 'Reject' button. +% NOTE: The modifications made are not saved into EEGLAB history. As of v4.2, +% events contained in rejected data portions are remembered in the EEG.urevent +% structure (see EEGLAB tutorial). +% +% Author: Arnaud Delorme, CNL / Salk Institute, 2001 +% +% See also: EEGLAB, EEGPLOT, POP_REJEPOCH + +% Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu +% +% This file is part of EEGLAB, see http://www.eeglab.org +% for the documentation and details. +% +% Redistribution and use in source and binary forms, with or without +% modification, are permitted provided that the following conditions are met: +% +% 1. Redistributions of source code must retain the above copyright notice, +% this list of conditions and the following disclaimer. +% +% 2. 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. +% +% 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 HOLDER 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. + +% 01-25-02 reformated help & license -ad +% 03-07-02 added srate argument to eegplot call -ad +% 03-27-02 added event latency recalculation for continuous data -ad + +function com = pop_eegplot_estudio( EEG, icacomp, superpose, reject, topcommand, varargin) + +com = ''; +if nargin < 1 + help pop_eegplot; + return; +end; +if nargin < 2 + icacomp = 1; +end; +if nargin < 3 + superpose = 0; +end +if nargin < 4 + reject = 1; +end +if icacomp == 0 + if isempty( EEG.icasphere ) + disp('Error: you must run ICA first'); return; + end +end + +if nargin < 3 && EEG.trials > 1 && ~isempty(EEG.event) + + % which set to save + % ----------------- + uilist = { { 'style' 'text' 'string' 'Add to previously marked rejections? (checked=yes)'} , ... + { 'style' 'checkbox' 'string' '' 'value' 1 } , ... + { 'style' 'text' 'string' 'Reject marked trials? (checked=yes)'} , ... + { 'style' 'checkbox' 'string' '' 'value' 0 } }; + result = inputgui( { [ 2 0.2] [ 2 0.2]} , uilist, 'pophelp(''pop_eegplot'');', ... + fastif(icacomp==0, 'Manual component rejection -- pop_eegplot()', ... + 'Reject epochs by visual inspection -- pop_eegplot()')); + size_result = size( result ); + if size_result(1) == 0 return; end + + if result{1}, superpose=1; end + if ~result{2}, reject=0; end + +end + +if EEG.trials > 1 && ~isempty(EEG.reject) + if icacomp == 1 macrorej = 'EEG.reject.rejmanual'; + macrorejE = 'EEG.reject.rejmanualE'; + else macrorej = 'EEG.reject.icarejmanual'; + macrorejE = 'EEG.reject.icarejmanualE'; + end + if icacomp == 1 + elecrange = [1:EEG.nbchan]; + else elecrange = [1:size(EEG.icaweights,1)]; + end + colrej = EEG.reject.rejmanualcol; + rej = eval(macrorej); + rejE = eval(macrorejE); + + eeg_rejmacro; % script macro for generating command and old rejection arrays + +else % case of a single trial (continuous data) + %if icacomp, + % command = ['if isempty(EEG.event) EEG.event = [eegplot2event(TMPREJ, -1)];' ... + % 'else EEG.event = [EEG.event(find(EEG.event(:,1) ~= -1),:); eegplot2event(TMPREJ, -1, [], [0.8 1 0.8])];' ... + % 'end;']; + %else, command = ['if isempty(EEG.event) EEG.event = [eegplot2event(TMPREJ, -1)];' ... + % 'else EEG.event = [EEG.event(find(EEG.event(:,1) ~= -2),:); eegplot2event(TMPREJ, -1, [], [0.8 1 0.8])];' ... + % 'end;']; + %end + %if reject + % command = ... + % [ command ... + % '[EEG.data EEG.xmax] = eegrej(EEG.data, EEG.event(find(EEG.event(:,1) < 0),3:end), EEG.xmax-EEG.xmin);' ... + % 'EEG.xmax = EEG.xmax+EEG.xmin;' ... + % 'EEG.event = EEG.event(find(EEG.event(:,1) >= 0),:);' ... + % 'EEG.icaact = [];' ... + % 'EEG = eeg_checkset(EEG);' ]; + eeglab_options; % changed from eeglaboptions 3/30/02 -sm + if reject == 0, command = []; + else + command = ... + [ '[EEGTMP LASTCOM] = eeg_eegrej(EEG,eegplot2event(TMPREJ, -1));' ... + 'if ~isempty(LASTCOM),' ... + ' EEG = eegh(LASTCOM, EEG);' ... + 'end;' ... + 'clear EEGTMP tmpcom;' ]; + if nargin < 4 + res = questdlg2( strvcat('Mark stretches of continuous data for rejection', ... + 'by dragging the left mouse button. Click on marked', ... + 'stretches to unmark. When done,press "REJECT" to', ... + 'excise marked stretches (Note: Leaves rejection', ... + 'boundary markers in the event table).'), 'Warning', 'Cancel', 'Continue', 'Continue'); + if strcmpi(res, 'Cancel'), return; end + end + end + eegplotoptions = { 'events', EEG.event }; + if ~isempty(EEG.chanlocs) && icacomp + eegplotoptions = { eegplotoptions{:} 'eloc_file', EEG.chanlocs }; + end +end + +if EEG.nbchan > 100 + disp('pop_eegplot() note: Baseline subtraction disabled to speed up display'); + eegplotoptions = { eegplotoptions{:} 'submean' 'off' }; +end + +%%changed by GH Oct. 2023 +try + command = erase(command,"eeglab('redraw');"); + command = erase(command,"[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);"); + rmstr = strcat("warndlg2(strvcat('Epochs (=trials) marked for rejection have been noted.','To actually reject these epochs, use the same menu item to','inspect/reject data and select",' "','Reject marked trials','" '," checkbox'), 'Warning');"); + command = erase(command,rmstr); +catch + command = strrep(command,"eeglab('redraw');",''); + command = strrep(command,"[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);",''); + rmstr = strcat("warndlg2(strvcat('Epochs (=trials) marked for rejection have been noted.','To actually reject these epochs, use the same menu item to','inspect/reject data and select",' "','Reject marked trials','" '," checkbox'), 'Warning');"); + command = strrep(command,rmstr,''); +end + + +if icacomp == 1 + eegplot( EEG.data, 'srate', EEG.srate, 'title', ['Scroll channel activities -- eegplot() -- ', EEG.setname], ... + 'limits', [EEG.xmin EEG.xmax]*1000 , 'command', command, eegplotoptions{:}, varargin{:}); +else + tmpdata = eeg_getdatact(EEG, 'component', [1:size(EEG.icaweights,1)]); + eegplot( tmpdata, 'srate', EEG.srate, 'title', ['Scroll component activities -- eegplot() -- ', EEG.setname], ... + 'limits', [EEG.xmin EEG.xmax]*1000 , 'command', command, eegplotoptions{:}, varargin{:}); +end +com = [ com sprintf('pop_eegplot( EEG, %d, %d, %d);', icacomp, superpose, reject) ]; +return; diff --git a/studio_functions/GUIs/EEG Tab/str2html_v01/license.txt b/studio_functions/GUIs/EEG Tab/str2html_v01/license.txt new file mode 100755 index 00000000..418ee0db --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/str2html_v01/license.txt @@ -0,0 +1,27 @@ +Copyright (c) 2014, Robert Cumming +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 the 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. diff --git a/studio_functions/GUIs/EEG Tab/str2html_v01/str2html.m b/studio_functions/GUIs/EEG Tab/str2html_v01/str2html.m new file mode 100755 index 00000000..9eb81f0c --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/str2html_v01/str2html.m @@ -0,0 +1,341 @@ +%%dowload from https://www.mathworks.com/matlabcentral/fileexchange/46755-str2html?s_tid=srchtitle + + +% str2html Convert input str to html format for use in uicontrols/menus +% +% uimenus and some uicontrols accept html format strings, e.g. pushbutton, +% listbox, popupmenu (this list is controlled by Mathworks) +% +% This function allows you to easily create html strings to display in +% the controls. +% +% The function works by passing in a str and arg pairs: +% +% htmlStr = str2html ( yourChar, P-V pairs ) +% +% yourChar 'a valid char string'; +% +% Valid arg pairs are: +% +% 'bold' true | ( false ) % bold format +% 'italic' true | ( false ) % italic format +% 'underline' true | ( false ) % underline format +% 'fontsize' 8 % size in int +% 'fontsize' '+2' % increment size from default +% 'colour' 'black' % colour of text $ +% 'color' 'black' % same as colour $ +% 'fontname' 'MS Sans Serif' % font name +% 'superscript' '' % any superscript text ^ +% 'subscript' '' % any subscript text ^ +% 'bgcolour' 'white' % background colour $ +% 'bgcolor' 'white' % same as bgcolour $ +% 'prefix' '' % add your own prefix hmtl* +% 'suffix' '' % add your own suffix hmtl* +% 'userWarn' true | false % flag to display warnings +% +% $ Colour and color are the same thing - only the different spelling is +% managed. User can input colour as 'NAME' or as 'HEXCODE' +% +% ^ If sub & super script are added - then the subscript is added first. +% +% * The idea of prefix and suffix is to add your own start and end tags +% to the html code that is generated - if only one is added a warning +% will be shown unless you add 'userWarn', false +% +% For combing HTML format strings into one larger string, e.g. multi +% format on one line or multiple lines use: +% +% yourCell{1} = str2html ( 'line1', pararm, value.... ); +% yourCell{2} = str2html ( 'line2', pararm, value.... ); +% yourCell{N} = str2html ( 'line2', pararm, value.... ); +% +% htmlStr = str2html ( yourCell, joinFormat ) +% +% yourCell cell array of HTML formatted strings +% joinFormat '\n' '\r' '
                            ' % html line break "
                            " +% ' ' % html space: " " +% 'yourString' % any ohter string provided by you. +% +% The code uses persistent variables so you can change the defaults +% use following syntax. Note : No output. +% +% str2html ( '*default*', 'bold', true ) +% str2html ( '*default*', 'fontname', 'Courier New' ); +% +% Special case for colour codes. e.g change default orange too: +% str2html ( '*default*', 'colour:orange', '#FFBF40' ); +% +% This will change the defaults for THIS MATLAB session ONLY. +% +% Reset all the changes made by the user. +% str2html ( '*reset*' ) +% +% Examples: +% +% str = str2html ( 'YOUR TEXT', 'bold', 1, 'italic', 1, 'underline', 1, ... +% 'fontsize', 5, 'colour', 'red', 'fontname', 'Courier New' ) +% +% str = str2html ( 'Change Background Colour', 'bgcolor', 'red', ... +% 'superscript', 'SuperScript', 'subscript', 'SUB', ... +% 'fontsize', '+2' ) +% +% % This adds a bullet point to your string. +% str = str2html ( 'Add your own HTML code:', ... +% 'prefix', '
                          • ', 'suffix', '
                          • ' ); +% +% +% For multi format lines or multiple lines use multiple calls: +% line1{1} = str2html ( 'line #1', 'bold', 1, 'fontname', 'Courier New' ); +% line1{2} = str2html ( 'No format' ); +% line1{3} = str2html ( 'underline', 'underline', 1 ); +% line1{4} = str2html ( 'italic', 'italic', 1, 'subscript', 'mySub' ); +% line1{5} = str2html ( 'finish', 'colour', 'green', ... +% 'superscript', 'mySuper!!' ); +% str{1} = str2html ( line1, ' ' ) +% str{2} = str2html ( 'line #2', 'italic', 1, 'color', 'red' ); +% str2 = str2html ( str, '\n' ); +% h = uicontrol ( 'style', 'listbox' ); +% set(h,'tooltipString', str2 ); +% +% see also test_str2html +% +% DEVELOPER NOTE: This file uses mlock +% +% Copyright Robert Cumming, rcumming @ matpi.com +% website: www.matpi.com +% +% $Id: str2html.m 30 2014-05-26 18:32:02Z Bob $ + +function output = str2html ( varargin ) + % lock the file so that persistent variable remains in memory. + mlock + + if nargin == 1 && nargout == 0 && strcmp ( varargin{1}, '-version' ) + fprintf ( '%s Version: $Id: str2html.m 30 2014-05-26 18:32:02Z Bob $\n', mfilename ); + return + end + + % check for the special cases for changing defaults or resetting factory values + if nargout == 0 + if strcmp ( varargin{1}, '*default*' ) + for ii=2:2:nargin + GetDefaults ( varargin{ii}, varargin{ii+1} ); + end + elseif strcmp ( varargin{1}, '*reset*' ) + GetDefaults ( '*reset*' ); + end + return + end + + % for combining multiple HTML together either on one line or on multiple lines + if iscell ( varargin{1} ) + output = CombineStrings ( varargin{:} ); + return + end + + % manage american/british spelling.... make all color and colour be colour.... + if nargin > 2 + index = strcmp ( varargin(2:2:end), 'color' ); + if any ( index ) + index = find ( index == 1 ); + if length ( index ) > 1 + error ( 'str2html:MultipleColour', 'User defined colour multiple times' ); + end + varargin{index*2} = 'colour'; + end + index = strcmp ( varargin(2:2:end), 'bgcolor' ); + if any ( index ) + index = find ( index == 1 ); + if length ( index ) > 1 + error ( 'str2html:MultipleBgColour', 'User defined bgcolour multiple times' ); + end + varargin{index*2} = 'bgcolour'; + end + end + + % process the input arguments + [str, options] = ProcessInputArguments ( varargin{:} ); + + % get the defaults. + [defaults, defChanged, colCode] = GetDefaults(); + + % start to build the output string + output = ''; + if ( options.bold ); output = sprintf ( '%s', output ); end + if ( options.underline ); output = sprintf ( '%s', output ); end + if ( options.italic ); output = sprintf ( '%s', output ); end + + % section for including font formattting + incFont = false; + fontstr = '', output, fontstr ); + end + + if isempty ( options.prefix ) && isempty ( options.suffix ) || ...% no prefix or suffix + ~isempty ( options.prefix ) && ~isempty ( options.suffix ) % no prefix or suffix + else + if options.userWarn + warning ( 'str2html:prefixSuffixPair', 'User did not provided prefix and suffix pair' ) + end + end + + if ~isempty ( options.prefix ) + output = sprintf ( '%s%s', output, options.prefix ); + end + + % add user string to the output + output = sprintf ( '%s%s', output, str ); + + % add any subscript to the END of the string (subscript first) + if ~isempty ( options.subscript ) + output = sprintf ( '%s%s', output, options.subscript ); + end + % add any superscript to the END of the string. + if ~isempty ( options.superscript ) + output = sprintf ( '%s%s', output, options.superscript ); + end + + if ~isempty ( options.suffix ) + output = sprintf ( '%s%s', output, options.suffix ); + end + + % close font tag + if incFont + output = sprintf ( '%s
                            ', output ); + end + + % close any other formatting + if ( options.italic ); output = sprintf ( '%s', output ); end + if ( options.underline ); output = sprintf ( '%s', output ); end + if ( options.bold ); output = sprintf ( '%s', output ); end + % close html + output = sprintf ( '%s', output ); +end +%-------------------------------------------------------------------------- +% str2html defaults - includes persistent variable to remember between calls +%-------------------------------------------------------------------------- +function [output, defChanged, colCode]= GetDefaults( force, item ) + persistent options defaultChanged colourCode + % 1st time into function or when user "resets" + if isempty ( options ) || nargin == 1 && strcmp ( force, '*reset*' ) + options.bold = false; + options.underline = false; + options.italic = false; + options.colour = 'black'; + options.superscript = ''; + options.subscript = ''; + options.fontname = 'MS Sans Serif'; + options.fontsize = 8; + options.bgcolour = 'white'; + options.prefix = ''; + options.suffix = ''; + options.userWarn = true; + defaultChanged = struct; + colourCode = struct; + end + % this for the user changing the internal defaults + if nargin == 2 + if isfield ( options, force ) + options.(force) = item; + defaultChanged.(force) = true; + else + % changing the default colour - e.g. change "orange" to be a HEX representation of that color + if length ( force ) > 7 && strcmp ( force(1:7), 'colour:' ) + colourCode.(force(8:end)) = item; + elseif length ( force ) > 6 && strcmp ( force(1:6), 'color:' ) + colourCode.(force(7:end)) = item; + else + error ( 'str2html:SetDefaults', 'User requested to set non-valid default value' ); + end + end + end + % copy persistent variables to output + output = options; + defChanged = defaultChanged; + colCode = colourCode; +end +%-------------------------------------------------------------------------- +% Process the input arguments against the defaults +%-------------------------------------------------------------------------- +function [str, options] = ProcessInputArguments ( varargin ) + options = GetDefaults(); + str = varargin{1}; + if mod(nargin,2) == 0 + error ( 'str2html:invalidArgsIn', 'user must input str and then arg pairs' ); + end + for ii=2:2:nargin + % check control is a valid option + if ~isfield ( options, varargin{ii} ) + error ( 'str2html:invalidOption', 'User specifed invalid option %s', varargin{ii} ); + end + options.(varargin{ii}) = varargin{ii+1}; + end +end +%-------------------------------------------------------------------------- +% Function for combining multiple html strings together +%-------------------------------------------------------------------------- +function output = CombineStrings ( varargin ) + nStr = length(varargin{1}); + for ii=1:nStr + if length ( varargin{1}{ii} ) > 6 && ( strcmpi ( varargin{1}{ii}(1:6), '' ) ) && ( strcmpi ( varargin{1}{ii}(end-6:end), '' ) ) + if ii==1 + output = varargin{1}{ii}(1:end-7); + elseif ii == nStr + output = strcat ( output, varargin{1}{ii}(7:end) ); + else + str = varargin{1}{ii}; + str(end-6:end) = []; + str(1:6) = []; + output = strcat ( output, str ); + end + else + error ( 'str2html:ConcatString', 'Input string not in HTML format' ) + end + % if user specified a str join code and its not the last string - add it here. + if nargin == 2 && ii ~= nStr + switch varargin{2} + case { '\n' '\r', '
                            ' } % line break + output = strcat ( output, '
                            ' ); + case ' ' % space + output = strcat ( output, ' ' ); + otherwise % any other + output = strcat ( output, varargin{2} ); + end + end + end +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG Tab/str2html_v01/test_str2html.m b/studio_functions/GUIs/EEG Tab/str2html_v01/test_str2html.m new file mode 100755 index 00000000..da28847e --- /dev/null +++ b/studio_functions/GUIs/EEG Tab/str2html_v01/test_str2html.m @@ -0,0 +1,85 @@ +% test_str2html - test script to run a simple and more complex tests +% +% 1st test will create a GUI which has 2 uicontrols with HTML format text +% in this test each line has the same format +% +% 2nd test will create a GUI with 3 uicontrols, where each line can have +% a combination of html formatting +% +% see also str2html +% +% Copyright Robert Cumming, rcumming @ matpi.com +% website: www.matpi.com +% +% $Id: test_str2html.m 30 2014-05-26 18:32:02Z Bob $ +function test_str2html ( varargin ); + if nargin == 1 && nargout == 0 && strcmp ( varargin{1}, '-version' ) + fprintf ( '%s Version: $Id: test_str2html.m 30 2014-05-26 18:32:02Z Bob $\n', mfilename ); + return + end + home + h = test_str2html_simpleFormatting; + uiwait ( h ); + test_str2html_combinations; + %% + fprintf ( 'If you run: \n str2html ( ''*default*'', ''bold'', true );\n\n and then run this function again you will see the impact of changing the default settings\n\n' ); + +end +function hFig = test_str2html_simpleFormatting + str{1} = str2html ( 'A list Box', 'color', 'green' ); + str{2} = str2html ( 'with different', 'color', 'red', 'bold', true ); + str{3} = str2html ( 'items which', 'bgcolor', 'yellow', 'underline', true ); + str{4} = str2html ( 'all have', 'italic', true ); + str{5} = str2html ( 'individual', 'fontsize', '-4' ); + str{6} = str2html ( 'formats', 'fontname', 'Courier New' ); + str{7} = ''; + str{8} = ''; + str{9} = str2html ( 'Hover over listbox to see tooltip', 'bold', 'true', 'color', 'blue' ); + + tooltip = str2html ( 'HTML also has sub and superscript', 'subscript', 'Sub Script Here', 'superscript', 'Super Script Here' ); + hFig = dialog ( 'windowstyle', 'normal' ); + uicontrol ( 'parent', hFig, 'style', 'listbox', 'units', 'normalized', ... + 'position', [0.05 0.5 0.9 0.45], 'string', str, 'fontsize', 12, 'tooltipstr', tooltip ); + btnStr{1} = str2html ( 'A Button Can Also use HTML', 'color', 'green', 'bold', 1 ); + btnStr{2} = str2html ( 'RightClick to see context menu', 'color', 'blue' ); + + uic = uicontextmenu('parent', hFig); + uimenu ( 'parent', uic, 'label', str2html ( 'Menu 01', 'colour', 'red', 'superscript', 'SUPER' ) ); + uicontrol ( 'parent', hFig, 'style', 'pushbutton', 'units', 'normalized', ... + 'position', [0.05 0.05 0.9 0.35], 'string', str2html ( btnStr, '\n' ), 'fontsize', 12, 'UIContext', uic ); +end +function test_str2html_combinations + + str{1} = str2html ( 'A Push Button containing', 'color', 'green' ); + line2{1} = str2html ( 'Multi-Line', 'bold', 1 ); + line2{2} = str2html ( 'HTML', 'underline', 1 ); + line2{3} = str2html ( 'with different' ); + line2{4} = str2html ( 'formatting', 'color', 'blue', 'italic', 1 ); + str{2} = str2html ( line2, ' ' ); + buttonstr = str2html ( str, '\n' ); + % create some other text to go in the tooltip + str{1} = str2html ( 'The tooltip can also have', 'color', 'green', 'fontname', 'Courier New', 'fontsize', '+2' ); + extras{1} = str2html ( 'HTML can also have super', 'superscript', 'script' ); + extras{2} = str2html ( 'and sub', 'subscript', 'script' ); + str{3} = str2html ( extras, ' ' ); + tooltip = str2html ( str, '\n' ); + % create the uicontrol and add the html format string to the button and tooltip + hFig = dialog ( 'windowstyle', 'normal' ); + uicontrol ( 'parent', hFig, 'style', 'pushbutton', 'units', 'normalized', ... + 'position', [0.05 0.8 0.4 0.1], 'string', buttonstr, 'tooltipstr', tooltip ); + + str{1} = str2html ( 'Pop/List box can have', 'color', 'green', 'fontname', 'Courier New', 'fontsize', '-2' ); + tooltip = str2html ( 'A list box can also have HTML', 'bgcolor', 'green', 'fontsize', 12 ); + uicontrol ( 'parent', hFig, 'style', 'listbox', 'units', 'normalized', ... + 'position', [0.05 0.3 0.7 0.3], 'string', str, 'tooltipstr', tooltip ); + + tooltip = str2html ( 'A popup menu can also have HTML', 'bgcolor', 'green', 'fontsize', 12 ); + uicontrol ( 'parent', hFig, 'style', 'popupmenu', 'units', 'normalized', ... + 'position', [0.05 0.2 0.7 0.1], 'string', str, 'tooltipstr', tooltip ); + + % add your own HTML tags - prefix and suffix, in this case its adding a bullet point. + yourCode{1} = str2html ( 'Add your own HTML code:', 'prefix', '
                          • ', 'suffix', '
                          • ' ); + uicontrol ( 'parent', hFig, 'style', 'pushbutton', 'units', 'normalized', ... + 'position', [0.05 0.05 0.7 0.1], 'string', yourCode ); + +end \ No newline at end of file diff --git a/studio_functions/GUIs/EEG_Tab_rename_gui.mlapp b/studio_functions/GUIs/EEG_Tab_rename_gui.mlapp new file mode 100644 index 00000000..6038cfa9 Binary files /dev/null and b/studio_functions/GUIs/EEG_Tab_rename_gui.mlapp differ diff --git a/studio_functions/GUIs/EEG_evenlist_gui.mlapp b/studio_functions/GUIs/EEG_evenlist_gui.mlapp new file mode 100644 index 00000000..9029d1b3 Binary files /dev/null and b/studio_functions/GUIs/EEG_evenlist_gui.mlapp differ diff --git a/studio_functions/GUIs/EEG_select_segement_artifact_GUI.mlapp b/studio_functions/GUIs/EEG_select_segement_artifact_GUI.mlapp new file mode 100644 index 00000000..a22657bd Binary files /dev/null and b/studio_functions/GUIs/EEG_select_segement_artifact_GUI.mlapp differ diff --git a/studio_functions/GUIs/EEG_trial_rejection_sumr.mlapp b/studio_functions/GUIs/EEG_trial_rejection_sumr.mlapp new file mode 100644 index 00000000..896303c4 Binary files /dev/null and b/studio_functions/GUIs/EEG_trial_rejection_sumr.mlapp differ diff --git a/studio_functions/GUIs/ERP Tab/.txt b/studio_functions/GUIs/ERP Tab/.txt new file mode 100644 index 00000000..6d1096e0 --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/.txt @@ -0,0 +1,1029 @@ +# Non-editable header begin -------------------------------------------------------------------------------- +# +# data format...............: continuous +# setname...................: 3_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new +# filename..................: 3_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new.set +# filepath..................: /Users/gzhang/Documents/Demo data/EEGsets/EEG set/ +# nchan.....................: 30 +# pnts......................: 154368 +# srate.....................: 256 +# nevents...................: 1003 +# generated by (bdf)........: +# generated by (set)........: 3_MMN_shifted_ds_reref_ucbip_hpfilt_ica_weighted_new +# reported in ..............: +# prog Version..............: 10.0 +# creation date.............: 15-Mar-2024 14:16:00 +# user Account..............: +# +# Non-editable header end -------------------------------------------------------------------------------- + + + + +# item bepoch ecode label onset diff dura b_flags a_flags enable bin +# (sec) (msec) (msec) (binary) (binary) + + +1 0 4 "" 0.5625 0.00 0.0 00000000 00000000 1 [ ] +2 0 1 "" 8.3135 7750.98 0.0 00000000 00000000 1 [ ] +3 0 180 "" 11.3438 3030.27 0.0 00000000 00000000 1 [ ] +4 0 180 "" 11.9736 629.88 0.0 00000000 00000000 1 [ ] +5 0 180 "" 12.5400 566.41 0.0 00000000 00000000 1 [ ] +6 0 180 "" 13.1562 616.21 0.0 00000000 00000000 1 [ ] +7 0 180 "" 13.7637 607.42 0.0 00000000 00000000 1 [ ] +8 0 180 "" 14.3096 545.90 0.0 00000000 00000000 1 [ ] +9 0 180 "" 14.9170 607.42 0.0 00000000 00000000 1 [ ] +10 0 180 "" 15.5264 609.38 0.0 00000000 00000000 1 [ ] +11 0 180 "" 16.0928 566.41 0.0 00000000 00000000 1 [ ] +12 0 180 "" 16.6963 603.52 0.0 00000000 00000000 1 [ ] +13 0 180 "" 17.3203 624.02 0.0 00000000 00000000 1 [ ] +14 0 180 "" 17.8662 545.90 0.0 00000000 00000000 1 [ ] +15 0 180 "" 18.4629 596.68 0.0 00000000 00000000 1 [ ] +16 0 180 "" 19.0830 620.12 0.0 00000000 00000000 1 [ ] +17 0 180 "" 19.6396 556.64 0.0 00000000 00000000 1 [ ] +18 0 80 "" 20.2627 623.05 0.0 00000000 00000000 1 [ ] +19 0 80 "" 20.8936 630.86 0.0 00000000 00000000 1 [ ] +20 0 80 "" 21.4668 573.24 0.0 00000000 00000000 1 [ ] +21 0 70 "" 22.0732 606.45 0.0 00000000 00000000 1 [ ] +22 0 80 "" 22.7031 629.88 0.0 00000000 00000000 1 [ ] +23 0 80 "" 23.2832 580.08 0.0 00000000 00000000 1 [ ] +24 0 80 "" 23.9131 629.88 0.0 00000000 00000000 1 [ ] +25 0 80 "" 24.4961 583.01 0.0 00000000 00000000 1 [ ] +26 0 70 "" 25.0625 566.41 0.0 00000000 00000000 1 [ ] +27 0 80 "" 25.6592 596.68 0.0 00000000 00000000 1 [ ] +28 0 80 "" 26.2363 577.15 0.0 00000000 00000000 1 [ ] +29 0 80 "" 26.7998 563.48 0.0 00000000 00000000 1 [ ] +30 0 80 "" 27.3594 559.57 0.0 00000000 00000000 1 [ ] +31 0 80 "" 27.9492 589.84 0.0 00000000 00000000 1 [ ] +32 0 70 "" 28.5859 636.72 0.0 00000000 00000000 1 [ ] +33 0 80 "" 29.2197 633.79 0.0 00000000 00000000 1 [ ] +34 0 80 "" 29.8525 632.81 0.0 00000000 00000000 1 [ ] +35 0 80 "" 30.4961 643.55 0.0 00000000 00000000 1 [ ] +36 0 80 "" 31.0732 577.15 0.0 00000000 00000000 1 [ ] +37 0 70 "" 31.6494 576.17 0.0 00000000 00000000 1 [ ] +38 0 80 "" 32.2393 589.84 0.0 00000000 00000000 1 [ ] +39 0 80 "" 32.8027 563.48 0.0 00000000 00000000 1 [ ] +40 0 80 "" 33.4229 620.12 0.0 00000000 00000000 1 [ ] +41 0 70 "" 34.0098 586.91 0.0 00000000 00000000 1 [ ] +42 0 80 "" 34.6123 602.54 0.0 00000000 00000000 1 [ ] +43 0 70 "" 35.1992 586.91 0.0 00000000 00000000 1 [ ] +44 0 80 "" 35.8291 629.88 0.0 00000000 00000000 1 [ ] +45 0 80 "" 36.4092 580.08 0.0 00000000 00000000 1 [ ] +46 0 70 "" 36.9824 573.24 0.0 00000000 00000000 1 [ ] +47 0 80 "" 37.6162 633.79 0.0 00000000 00000000 1 [ ] +48 0 80 "" 38.2363 620.12 0.0 00000000 00000000 1 [ ] +49 0 80 "" 38.7764 540.04 0.0 00000000 00000000 1 [ ] +50 0 80 "" 39.3223 545.90 0.0 00000000 00000000 1 [ ] +51 0 80 "" 39.9424 620.12 0.0 00000000 00000000 1 [ ] +52 0 80 "" 40.5723 629.88 0.0 00000000 00000000 1 [ ] +53 0 80 "" 41.1855 613.28 0.0 00000000 00000000 1 [ ] +54 0 80 "" 41.7559 570.31 0.0 00000000 00000000 1 [ ] +55 0 80 "" 42.3828 626.95 0.0 00000000 00000000 1 [ ] +56 0 70 "" 42.9893 606.45 0.0 00000000 00000000 1 [ ] +57 0 80 "" 43.5693 580.08 0.0 00000000 00000000 1 [ ] +58 0 70 "" 44.1689 599.61 0.0 00000000 00000000 1 [ ] +59 0 80 "" 44.7490 580.08 0.0 00000000 00000000 1 [ ] +60 0 80 "" 45.2793 530.27 0.0 00000000 00000000 1 [ ] +61 0 70 "" 45.8896 610.35 0.0 00000000 00000000 1 [ ] +62 0 80 "" 46.4863 596.68 0.0 00000000 00000000 1 [ ] +63 0 80 "" 47.0488 562.50 0.0 00000000 00000000 1 [ ] +64 0 80 "" 47.5996 550.78 0.0 00000000 00000000 1 [ ] +65 0 80 "" 48.1924 592.77 0.0 00000000 00000000 1 [ ] +66 0 80 "" 48.7422 549.80 0.0 00000000 00000000 1 [ ] +67 0 80 "" 49.3096 567.38 0.0 00000000 00000000 1 [ ] +68 0 80 "" 49.9355 625.98 0.0 00000000 00000000 1 [ ] +69 0 80 "" 50.5557 620.12 0.0 00000000 00000000 1 [ ] +70 0 80 "" 51.1260 570.31 0.0 00000000 00000000 1 [ ] +71 0 80 "" 51.7188 592.77 0.0 00000000 00000000 1 [ ] +72 0 80 "" 52.3291 610.35 0.0 00000000 00000000 1 [ ] +73 0 70 "" 52.9492 620.12 0.0 00000000 00000000 1 [ ] +74 0 80 "" 53.5693 620.12 0.0 00000000 00000000 1 [ ] +75 0 80 "" 54.1523 583.01 0.0 00000000 00000000 1 [ ] +76 0 70 "" 54.7021 549.80 0.0 00000000 00000000 1 [ ] +77 0 80 "" 55.3252 623.05 0.0 00000000 00000000 1 [ ] +78 0 80 "" 55.9453 620.12 0.0 00000000 00000000 1 [ ] +79 0 80 "" 56.5225 577.15 0.0 00000000 00000000 1 [ ] +80 0 70 "" 57.0625 540.04 0.0 00000000 00000000 1 [ ] +81 0 80 "" 57.6689 606.45 0.0 00000000 00000000 1 [ ] +82 0 70 "" 58.2354 566.41 0.0 00000000 00000000 1 [ ] +83 0 80 "" 58.8594 624.02 0.0 00000000 00000000 1 [ ] +84 0 80 "" 59.4189 559.57 0.0 00000000 00000000 1 [ ] +85 0 70 "" 60.0557 636.72 0.0 00000000 00000000 1 [ ] +86 0 80 "" 60.6357 580.08 0.0 00000000 00000000 1 [ ] +87 0 70 "" 61.2656 629.88 0.0 00000000 00000000 1 [ ] +88 0 80 "" 61.8555 589.84 0.0 00000000 00000000 1 [ ] +89 0 80 "" 62.4551 599.61 0.0 00000000 00000000 1 [ ] +90 0 80 "" 63.0488 593.75 0.0 00000000 00000000 1 [ ] +91 0 80 "" 63.6885 639.65 0.0 00000000 00000000 1 [ ] +92 0 80 "" 64.3125 624.02 0.0 00000000 00000000 1 [ ] +93 0 70 "" 64.9092 596.68 0.0 00000000 00000000 1 [ ] +94 0 80 "" 65.4854 576.17 0.0 00000000 00000000 1 [ ] +95 0 80 "" 66.1250 639.65 0.0 00000000 00000000 1 [ ] +96 0 80 "" 66.6855 560.55 0.0 00000000 00000000 1 [ ] +97 0 80 "" 67.2559 570.31 0.0 00000000 00000000 1 [ ] +98 0 80 "" 67.8418 585.94 0.0 00000000 00000000 1 [ ] +99 0 80 "" 68.4189 577.15 0.0 00000000 00000000 1 [ ] +100 0 70 "" 68.9824 563.48 0.0 00000000 00000000 1 [ ] +101 0 80 "" 69.5850 602.54 0.0 00000000 00000000 1 [ ] +102 0 70 "" 70.1523 567.38 0.0 00000000 00000000 1 [ ] +103 0 80 "" 70.6885 536.13 0.0 00000000 00000000 1 [ ] +104 0 80 "" 71.2588 570.31 0.0 00000000 00000000 1 [ ] +105 0 80 "" 71.8252 566.41 0.0 00000000 00000000 1 [ ] +106 0 80 "" 72.4150 589.84 0.0 00000000 00000000 1 [ ] +107 0 80 "" 73.0020 586.91 0.0 00000000 00000000 1 [ ] +108 0 70 "" 73.6250 623.05 0.0 00000000 00000000 1 [ ] +109 0 80 "" 74.2588 633.79 0.0 00000000 00000000 1 [ ] +110 0 70 "" 74.8584 599.61 0.0 00000000 00000000 1 [ ] +111 0 80 "" 75.4248 566.41 0.0 00000000 00000000 1 [ ] +112 0 70 "" 76.0283 603.52 0.0 00000000 00000000 1 [ ] +113 0 80 "" 76.5947 566.41 0.0 00000000 00000000 1 [ ] +114 0 80 "" 77.1855 590.82 0.0 00000000 00000000 1 [ ] +115 0 80 "" 77.7783 592.77 0.0 00000000 00000000 1 [ ] +116 0 70 "" 78.3848 606.45 0.0 00000000 00000000 1 [ ] +117 0 80 "" 78.9785 593.75 0.0 00000000 00000000 1 [ ] +118 0 80 "" 79.5918 613.28 0.0 00000000 00000000 1 [ ] +119 0 80 "" 80.2021 610.35 0.0 00000000 00000000 1 [ ] +120 0 80 "" 80.8184 616.21 0.0 00000000 00000000 1 [ ] +121 0 80 "" 81.4248 606.45 0.0 00000000 00000000 1 [ ] +122 0 80 "" 82.0283 603.52 0.0 00000000 00000000 1 [ ] +123 0 70 "" 82.6621 633.79 0.0 00000000 00000000 1 [ ] +124 0 80 "" 83.2119 549.80 0.0 00000000 00000000 1 [ ] +125 0 80 "" 83.7520 540.04 0.0 00000000 00000000 1 [ ] +126 0 80 "" 84.3486 596.68 0.0 00000000 00000000 1 [ ] +127 0 80 "" 84.9688 620.12 0.0 00000000 00000000 1 [ ] +128 0 80 "" 85.5479 579.10 0.0 00000000 00000000 1 [ ] +129 0 70 "" 86.1084 560.55 0.0 00000000 00000000 1 [ ] +130 0 80 "" 86.7119 603.52 0.0 00000000 00000000 1 [ ] +131 0 70 "" 87.2783 566.41 0.0 00000000 00000000 1 [ ] +132 0 80 "" 87.8252 546.88 0.0 00000000 00000000 1 [ ] +133 0 80 "" 88.3916 566.41 0.0 00000000 00000000 1 [ ] +134 0 70 "" 88.9814 589.84 0.0 00000000 00000000 1 [ ] +135 0 80 "" 89.5449 563.48 0.0 00000000 00000000 1 [ ] +136 0 70 "" 90.1211 576.17 0.0 00000000 00000000 1 [ ] +137 0 80 "" 90.6650 543.95 0.0 00000000 00000000 1 [ ] +138 0 80 "" 91.2148 549.80 0.0 00000000 00000000 1 [ ] +139 0 80 "" 91.8486 633.79 0.0 00000000 00000000 1 [ ] +140 0 80 "" 92.4111 562.50 0.0 00000000 00000000 1 [ ] +141 0 80 "" 93.0352 624.02 0.0 00000000 00000000 1 [ ] +142 0 80 "" 93.6045 569.34 0.0 00000000 00000000 1 [ ] +143 0 80 "" 94.2119 607.42 0.0 00000000 00000000 1 [ ] +144 0 80 "" 94.7783 566.41 0.0 00000000 00000000 1 [ ] +145 0 80 "" 95.3477 569.34 0.0 00000000 00000000 1 [ ] +146 0 80 "" 95.9648 617.19 0.0 00000000 00000000 1 [ ] +147 0 80 "" 96.5283 563.48 0.0 00000000 00000000 1 [ ] +148 0 80 "" 97.0645 536.13 0.0 00000000 00000000 1 [ ] +149 0 80 "" 97.6650 600.59 0.0 00000000 00000000 1 [ ] +150 0 80 "" 98.2314 566.41 0.0 00000000 00000000 1 [ ] +151 0 80 "" 98.7578 526.37 0.0 00000000 00000000 1 [ ] +152 0 80 "" 99.3613 603.52 0.0 00000000 00000000 1 [ ] +153 0 70 "" 99.9678 606.45 0.0 00000000 00000000 1 [ ] +154 0 80 "" 100.5244 556.64 0.0 00000000 00000000 1 [ ] +155 0 80 "" 101.0781 553.71 0.0 00000000 00000000 1 [ ] +156 0 70 "" 101.7051 626.95 0.0 00000000 00000000 1 [ ] +157 0 80 "" 102.2979 592.77 0.0 00000000 00000000 1 [ ] +158 0 80 "" 102.8711 573.24 0.0 00000000 00000000 1 [ ] +159 0 70 "" 103.4717 600.59 0.0 00000000 00000000 1 [ ] +160 0 80 "" 104.0879 616.21 0.0 00000000 00000000 1 [ ] +161 0 70 "" 104.7148 626.95 0.0 00000000 00000000 1 [ ] +162 0 80 "" 105.2842 569.34 0.0 00000000 00000000 1 [ ] +163 0 80 "" 105.8281 543.95 0.0 00000000 00000000 1 [ ] +164 0 80 "" 106.4043 576.17 0.0 00000000 00000000 1 [ ] +165 0 80 "" 106.9414 537.11 0.0 00000000 00000000 1 [ ] +166 0 80 "" 107.5449 603.52 0.0 00000000 00000000 1 [ ] +167 0 80 "" 108.0947 549.80 0.0 00000000 00000000 1 [ ] +168 0 70 "" 108.6748 580.08 0.0 00000000 00000000 1 [ ] +169 0 80 "" 109.2246 549.80 0.0 00000000 00000000 1 [ ] +170 0 80 "" 109.8516 626.95 0.0 00000000 00000000 1 [ ] +171 0 80 "" 110.4541 602.54 0.0 00000000 00000000 1 [ ] +172 0 80 "" 111.0713 617.19 0.0 00000000 00000000 1 [ ] +173 0 80 "" 111.6943 623.05 0.0 00000000 00000000 1 [ ] +174 0 70 "" 112.2510 556.64 0.0 00000000 00000000 1 [ ] +175 0 80 "" 112.7910 540.04 0.0 00000000 00000000 1 [ ] +176 0 70 "" 113.3613 570.31 0.0 00000000 00000000 1 [ ] +177 0 80 "" 113.8975 536.13 0.0 00000000 00000000 1 [ ] +178 0 80 "" 114.4609 563.48 0.0 00000000 00000000 1 [ ] +179 0 80 "" 115.0215 560.55 0.0 00000000 00000000 1 [ ] +180 0 70 "" 115.6514 629.88 0.0 00000000 00000000 1 [ ] +181 0 80 "" 116.2578 606.45 0.0 00000000 00000000 1 [ ] +182 0 70 "" 116.8008 542.97 0.0 00000000 00000000 1 [ ] +183 0 80 "" 117.3848 583.98 0.0 00000000 00000000 1 [ ] +184 0 80 "" 117.9775 592.77 0.0 00000000 00000000 1 [ ] +185 0 80 "" 118.6074 629.88 0.0 00000000 00000000 1 [ ] +186 0 80 "" 119.1572 549.80 0.0 00000000 00000000 1 [ ] +187 0 80 "" 119.7812 624.02 0.0 00000000 00000000 1 [ ] +188 0 80 "" 120.3574 576.17 0.0 00000000 00000000 1 [ ] +189 0 80 "" 120.9404 583.01 0.0 00000000 00000000 1 [ ] +190 0 80 "" 121.5742 633.79 0.0 00000000 00000000 1 [ ] +191 0 80 "" 122.1240 549.80 0.0 00000000 00000000 1 [ ] +192 0 80 "" 122.7305 606.45 0.0 00000000 00000000 1 [ ] +193 0 80 "" 123.3379 607.42 0.0 00000000 00000000 1 [ ] +194 0 80 "" 123.9404 602.54 0.0 00000000 00000000 1 [ ] +195 0 80 "" 124.4873 546.88 0.0 00000000 00000000 1 [ ] +196 0 80 "" 125.0977 610.35 0.0 00000000 00000000 1 [ ] +197 0 80 "" 125.6572 559.57 0.0 00000000 00000000 1 [ ] +198 0 80 "" 126.2178 560.55 0.0 00000000 00000000 1 [ ] +199 0 70 "" 126.8145 596.68 0.0 00000000 00000000 1 [ ] +200 0 80 "" 127.4541 639.65 0.0 00000000 00000000 1 [ ] +201 0 70 "" 128.0703 616.21 0.0 00000000 00000000 1 [ ] +202 0 80 "" 128.6543 583.98 0.0 00000000 00000000 1 [ ] +203 0 70 "" 129.2842 629.88 0.0 00000000 00000000 1 [ ] +204 0 80 "" 129.9004 616.21 0.0 00000000 00000000 1 [ ] +205 0 80 "" 130.4639 563.48 0.0 00000000 00000000 1 [ ] +206 0 80 "" 131.0938 629.88 0.0 00000000 00000000 1 [ ] +207 0 80 "" 131.6543 560.55 0.0 00000000 00000000 1 [ ] +208 0 80 "" 132.2471 592.77 0.0 00000000 00000000 1 [ ] +209 0 80 "" 132.8008 553.71 0.0 00000000 00000000 1 [ ] +210 0 80 "" 133.3838 583.01 0.0 00000000 00000000 1 [ ] +211 0 70 "" 133.9541 570.31 0.0 00000000 00000000 1 [ ] +212 0 80 "" 134.5439 589.84 0.0 00000000 00000000 1 [ ] +213 0 70 "" 135.1572 613.28 0.0 00000000 00000000 1 [ ] +214 0 80 "" 135.7334 576.17 0.0 00000000 00000000 1 [ ] +215 0 80 "" 136.3477 614.26 0.0 00000000 00000000 1 [ ] +216 0 80 "" 136.9238 576.17 0.0 00000000 00000000 1 [ ] +217 0 70 "" 137.5508 626.95 0.0 00000000 00000000 1 [ ] +218 0 80 "" 138.1709 620.12 0.0 00000000 00000000 1 [ ] +219 0 70 "" 138.7705 599.61 0.0 00000000 00000000 1 [ ] +220 0 80 "" 139.4102 639.65 0.0 00000000 00000000 1 [ ] +221 0 80 "" 140.0400 629.88 0.0 00000000 00000000 1 [ ] +222 0 70 "" 140.6006 560.55 0.0 00000000 00000000 1 [ ] +223 0 80 "" 141.1934 592.77 0.0 00000000 00000000 1 [ ] +224 0 80 "" 141.7871 593.75 0.0 00000000 00000000 1 [ ] +225 0 70 "" 142.3633 576.17 0.0 00000000 00000000 1 [ ] +226 0 80 "" 142.9971 633.79 0.0 00000000 00000000 1 [ ] +227 0 70 "" 143.5967 599.61 0.0 00000000 00000000 1 [ ] +228 0 80 "" 144.1602 563.48 0.0 00000000 00000000 1 [ ] +229 0 80 "" 144.7139 553.71 0.0 00000000 00000000 1 [ ] +230 0 80 "" 145.3008 586.91 0.0 00000000 00000000 1 [ ] +231 0 80 "" 145.8438 542.97 0.0 00000000 00000000 1 [ ] +232 0 80 "" 146.4766 632.81 0.0 00000000 00000000 1 [ ] +233 0 70 "" 147.0605 583.98 0.0 00000000 00000000 1 [ ] +234 0 80 "" 147.6035 542.97 0.0 00000000 00000000 1 [ ] +235 0 80 "" 148.2305 626.95 0.0 00000000 00000000 1 [ ] +236 0 80 "" 148.8203 589.84 0.0 00000000 00000000 1 [ ] +237 0 80 "" 149.4473 626.95 0.0 00000000 00000000 1 [ ] +238 0 70 "" 150.0205 573.24 0.0 00000000 00000000 1 [ ] +239 0 80 "" 150.6201 599.61 0.0 00000000 00000000 1 [ ] +240 0 80 "" 151.2100 589.84 0.0 00000000 00000000 1 [ ] +241 0 80 "" 151.8340 624.02 0.0 00000000 00000000 1 [ ] +242 0 80 "" 152.4473 613.28 0.0 00000000 00000000 1 [ ] +243 0 70 "" 153.0635 616.21 0.0 00000000 00000000 1 [ ] +244 0 80 "" 153.5967 533.20 0.0 00000000 00000000 1 [ ] +245 0 70 "" 154.1670 570.31 0.0 00000000 00000000 1 [ ] +246 0 80 "" 154.7568 589.84 0.0 00000000 00000000 1 [ ] +247 0 80 "" 155.3506 593.75 0.0 00000000 00000000 1 [ ] +248 0 70 "" 155.8936 542.97 0.0 00000000 00000000 1 [ ] +249 0 80 "" 156.5098 616.21 0.0 00000000 00000000 1 [ ] +250 0 80 "" 157.0732 563.48 0.0 00000000 00000000 1 [ ] +251 0 80 "" 157.6504 577.15 0.0 00000000 00000000 1 [ ] +252 0 80 "" 158.2734 623.05 0.0 00000000 00000000 1 [ ] +253 0 80 "" 158.8398 566.41 0.0 00000000 00000000 1 [ ] +254 0 80 "" 159.4238 583.98 0.0 00000000 00000000 1 [ ] +255 0 80 "" 159.9805 556.64 0.0 00000000 00000000 1 [ ] +256 0 80 "" 160.6035 623.05 0.0 00000000 00000000 1 [ ] +257 0 70 "" 161.2168 613.28 0.0 00000000 00000000 1 [ ] +258 0 80 "" 161.8096 592.77 0.0 00000000 00000000 1 [ ] +259 0 70 "" 162.3633 553.71 0.0 00000000 00000000 1 [ ] +260 0 80 "" 162.9365 573.24 0.0 00000000 00000000 1 [ ] +261 0 80 "" 163.5029 566.41 0.0 00000000 00000000 1 [ ] +262 0 70 "" 164.0635 560.55 0.0 00000000 00000000 1 [ ] +263 0 80 "" 164.6562 592.77 0.0 00000000 00000000 1 [ ] +264 0 80 "" 165.2998 643.55 0.0 00000000 00000000 1 [ ] +265 0 70 "" 165.8828 583.01 0.0 00000000 00000000 1 [ ] +266 0 80 "" 166.4834 600.59 0.0 00000000 00000000 1 [ ] +267 0 80 "" 167.0830 599.61 0.0 00000000 00000000 1 [ ] +268 0 70 "" 167.7266 643.55 0.0 00000000 00000000 1 [ ] +269 0 80 "" 168.3467 620.12 0.0 00000000 00000000 1 [ ] +270 0 80 "" 168.9297 583.01 0.0 00000000 00000000 1 [ ] +271 0 70 "" 169.4727 542.97 0.0 00000000 00000000 1 [ ] +272 0 80 "" 170.0928 620.12 0.0 00000000 00000000 1 [ ] +273 0 80 "" 170.6963 603.52 0.0 00000000 00000000 1 [ ] +274 0 80 "" 171.3262 629.88 0.0 00000000 00000000 1 [ ] +275 0 80 "" 171.9600 633.79 0.0 00000000 00000000 1 [ ] +276 0 80 "" 172.5693 609.38 0.0 00000000 00000000 1 [ ] +277 0 70 "" 173.1660 596.68 0.0 00000000 00000000 1 [ ] +278 0 80 "" 173.7627 596.68 0.0 00000000 00000000 1 [ ] +279 0 80 "" 174.3027 540.04 0.0 00000000 00000000 1 [ ] +280 0 80 "" 174.8965 593.75 0.0 00000000 00000000 1 [ ] +281 0 80 "" 175.5361 639.65 0.0 00000000 00000000 1 [ ] +282 0 80 "" 176.1426 606.45 0.0 00000000 00000000 1 [ ] +283 0 80 "" 176.7461 603.52 0.0 00000000 00000000 1 [ ] +284 0 80 "" 177.3164 570.31 0.0 00000000 00000000 1 [ ] +285 0 80 "" 177.8701 553.71 0.0 00000000 00000000 1 [ ] +286 0 70 "" 178.4834 613.28 0.0 00000000 00000000 1 [ ] +287 0 80 "" 179.1025 619.14 0.0 00000000 00000000 1 [ ] +288 0 70 "" 179.7393 636.72 0.0 00000000 00000000 1 [ ] +289 0 80 "" 180.2930 553.71 0.0 00000000 00000000 1 [ ] +290 0 80 "" 180.9258 632.81 0.0 00000000 00000000 1 [ ] +291 0 70 "" 181.5225 596.68 0.0 00000000 00000000 1 [ ] +292 0 80 "" 182.0625 540.04 0.0 00000000 00000000 1 [ ] +293 0 80 "" 182.6758 613.28 0.0 00000000 00000000 1 [ ] +294 0 80 "" 183.2363 560.55 0.0 00000000 00000000 1 [ ] +295 0 80 "" 183.8057 569.34 0.0 00000000 00000000 1 [ ] +296 0 70 "" 184.4229 617.19 0.0 00000000 00000000 1 [ ] +297 0 80 "" 184.9629 540.04 0.0 00000000 00000000 1 [ ] +298 0 80 "" 185.5225 559.57 0.0 00000000 00000000 1 [ ] +299 0 70 "" 186.0664 543.95 0.0 00000000 00000000 1 [ ] +300 0 80 "" 186.6924 625.98 0.0 00000000 00000000 1 [ ] +301 0 80 "" 187.2490 556.64 0.0 00000000 00000000 1 [ ] +302 0 80 "" 187.8496 600.59 0.0 00000000 00000000 1 [ ] +303 0 80 "" 188.4463 596.68 0.0 00000000 00000000 1 [ ] +304 0 80 "" 189.0059 559.57 0.0 00000000 00000000 1 [ ] +305 0 70 "" 189.5625 556.64 0.0 00000000 00000000 1 [ ] +306 0 80 "" 190.1064 543.95 0.0 00000000 00000000 1 [ ] +307 0 70 "" 190.7197 613.28 0.0 00000000 00000000 1 [ ] +308 0 80 "" 191.3057 585.94 0.0 00000000 00000000 1 [ ] +309 0 80 "" 191.9229 617.19 0.0 00000000 00000000 1 [ ] +310 0 70 "" 192.4795 556.64 0.0 00000000 00000000 1 [ ] +311 0 80 "" 193.1162 636.72 0.0 00000000 00000000 1 [ ] +312 0 80 "" 193.7090 592.77 0.0 00000000 00000000 1 [ ] +313 0 70 "" 194.2559 546.88 0.0 00000000 00000000 1 [ ] +314 0 80 "" 194.8789 623.05 0.0 00000000 00000000 1 [ ] +315 0 70 "" 195.4824 603.52 0.0 00000000 00000000 1 [ ] +316 0 80 "" 196.0361 553.71 0.0 00000000 00000000 1 [ ] +317 0 80 "" 196.6523 616.21 0.0 00000000 00000000 1 [ ] +318 0 80 "" 197.2256 573.24 0.0 00000000 00000000 1 [ ] +319 0 70 "" 197.8320 606.45 0.0 00000000 00000000 1 [ ] +320 0 80 "" 198.4688 636.72 0.0 00000000 00000000 1 [ ] +321 0 80 "" 199.0225 553.71 0.0 00000000 00000000 1 [ ] +322 0 80 "" 199.6221 599.61 0.0 00000000 00000000 1 [ ] +323 0 80 "" 200.1758 553.71 0.0 00000000 00000000 1 [ ] +324 0 70 "" 200.7061 530.27 0.0 00000000 00000000 1 [ ] +325 0 80 "" 201.3154 609.38 0.0 00000000 00000000 1 [ ] +326 0 80 "" 201.8994 583.98 0.0 00000000 00000000 1 [ ] +327 0 70 "" 202.5254 625.98 0.0 00000000 00000000 1 [ ] +328 0 80 "" 203.1592 633.79 0.0 00000000 00000000 1 [ ] +329 0 80 "" 203.7725 613.28 0.0 00000000 00000000 1 [ ] +330 0 70 "" 204.3359 563.48 0.0 00000000 00000000 1 [ ] +331 0 80 "" 204.9053 569.34 0.0 00000000 00000000 1 [ ] +332 0 80 "" 205.4824 577.15 0.0 00000000 00000000 1 [ ] +333 0 80 "" 206.0527 570.31 0.0 00000000 00000000 1 [ ] +334 0 80 "" 206.6660 613.28 0.0 00000000 00000000 1 [ ] +335 0 80 "" 207.2422 576.17 0.0 00000000 00000000 1 [ ] +336 0 80 "" 207.8252 583.01 0.0 00000000 00000000 1 [ ] +337 0 80 "" 208.4053 580.08 0.0 00000000 00000000 1 [ ] +338 0 80 "" 208.9521 546.88 0.0 00000000 00000000 1 [ ] +339 0 80 "" 209.5156 563.48 0.0 00000000 00000000 1 [ ] +340 0 80 "" 210.1260 610.35 0.0 00000000 00000000 1 [ ] +341 0 80 "" 210.6787 552.73 0.0 00000000 00000000 1 [ ] +342 0 80 "" 211.2686 589.84 0.0 00000000 00000000 1 [ ] +343 0 70 "" 211.8057 537.11 0.0 00000000 00000000 1 [ ] +344 0 80 "" 212.3721 566.41 0.0 00000000 00000000 1 [ ] +345 0 70 "" 212.9756 603.52 0.0 00000000 00000000 1 [ ] +346 0 80 "" 213.5586 583.01 0.0 00000000 00000000 1 [ ] +347 0 80 "" 214.1123 553.71 0.0 00000000 00000000 1 [ ] +348 0 80 "" 214.6719 559.57 0.0 00000000 00000000 1 [ ] +349 0 80 "" 215.2490 577.15 0.0 00000000 00000000 1 [ ] +350 0 80 "" 215.8789 629.88 0.0 00000000 00000000 1 [ ] +351 0 70 "" 216.4551 576.17 0.0 00000000 00000000 1 [ ] +352 0 80 "" 216.9854 530.27 0.0 00000000 00000000 1 [ ] +353 0 80 "" 217.6123 626.95 0.0 00000000 00000000 1 [ ] +354 0 70 "" 218.1650 552.73 0.0 00000000 00000000 1 [ ] +355 0 80 "" 218.7588 593.75 0.0 00000000 00000000 1 [ ] +356 0 70 "" 219.3916 632.81 0.0 00000000 00000000 1 [ ] +357 0 80 "" 219.9658 574.22 0.0 00000000 00000000 1 [ ] +358 0 80 "" 220.5186 552.73 0.0 00000000 00000000 1 [ ] +359 0 80 "" 221.0820 563.48 0.0 00000000 00000000 1 [ ] +360 0 80 "" 221.6553 573.24 0.0 00000000 00000000 1 [ ] +361 0 80 "" 222.2725 617.19 0.0 00000000 00000000 1 [ ] +362 0 80 "" 222.8818 609.38 0.0 00000000 00000000 1 [ ] +363 0 80 "" 223.5049 623.05 0.0 00000000 00000000 1 [ ] +364 0 70 "" 224.0654 560.55 0.0 00000000 00000000 1 [ ] +365 0 80 "" 224.6289 563.48 0.0 00000000 00000000 1 [ ] +366 0 80 "" 225.2021 573.24 0.0 00000000 00000000 1 [ ] +367 0 70 "" 225.7314 529.30 0.0 00000000 00000000 1 [ ] +368 0 80 "" 226.3389 607.42 0.0 00000000 00000000 1 [ ] +369 0 80 "" 226.9590 620.12 0.0 00000000 00000000 1 [ ] +370 0 80 "" 227.5117 552.73 0.0 00000000 00000000 1 [ ] +371 0 80 "" 228.1318 620.12 0.0 00000000 00000000 1 [ ] +372 0 80 "" 228.6885 556.64 0.0 00000000 00000000 1 [ ] +373 0 70 "" 229.3047 616.21 0.0 00000000 00000000 1 [ ] +374 0 80 "" 229.9316 626.95 0.0 00000000 00000000 1 [ ] +375 0 80 "" 230.5420 610.35 0.0 00000000 00000000 1 [ ] +376 0 80 "" 231.1182 576.17 0.0 00000000 00000000 1 [ ] +377 0 80 "" 231.7080 589.84 0.0 00000000 00000000 1 [ ] +378 0 80 "" 232.3086 600.59 0.0 00000000 00000000 1 [ ] +379 0 80 "" 232.9453 636.72 0.0 00000000 00000000 1 [ ] +380 0 80 "" 233.5312 585.94 0.0 00000000 00000000 1 [ ] +381 0 80 "" 234.1113 580.08 0.0 00000000 00000000 1 [ ] +382 0 80 "" 234.6914 580.08 0.0 00000000 00000000 1 [ ] +383 0 70 "" 235.3281 636.72 0.0 00000000 00000000 1 [ ] +384 0 80 "" 235.9150 586.91 0.0 00000000 00000000 1 [ ] +385 0 70 "" 236.4482 533.20 0.0 00000000 00000000 1 [ ] +386 0 80 "" 237.0020 553.71 0.0 00000000 00000000 1 [ ] +387 0 70 "" 237.5654 563.48 0.0 00000000 00000000 1 [ ] +388 0 80 "" 238.1553 589.84 0.0 00000000 00000000 1 [ ] +389 0 80 "" 238.7080 552.73 0.0 00000000 00000000 1 [ ] +390 0 80 "" 239.2578 549.80 0.0 00000000 00000000 1 [ ] +391 0 80 "" 239.8320 574.22 0.0 00000000 00000000 1 [ ] +392 0 80 "" 240.4082 576.17 0.0 00000000 00000000 1 [ ] +393 0 80 "" 240.9551 546.88 0.0 00000000 00000000 1 [ ] +394 0 80 "" 241.5479 592.77 0.0 00000000 00000000 1 [ ] +395 0 70 "" 242.0947 546.88 0.0 00000000 00000000 1 [ ] +396 0 80 "" 242.7217 626.95 0.0 00000000 00000000 1 [ ] +397 0 70 "" 243.3047 583.01 0.0 00000000 00000000 1 [ ] +398 0 80 "" 243.8711 566.41 0.0 00000000 00000000 1 [ ] +399 0 70 "" 244.4580 586.91 0.0 00000000 00000000 1 [ ] +400 0 80 "" 245.0586 600.59 0.0 00000000 00000000 1 [ ] +401 0 80 "" 245.5947 536.13 0.0 00000000 00000000 1 [ ] +402 0 70 "" 246.1582 563.48 0.0 00000000 00000000 1 [ ] +403 0 80 "" 246.7812 623.05 0.0 00000000 00000000 1 [ ] +404 0 80 "" 247.3252 543.95 0.0 00000000 00000000 1 [ ] +405 0 70 "" 247.8584 533.20 0.0 00000000 00000000 1 [ ] +406 0 80 "" 248.4717 613.28 0.0 00000000 00000000 1 [ ] +407 0 80 "" 249.0479 576.17 0.0 00000000 00000000 1 [ ] +408 0 70 "" 249.6748 626.95 0.0 00000000 00000000 1 [ ] +409 0 80 "" 250.2480 573.24 0.0 00000000 00000000 1 [ ] +410 0 80 "" 250.8750 626.95 0.0 00000000 00000000 1 [ ] +411 0 80 "" 251.4580 583.01 0.0 00000000 00000000 1 [ ] +412 0 70 "" 252.0811 623.05 0.0 00000000 00000000 1 [ ] +413 0 80 "" 252.6885 607.42 0.0 00000000 00000000 1 [ ] +414 0 80 "" 253.2676 579.10 0.0 00000000 00000000 1 [ ] +415 0 80 "" 253.8047 537.11 0.0 00000000 00000000 1 [ ] +416 0 80 "" 254.3945 589.84 0.0 00000000 00000000 1 [ ] +417 0 80 "" 255.0010 606.45 0.0 00000000 00000000 1 [ ] +418 0 80 "" 255.5479 546.88 0.0 00000000 00000000 1 [ ] +419 0 80 "" 256.1846 636.72 0.0 00000000 00000000 1 [ ] +420 0 80 "" 256.7812 596.68 0.0 00000000 00000000 1 [ ] +421 0 80 "" 257.3682 586.91 0.0 00000000 00000000 1 [ ] +422 0 80 "" 257.9375 569.34 0.0 00000000 00000000 1 [ ] +423 0 80 "" 258.5215 583.98 0.0 00000000 00000000 1 [ ] +424 0 80 "" 259.0645 542.97 0.0 00000000 00000000 1 [ ] +425 0 80 "" 259.6748 610.35 0.0 00000000 00000000 1 [ ] +426 0 80 "" 260.2979 623.05 0.0 00000000 00000000 1 [ ] +427 0 80 "" 260.9307 632.81 0.0 00000000 00000000 1 [ ] +428 0 80 "" 261.5449 614.26 0.0 00000000 00000000 1 [ ] +429 0 80 "" 262.0947 549.80 0.0 00000000 00000000 1 [ ] +430 0 70 "" 262.6943 599.61 0.0 00000000 00000000 1 [ ] +431 0 80 "" 263.2812 586.91 0.0 00000000 00000000 1 [ ] +432 0 80 "" 263.8740 592.77 0.0 00000000 00000000 1 [ ] +433 0 80 "" 264.4746 600.59 0.0 00000000 00000000 1 [ ] +434 0 70 "" 265.0674 592.77 0.0 00000000 00000000 1 [ ] +435 0 80 "" 265.6240 556.64 0.0 00000000 00000000 1 [ ] +436 0 80 "" 266.1875 563.48 0.0 00000000 00000000 1 [ ] +437 0 80 "" 266.7539 566.41 0.0 00000000 00000000 1 [ ] +438 0 70 "" 267.3740 620.12 0.0 00000000 00000000 1 [ ] +439 0 80 "" 267.9277 553.71 0.0 00000000 00000000 1 [ ] +440 0 80 "" 268.4814 553.71 0.0 00000000 00000000 1 [ ] +441 0 80 "" 269.0879 606.45 0.0 00000000 00000000 1 [ ] +442 0 80 "" 269.7305 642.58 0.0 00000000 00000000 1 [ ] +443 0 80 "" 270.3076 577.15 0.0 00000000 00000000 1 [ ] +444 0 80 "" 270.8779 570.31 0.0 00000000 00000000 1 [ ] +445 0 80 "" 271.4873 609.38 0.0 00000000 00000000 1 [ ] +446 0 80 "" 272.0273 540.04 0.0 00000000 00000000 1 [ ] +447 0 80 "" 272.6445 617.19 0.0 00000000 00000000 1 [ ] +448 0 80 "" 273.2344 589.84 0.0 00000000 00000000 1 [ ] +449 0 70 "" 273.7939 559.57 0.0 00000000 00000000 1 [ ] +450 0 80 "" 274.3877 593.75 0.0 00000000 00000000 1 [ ] +451 0 80 "" 274.9141 526.37 0.0 00000000 00000000 1 [ ] +452 0 80 "" 275.5176 603.52 0.0 00000000 00000000 1 [ ] +453 0 80 "" 276.1377 620.12 0.0 00000000 00000000 1 [ ] +454 0 80 "" 276.7305 592.77 0.0 00000000 00000000 1 [ ] +455 0 80 "" 277.3438 613.28 0.0 00000000 00000000 1 [ ] +456 0 80 "" 277.9111 567.38 0.0 00000000 00000000 1 [ ] +457 0 70 "" 278.5244 613.28 0.0 00000000 00000000 1 [ ] +458 0 80 "" 279.0645 540.04 0.0 00000000 00000000 1 [ ] +459 0 80 "" 279.6641 599.61 0.0 00000000 00000000 1 [ ] +460 0 80 "" 280.2637 599.61 0.0 00000000 00000000 1 [ ] +461 0 80 "" 280.8174 553.71 0.0 00000000 00000000 1 [ ] +462 0 80 "" 281.4307 613.28 0.0 00000000 00000000 1 [ ] +463 0 80 "" 282.0137 583.01 0.0 00000000 00000000 1 [ ] +464 0 80 "" 282.5771 563.48 0.0 00000000 00000000 1 [ ] +465 0 70 "" 283.1211 543.95 0.0 00000000 00000000 1 [ ] +466 0 80 "" 283.6904 569.34 0.0 00000000 00000000 1 [ ] +467 0 80 "" 284.2441 553.71 0.0 00000000 00000000 1 [ ] +468 0 80 "" 284.7773 533.20 0.0 00000000 00000000 1 [ ] +469 0 80 "" 285.3711 593.75 0.0 00000000 00000000 1 [ ] +470 0 80 "" 285.9736 602.54 0.0 00000000 00000000 1 [ ] +471 0 80 "" 286.6172 643.55 0.0 00000000 00000000 1 [ ] +472 0 80 "" 287.2471 629.88 0.0 00000000 00000000 1 [ ] +473 0 80 "" 287.8604 613.28 0.0 00000000 00000000 1 [ ] +474 0 80 "" 288.4336 573.24 0.0 00000000 00000000 1 [ ] +475 0 80 "" 289.0146 581.05 0.0 00000000 00000000 1 [ ] +476 0 80 "" 289.6172 602.54 0.0 00000000 00000000 1 [ ] +477 0 80 "" 290.2236 606.45 0.0 00000000 00000000 1 [ ] +478 0 80 "" 290.8506 626.95 0.0 00000000 00000000 1 [ ] +479 0 80 "" 291.4873 636.72 0.0 00000000 00000000 1 [ ] +480 0 80 "" 292.0703 583.01 0.0 00000000 00000000 1 [ ] +481 0 80 "" 292.6807 610.35 0.0 00000000 00000000 1 [ ] +482 0 80 "" 293.3203 639.65 0.0 00000000 00000000 1 [ ] +483 0 80 "" 293.9072 586.91 0.0 00000000 00000000 1 [ ] +484 0 70 "" 294.5205 613.28 0.0 00000000 00000000 1 [ ] +485 0 80 "" 295.1006 580.08 0.0 00000000 00000000 1 [ ] +486 0 80 "" 295.6572 556.64 0.0 00000000 00000000 1 [ ] +487 0 80 "" 296.2607 603.52 0.0 00000000 00000000 1 [ ] +488 0 80 "" 296.8672 606.45 0.0 00000000 00000000 1 [ ] +489 0 70 "" 297.4668 599.61 0.0 00000000 00000000 1 [ ] +490 0 80 "" 298.0674 600.59 0.0 00000000 00000000 1 [ ] +491 0 80 "" 298.6807 613.28 0.0 00000000 00000000 1 [ ] +492 0 80 "" 299.2666 585.94 0.0 00000000 00000000 1 [ ] +493 0 80 "" 299.8838 617.19 0.0 00000000 00000000 1 [ ] +494 0 80 "" 300.4736 589.84 0.0 00000000 00000000 1 [ ] +495 0 70 "" 301.0566 583.01 0.0 00000000 00000000 1 [ ] +496 0 80 "" 301.6299 573.24 0.0 00000000 00000000 1 [ ] +497 0 80 "" 302.2637 633.79 0.0 00000000 00000000 1 [ ] +498 0 80 "" 302.8867 623.05 0.0 00000000 00000000 1 [ ] +499 0 80 "" 303.5098 623.05 0.0 00000000 00000000 1 [ ] +500 0 80 "" 304.0938 583.98 0.0 00000000 00000000 1 [ ] +501 0 80 "" 304.7334 639.65 0.0 00000000 00000000 1 [ ] +502 0 80 "" 305.3672 633.79 0.0 00000000 00000000 1 [ ] +503 0 80 "" 305.9668 599.61 0.0 00000000 00000000 1 [ ] +504 0 80 "" 306.5098 542.97 0.0 00000000 00000000 1 [ ] +505 0 80 "" 307.0635 553.71 0.0 00000000 00000000 1 [ ] +506 0 80 "" 307.6064 542.97 0.0 00000000 00000000 1 [ ] +507 0 80 "" 308.1504 543.95 0.0 00000000 00000000 1 [ ] +508 0 80 "" 308.7402 589.84 0.0 00000000 00000000 1 [ ] +509 0 80 "" 309.2871 546.88 0.0 00000000 00000000 1 [ ] +510 0 80 "" 309.8896 602.54 0.0 00000000 00000000 1 [ ] +511 0 80 "" 310.4805 590.82 0.0 00000000 00000000 1 [ ] +512 0 80 "" 311.0400 559.57 0.0 00000000 00000000 1 [ ] +513 0 70 "" 311.6738 633.79 0.0 00000000 00000000 1 [ ] +514 0 80 "" 312.2764 602.54 0.0 00000000 00000000 1 [ ] +515 0 80 "" 312.8564 580.08 0.0 00000000 00000000 1 [ ] +516 0 80 "" 313.4463 589.84 0.0 00000000 00000000 1 [ ] +517 0 70 "" 314.0303 583.98 0.0 00000000 00000000 1 [ ] +518 0 80 "" 314.6562 625.98 0.0 00000000 00000000 1 [ ] +519 0 80 "" 315.2266 570.31 0.0 00000000 00000000 1 [ ] +520 0 80 "" 315.8369 610.35 0.0 00000000 00000000 1 [ ] +521 0 80 "" 316.4062 569.34 0.0 00000000 00000000 1 [ ] +522 0 80 "" 316.9570 550.78 0.0 00000000 00000000 1 [ ] +523 0 80 "" 317.5566 599.61 0.0 00000000 00000000 1 [ ] +524 0 70 "" 318.1533 596.68 0.0 00000000 00000000 1 [ ] +525 0 80 "" 318.7666 613.28 0.0 00000000 00000000 1 [ ] +526 0 80 "" 319.3203 553.71 0.0 00000000 00000000 1 [ ] +527 0 80 "" 319.8896 569.34 0.0 00000000 00000000 1 [ ] +528 0 80 "" 320.4863 596.68 0.0 00000000 00000000 1 [ ] +529 0 80 "" 321.0527 566.41 0.0 00000000 00000000 1 [ ] +530 0 80 "" 321.6299 577.15 0.0 00000000 00000000 1 [ ] +531 0 80 "" 322.2295 599.61 0.0 00000000 00000000 1 [ ] +532 0 80 "" 322.8564 626.95 0.0 00000000 00000000 1 [ ] +533 0 70 "" 323.4268 570.31 0.0 00000000 00000000 1 [ ] +534 0 80 "" 324.0098 583.01 0.0 00000000 00000000 1 [ ] +535 0 80 "" 324.6201 610.35 0.0 00000000 00000000 1 [ ] +536 0 80 "" 325.2168 596.68 0.0 00000000 00000000 1 [ ] +537 0 80 "" 325.8428 625.98 0.0 00000000 00000000 1 [ ] +538 0 80 "" 326.4668 624.02 0.0 00000000 00000000 1 [ ] +539 0 80 "" 327.0566 589.84 0.0 00000000 00000000 1 [ ] +540 0 70 "" 327.6260 569.34 0.0 00000000 00000000 1 [ ] +541 0 80 "" 328.1602 534.18 0.0 00000000 00000000 1 [ ] +542 0 80 "" 328.7793 619.14 0.0 00000000 00000000 1 [ ] +543 0 80 "" 329.4092 629.88 0.0 00000000 00000000 1 [ ] +544 0 80 "" 329.9697 560.55 0.0 00000000 00000000 1 [ ] +545 0 70 "" 330.5293 559.57 0.0 00000000 00000000 1 [ ] +546 0 80 "" 331.0996 570.31 0.0 00000000 00000000 1 [ ] +547 0 80 "" 331.6895 589.84 0.0 00000000 00000000 1 [ ] +548 0 70 "" 332.2900 600.59 0.0 00000000 00000000 1 [ ] +549 0 80 "" 332.8301 540.04 0.0 00000000 00000000 1 [ ] +550 0 80 "" 333.3730 542.97 0.0 00000000 00000000 1 [ ] +551 0 70 "" 333.9629 589.84 0.0 00000000 00000000 1 [ ] +552 0 80 "" 334.5664 603.52 0.0 00000000 00000000 1 [ ] +553 0 80 "" 335.1758 609.38 0.0 00000000 00000000 1 [ ] +554 0 80 "" 335.7393 563.48 0.0 00000000 00000000 1 [ ] +555 0 80 "" 336.3359 596.68 0.0 00000000 00000000 1 [ ] +556 0 80 "" 336.9199 583.98 0.0 00000000 00000000 1 [ ] +557 0 80 "" 337.5166 596.68 0.0 00000000 00000000 1 [ ] +558 0 80 "" 338.0859 569.34 0.0 00000000 00000000 1 [ ] +559 0 70 "" 338.6260 540.04 0.0 00000000 00000000 1 [ ] +560 0 80 "" 339.2461 620.12 0.0 00000000 00000000 1 [ ] +561 0 80 "" 339.7793 533.20 0.0 00000000 00000000 1 [ ] +562 0 80 "" 340.3125 533.20 0.0 00000000 00000000 1 [ ] +563 0 80 "" 340.9365 624.02 0.0 00000000 00000000 1 [ ] +564 0 80 "" 341.4863 549.80 0.0 00000000 00000000 1 [ ] +565 0 80 "" 342.0527 566.41 0.0 00000000 00000000 1 [ ] +566 0 80 "" 342.6191 566.41 0.0 00000000 00000000 1 [ ] +567 0 80 "" 343.1895 570.31 0.0 00000000 00000000 1 [ ] +568 0 70 "" 343.7627 573.24 0.0 00000000 00000000 1 [ ] +569 0 80 "" 344.3057 542.97 0.0 00000000 00000000 1 [ ] +570 0 70 "" 344.8525 546.88 0.0 00000000 00000000 1 [ ] +571 0 80 "" 345.3994 546.88 0.0 00000000 00000000 1 [ ] +572 0 80 "" 345.9893 589.84 0.0 00000000 00000000 1 [ ] +573 0 80 "" 346.5625 573.24 0.0 00000000 00000000 1 [ ] +574 0 80 "" 347.1592 596.68 0.0 00000000 00000000 1 [ ] +575 0 80 "" 347.7695 610.35 0.0 00000000 00000000 1 [ ] +576 0 80 "" 348.4023 632.81 0.0 00000000 00000000 1 [ ] +577 0 80 "" 349.0391 636.72 0.0 00000000 00000000 1 [ ] +578 0 70 "" 349.6494 610.35 0.0 00000000 00000000 1 [ ] +579 0 80 "" 350.2559 606.45 0.0 00000000 00000000 1 [ ] +580 0 70 "" 350.8721 616.21 0.0 00000000 00000000 1 [ ] +581 0 80 "" 351.4229 550.78 0.0 00000000 00000000 1 [ ] +582 0 80 "" 352.0527 629.88 0.0 00000000 00000000 1 [ ] +583 0 80 "" 352.6787 625.98 0.0 00000000 00000000 1 [ ] +584 0 80 "" 353.2627 583.98 0.0 00000000 00000000 1 [ ] +585 0 80 "" 353.8926 629.88 0.0 00000000 00000000 1 [ ] +586 0 80 "" 354.4258 533.20 0.0 00000000 00000000 1 [ ] +587 0 80 "" 355.0459 620.12 0.0 00000000 00000000 1 [ ] +588 0 80 "" 355.6260 580.08 0.0 00000000 00000000 1 [ ] +589 0 70 "" 356.1992 573.24 0.0 00000000 00000000 1 [ ] +590 0 80 "" 356.8291 629.88 0.0 00000000 00000000 1 [ ] +591 0 80 "" 357.4053 576.17 0.0 00000000 00000000 1 [ ] +592 0 80 "" 358.0293 624.02 0.0 00000000 00000000 1 [ ] +593 0 80 "" 358.6523 623.05 0.0 00000000 00000000 1 [ ] +594 0 80 "" 359.2891 636.72 0.0 00000000 00000000 1 [ ] +595 0 80 "" 359.8691 580.08 0.0 00000000 00000000 1 [ ] +596 0 80 "" 360.4326 563.48 0.0 00000000 00000000 1 [ ] +597 0 70 "" 361.0254 592.77 0.0 00000000 00000000 1 [ ] +598 0 80 "" 361.6055 580.08 0.0 00000000 00000000 1 [ ] +599 0 80 "" 362.1826 577.15 0.0 00000000 00000000 1 [ ] +600 0 80 "" 362.7393 556.64 0.0 00000000 00000000 1 [ ] +601 0 80 "" 363.2988 559.57 0.0 00000000 00000000 1 [ ] +602 0 80 "" 363.8525 553.71 0.0 00000000 00000000 1 [ ] +603 0 80 "" 364.4258 573.24 0.0 00000000 00000000 1 [ ] +604 0 80 "" 365.0557 629.88 0.0 00000000 00000000 1 [ ] +605 0 70 "" 365.6689 613.28 0.0 00000000 00000000 1 [ ] +606 0 80 "" 366.2119 542.97 0.0 00000000 00000000 1 [ ] +607 0 70 "" 366.7617 549.80 0.0 00000000 00000000 1 [ ] +608 0 80 "" 367.3857 624.02 0.0 00000000 00000000 1 [ ] +609 0 80 "" 368.0020 616.21 0.0 00000000 00000000 1 [ ] +610 0 70 "" 368.5723 570.31 0.0 00000000 00000000 1 [ ] +611 0 80 "" 369.1523 580.08 0.0 00000000 00000000 1 [ ] +612 0 80 "" 369.7021 549.80 0.0 00000000 00000000 1 [ ] +613 0 70 "" 370.2354 533.20 0.0 00000000 00000000 1 [ ] +614 0 80 "" 370.7891 553.71 0.0 00000000 00000000 1 [ ] +615 0 70 "" 371.4258 636.72 0.0 00000000 00000000 1 [ ] +616 0 80 "" 372.0020 576.17 0.0 00000000 00000000 1 [ ] +617 0 80 "" 372.6152 613.28 0.0 00000000 00000000 1 [ ] +618 0 80 "" 373.1650 549.80 0.0 00000000 00000000 1 [ ] +619 0 70 "" 373.7852 620.12 0.0 00000000 00000000 1 [ ] +620 0 80 "" 374.3389 553.71 0.0 00000000 00000000 1 [ ] +621 0 80 "" 374.8887 549.80 0.0 00000000 00000000 1 [ ] +622 0 80 "" 375.4619 573.24 0.0 00000000 00000000 1 [ ] +623 0 80 "" 376.0654 603.52 0.0 00000000 00000000 1 [ ] +624 0 80 "" 376.6582 592.77 0.0 00000000 00000000 1 [ ] +625 0 70 "" 377.2090 550.78 0.0 00000000 00000000 1 [ ] +626 0 80 "" 377.7891 580.08 0.0 00000000 00000000 1 [ ] +627 0 70 "" 378.4219 632.81 0.0 00000000 00000000 1 [ ] +628 0 80 "" 379.0488 626.95 0.0 00000000 00000000 1 [ ] +629 0 80 "" 379.6484 599.61 0.0 00000000 00000000 1 [ ] +630 0 80 "" 380.2715 623.05 0.0 00000000 00000000 1 [ ] +631 0 70 "" 380.8584 586.91 0.0 00000000 00000000 1 [ ] +632 0 80 "" 381.4385 580.08 0.0 00000000 00000000 1 [ ] +633 0 80 "" 382.0752 636.72 0.0 00000000 00000000 1 [ ] +634 0 80 "" 382.6748 599.61 0.0 00000000 00000000 1 [ ] +635 0 80 "" 383.2119 537.11 0.0 00000000 00000000 1 [ ] +636 0 80 "" 383.8154 603.52 0.0 00000000 00000000 1 [ ] +637 0 80 "" 384.3887 573.24 0.0 00000000 00000000 1 [ ] +638 0 80 "" 385.0186 629.88 0.0 00000000 00000000 1 [ ] +639 0 80 "" 385.5654 546.88 0.0 00000000 00000000 1 [ ] +640 0 80 "" 386.1416 576.17 0.0 00000000 00000000 1 [ ] +641 0 70 "" 386.7881 646.48 0.0 00000000 00000000 1 [ ] +642 0 80 "" 387.3281 540.04 0.0 00000000 00000000 1 [ ] +643 0 70 "" 387.9385 610.35 0.0 00000000 00000000 1 [ ] +644 0 80 "" 388.5654 626.95 0.0 00000000 00000000 1 [ ] +645 0 80 "" 389.1885 623.05 0.0 00000000 00000000 1 [ ] +646 0 70 "" 389.7480 559.57 0.0 00000000 00000000 1 [ ] +647 0 80 "" 390.3184 570.31 0.0 00000000 00000000 1 [ ] +648 0 80 "" 390.8584 540.04 0.0 00000000 00000000 1 [ ] +649 0 70 "" 391.4648 606.45 0.0 00000000 00000000 1 [ ] +650 0 80 "" 392.0947 629.88 0.0 00000000 00000000 1 [ ] +651 0 80 "" 392.6953 600.59 0.0 00000000 00000000 1 [ ] +652 0 80 "" 393.2480 552.73 0.0 00000000 00000000 1 [ ] +653 0 80 "" 393.8545 606.45 0.0 00000000 00000000 1 [ ] +654 0 80 "" 394.4512 596.68 0.0 00000000 00000000 1 [ ] +655 0 80 "" 394.9912 540.04 0.0 00000000 00000000 1 [ ] +656 0 80 "" 395.5215 530.27 0.0 00000000 00000000 1 [ ] +657 0 80 "" 396.1211 599.61 0.0 00000000 00000000 1 [ ] +658 0 80 "" 396.7412 620.12 0.0 00000000 00000000 1 [ ] +659 0 80 "" 397.2920 550.78 0.0 00000000 00000000 1 [ ] +660 0 80 "" 397.8750 583.01 0.0 00000000 00000000 1 [ ] +661 0 80 "" 398.4619 586.91 0.0 00000000 00000000 1 [ ] +662 0 80 "" 399.0410 579.10 0.0 00000000 00000000 1 [ ] +663 0 80 "" 399.5850 543.95 0.0 00000000 00000000 1 [ ] +664 0 80 "" 400.1484 563.48 0.0 00000000 00000000 1 [ ] +665 0 70 "" 400.6943 545.90 0.0 00000000 00000000 1 [ ] +666 0 80 "" 401.3213 626.95 0.0 00000000 00000000 1 [ ] +667 0 70 "" 401.8750 553.71 0.0 00000000 00000000 1 [ ] +668 0 80 "" 402.4287 553.71 0.0 00000000 00000000 1 [ ] +669 0 80 "" 403.0146 585.94 0.0 00000000 00000000 1 [ ] +670 0 80 "" 403.6182 603.52 0.0 00000000 00000000 1 [ ] +671 0 80 "" 404.2080 589.84 0.0 00000000 00000000 1 [ ] +672 0 80 "" 404.7617 553.71 0.0 00000000 00000000 1 [ ] +673 0 80 "" 405.3613 599.61 0.0 00000000 00000000 1 [ ] +674 0 70 "" 405.9551 593.75 0.0 00000000 00000000 1 [ ] +675 0 80 "" 406.5645 609.38 0.0 00000000 00000000 1 [ ] +676 0 70 "" 407.1680 603.52 0.0 00000000 00000000 1 [ ] +677 0 80 "" 407.7080 540.04 0.0 00000000 00000000 1 [ ] +678 0 80 "" 408.2979 589.84 0.0 00000000 00000000 1 [ ] +679 0 80 "" 408.8916 593.75 0.0 00000000 00000000 1 [ ] +680 0 80 "" 409.5283 636.72 0.0 00000000 00000000 1 [ ] +681 0 80 "" 410.1182 589.84 0.0 00000000 00000000 1 [ ] +682 0 70 "" 410.6943 576.17 0.0 00000000 00000000 1 [ ] +683 0 80 "" 411.3281 633.79 0.0 00000000 00000000 1 [ ] +684 0 70 "" 411.9082 580.08 0.0 00000000 00000000 1 [ ] +685 0 80 "" 412.5146 606.45 0.0 00000000 00000000 1 [ ] +686 0 80 "" 413.0850 570.31 0.0 00000000 00000000 1 [ ] +687 0 80 "" 413.6416 556.64 0.0 00000000 00000000 1 [ ] +688 0 70 "" 414.1953 553.71 0.0 00000000 00000000 1 [ ] +689 0 80 "" 414.7676 572.27 0.0 00000000 00000000 1 [ ] +690 0 80 "" 415.3740 606.45 0.0 00000000 00000000 1 [ ] +691 0 80 "" 415.9248 550.78 0.0 00000000 00000000 1 [ ] +692 0 80 "" 416.5479 623.05 0.0 00000000 00000000 1 [ ] +693 0 80 "" 417.1143 566.41 0.0 00000000 00000000 1 [ ] +694 0 80 "" 417.6846 570.31 0.0 00000000 00000000 1 [ ] +695 0 80 "" 418.2510 566.41 0.0 00000000 00000000 1 [ ] +696 0 80 "" 418.8281 577.15 0.0 00000000 00000000 1 [ ] +697 0 80 "" 419.4512 623.05 0.0 00000000 00000000 1 [ ] +698 0 80 "" 420.0146 563.48 0.0 00000000 00000000 1 [ ] +699 0 70 "" 420.6074 592.77 0.0 00000000 00000000 1 [ ] +700 0 80 "" 421.2480 640.62 0.0 00000000 00000000 1 [ ] +701 0 70 "" 421.7979 549.80 0.0 00000000 00000000 1 [ ] +702 0 80 "" 422.3809 583.01 0.0 00000000 00000000 1 [ ] +703 0 80 "" 422.9580 577.15 0.0 00000000 00000000 1 [ ] +704 0 80 "" 423.5908 632.81 0.0 00000000 00000000 1 [ ] +705 0 80 "" 424.2012 610.35 0.0 00000000 00000000 1 [ ] +706 0 70 "" 424.7510 549.80 0.0 00000000 00000000 1 [ ] +707 0 80 "" 425.3506 599.61 0.0 00000000 00000000 1 [ ] +708 0 80 "" 425.8945 543.95 0.0 00000000 00000000 1 [ ] +709 0 80 "" 426.4980 603.52 0.0 00000000 00000000 1 [ ] +710 0 80 "" 427.0605 562.50 0.0 00000000 00000000 1 [ ] +711 0 80 "" 427.6445 583.98 0.0 00000000 00000000 1 [ ] +712 0 80 "" 428.2012 556.64 0.0 00000000 00000000 1 [ ] +713 0 80 "" 428.7646 563.48 0.0 00000000 00000000 1 [ ] +714 0 80 "" 429.3779 613.28 0.0 00000000 00000000 1 [ ] +715 0 80 "" 429.9873 609.38 0.0 00000000 00000000 1 [ ] +716 0 80 "" 430.5605 573.24 0.0 00000000 00000000 1 [ ] +717 0 70 "" 431.1309 570.31 0.0 00000000 00000000 1 [ ] +718 0 80 "" 431.6846 553.71 0.0 00000000 00000000 1 [ ] +719 0 80 "" 432.2471 562.50 0.0 00000000 00000000 1 [ ] +720 0 80 "" 432.8174 570.31 0.0 00000000 00000000 1 [ ] +721 0 70 "" 433.4512 633.79 0.0 00000000 00000000 1 [ ] +722 0 80 "" 434.0811 629.88 0.0 00000000 00000000 1 [ ] +723 0 80 "" 434.6172 536.13 0.0 00000000 00000000 1 [ ] +724 0 80 "" 435.1973 580.08 0.0 00000000 00000000 1 [ ] +725 0 70 "" 435.7510 553.71 0.0 00000000 00000000 1 [ ] +726 0 80 "" 436.3369 585.94 0.0 00000000 00000000 1 [ ] +727 0 70 "" 436.9678 630.86 0.0 00000000 00000000 1 [ ] +728 0 80 "" 437.5508 583.01 0.0 00000000 00000000 1 [ ] +729 0 80 "" 438.1641 613.28 0.0 00000000 00000000 1 [ ] +730 0 80 "" 438.7109 546.88 0.0 00000000 00000000 1 [ ] +731 0 80 "" 439.2803 569.34 0.0 00000000 00000000 1 [ ] +732 0 70 "" 439.9209 640.62 0.0 00000000 00000000 1 [ ] +733 0 80 "" 440.5342 613.28 0.0 00000000 00000000 1 [ ] +734 0 70 "" 441.1035 569.34 0.0 00000000 00000000 1 [ ] +735 0 80 "" 441.6504 546.88 0.0 00000000 00000000 1 [ ] +736 0 80 "" 442.2373 586.91 0.0 00000000 00000000 1 [ ] +737 0 80 "" 442.7871 549.80 0.0 00000000 00000000 1 [ ] +738 0 80 "" 443.3877 600.59 0.0 00000000 00000000 1 [ ] +739 0 80 "" 443.9238 536.13 0.0 00000000 00000000 1 [ ] +740 0 80 "" 444.5439 620.12 0.0 00000000 00000000 1 [ ] +741 0 80 "" 445.1172 573.24 0.0 00000000 00000000 1 [ ] +742 0 80 "" 445.7109 593.75 0.0 00000000 00000000 1 [ ] +743 0 80 "" 446.2734 562.50 0.0 00000000 00000000 1 [ ] +744 0 80 "" 446.8701 596.68 0.0 00000000 00000000 1 [ ] +745 0 80 "" 447.4502 580.08 0.0 00000000 00000000 1 [ ] +746 0 80 "" 448.0801 629.88 0.0 00000000 00000000 1 [ ] +747 0 80 "" 448.6709 590.82 0.0 00000000 00000000 1 [ ] +748 0 70 "" 449.3174 646.48 0.0 00000000 00000000 1 [ ] +749 0 80 "" 449.8809 563.48 0.0 00000000 00000000 1 [ ] +750 0 80 "" 450.4805 599.61 0.0 00000000 00000000 1 [ ] +751 0 70 "" 451.0908 610.35 0.0 00000000 00000000 1 [ ] +752 0 80 "" 451.6201 529.30 0.0 00000000 00000000 1 [ ] +753 0 80 "" 452.1504 530.27 0.0 00000000 00000000 1 [ ] +754 0 80 "" 452.7500 599.61 0.0 00000000 00000000 1 [ ] +755 0 80 "" 453.3369 586.91 0.0 00000000 00000000 1 [ ] +756 0 70 "" 453.8867 549.80 0.0 00000000 00000000 1 [ ] +757 0 80 "" 454.4199 533.20 0.0 00000000 00000000 1 [ ] +758 0 80 "" 455.0332 613.28 0.0 00000000 00000000 1 [ ] +759 0 70 "" 455.6670 633.79 0.0 00000000 00000000 1 [ ] +760 0 80 "" 456.2373 570.31 0.0 00000000 00000000 1 [ ] +761 0 80 "" 456.8604 623.05 0.0 00000000 00000000 1 [ ] +762 0 80 "" 457.4873 626.95 0.0 00000000 00000000 1 [ ] +763 0 80 "" 458.0439 556.64 0.0 00000000 00000000 1 [ ] +764 0 70 "" 458.6270 583.01 0.0 00000000 00000000 1 [ ] +765 0 80 "" 459.2266 599.61 0.0 00000000 00000000 1 [ ] +766 0 80 "" 459.7832 556.64 0.0 00000000 00000000 1 [ ] +767 0 80 "" 460.4268 643.55 0.0 00000000 00000000 1 [ ] +768 0 80 "" 461.0205 593.75 0.0 00000000 00000000 1 [ ] +769 0 80 "" 461.6104 589.84 0.0 00000000 00000000 1 [ ] +770 0 80 "" 462.2432 632.81 0.0 00000000 00000000 1 [ ] +771 0 80 "" 462.7939 550.78 0.0 00000000 00000000 1 [ ] +772 0 80 "" 463.3633 569.34 0.0 00000000 00000000 1 [ ] +773 0 80 "" 463.9902 626.95 0.0 00000000 00000000 1 [ ] +774 0 80 "" 464.5898 599.61 0.0 00000000 00000000 1 [ ] +775 0 80 "" 465.1465 556.64 0.0 00000000 00000000 1 [ ] +776 0 80 "" 465.7734 626.95 0.0 00000000 00000000 1 [ ] +777 0 80 "" 466.3467 573.24 0.0 00000000 00000000 1 [ ] +778 0 80 "" 466.8838 537.11 0.0 00000000 00000000 1 [ ] +779 0 80 "" 467.5068 623.05 0.0 00000000 00000000 1 [ ] +780 0 80 "" 468.0732 566.41 0.0 00000000 00000000 1 [ ] +781 0 80 "" 468.6201 546.88 0.0 00000000 00000000 1 [ ] +782 0 70 "" 469.1797 559.57 0.0 00000000 00000000 1 [ ] +783 0 80 "" 469.7129 533.20 0.0 00000000 00000000 1 [ ] +784 0 70 "" 470.3203 607.42 0.0 00000000 00000000 1 [ ] +785 0 80 "" 470.8799 559.57 0.0 00000000 00000000 1 [ ] +786 0 70 "" 471.4736 593.75 0.0 00000000 00000000 1 [ ] +787 0 80 "" 472.0596 585.94 0.0 00000000 00000000 1 [ ] +788 0 70 "" 472.6699 610.35 0.0 00000000 00000000 1 [ ] +789 0 80 "" 473.2363 566.41 0.0 00000000 00000000 1 [ ] +790 0 70 "" 473.7861 549.80 0.0 00000000 00000000 1 [ ] +791 0 80 "" 474.3799 593.75 0.0 00000000 00000000 1 [ ] +792 0 70 "" 474.9102 530.27 0.0 00000000 00000000 1 [ ] +793 0 80 "" 475.4961 585.94 0.0 00000000 00000000 1 [ ] +794 0 70 "" 476.0869 590.82 0.0 00000000 00000000 1 [ ] +795 0 80 "" 476.6396 552.73 0.0 00000000 00000000 1 [ ] +796 0 80 "" 477.1836 543.95 0.0 00000000 00000000 1 [ ] +797 0 80 "" 477.8164 632.81 0.0 00000000 00000000 1 [ ] +798 0 80 "" 478.4033 586.91 0.0 00000000 00000000 1 [ ] +799 0 70 "" 479.0068 603.52 0.0 00000000 00000000 1 [ ] +800 0 80 "" 479.5732 566.41 0.0 00000000 00000000 1 [ ] +801 0 70 "" 480.2031 629.88 0.0 00000000 00000000 1 [ ] +802 0 80 "" 480.7734 570.31 0.0 00000000 00000000 1 [ ] +803 0 80 "" 481.3936 620.12 0.0 00000000 00000000 1 [ ] +804 0 70 "" 482.0029 609.38 0.0 00000000 00000000 1 [ ] +805 0 80 "" 482.5898 586.91 0.0 00000000 00000000 1 [ ] +806 0 80 "" 483.1465 556.64 0.0 00000000 00000000 1 [ ] +807 0 70 "" 483.7461 599.61 0.0 00000000 00000000 1 [ ] +808 0 80 "" 484.3096 563.48 0.0 00000000 00000000 1 [ ] +809 0 80 "" 484.8926 583.01 0.0 00000000 00000000 1 [ ] +810 0 70 "" 485.4834 590.82 0.0 00000000 00000000 1 [ ] +811 0 80 "" 486.0361 552.73 0.0 00000000 00000000 1 [ ] +812 0 80 "" 486.5928 556.64 0.0 00000000 00000000 1 [ ] +813 0 80 "" 487.1660 573.24 0.0 00000000 00000000 1 [ ] +814 0 80 "" 487.7061 540.04 0.0 00000000 00000000 1 [ ] +815 0 80 "" 488.3232 617.19 0.0 00000000 00000000 1 [ ] +816 0 80 "" 488.8691 545.90 0.0 00000000 00000000 1 [ ] +817 0 70 "" 489.4766 607.42 0.0 00000000 00000000 1 [ ] +818 0 80 "" 490.0264 549.80 0.0 00000000 00000000 1 [ ] +819 0 70 "" 490.5996 573.24 0.0 00000000 00000000 1 [ ] +820 0 80 "" 491.2129 613.28 0.0 00000000 00000000 1 [ ] +821 0 80 "" 491.8027 589.84 0.0 00000000 00000000 1 [ ] +822 0 80 "" 492.4229 620.12 0.0 00000000 00000000 1 [ ] +823 0 70 "" 493.0430 620.12 0.0 00000000 00000000 1 [ ] +824 0 80 "" 493.6562 613.28 0.0 00000000 00000000 1 [ ] +825 0 80 "" 494.2891 632.81 0.0 00000000 00000000 1 [ ] +826 0 80 "" 494.9199 630.86 0.0 00000000 00000000 1 [ ] +827 0 80 "" 495.5264 606.45 0.0 00000000 00000000 1 [ ] +828 0 80 "" 496.1064 580.08 0.0 00000000 00000000 1 [ ] +829 0 80 "" 496.7295 623.05 0.0 00000000 00000000 1 [ ] +830 0 80 "" 497.3496 620.12 0.0 00000000 00000000 1 [ ] +831 0 80 "" 497.9531 603.52 0.0 00000000 00000000 1 [ ] +832 0 80 "" 498.5059 552.73 0.0 00000000 00000000 1 [ ] +833 0 80 "" 499.1289 623.05 0.0 00000000 00000000 1 [ ] +834 0 80 "" 499.7295 600.59 0.0 00000000 00000000 1 [ ] +835 0 80 "" 500.2822 552.73 0.0 00000000 00000000 1 [ ] +836 0 80 "" 500.8564 574.22 0.0 00000000 00000000 1 [ ] +837 0 80 "" 501.4092 552.73 0.0 00000000 00000000 1 [ ] +838 0 80 "" 501.9824 573.24 0.0 00000000 00000000 1 [ ] +839 0 80 "" 502.5859 603.52 0.0 00000000 00000000 1 [ ] +840 0 80 "" 503.2061 620.12 0.0 00000000 00000000 1 [ ] +841 0 80 "" 503.8291 623.05 0.0 00000000 00000000 1 [ ] +842 0 80 "" 504.3789 549.80 0.0 00000000 00000000 1 [ ] +843 0 80 "" 504.9893 610.35 0.0 00000000 00000000 1 [ ] +844 0 70 "" 505.6260 636.72 0.0 00000000 00000000 1 [ ] +845 0 80 "" 506.1895 563.48 0.0 00000000 00000000 1 [ ] +846 0 80 "" 506.7959 606.45 0.0 00000000 00000000 1 [ ] +847 0 80 "" 507.4463 650.39 0.0 00000000 00000000 1 [ ] +848 0 80 "" 508.0430 596.68 0.0 00000000 00000000 1 [ ] +849 0 70 "" 508.5928 549.80 0.0 00000000 00000000 1 [ ] +850 0 80 "" 509.1963 603.52 0.0 00000000 00000000 1 [ ] +851 0 80 "" 509.7861 589.84 0.0 00000000 00000000 1 [ ] +852 0 70 "" 510.3789 592.77 0.0 00000000 00000000 1 [ ] +853 0 80 "" 510.9287 549.80 0.0 00000000 00000000 1 [ ] +854 0 80 "" 511.5322 603.52 0.0 00000000 00000000 1 [ ] +855 0 70 "" 512.1357 603.52 0.0 00000000 00000000 1 [ ] +856 0 80 "" 512.6992 563.48 0.0 00000000 00000000 1 [ ] +857 0 80 "" 513.3457 646.48 0.0 00000000 00000000 1 [ ] +858 0 80 "" 513.9521 606.45 0.0 00000000 00000000 1 [ ] +859 0 70 "" 514.5527 600.59 0.0 00000000 00000000 1 [ ] +860 0 80 "" 515.1387 585.94 0.0 00000000 00000000 1 [ ] +861 0 80 "" 515.7754 636.72 0.0 00000000 00000000 1 [ ] +862 0 70 "" 516.3721 596.68 0.0 00000000 00000000 1 [ ] +863 0 80 "" 516.9893 617.19 0.0 00000000 00000000 1 [ ] +864 0 70 "" 517.5459 556.64 0.0 00000000 00000000 1 [ ] +865 0 80 "" 518.1055 559.57 0.0 00000000 00000000 1 [ ] +866 0 70 "" 518.7021 596.68 0.0 00000000 00000000 1 [ ] +867 0 80 "" 519.2822 580.08 0.0 00000000 00000000 1 [ ] +868 0 70 "" 519.8418 559.57 0.0 00000000 00000000 1 [ ] +869 0 80 "" 520.4658 624.02 0.0 00000000 00000000 1 [ ] +870 0 80 "" 520.9990 533.20 0.0 00000000 00000000 1 [ ] +871 0 80 "" 521.5986 599.61 0.0 00000000 00000000 1 [ ] +872 0 80 "" 522.1553 556.64 0.0 00000000 00000000 1 [ ] +873 0 80 "" 522.7090 553.71 0.0 00000000 00000000 1 [ ] +874 0 70 "" 523.3057 596.68 0.0 00000000 00000000 1 [ ] +875 0 80 "" 523.8789 573.24 0.0 00000000 00000000 1 [ ] +876 0 80 "" 524.4756 596.68 0.0 00000000 00000000 1 [ ] +877 0 80 "" 525.0723 596.68 0.0 00000000 00000000 1 [ ] +878 0 80 "" 525.6523 580.08 0.0 00000000 00000000 1 [ ] +879 0 70 "" 526.2090 556.64 0.0 00000000 00000000 1 [ ] +880 0 80 "" 526.8018 592.77 0.0 00000000 00000000 1 [ ] +881 0 80 "" 527.3623 560.55 0.0 00000000 00000000 1 [ ] +882 0 80 "" 527.9121 549.80 0.0 00000000 00000000 1 [ ] +883 0 70 "" 528.5322 620.12 0.0 00000000 00000000 1 [ ] +884 0 80 "" 529.1621 629.88 0.0 00000000 00000000 1 [ ] +885 0 80 "" 529.7783 616.21 0.0 00000000 00000000 1 [ ] +886 0 80 "" 530.3252 546.88 0.0 00000000 00000000 1 [ ] +887 0 80 "" 530.8984 573.24 0.0 00000000 00000000 1 [ ] +888 0 70 "" 531.5117 613.28 0.0 00000000 00000000 1 [ ] +889 0 80 "" 532.1221 610.35 0.0 00000000 00000000 1 [ ] +890 0 70 "" 532.7422 620.12 0.0 00000000 00000000 1 [ ] +891 0 80 "" 533.3457 603.52 0.0 00000000 00000000 1 [ ] +892 0 80 "" 533.8955 549.80 0.0 00000000 00000000 1 [ ] +893 0 80 "" 534.4990 603.52 0.0 00000000 00000000 1 [ ] +894 0 70 "" 535.0420 542.97 0.0 00000000 00000000 1 [ ] +895 0 80 "" 535.5752 533.20 0.0 00000000 00000000 1 [ ] +896 0 80 "" 536.1787 603.52 0.0 00000000 00000000 1 [ ] +897 0 80 "" 536.7422 563.48 0.0 00000000 00000000 1 [ ] +898 0 80 "" 537.3555 613.28 0.0 00000000 00000000 1 [ ] +899 0 70 "" 537.9414 585.94 0.0 00000000 00000000 1 [ ] +900 0 80 "" 538.4883 546.88 0.0 00000000 00000000 1 [ ] +901 0 80 "" 539.0488 560.55 0.0 00000000 00000000 1 [ ] +902 0 80 "" 539.6787 629.88 0.0 00000000 00000000 1 [ ] +903 0 80 "" 540.2656 586.91 0.0 00000000 00000000 1 [ ] +904 0 70 "" 540.8984 632.81 0.0 00000000 00000000 1 [ ] +905 0 80 "" 541.4482 549.80 0.0 00000000 00000000 1 [ ] +906 0 80 "" 542.0283 580.08 0.0 00000000 00000000 1 [ ] +907 0 80 "" 542.5752 546.88 0.0 00000000 00000000 1 [ ] +908 0 80 "" 543.1953 620.12 0.0 00000000 00000000 1 [ ] +909 0 80 "" 543.8389 643.55 0.0 00000000 00000000 1 [ ] +910 0 80 "" 544.4287 589.84 0.0 00000000 00000000 1 [ ] +911 0 80 "" 545.0586 629.88 0.0 00000000 00000000 1 [ ] +912 0 80 "" 545.6016 542.97 0.0 00000000 00000000 1 [ ] +913 0 70 "" 546.2119 610.35 0.0 00000000 00000000 1 [ ] +914 0 80 "" 546.8320 620.12 0.0 00000000 00000000 1 [ ] +915 0 80 "" 547.4453 613.28 0.0 00000000 00000000 1 [ ] +916 0 80 "" 547.9980 552.73 0.0 00000000 00000000 1 [ ] +917 0 80 "" 548.5586 560.55 0.0 00000000 00000000 1 [ ] +918 0 80 "" 549.1221 563.48 0.0 00000000 00000000 1 [ ] +919 0 70 "" 549.7383 616.21 0.0 00000000 00000000 1 [ ] +920 0 80 "" 550.3652 626.95 0.0 00000000 00000000 1 [ ] +921 0 80 "" 550.9648 599.61 0.0 00000000 00000000 1 [ ] +922 0 80 "" 551.5615 596.68 0.0 00000000 00000000 1 [ ] +923 0 70 "" 552.1416 580.08 0.0 00000000 00000000 1 [ ] +924 0 80 "" 552.7578 616.21 0.0 00000000 00000000 1 [ ] +925 0 80 "" 553.3779 620.12 0.0 00000000 00000000 1 [ ] +926 0 80 "" 553.9414 563.48 0.0 00000000 00000000 1 [ ] +927 0 70 "" 554.5615 620.12 0.0 00000000 00000000 1 [ ] +928 0 80 "" 555.1484 586.91 0.0 00000000 00000000 1 [ ] +929 0 70 "" 555.7344 585.94 0.0 00000000 00000000 1 [ ] +930 0 80 "" 556.2910 556.64 0.0 00000000 00000000 1 [ ] +931 0 70 "" 556.9248 633.79 0.0 00000000 00000000 1 [ ] +932 0 80 "" 557.4785 553.71 0.0 00000000 00000000 1 [ ] +933 0 80 "" 558.1113 632.81 0.0 00000000 00000000 1 [ ] +934 0 80 "" 558.7412 629.88 0.0 00000000 00000000 1 [ ] +935 0 80 "" 559.3379 596.68 0.0 00000000 00000000 1 [ ] +936 0 80 "" 559.9150 577.15 0.0 00000000 00000000 1 [ ] +937 0 80 "" 560.4785 563.48 0.0 00000000 00000000 1 [ ] +938 0 80 "" 561.0977 619.14 0.0 00000000 00000000 1 [ ] +939 0 70 "" 561.7178 620.12 0.0 00000000 00000000 1 [ ] +940 0 80 "" 562.2812 563.48 0.0 00000000 00000000 1 [ ] +941 0 80 "" 562.8613 580.08 0.0 00000000 00000000 1 [ ] +942 0 80 "" 563.4014 540.04 0.0 00000000 00000000 1 [ ] +943 0 80 "" 563.9814 580.08 0.0 00000000 00000000 1 [ ] +944 0 70 "" 564.5518 570.31 0.0 00000000 00000000 1 [ ] +945 0 80 "" 565.1416 589.84 0.0 00000000 00000000 1 [ ] +946 0 80 "" 565.6914 549.80 0.0 00000000 00000000 1 [ ] +947 0 70 "" 566.3115 620.12 0.0 00000000 00000000 1 [ ] +948 0 80 "" 566.8613 549.80 0.0 00000000 00000000 1 [ ] +949 0 70 "" 567.4248 563.48 0.0 00000000 00000000 1 [ ] +950 0 80 "" 568.0684 643.55 0.0 00000000 00000000 1 [ ] +951 0 70 "" 568.6143 545.90 0.0 00000000 00000000 1 [ ] +952 0 80 "" 569.1445 530.27 0.0 00000000 00000000 1 [ ] +953 0 80 "" 569.7676 623.05 0.0 00000000 00000000 1 [ ] +954 0 80 "" 570.3145 546.88 0.0 00000000 00000000 1 [ ] +955 0 80 "" 570.8643 549.80 0.0 00000000 00000000 1 [ ] +956 0 80 "" 571.4678 603.52 0.0 00000000 00000000 1 [ ] +957 0 80 "" 572.0615 593.75 0.0 00000000 00000000 1 [ ] +958 0 80 "" 572.6611 599.61 0.0 00000000 00000000 1 [ ] +959 0 80 "" 573.2441 583.01 0.0 00000000 00000000 1 [ ] +960 0 80 "" 573.8076 563.48 0.0 00000000 00000000 1 [ ] +961 0 80 "" 574.3545 546.88 0.0 00000000 00000000 1 [ ] +962 0 80 "" 574.9844 629.88 0.0 00000000 00000000 1 [ ] +963 0 80 "" 575.5840 599.61 0.0 00000000 00000000 1 [ ] +964 0 70 "" 576.1543 570.31 0.0 00000000 00000000 1 [ ] +965 0 80 "" 576.7881 633.79 0.0 00000000 00000000 1 [ ] +966 0 80 "" 577.3574 569.34 0.0 00000000 00000000 1 [ ] +967 0 70 "" 577.9609 603.52 0.0 00000000 00000000 1 [ ] +968 0 80 "" 578.5811 620.12 0.0 00000000 00000000 1 [ ] +969 0 80 "" 579.2080 626.95 0.0 00000000 00000000 1 [ ] +970 0 70 "" 579.7676 559.57 0.0 00000000 00000000 1 [ ] +971 0 80 "" 580.3340 566.41 0.0 00000000 00000000 1 [ ] +972 0 80 "" 580.9707 636.72 0.0 00000000 00000000 1 [ ] +973 0 80 "" 581.6172 646.48 0.0 00000000 00000000 1 [ ] +974 0 80 "" 582.1973 580.08 0.0 00000000 00000000 1 [ ] +975 0 80 "" 582.7441 546.88 0.0 00000000 00000000 1 [ ] +976 0 80 "" 583.3838 639.65 0.0 00000000 00000000 1 [ ] +977 0 80 "" 583.9941 610.35 0.0 00000000 00000000 1 [ ] +978 0 80 "" 584.5205 526.37 0.0 00000000 00000000 1 [ ] +979 0 80 "" 585.0645 543.95 0.0 00000000 00000000 1 [ ] +980 0 80 "" 585.6377 573.24 0.0 00000000 00000000 1 [ ] +981 0 80 "" 586.1846 546.88 0.0 00000000 00000000 1 [ ] +982 0 80 "" 586.8037 619.14 0.0 00000000 00000000 1 [ ] +983 0 80 "" 587.4004 596.68 0.0 00000000 00000000 1 [ ] +984 0 80 "" 588.0342 633.79 0.0 00000000 00000000 1 [ ] +985 0 80 "" 588.6279 593.75 0.0 00000000 00000000 1 [ ] +986 0 80 "" 589.1846 556.64 0.0 00000000 00000000 1 [ ] +987 0 80 "" 589.7539 569.34 0.0 00000000 00000000 1 [ ] +988 0 80 "" 590.3340 580.08 0.0 00000000 00000000 1 [ ] +989 0 80 "" 590.8672 533.20 0.0 00000000 00000000 1 [ ] +990 0 70 "" 591.4639 596.68 0.0 00000000 00000000 1 [ ] +991 0 80 "" 592.0840 620.12 0.0 00000000 00000000 1 [ ] +992 0 70 "" 592.7207 636.72 0.0 00000000 00000000 1 [ ] +993 0 80 "" 593.3408 620.12 0.0 00000000 00000000 1 [ ] +994 0 80 "" 593.9277 586.91 0.0 00000000 00000000 1 [ ] +995 0 70 "" 594.5508 623.05 0.0 00000000 00000000 1 [ ] +996 0 80 "" 595.1543 603.52 0.0 00000000 00000000 1 [ ] +997 0 70 "" 595.7109 556.64 0.0 00000000 00000000 1 [ ] +998 0 80 "" 596.2705 559.57 0.0 00000000 00000000 1 [ ] +999 0 70 "" 596.8076 537.11 0.0 00000000 00000000 1 [ ] +1000 0 80 "" 597.4141 606.45 0.0 00000000 00000000 1 [ ] +1001 0 80 "" 598.0176 603.52 0.0 00000000 00000000 1 [ ] +1002 0 80 "" 598.6475 629.88 0.0 00000000 00000000 1 [ ] +1003 0 1 "" 601.4287 2781.25 0.0 00000000 00000000 1 [ ] diff --git a/studio_functions/GUIs/ERP Tab/binoper_studioGUI.m b/studio_functions/GUIs/ERP Tab/binoper_studioGUI.m index 5a66387f..53b1db63 100755 --- a/studio_functions/GUIs/ERP Tab/binoper_studioGUI.m +++ b/studio_functions/GUIs/ERP Tab/binoper_studioGUI.m @@ -162,9 +162,8 @@ function binoper_studioGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Name & version % -erplab_studio_default_values; -version = erplabstudiover; - +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - Bin Operation GUI']) %formulas = erpworkingmemory('binformulas'); diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_CSD_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_CSD_GUI.m index 98d47310..59018577 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_CSD_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_CSD_GUI.m @@ -2,16 +2,15 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && Nov. 2023 % ERPLAB Studio function varargout = f_ERP_CSD_GUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@onErpChanged); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); gui_erp_CSD = struct(); @@ -21,11 +20,14 @@ [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; if nargin == 0 fig = figure(); % Parent figure - ERP_CSD_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Convert Voltage to CSD', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_CSD_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Convert Voltage to CSD', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_CSD_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Convert Voltage to CSD', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_CSD_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Convert Voltage to CSD', 'Padding', 5,... + 'BackgroundColor',ColorB_def); else - ERP_CSD_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Convert Voltage to CSD', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_CSD_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Convert Voltage to CSD', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @tool_link end %-----------------------------Draw the panel------------------------------------- @@ -35,272 +37,340 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_bin_operation(FonsizeDefault); varargout{1} = ERP_CSD_gui; function drawui_erp_bin_operation(FonsizeDefault) FontSize_defualt = FonsizeDefault; - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end + Enable_label = 'off'; [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; %%--------------------channel and bin setting---------------------- gui_erp_CSD.DataSelBox = uiextras.VBox('Parent', ERP_CSD_gui,'BackgroundColor',ColorB_def); - %%Display the lacations of electrodes: may use other function to - %%replace current one. - % gui_erp_CSD.erp_h_erp = uicontrol('Style','radiobutton','Parent', gui_erp_CSD.erp_history_title,'String','ERP','callback',@ERP_H_ERP,'Value',0); % 2F - gui_erp_CSD.erp_history_table = uiextras.HBox('Parent', gui_erp_CSD.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_CSD.erp_h_erp = axes( 'Parent', gui_erp_CSD.erp_history_table, 'ActivePositionProperty', 'Position'); - set( gui_erp_CSD.erp_h_erp,'xticklabel', [], 'yticklabel', []); - - %%Parameters gui_erp_CSD.sif_title = uiextras.HBox('Parent', gui_erp_CSD.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_CSD.sif_text = uicontrol('Style','text','Parent', gui_erp_CSD.sif_title,... 'String','Spline interpolation flexibility m-constant value (4 is recommended)','FontSize',FontSize_defualt,'Max',10,'BackgroundColor',ColorB_def); % 2F gui_erp_CSD.sif_num = uicontrol('Style','edit','Parent', gui_erp_CSD.sif_title,... - 'String','4','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_sif); % 2F + 'String','4','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_sif,'BackgroundColor',[1 1 1]); % 2F set(gui_erp_CSD.sif_title,'Sizes',[210,50]); - + gui_erp_CSD.sif_num.KeyPressFcn = @erp_csd_presskey; + gui_erp_CSD.Para{1} = str2num(gui_erp_CSD.sif_num.String); gui_erp_CSD.scl_title = uiextras.HBox('Parent', gui_erp_CSD.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_CSD.scl_text = uicontrol('Style','text','Parent', gui_erp_CSD.scl_title,... 'String','Smoothing constant lambda (0.00001 is recommended)','FontSize',FontSize_defualt,'Max',10,'BackgroundColor',ColorB_def); % 2F gui_erp_CSD.scl_num = uicontrol('Style','edit','Parent', gui_erp_CSD.scl_title,... - 'String','0.00001','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_scl); % 2F + 'String','0.00001','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_scl,'BackgroundColor',[1 1 1]); % 2F set(gui_erp_CSD.scl_title,'Sizes',[210,50]); - + gui_erp_CSD.scl_num.KeyPressFcn = @erp_csd_presskey; + gui_erp_CSD.Para{2} = str2num(gui_erp_CSD.scl_num.String); gui_erp_CSD.hr_title = uiextras.HBox('Parent', gui_erp_CSD.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_CSD.hr_text = uicontrol('Style','text','Parent', gui_erp_CSD.hr_title,... 'String','Head radius CSD rescaling values (10cm is recommended)','FontSize',FontSize_defualt,'Max',10,'BackgroundColor',ColorB_def); % 2F gui_erp_CSD.hr_num = uicontrol('Style','edit','Parent', gui_erp_CSD.hr_title,... - 'String','10','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_hr); % 2F + 'String','10','FontSize',FontSize_defualt,'Enable',Enable_label,'callback',@csd_hr,'BackgroundColor',[1 1 1]); % 2F set(gui_erp_CSD.hr_title,'Sizes',[210,50]); - + gui_erp_CSD.hr_num.KeyPressFcn = @erp_csd_presskey; + gui_erp_CSD.Para{3} = str2num(gui_erp_CSD.hr_num.String); %%-----------------Run--------------------------------------------- gui_erp_CSD.run_title = uiextras.HBox('Parent', gui_erp_CSD.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_CSD.run_title); + gui_erp_CSD.cancel= uicontrol('Style','pushbutton','Parent', gui_erp_CSD.run_title ,'Enable',Enable_label,... + 'String','Cancel','callback',@tool_cancel,'FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Max',10); % 2F + uiextras.Empty('Parent', gui_erp_CSD.run_title); gui_erp_CSD.run = uicontrol('Style','pushbutton','Parent',gui_erp_CSD.run_title,... - 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F uiextras.Empty('Parent', gui_erp_CSD.run_title); - set(gui_erp_CSD.run_title,'Sizes',[85 90 85]); - - gui_erp_CSD.location_title = uiextras.HBox('Parent', gui_erp_CSD.DataSelBox,'BackgroundColor',ColorB_def); - uicontrol('Style','pushbutton','Parent',gui_erp_CSD.location_title,... - 'String','?','callback',@tool_link,'FontSize',16,'BackgroundColor',[1 1 1],'Max',10); % 2F - gui_erp_CSD.location = uicontrol('Style','pushbutton','Parent',gui_erp_CSD.location_title,... - 'String','Expand Locations','callback',@CSD_undock_loct,'FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Enable',Enable_label); % 2F - set(gui_erp_CSD.DataSelBox,'Sizes',[230,40,40,40,30,30]); + set(gui_erp_CSD.run_title,'Sizes',[15 105 30 105 15]); + set(gui_erp_CSD.DataSelBox,'Sizes',[40,40,40,30]); + estudioworkingmemory('ERPTab_csd',0); end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% - function CSD_undock_loct(~,~) - %%https://github.com/lucklab/erplab/wiki/Current-Source-Density-(CSD)-tool -browser - csd_chan_locations; - end %%-------------------Setting value for Spline interpolation flexibility m-constant value---------------- function csd_sif(source,~) - mcont = str2double(source.String); - if isnan(mcont) - gui_erp_CSD.sif_num.String=4; - beep; - msgboxText = ['Convert voltage to CSD - Please ensure that the input was a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; - else - % input seems valid - % Save the new value - gui_erp_CSD.sif_num.String = mcont; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_CSD.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_CSD.run.ForegroundColor = [1 1 1]; + ERP_CSD_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_CSD.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_csd',1); + + mcont = str2num(source.String); + if isempty(mcont) || numel(mcont)~=1 + gui_erp_CSD.sif_num.String='4'; + msgboxText = ['Convert voltage to CSD - Please ensure that the input was a single value']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); end end %%-------------------Setting value for Smoothing constant lambda--------------------------------------- function csd_scl(source,~) - mcont = str2double(source.String); - if isnan(mcont) - gui_erp_CSD.scl_num.String=4; - beep; - msgboxText = ['Convert voltage to CSD - Please ensure that the input was a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; - else - % input seems valid - % Save the new value - gui_erp_CSD.scl_num.String = mcont; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_CSD.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_CSD.run.ForegroundColor = [1 1 1]; + ERP_CSD_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_CSD.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_csd',1); + + mcont = str2num(source.String); + if isempty(mcont) || numel(mcont)~=1 + gui_erp_CSD.scl_num.String='0.0001'; + msgboxText = ['Convert voltage to CSD - Please ensure that the input was a single value']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); end end %%-------------------setting Head radius CSD rescaling values--------------------------------------- function csd_hr(source,~) - mcont = str2double(source.String); - - if isnan(mcont) - gui_erp_CSD.hr_num.String=4; - beep; - msgboxText = ['Convert voltage to CSD - Please ensure that the input was a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; - else - % input seems valid - % Save the new value - gui_erp_CSD.hr_num.String = mcont; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_CSD.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_CSD.run.ForegroundColor = [1 1 1]; + ERP_CSD_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_CSD.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_csd',1); + mcont = str2num(source.String); + if isempty(mcont) || numel(mcont)~=1 + gui_erp_CSD.hr_num.String='10'; + msgboxText = ['Convert voltage to CSD - Please ensure that the input was a single value']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); end end -%%---------------------CSD tool link------------------------------------- - function tool_link(~,~) - web('https://github.com/lucklab/erplab/wiki/Current-Source-Density-(CSD)-tool','-browser'); - end + %%---------------------Run------------------------------------------------- function apply_run(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end csd_param(1) = str2double(gui_erp_CSD.sif_num.String); csd_param(2) = str2double(gui_erp_CSD.scl_num.String); csd_param(3) = str2double(gui_erp_CSD.hr_num.String); csd_param(4) = 1; - erpworkingmemory('csd_param',csd_param); - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - beep; - msgboxText = ['Convert voltage to CSD - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + estudioworkingmemory('csd_param',csd_param); + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); end + gui_erp_CSD.run.BackgroundColor = [1 1 1]; + gui_erp_CSD.run.ForegroundColor = [0 0 0]; + ERP_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [1 1 1]; + gui_erp_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_csd',0); + %%---------------------Compute CSD for each ERPset---------------- - try - erpworkingmemory('f_ERP_proces_messg','Convert Voltage to CSD'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - ALLERPCOM = evalin('base','ALLERPCOM'); - % Set names of slected ERPsets - Save_file_label = 0; - Answer = f_ERP_save_multi_file(observe_ERPDAT.ALLERP,Selectederp_Index,'_CSD'); - if isempty(Answer) - beep; - disp('User selected Cancel'); + estudioworkingmemory('f_ERP_proces_messg','Convert Voltage to CSD'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = []; end + % Set names of slected ERPsets + + gui_erp_CSD.Para{1} = str2num(gui_erp_CSD.sif_num.String); + gui_erp_CSD.Para{2} = str2num(gui_erp_CSD.scl_num.String); + gui_erp_CSD.Para{3} = str2num(gui_erp_CSD.hr_num.String); + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + %%Loop for the selcted ERPsets + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + [eloc, labels, theta, radius, indices] = readlocs(ERP.chanlocs); + thetacheck= isnan(theta); + radiuscheck= isnan(radius); + [~,ypostheta] = find(thetacheck(:)==1); + [~,yposradius] = find(radiuscheck(:)==1); + if ~isempty(ypostheta) && ~isempty(yposradius) + msgboxText = ['Current Source Density: Some electrodes for ERPset ',num2str(ERPArray(Numoferp)),32,'are missing electrode channel locations. Please check channel locations and try again.']; + titlNamerro = 'Warning for EEG Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - if ~isempty(Answer{1}) - ALLERP_out = Answer{1}; - Save_file_label = Answer{2}; - end - - %%Loop for the selcted ERPsets - for Numofselectederp = 1:numel(Selectederp_Index) - ERP = ALLERP_out(Selectederp_Index(Numofselectederp)); - [ERP, ERPCOM] = pop_currentsourcedensity(ERP); + ERP = pop_currentsourcedensity(ERP,'EStudio'); + ERPCOM = sprintf('%s=pop_currentsourcedensity(%s, %s);', 'ERP','ERP', '"EStudio"'); + if Numoferp == numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - %%display the loctions of electrodes for each selected ERPsets. - path_to_pic = which('CSD_elec_plot.png'); - if numel(path_to_pic) ~= 0 % iff a path to the pic exists, show it - myImage = imread('CSD_elec_plot.png'); - imshow(myImage,'Parent',gui_erp_CSD.erp_h_erp); - end - - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP;%%Save the transformed ERPset - if Save_file_label==1 - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + end + if Numoferp==1 + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + end%%Loop for ERPsets end + + Save_file_label = 0; + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_CSD'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - end%%Loop for ERPsets end - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('f_ERP_bin_opt',1); - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selectederp_Index)+1:length(observe_ERPDAT.ALLERP)]; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selectederp_Index)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; end - - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - return; + ALLERP(length(ALLERP)+1) = ERP; + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + + observe_ERPDAT.ALLERP = ALLERP; + estudioworkingmemory('f_ERP_bin_opt',1); + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - Selected_ERP_afd =observe_ERPDAT.CURRENTERP; - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%% end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end +%%----------------------function cancel------------------------------------ + function tool_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=8 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_CSD.sif_num.String = num2str( gui_erp_CSD.Para{1}); + gui_erp_CSD.scl_num.String= num2str( gui_erp_CSD.Para{2}); + gui_erp_CSD.hr_num.String = num2str( gui_erp_CSD.Para{3}); + + gui_erp_CSD.run.BackgroundColor = [1 1 1]; + gui_erp_CSD.run.ForegroundColor = [0 0 0]; + ERP_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [1 1 1]; + gui_erp_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_csd',0); + end %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - - if isempty(Selectederp_Index) - beep; - msgboxText = ['Convert voltage to CSD - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; + if observe_ERPDAT.Count_currentERP~=17 + return; end - if isempty(checked_ERPset_Index) - checked_ERPset_Index = f_checkerpsets(observe_ERPDAT.ALLERP,Selectederp_Index); + ViewerFlag=estudioworkingmemory('ViewerFlag');%%when open advanced wave viewer + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); end - if checked_curr_index || any(checked_ERPset_Index(:)) + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || ViewerFlag==1 Enable_label = 'off'; - else Enable_label = 'on'; - end gui_erp_CSD.run.Enable = Enable_label; gui_erp_CSD.sif_num.Enable = Enable_label; gui_erp_CSD.scl_num.Enable = Enable_label; gui_erp_CSD.hr_num.Enable = Enable_label; - gui_erp_CSD.location.Enable = Enable_label; + gui_erp_CSD.cancel.Enable = Enable_label; + observe_ERPDAT.Count_currentERP=18; + end + +%%--------------press return to execute "Apply"---------------------------- + function erp_csd_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_csd'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + apply_run(); + gui_erp_CSD.run.BackgroundColor = [1 1 1]; + gui_erp_CSD.run.ForegroundColor = [0 0 0]; + ERP_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [1 1 1]; + gui_erp_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_csd',0); + else + return; + end + end + + + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=14 + return; + end + gui_erp_CSD.run.BackgroundColor = [1 1 1]; + gui_erp_CSD.run.ForegroundColor = [0 0 0]; + ERP_CSD_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_CSD.cancel.BackgroundColor = [1 1 1]; + gui_erp_CSD.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_csd',0); + gui_erp_CSD.sif_num.String = '4'; + gui_erp_CSD.scl_num.String = '0.00001'; + gui_erp_CSD.hr_num.String = '10'; + observe_ERPDAT.Reset_erp_paras_panel=15; end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_append_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_append_GUI.m old mode 100644 new mode 100755 index d0fa6348..2644c101 --- a/studio_functions/GUIs/ERP Tab/f_ERP_append_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_append_GUI.m @@ -1,24 +1,20 @@ -%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Author: Guanghui ZHANG %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && Nov. 2023 % ERPLAB Studio function varargout = f_ERP_append_GUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@onErpChanged); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); -% addlistener(observe_ERPDAT,'Process_messg_change',@Process_messg_change); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); gui_erp_append = struct(); %-----------------------------Name the title---------------------------------------------- -% global box_erp_history; - try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch @@ -27,11 +23,14 @@ if nargin == 0 fig = figure(); % Parent figure - box_erp_history = uiextras.BoxPanel('Parent', fig, 'Title', 'Append ERPsets', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + box_erp_append = uiextras.BoxPanel('Parent', fig, 'Title', 'Append ERPsets', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - box_erp_history = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Append ERPsets', 'Padding', 5,'BackgroundColor',ColorB_def); + box_erp_append = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Append ERPsets', 'Padding', 5,... + 'BackgroundColor',ColorB_def); else - box_erp_history = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Append ERPsets', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + box_erp_append = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Append ERPsets', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @append_help end %-----------------------------Draw the panel------------------------------------- @@ -41,10 +40,10 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_append(FonsizeDefault); -varargout{1} = box_erp_history; +varargout{1} = box_erp_append; function drawui_erp_append(FonsizeDefault) try @@ -52,17 +51,20 @@ function drawui_erp_append(FonsizeDefault) catch ColorB_def = [0.95 0.95 0.95]; end + %%--------------------channel and bin setting---------------------- - gui_erp_append.DataSelBox = uiextras.VBox('Parent', box_erp_history,'BackgroundColor',ColorB_def); + gui_erp_append.DataSelBox = uiextras.VBox('Parent', box_erp_append,'BackgroundColor',ColorB_def); gui_erp_append.erpappend_select_title = uiextras.HBox('Parent', gui_erp_append.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_append.erpappend_select_title); gui_erp_append.sameerpset = uicontrol('Style','radiobutton','Parent', gui_erp_append.erpappend_select_title,'String','Same as ERPset Panel',... - 'callback',@same_to_erpset,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',1); % 2F - + 'callback',@same_to_erpset,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',1,'Enable','off'); % 2F + gui_erp_append.Paras{1} = gui_erp_append.sameerpset.Value; + gui_erp_append.sameerpset.KeyPressFcn = @erp_append_presskey; gui_erp_append.erpset_custom = uicontrol('Style','radiobutton','Parent',gui_erp_append.erpappend_select_title,'String','Custom',... - 'callback',@erpsetcutom,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0); + 'callback',@erpsetcutom,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); + gui_erp_append.erpset_custom.KeyPressFcn = @erp_append_presskey; set(gui_erp_append.erpappend_select_title, 'Sizes',[50 145 70]); gui_erp_append.erp_append_title = uiextras.HBox('Parent', gui_erp_append.DataSelBox,'BackgroundColor',ColorB_def); @@ -71,40 +73,47 @@ function drawui_erp_append(FonsizeDefault) gui_erp_append.erpset_edit = uicontrol('Style','edit','Parent', gui_erp_append.erp_append_title,'String',' ',... 'callback',@erpset_edit,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); % 2F set(gui_erp_append.erp_append_title, 'Sizes',[65 200]); - + gui_erp_append.Paras{2} = str2num(gui_erp_append.erpset_edit.String); + gui_erp_append.erpset_edit.KeyPressFcn = @erp_append_presskey; gui_erp_append.advance_help_title = uiextras.HBox('Parent',gui_erp_append.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); % uiextras.Empty('Parent', gui_erp_append.advance_help_title); - uicontrol('Style', 'pushbutton','Parent',gui_erp_append.advance_help_title,'String','?','callback',@erpset_append_help,'Enable','on','FontSize',16); + gui_erp_append.append_cancel= uicontrol('Style', 'pushbutton','Parent',gui_erp_append.advance_help_title,... + 'String','Cancel','callback',@append_cancel,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % uiextras.Empty('Parent', gui_erp_append.advance_help_title); gui_erp_append.append_advance = uicontrol('Style', 'pushbutton','Parent',gui_erp_append.advance_help_title,... - 'String','Advanced','callback',@advance_erpappend,'FontSize',FonsizeDefault); + 'String','Advanced','callback',@advance_erpappend,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); gui_erp_append.append_run = uicontrol('Style', 'pushbutton','Parent',gui_erp_append.advance_help_title,'String','Run',... - 'callback',@append_run,'FontSize',FonsizeDefault); - + 'callback',@append_run,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); set(gui_erp_append.DataSelBox,'Sizes',[30 25 30]); - - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - Enableflag = 'off'; - else - Enableflag = 'on'; - end - gui_erp_append.erpset_edit.Enable = Enableflag; - gui_erp_append.erpset_option.Enable = Enableflag; - gui_erp_append.append_advance.Enable = Enableflag; - gui_erp_append.append_run.Enable = Enableflag; - gui_erp_append.sameerpset.Enable = Enableflag; - gui_erp_append.erpset_custom.Enable = Enableflag; + estudioworkingmemory('ERPTab_append',0); end - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% %%-------------------------same_to_erpset---------------------------------- function same_to_erpset(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [msgboxText,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(msgboxText) && eegpanelIndex~=12 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_append',1); + gui_erp_append.append_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_append.append_run.ForegroundColor = [1 1 1]; + box_erp_append.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_append.append_cancel.ForegroundColor = [1 1 1]; + gui_erp_append.append_advance.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_append.append_advance.ForegroundColor = [1 1 1]; + gui_erp_append.sameerpset.Value=1; gui_erp_append.erpset_custom.Value=0; gui_erp_append.erpset_edit.Enable = 'off'; @@ -115,394 +124,496 @@ function same_to_erpset(~,~) %%-----------------erpsetcutom--------------------------------------------- function erpsetcutom(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [msgboxText,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(msgboxText) && eegpanelIndex~=12 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_append',1); + gui_erp_append.append_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_append.append_run.ForegroundColor = [1 1 1]; + box_erp_append.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_append.append_cancel.ForegroundColor = [1 1 1]; + gui_erp_append.append_advance.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_append.append_advance.ForegroundColor = [1 1 1]; + gui_erp_append.sameerpset.Value=0; gui_erp_append.erpset_custom.Value=1; gui_erp_append.erpset_edit.Enable = 'on'; end -%%-------------------------Append help------------------------------------ - function erpset_append_help(~,~) - web('https://github.com/lucklab/erplab/wiki/Appending-ERPSETS','-browser'); - end - - %%-------------------edit the ERPset to append----------------------------- function erpset_edit(Source,~) - ERPArray = str2num(Source.String); - if isempty(ERPArray) || numel(ERPArray)==1 - messgStr = strcat('Append ERPsets > You have to specify 2 ERPsets, at least.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end - if min(ERPArray) <=0 - messgStr = strcat('Append ERPsets > Index of inputs should not be larger than 0.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + %%first checking if the changes on the other panels have been applied + [msgboxText,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(msgboxText) && eegpanelIndex~=12 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_append',1); + gui_erp_append.append_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_append.append_run.ForegroundColor = [1 1 1]; + box_erp_append.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_append.append_cancel.ForegroundColor = [1 1 1]; + gui_erp_append.append_advance.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_append.append_advance.ForegroundColor = [1 1 1]; + + ERPArray = ceil(str2num(Source.String)); + if numel(ERPArray)<2 + msgboxText = strcat('Append ERPsets > You have to specify 2 ERPsets, at least.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + + return; + end + if any(ERPArray <1) + msgboxText = strcat('Append ERPsets > Index of inputs should not be larger than 0.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; return; end - if max(ERPArray) > length(observe_ERPDAT.ALLERP) - messgStr = strcat('Append ERPsets > Index of inputs should not be larger than',32,num2str(length(observe_ERPDAT.ALLERP)),'.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + if any(ERPArray > length(observe_ERPDAT.ALLERP)) + msgboxText = strcat('Append ERPsets > Index of inputs should not be larger than',32,num2str(length(observe_ERPDAT.ALLERP)),'.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; return; end end +%%--------------------------cancel----------------------------------------- + function append_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [msgboxText,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(msgboxText) && eegpanelIndex~=12 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_append',0); + gui_erp_append.append_run.BackgroundColor = [1 1 1]; + gui_erp_append.append_run.ForegroundColor = [0 0 0]; + box_erp_append.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [1 1 1]; + gui_erp_append.append_cancel.ForegroundColor = [0 0 0]; + gui_erp_append.append_advance.BackgroundColor = [1 1 1]; + gui_erp_append.append_advance.ForegroundColor = [0 0 0]; + + try sameerpset = gui_erp_append.Paras{1}; catch gui_erp_append.Paras{1}=1; sameerpset=1;end + if isempty(sameerpset) || numel(sameerpset)~=1 || (sameerpset~=0 && sameerpset~=1) + gui_erp_append.Paras{1}=1; sameerpset=1; + end + gui_erp_append.sameerpset.Value=sameerpset; + gui_erp_append.erpset_custom.Value=~sameerpset; + if sameerpset==1 + gui_erp_append.erpset_edit.Enable = 'off'; + else + gui_erp_append.erpset_edit.Enable = 'on'; + end + + try erpset_edit=gui_erp_append.Paras{2}; catch erpset_edit = [];gui_erp_append.Paras{2} = [];end + if isempty(erpset_edit) || any(erpset_edit> length(observe_ERPDAT.ALLERP)) || any(erpset_edit<1) + erpset_edit = [];gui_erp_append.Paras{2} = []; + end + gui_erp_append.erpset_edit.String = num2str(erpset_edit); + if sameerpset==1 + ERPArrayERPpanel = estudioworkingmemory('selectederpstudio'); + gui_erp_append.erpset_edit.String = num2str(ERPArrayERPpanel); + end + end + + %%-----------------Advance setting for ERPset append----------------------- function advance_erpappend(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [msgboxText,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(msgboxText) && eegpanelIndex~=12 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + %%Send message to Message panel - erpworkingmemory('f_ERP_proces_messg','Append ERPsets'); + estudioworkingmemory('f_ERP_proces_messg','Append ERPsets'); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. ERPArray = str2num(gui_erp_append.erpset_edit.String); - if isempty(ERPArray) || numel(ERPArray)==1 - messgStr = strcat('Append ERPsets > You have to specify 2 ERPsets, at least.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + if isempty(ERPArray) || numel(ERPArray)<2 + msgboxText = strcat('Append ERPsets > You have to specify 2 ERPsets, at least.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - if min(ERPArray) <=0 - messgStr = strcat('Append ERPsets > Index of inputs should not be larger than 0.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + if any(ERPArray <=0) + msgboxText = strcat('Append ERPsets > Index of inputs should not be larger than 0.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - if max(ERPArray) > length(observe_ERPDAT.ALLERP) - messgStr = strcat('Append ERPsets > Index of inputs should not be larger than',32,num2str(length(observe_ERPDAT.ALLERP)),'.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - beep; - observe_ERPDAT.Process_messg=4; + if any(ERPArray > length(observe_ERPDAT.ALLERP)) + msgboxText = strcat('Append ERPsets > Index of inputs should not be larger than',32,num2str(length(observe_ERPDAT.ALLERP)),'.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end %%check number of samples/channels, and data type - messgStr = check_ERPset(ERPArray); - if ~isempty(messgStr) - erpworkingmemory('f_ERP_proces_messg',messgStr); - beep; - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + msgboxText = check_ERPset(ERPArray); + if ~isempty(msgboxText) + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return end + estudioworkingmemory('ERPTab_append',0); + gui_erp_append.append_run.BackgroundColor = [1 1 1]; + gui_erp_append.append_run.ForegroundColor = [0 0 0]; + box_erp_append.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [1 1 1]; + gui_erp_append.append_cancel.ForegroundColor = [0 0 0]; + gui_erp_append.append_advance.BackgroundColor = [1 1 1]; + gui_erp_append.append_advance.ForegroundColor = [0 0 0]; - try - ALLERP= observe_ERPDAT.ALLERP; - nloadedset = length(observe_ERPDAT.ALLERP); - def = estudioworkingmemory('pop_appenderp'); - if isempty(def) - if isempty(observe_ERPDAT.ALLERP) - inp1 = 1; %from hard drive - erpset = []; - erpoption = 1; - else - inp1 = 0; %from erpset menu - erpset = 1:length(ALLERP); - erpoption = 1;%% 1. same as ERPset panel; 2 custom define - end - isprefix = 0; - prefixlist = ''; - def = {inp1 erpoption, erpset prefixlist}; - %def = { erpset prefixlist}; + + ALLERP= observe_ERPDAT.ALLERP; + nloadedset = length(observe_ERPDAT.ALLERP); + def = estudioworkingmemory('pop_appenderp'); + if isempty(def) + if isempty(observe_ERPDAT.ALLERP) + inp1 = 1; %from hard drive + erpset = []; + erpoption = 1; else - if ~isempty(ALLERP) - if isnumeric(def{2}) % JavierLC 11-17-11 - [uu, mm] = unique_bc2(def{3}, 'first'); - def{3} = [def{3}(sort(mm))]; - end - end + inp1 = 0; %from erpset menu + erpset = 1:length(ALLERP); + erpoption = 1;%% 1. same as ERPset panel; 2 custom define end - - ERPsetArraydef = str2num(gui_erp_append.erpset_edit.String); - if isempty(ERPsetArraydef) || max(ERPsetArraydef)> length(observe_ERPDAT.ALLERP) - ERPsetArraydef = observe_ERPDAT.CURRENTERP; + isprefix = 0; + prefixlist = ''; + def = {inp1 erpoption, erpset prefixlist}; + %def = { erpset prefixlist}; + else + if ~isempty(ALLERP) + if isnumeric(def{2}) % JavierLC 11-17-11 + [uu, mm] = unique_bc2(def{3}, 'first'); + def{3} = [def{3}(sort(mm))]; + end end - def{1} = 0; - def{3} = ERPsetArraydef; - def{2} = gui_erp_append.sameerpset.Value; - ERPArrayERPpanel = estudioworkingmemory('selectederpstudio'); - def{5} = ERPArrayERPpanel; - - % - % Call GUI - % - answer = f_appenderpGUI(nloadedset, def); - if isempty(answer) - disp('User selected Cancel') + end + + ERPsetArraydef = str2num(gui_erp_append.erpset_edit.String); + if isempty(ERPsetArraydef) || any(ERPsetArraydef> length(observe_ERPDAT.ALLERP)) + ERPsetArraydef = observe_ERPDAT.CURRENTERP; + end + def{1} = 0; + def{3} = ERPsetArraydef; + def{2} = gui_erp_append.sameerpset.Value; + ERPArrayERPpanel = estudioworkingmemory('selectederpstudio'); + def{5} = ERPArrayERPpanel; + + % + % Call GUI + % + answer = f_appenderpGUI(nloadedset, def); + if isempty(answer) + observe_ERPDAT.Process_messg =2; + return; + end + optioni = answer{1}; %1 means from hard drive, 0 means from erpsets menu + ERPsetop = answer{2}; + erpset = answer{3}; + prefixlist = answer{4}; + + + estudioworkingmemory('pop_appenderp',answer); + + if optioni==1 % from files + filelist = erpset; + ALLERP = {ALLERP, filelist}; % truco + else % from erpsets menu + %erpset = erpset; + end + if isempty(prefixlist) + prefixliststr = ''; % do not include prefix + elseif isnumeric(prefixlist) + prefixliststr = 'erpname'; % use erpname instead + else + prefixliststr = prefixlist; % include prefix from list + end + estudioworkingmemory('pop_appenderp', { optioni, erpset, prefixlist }); + + ALLERPCOM = evalin('base','ALLERPCOM'); + + if optioni==0 + msgboxText = check_ERPset(erpset); + if ~isempty(msgboxText) + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return end - optioni = answer{1}; %1 means from hard drive, 0 means from erpsets menu - ERPsetop = answer{2}; - erpset = answer{3}; - prefixlist = answer{4}; - - - estudioworkingmemory('pop_appenderp',answer); - - if optioni==1 % from files - filelist = erpset; - ALLERP = {ALLERP, filelist}; % truco - else % from erpsets menu - %erpset = erpset; - end - if isempty(prefixlist) - prefixliststr = ''; % do not include prefix - elseif isnumeric(prefixlist) - prefixliststr = 'erpname'; % use erpname instead - else - prefixliststr = prefixlist; % include prefix from list - end - erpworkingmemory('pop_appenderp', { optioni, erpset, prefixlist }); - - ALLERPCOM = evalin('base','ALLERPCOM'); - - if optioni==0 - messgStr = check_ERPset(erpset); - if ~isempty(messgStr) - erpworkingmemory('f_ERP_proces_messg',messgStr); - beep; - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; - return - end - %%check prefixes - + %%check prefixes + if ~isnumeric(prefixlist) if ~isempty(prefixliststr) && numel(erpset) ~= length(prefixliststr) - messgStr = strcat('Append ERPsets > prefixes must to be as large as ERPset indx'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - beep; - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + msgboxText = strcat('Append ERPsets > prefixes must to be as large as ERPset indx'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return end end - % - % Somersault - % - if optioni==1 && ~isempty(erpset) - if isempty(prefixliststr) - [ERP,ERPCOM] = pop_appenderp( erpset, 'Saveas', 'off', 'History', 'gui'); - else - fid_list = fopen( erpset ); - formcell = textscan(fid_list, '%[^\n]','CommentStyle','#', 'whitespace', ''); - lista = formcell{:}; - - if numel(lista) ~= length(prefixliststr) - messgStr = strcat('Append ERPsets > prefixes must to be as large as ERPset indx'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - beep; - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; - return - end - - [ERP, ERPCOM] = pop_appenderp(erpset, 'Prefixes', prefixliststr, 'Saveas', 'off', 'History', 'gui'); - end + end + % + % Somersault + % + if optioni==1 && ~isempty(erpset) + if isempty(prefixliststr) + [ERP,ERPCOM] = pop_appenderp( erpset, 'Saveas', 'off', 'History', 'gui'); else - - if isempty(prefixliststr) - [ERP, ERPCOM] = pop_appenderp(ALLERP, 'Erpsets', erpset, 'Saveas', 'off', 'History', 'gui'); - else - [ERP, ERPCOM] = pop_appenderp(ALLERP, 'Erpsets', erpset, 'Prefixes', prefixliststr, 'Saveas', 'off', 'History', 'gui'); + fid_list = fopen( erpset ); + formcell = textscan(fid_list, '%[^\n]','CommentStyle','#', 'whitespace', ''); + lista = formcell{:}; + if numel(lista) ~= length(prefixliststr) + msgboxText = strcat('Append ERPsets > prefixes must to be as large as ERPset indx'); + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg=2; + return end + [ERP, ERPCOM] = pop_appenderp(erpset, 'Prefixes', prefixliststr, 'Saveas', 'off', 'History', 'gui'); end - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1);%%SAVE the command - pathName_def = erpworkingmemory('ERP_save_folder'); - if isempty(pathName_def) - pathName_def =cd; + else + if isempty(prefixliststr) + [ERP, ERPCOM] = pop_appenderp(ALLERP, 'Erpsets', erpset, 'Saveas', 'off', 'History', 'gui'); + else + [ERP, ERPCOM] = pop_appenderp(ALLERP, 'Erpsets', erpset, 'Prefixes', prefixliststr, 'Saveas', 'off', 'History', 'gui'); end - erpName_new = ''; - fileName_new = ''; - pathName_new = ''; - Save_file_label =0; - - Answer = f_ERP_save_single_file(strcat('append'),'',length(observe_ERPDAT.ALLERP)+1); - if isempty(Answer) - % erpName_new = strcat(num2str(length(observe_ERPDAT.ALLERP)+1),'append'); - % Save_file_label =0; - disp('User selected Cancel.'); - return; + end + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2);%%SAVE the command + pathName_def = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName_def) + pathName_def =cd; + end + erpName_new = ''; + fileName_new = ''; + pathName_new = ''; + Save_file_label =0; + + Answer = f_ERP_save_single_file(strcat('append'),'',length(observe_ERPDAT.ALLERP)+1); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + + if ~isempty(Answer) + ERPName = Answer{1}; + if ~isempty(ERPName) + erpName_new = ERPName; end - - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - erpName_new = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - fileName_new = ''; - Save_file_label =0; - elseif ~isempty(fileName_full) - - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = pathName_def; - end - fileName_new = [file_name,ext]; - pathName_new = pathstr; - Save_file_label =1; + fileName_full = Answer{2}; + if isempty(fileName_full) + fileName_new = ''; + Save_file_label =0; + elseif ~isempty(fileName_full) + [pathstr, file_name, ext] = fileparts(fileName_full); + ext = '.erp'; + if strcmp(pathstr,'') + pathstr = pathName_def; end + fileName_new = [file_name,ext]; + pathName_new = pathstr; + Save_file_label =1; end - - ERP.erpname = erpName_new; - ERP.filename = fileName_new; - ERP.filepath = pathName_new; - if Save_file_label==1 - ERP_save =ERP; - ERP_save.filepath = pathName_new; - [ERP, issave, ERPCOM] = pop_savemyerp(ERP_save, 'erpname', ERP_save.erpname, 'filename', ERP_save.erpname, 'filepath',ERP_save.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - end - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - assignin('base','ERP',observe_ERPDAT.ERP); - assignin('base','CURRENTERP',observe_ERPDAT.CURRENTERP); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Process_messg =2; - estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); - OpValue = answer{2}; - gui_erp_append.sameerpset.Value = OpValue; - gui_erp_append.erpset_custom.Value = ~OpValue; - gui_erp_append.erpset_edit.String = num2str(answer{3}); - - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - catch - observe_ERPDAT.Process_messg =3; - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + + ERP.erpname = erpName_new; + ERP.filename = fileName_new; + ERP.filepath = pathName_new; + if Save_file_label==1 + ERP_save =ERP; + ERP_save.filepath = pathName_new; + [ERP, issave, ERPCOM] = pop_savemyerp(ERP_save, 'erpname', ERP_save.erpname, 'filename', ERP_save.erpname, 'filepath',ERP_save.filepath); + ERPCOM = f_erp_save_history(ERP_save.erpname,ERP_save.filename,ERP_save.filepath); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + end + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','CURRENTERP',observe_ERPDAT.CURRENTERP); + estudioworkingmemory('f_ERP_bin_opt',1); + observe_ERPDAT.Process_messg =2; + estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); + OpValue = answer{2}; + gui_erp_append.sameerpset.Value = OpValue; + gui_erp_append.erpset_custom.Value = ~OpValue; + gui_erp_append.erpset_edit.String = num2str(answer{3}); + observe_ERPDAT.Count_currentERP = 1; end - - %%--------------------------Run-------------------------------------------- function append_run(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [msgboxText,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(msgboxText) && eegpanelIndex~=12 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end %%Send message to Message panel - erpworkingmemory('f_ERP_proces_messg','Append ERPsets'); + estudioworkingmemory('f_ERP_proces_messg','Append ERPsets'); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. %%-------check the inputed ERPsetArray----------------------------- ERPArray = str2num(gui_erp_append.erpset_edit.String); - if isempty(ERPArray) || numel(ERPArray)==1 - messgStr = strcat('Append ERPsets > You have to specify 2 ERPsets, at least.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + if isempty(ERPArray) || numel(ERPArray)<2 + msgboxText = strcat('Append ERPsets > You have to specify 2 ERPsets, at least.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - if min(ERPArray) <=0 - messgStr = strcat('Append ERPsets > Index of inputs should not be larger than 0.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + if any(ERPArray <=0) + msgboxText = strcat('Append ERPsets > Index of inputs should not be larger than 0.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - if max(ERPArray) > length(observe_ERPDAT.ALLERP) - messgStr = strcat('Append ERPsets > Index of inputs should not be larger than',32,num2str(length(observe_ERPDAT.ALLERP)),'.'); - erpworkingmemory('f_ERP_proces_messg',messgStr); - fprintf(2,['\n Warning: ',messgStr,'.\n']); - beep; - observe_ERPDAT.Process_messg=4; + if any(ERPArray > length(observe_ERPDAT.ALLERP)) + msgboxText = strcat('Append ERPsets > Index of inputs should not be larger than',32,num2str(length(observe_ERPDAT.ALLERP)),'.'); + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end %%check number of samples/channels, and data type - messgStr = check_ERPset(ERPArray); - if ~isempty(messgStr) - erpworkingmemory('f_ERP_proces_messg',messgStr); - beep; - fprintf(2,['\n Warning: ',messgStr,'.\n']); - observe_ERPDAT.Process_messg=4; + msgboxText = check_ERPset(ERPArray); + if ~isempty(msgboxText) + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return end + estudioworkingmemory('ERPTab_append',0); + gui_erp_append.append_run.BackgroundColor = [1 1 1]; + gui_erp_append.append_run.ForegroundColor = [0 0 0]; + box_erp_append.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [1 1 1]; + gui_erp_append.append_cancel.ForegroundColor = [0 0 0]; + gui_erp_append.append_advance.BackgroundColor = [1 1 1]; + gui_erp_append.append_advance.ForegroundColor = [0 0 0]; + ALLERPCOM = evalin('base','ALLERPCOM'); ALLERP = observe_ERPDAT.ALLERP; prefixliststr = ''; for Numoferpset = 1:numel(ERPArray) prefixliststr{Numoferpset} = ALLERP(ERPArray(Numoferpset)).erpname; - end - try - [ERP, ERPCOM] = pop_appenderp(ALLERP, 'Erpsets', ERPArray, 'Prefixes', prefixliststr, 'Saveas', 'off', 'History', 'gui'); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1);%%SAVE the command - pathName_def = erpworkingmemory('ERP_save_folder'); - if isempty(pathName_def) - pathName_def =cd; - end - erpName_new = ''; - fileName_new = ''; - pathName_new = ''; - Save_file_label =0; - Answer = f_ERP_save_single_file(strcat('append'),'',length(observe_ERPDAT.ALLERP)+1); - if isempty(Answer) - disp('User selected Cancel.'); - return; - % erpName_new = strcat(num2str(length(observe_ERPDAT.ALLERP)+1),'append'); - % Save_file_label =0; + [ERP, ERPCOM] = pop_appenderp(ALLERP, 'Erpsets', ERPArray, 'Prefixes', prefixliststr, 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2);%%SAVE the command + pathName_def = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName_def) + pathName_def =cd; + end + erpName_new = ''; + fileName_new = ''; + pathName_new = ''; + Save_file_label =0; + Answer = f_ERP_save_single_file(strcat('append'),'',length(observe_ERPDAT.ALLERP)+1); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer) + ERPName = Answer{1}; + if ~isempty(ERPName) + erpName_new = ERPName; end - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - erpName_new = ERPName; + fileName_full = Answer{2}; + if isempty(fileName_full) + fileName_new = ''; + Save_file_label =0; + elseif ~isempty(fileName_full) + [pathstr, file_name, ext] = fileparts(fileName_full); + ext = '.erp'; + if strcmp(pathstr,'') + pathstr = pathName_def; end - fileName_full = Answer{2}; - if isempty(fileName_full) - fileName_new = ''; - Save_file_label =0; - elseif ~isempty(fileName_full) - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = pathName_def; - end - fileName_new = [file_name,ext]; - pathName_new = pathstr; - Save_file_label =1; - end - end - ERP.erpname = erpName_new; - ERP.filename = fileName_new; - ERP.filepath = pathName_new; - if Save_file_label==1 - ERP_save =ERP; - ERP_save.filepath = pathName_new; - [ERP, issave, ERPCOM] = pop_savemyerp(ERP_save, 'erpname', ERP_save.erpname, 'filename', ERP_save.erpname, 'filepath',ERP_save.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + fileName_new = [file_name,ext]; + pathName_new = pathstr; + Save_file_label =1; end - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Process_messg =2; - estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - catch - observe_ERPDAT.Process_messg =3; - return; - end%% end try - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + end + ERP.erpname = erpName_new; + ERP.filename = fileName_new; + ERP.filepath = pathName_new; + if Save_file_label==1 + ERP_save =ERP; + ERP_save.filepath = pathName_new; + [ERP, issave, ERPCOM] = pop_savemyerp(ERP_save, 'erpname', ERP_save.erpname, 'filename', ERP_save.erpname, 'filepath',ERP_save.filepath); + ERPCOM = f_erp_save_history(ERP_save.erpname,ERP_save.filename,ERP_save.filepath); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + ERP.filename = ''; + ERP.filepath = ''; + ERP.saved = 'no'; + end + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('f_ERP_bin_opt',1); + observe_ERPDAT.Process_messg =2; + estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP = 1; end %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') + if observe_ERPDAT.Count_currentERP~=13 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 Enableflag = 'off'; else Enableflag = 'on'; @@ -513,14 +624,15 @@ function Count_currentERPChanged(~,~) gui_erp_append.append_run.Enable = Enableflag; gui_erp_append.sameerpset.Enable = Enableflag; gui_erp_append.erpset_custom.Enable = Enableflag; + gui_erp_append.append_cancel.Enable = Enableflag; if gui_erp_append.sameerpset.Value ==1%%same to the - %%selected erpsert as the "ERPset" panel. ERPArray = estudioworkingmemory('selectederpstudio'); gui_erp_append.erpset_edit.String = num2str(ERPArray); gui_erp_append.erpset_edit.Enable = 'off'; else gui_erp_append.erpset_edit.Enable = 'on'; end + observe_ERPDAT.Count_currentERP=14; end @@ -544,12 +656,58 @@ function Count_currentERPChanged(~,~) end if length(unique(numchans))>1 - msgboxText = 'Append ERPsets > The selected ERPsets have different number of channel'; + msgboxText = 'Append ERPsets > The selected ERPsets have different number of channels'; end if length(unique(chckdatatype))>1 - msgboxText = 'Append ERPsets > The selected ERPsets have different data type'; + msgboxText = 'Append ERPsets > The selected ERPsets have different data types'; end end end +%%--------------press return to execute "Apply"---------------------------- + function erp_append_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_append'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + append_run(); + estudioworkingmemory('ERPTab_append',0); + gui_erp_append.append_run.BackgroundColor = [1 1 1]; + gui_erp_append.append_run.ForegroundColor = [0 0 0]; + box_erp_append.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [1 1 1]; + gui_erp_append.append_cancel.ForegroundColor = [0 0 0]; + gui_erp_append.append_advance.BackgroundColor = [1 1 1]; + gui_erp_append.append_advance.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------reset this panel with the default parameters--------------- + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=12 + return; + end + estudioworkingmemory('ERPTab_append',0); + gui_erp_append.append_run.BackgroundColor = [1 1 1]; + gui_erp_append.append_run.ForegroundColor = [0 0 0]; + box_erp_append.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_append.append_cancel.BackgroundColor = [1 1 1]; + gui_erp_append.append_cancel.ForegroundColor = [0 0 0]; + gui_erp_append.append_advance.BackgroundColor = [1 1 1]; + gui_erp_append.append_advance.ForegroundColor = [0 0 0]; + gui_erp_append.sameerpset.Value=1; + gui_erp_append.erpset_custom.Value=0; + gui_erp_append.erpset_edit.Enable = 'off'; + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || numel(ERPArray)==1 + gui_erp_append.erpset_edit.String=''; + else + gui_erp_append.erpset_edit.String=num2str(ERPArray); + end + observe_ERPDAT.Reset_erp_paras_panel=13; + end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_baselinecorr_detrend_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_baselinecorr_detrend_GUI.m index e5264de1..8ed77c82 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_baselinecorr_detrend_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_baselinecorr_detrend_GUI.m @@ -1,19 +1,17 @@ -%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Author: Guanghui ZHANG %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && Nov. 2023 % ERPLAB Studio function varargout = f_ERP_baselinecorr_detrend_GUI(varargin) -% global gui_erp_blc_dt; global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@erpschange); -% addlistener(observe_ERPDAT,'ERP_change',@drawui_CB); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); %%---------------------------gui------------------------------------------- [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; @@ -33,7 +31,7 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end erp_blc_dt_gui(FonsizeDefault); varargout{1} = ERP_basecorr_detrend_box; @@ -41,11 +39,7 @@ function erp_blc_dt_gui(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end + Enable_label = 'off'; gui_erp_blc_dt.blc_dt = uiextras.VBox('Parent',ERP_basecorr_detrend_box,'Spacing',1,'BackgroundColor',ColorB_def); %%Measurement type @@ -53,64 +47,66 @@ function erp_blc_dt_gui(FonsizeDefault) uicontrol('Style', 'text','Parent', gui_erp_blc_dt.blc_dt_type_title,... 'String','Type:','FontWeight','bold','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); gui_erp_blc_dt.blc_dt_option = uiextras.HBox('Parent', gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); - gui_erp_blc_dt.blc = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_dt_option,... 'String','Baseline Correction','callback',@baseline_correction_erp,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_blc_dt.blcp.KeyPressFcn= @erp_blcorrdetrend_presskey; gui_erp_blc_dt.dt = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_dt_option,... 'String','Linear detrend','callback',@detrend_erp,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_blc_dt.dt.KeyPressFcn= @erp_blcorrdetrend_presskey; + gui_erp_blc_dt.ERPTab_baseline_detrend{1} = gui_erp_blc_dt.blc.Value; %%Baseline period: Pre, post whole custom gui_erp_blc_dt.blc_dt_baseline_period_title = uiextras.HBox('Parent', gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); - uicontrol('Style', 'text','Parent', gui_erp_blc_dt.blc_dt_baseline_period_title,... + gui_erp_blc_dt.blc_dt_title = uicontrol('Style', 'text','Parent', gui_erp_blc_dt.blc_dt_baseline_period_title,... 'String','Baseline Period:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); gui_erp_blc_dt.blc_dt_bp_option = uiextras.HBox('Parent', gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); - gui_erp_blc_dt.pre = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_dt_bp_option,... 'String','Pre','callback',@pre_erp,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_blc_dt.pre.KeyPressFcn= @erp_blcorrdetrend_presskey; gui_erp_blc_dt.post = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_dt_bp_option,... 'String','Post','callback',@post_erp,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_blc_dt.post.KeyPressFcn= @erp_blcorrdetrend_presskey; gui_erp_blc_dt.whole = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_dt_bp_option,... 'String','Whole','callback',@whole_erp,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_blc_dt.whole.KeyPressFcn= @erp_blcorrdetrend_presskey; gui_erp_blc_dt.blc_dt_bp_option_cust = uiextras.HBox('Parent', gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); - gui_erp_blc_dt.custom = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_dt_bp_option_cust,... 'String','Custom (ms) [start stop]','callback',@custom_erp,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_blc_dt.custom.KeyPressFcn= @erp_blcorrdetrend_presskey; gui_erp_blc_dt.custom_edit = uicontrol('Style', 'edit','Parent', gui_erp_blc_dt.blc_dt_bp_option_cust,... 'String','','callback',@custom_edit,'Enable',Enable_label,'FontSize',FonsizeDefault); - - if observe_ERPDAT.ERP.times(1)>=0 - CUstom_String = ''; + gui_erp_blc_dt.custom_edit.KeyPressFcn= @erp_blcorrdetrend_presskey; + set(gui_erp_blc_dt.blc_dt_bp_option_cust, 'Sizes',[160 100]); + if gui_erp_blc_dt.pre.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = 1; + elseif gui_erp_blc_dt.post.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = 2; + elseif gui_erp_blc_dt.whole.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = 3; + elseif gui_erp_blc_dt.custom.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = str2num(gui_erp_blc_dt.custom_edit.String); else - CUstom_String = num2str([observe_ERPDAT.ERP.times(1),0]); + gui_erp_blc_dt.ERPTab_baseline_detrend{2} =1; end - gui_erp_blc_dt.custom_edit.String = CUstom_String; - set(gui_erp_blc_dt.blc_dt_bp_option_cust, 'Sizes',[160 135]); - - %%Bin and channels selection gui_erp_blc_dt.blc_dt_bin_chan_title = uiextras.HBox('Parent', gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); uicontrol('Style', 'text','Parent', gui_erp_blc_dt.blc_dt_bin_chan_title,... 'String','Bin and Chan Selection:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_blc_dt.blc_bin_chan_option = uiextras.HBox('Parent', gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); - gui_erp_blc_dt.all_bin_chan = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_bin_chan_option,... 'String','All(Recommended)','callback',@All_bin_chan,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_blc_dt.all_bin_chan.KeyPressFcn= @erp_blcorrdetrend_presskey; gui_erp_blc_dt.Selected_bin_chan = uicontrol('Style', 'radiobutton','Parent', gui_erp_blc_dt.blc_bin_chan_option,... 'String','Selected bin & chan','callback',@Selected_bin_chan,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_blc_dt.Selected_bin_chan.KeyPressFcn= @erp_blcorrdetrend_presskey; set(gui_erp_blc_dt.blc_bin_chan_option, 'Sizes',[125 175]); - + gui_erp_blc_dt.ERPTab_baseline_detrend{3} = gui_erp_blc_dt.all_bin_chan.Value; %%Cancel and advanced gui_erp_blc_dt.other_option = uiextras.HBox('Parent',gui_erp_blc_dt.blc_dt,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_blc_dt.other_option,'BackgroundColor',ColorB_def); - gui_erp_blc_dt.reset = uicontrol('Parent',gui_erp_blc_dt.other_option,'Style','pushbutton',... - 'String','Reset','callback',@Reset_blc_dt,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_erp_blc_dt.Cancel = uicontrol('Parent',gui_erp_blc_dt.other_option,'Style','pushbutton',... + 'String','Cancel','callback',@Cancel_blc_dt,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); uiextras.Empty('Parent', gui_erp_blc_dt.other_option); gui_erp_blc_dt.apply = uicontrol('Style','pushbutton','Parent',gui_erp_blc_dt.other_option,... 'String','Apply','callback',@apply_blc_dt,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); @@ -119,25 +115,73 @@ function erp_blc_dt_gui(FonsizeDefault) set(gui_erp_blc_dt.blc_dt,'Sizes',[18 25 15 25 25 15 25 30]); + estudioworkingmemory('ERPTab_baseline_detrend',0); end -%%**************************************************************************************************************************************** -%%******************* Subfunctions *************************************************************************************************** -%%**************************************************************************************************************************************** +%%************************************************************************* +%%******************* Subfunctions ************************************ +%%************************************************************************* -%%--------------------------------setting for amplitude------------------ - function baseline_correction_erp(source,~) +%%--------------------------------setting for amplitude-------------------- + function baseline_correction_erp(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.blc.Value =1; gui_erp_blc_dt.dt.Value = 0; + gui_erp_blc_dt.blc_dt_title.String = 'Baseline Period:'; end -%%--------------------------Setting for phase----------------------------- +%%--------------------------Setting for phase------------------------------ function detrend_erp(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.dt.Value = 1; gui_erp_blc_dt.blc.Value =0; + gui_erp_blc_dt.blc_dt_title.String = 'Calculate Trend During:'; end -%%----------------Setting for "pre"----------------------------------------- +%%----------------Setting for "pre"---------------------------------------- function pre_erp(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.pre.Value=1; gui_erp_blc_dt.post.Value=0; gui_erp_blc_dt.whole.Value=0; @@ -149,29 +193,56 @@ function pre_erp(~,~) CUstom_String = num2str([observe_ERPDAT.ERP.times(1),0]); end gui_erp_blc_dt.custom_edit.String = CUstom_String; - end -%%----------------Setting for "post"----------------------------------------- +%%----------------Setting for "post"--------------------------------------- function post_erp(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.pre.Value=0; gui_erp_blc_dt.post.Value=1; gui_erp_blc_dt.whole.Value=0; gui_erp_blc_dt.custom.Value=0; gui_erp_blc_dt.custom_edit.Enable = 'off'; - if observe_ERPDAT.ERP.times(end)<=0 CUstom_String = ''; else CUstom_String = num2str([0 observe_ERPDAT.ERP.times(end)]); end gui_erp_blc_dt.custom_edit.String = CUstom_String; - end -%%----------------Setting for "whole"----------------------------------------- +%%----------------Setting for "whole"-------------------------------------- function whole_erp(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.pre.Value=0; gui_erp_blc_dt.post.Value=0; gui_erp_blc_dt.whole.Value=1; @@ -181,8 +252,23 @@ function whole_erp(~,~) gui_erp_blc_dt.custom_edit.String = CUstom_String; end -%%----------------Setting for "custom"----------------------------------------- +%%----------------Setting for "custom"------------------------------------- function custom_erp(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.pre.Value=0; gui_erp_blc_dt.post.Value=0; gui_erp_blc_dt.whole.Value=0; @@ -190,49 +276,53 @@ function custom_erp(~,~) gui_erp_blc_dt.custom_edit.Enable = 'on'; end -%%----------------input baseline period defined by user---------------------- +%%----------------input baseline period defined by user-------------------- function custom_edit(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); + lat_osci = str2num(Source.String); if isempty(lat_osci) - beep; msgboxText = ['Baseline Correction & Linear Detrend - Invalid input for "baseline range"']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if numel(lat_osci) ==1 - beep; msgboxText = ['Baseline Correction & Linear Detrend - Wrong baseline range. Please, enter two values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if lat_osci(1)>= lat_osci(2) - beep; msgboxText = ['Baseline Correction & Linear Detrend - The first value must be smaller than the second one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if lat_osci(2) > observe_ERPDAT.ERP.times(end) - beep; msgboxText = ['Baseline Correction & Linear Detrend - Second value must be smaller than',32,num2str(observe_ERPDAT.ERP.times(end))]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if lat_osci(1) < observe_ERPDAT.ERP.times(1) - beep; msgboxText = ['Baseline Correction & Linear Detrend - First value must be larger than',32,num2str(observe_ERPDAT.ERP.times(1))]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end @@ -240,28 +330,63 @@ function custom_edit(Source,~) %%---------------------Setting for all chan and bin------------------------ function All_bin_chan(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.all_bin_chan.Value = 1; gui_erp_blc_dt.Selected_bin_chan.Value = 0; end %%----------------Setting for selected bin and chan------------------------ function Selected_bin_chan(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_blc_dt.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_blc_dt.apply.ForegroundColor = [1 1 1]; + ERP_basecorr_detrend_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_blc_dt.Cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_baseline_detrend',1); gui_erp_blc_dt.all_bin_chan.Value = 0; gui_erp_blc_dt.Selected_bin_chan.Value = 1; end %%--------------------------Setting for plot------------------------------- function apply_blc_dt(~,~) - + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end Selected_erpset = estudioworkingmemory('selectederpstudio'); if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + Selected_erpset = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = Selected_erpset; estudioworkingmemory('selectederpstudio',Selected_erpset); end - - try if gui_erp_blc_dt.pre.Value==1 BaselineMethod = 'pre'; @@ -275,303 +400,300 @@ function apply_blc_dt(~,~) catch BaselineMethod = 'pre'; end - %%Check the baseline period defined by the custom. if gui_erp_blc_dt.custom.Value ==1 if isempty(BaselineMethod) - beep; - msgboxText = ['Baseline Correction & Linear Detrend - Invalid input for baseline range; Please reset two values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Baseline Correction & Linear Detrend - Invalid input for baseline range; Please Cancel two values']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if numel(BaselineMethod) ==1 - beep; msgboxText = ['Baseline Correction & Linear Detrend - Wrong baseline range. Please, enter two values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if BaselineMethod(1)>= BaselineMethod(2) - beep; msgboxText = ['Baseline Correction & Linear Detrend - The first value must be smaller than the second one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if roundn(BaselineMethod(2),-3) > roundn(observe_ERPDAT.ERP.times(end),-3) - beep; msgboxText = ['Baseline Correction & Linear Detrend - Second value must be smaller than',32,num2str(observe_ERPDAT.ERP.times(end))]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if roundn(BaselineMethod(1),-3) < roundn(observe_ERPDAT.ERP.times(1),-3) - beep; msgboxText = ['Baseline Correction & Linear Detrend - First value must be larger than',32,num2str(observe_ERPDAT.ERP.times(1))]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end - %%Run the function based on the defined parameters - Check_Selected_erpset = [0 0 0 0 0 0 0]; - S_ws_binchan= estudioworkingmemory('geterpbinchan'); - if numel(Selected_erpset)>1 - try - Check_Selected_erpset = S_ws_binchan.checked_ERPset_Index; - catch - Check_Selected_erpset = f_checkerpsets(observe_ERPDAT.ALLERP,Selected_erpset); - end - end - %%--------------Loop start for removeing baseline for the selected ERPsets------------ if gui_erp_blc_dt.dt.Value ==1 - Suffix_str = char(strcat('detrend')); + Suffix_str = char(strcat('_detrend')); else - Suffix_str = char(strcat('baselinecorr')); + Suffix_str = char(strcat('_baselinecorr')); end - if numel(Selected_erpset)>1 + + %%%%-------------------Loop fpor baseline correction--------------- + estudioworkingmemory('f_ERP_proces_messg','Baseline correction & Linear detrend'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + + ALLERPCOM = evalin('base','ALLERPCOM'); + gui_erp_blc_dt.apply.BackgroundColor = [ 1 1 1]; + gui_erp_blc_dt.apply.ForegroundColor = [0 0 0]; + ERP_basecorr_detrend_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [1 1 1]; + gui_erp_blc_dt.Cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_baseline_detrend',0); + + gui_erp_blc_dt.ERPTab_baseline_detrend{1} = gui_erp_blc_dt.blc.Value; + if gui_erp_blc_dt.pre.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = 1; + elseif gui_erp_blc_dt.post.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = 2; + elseif gui_erp_blc_dt.whole.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = 3; + elseif gui_erp_blc_dt.custom.Value==1 + gui_erp_blc_dt.ERPTab_baseline_detrend{2} = str2num(gui_erp_blc_dt.custom_edit.String); + else + gui_erp_blc_dt.ERPTab_baseline_detrend{2} =1; + end + gui_erp_blc_dt.ERPTab_baseline_detrend{3} = gui_erp_blc_dt.all_bin_chan.Value; + if gui_erp_blc_dt.all_bin_chan.Value == 1 + BinArray = [1:observe_ERPDAT.ERP.nbin]; + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + else + BinArray = estudioworkingmemory('ERP_BinArray'); + ChanArray = estudioworkingmemory('ERP_ChanArray'); + end + + ALLERP = observe_ERPDAT.ALLERP; + BinArray = []; + ChanArray = []; + ALLERP_out = []; + for Numoferp = 1:numel(Selected_erpset) + ERP = ALLERP(Selected_erpset(Numoferp)); + + if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; + end + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = [1:ERP.nbin]; + end if gui_erp_blc_dt.dt.Value ==1 - Suffix_str = char(strcat('detrend')); + [ERP ERPCOM] = pop_erplindetrend( ERP,'Baseline', BaselineMethod ,'ChanArray',ChanArray,... + 'BinArray',BinArray, 'Saveas', 'off','History','gui'); else - Suffix_str = char(strcat('baselinecorr')); + [ERP ERPCOM]= pop_blcerp( ERP , 'Baseline', BaselineMethod,'ChanArray',ChanArray,... + 'BinArray',BinArray,'Saveas', 'off','History','gui'); end - - Answer = f_ERP_save_multi_file(observe_ERPDAT.ALLERP,Selected_erpset,Suffix_str); - if isempty(Answer) - beep; - disp('User selected Cancel'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; return; end - - if ~isempty(Answer{1}) - ALLERP_advance = Answer{1}; - Save_file_label = Answer{2}; + if Numoferp ==numel(Selected_erpset) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - elseif numel(Selected_erpset)==1 - Save_file_label = 0; - ALLERP_advance = observe_ERPDAT.ALLERP; + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + end%%Loop end for the selected ERset + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(Selected_erpset),Suffix_str); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; end - - %%%%-------------------Loop fpor baseline correction--------------- - erpworkingmemory('f_ERP_proces_messg','Baseline correction & Linear detrend'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - - ALLERPCOM = evalin('base','ALLERPCOM'); - - try - BinArray = []; - ChanArray = []; - for Numoferp = 1:numel(Selected_erpset) - - if Selected_erpset(Numoferp)> length(observe_ERPDAT.ALLERP) - error('EStudio says: No corresponding ERP exists in ALLEERP'); - break; - end - - ERP = observe_ERPDAT.ALLERP(Selected_erpset(Numoferp)); - if (Check_Selected_erpset(1)==1 || Check_Selected_erpset(2)==2) && gui_erp_blc_dt.Selected_bin_chan.Value ==1 - if Check_Selected_erpset(1) ==1 - msgboxText = ['Number of bins across the selected ERPsets is different!']; - elseif Check_Selected_erpset(2)==2 - msgboxText = ['Number of channels across the selected ERPsets is different!']; - elseif Check_Selected_erpset(1)==1 && Check_Selected_erpset(2)==2 - msgboxText = ['Number of channels and bins vary across the selected ERPsets']; - end - question = [ '%s\n\n "All" will be active instead of "Selected bin and chan".']; - title = 'EStudio: Baseline correction & linear detrend'; - button = questdlg(sprintf(question, msgboxText), title,'OK','OK'); - BinArray = []; - ChanArray = []; - end - - if (Check_Selected_erpset(1)==0 && Check_Selected_erpset(2)==0) && gui_erp_blc_dt.Selected_bin_chan.Value ==1 - try - BinArray = S_ws_binchan.bins{1}; - ChanArray = S_ws_binchan.elecs_shown{1}; - [chk, msgboxText] = f_ERP_chckbinandchan(ERP, BinArray, [],1); - if chk(1)==1 - BinArray = [1:ERP.nbin]; - end - [chk, msgboxText] = f_ERP_chckbinandchan(ERP,[], ChanArray,2); - if chk(2)==1 - ChanArray = [1:ERP.nchan]; - end - - catch - BinArray = [1:ERP.nbin]; - ChanArray = [1:ERP.nchan]; - end - end - - if gui_erp_blc_dt.all_bin_chan.Value == 1 - BinArray = [1:ERP.nbin]; - ChanArray = [1:ERP.nchan]; - end - - - if gui_erp_blc_dt.dt.Value ==1 - [ERP ERPCOM] = pop_erplindetrend( ERP, BaselineMethod , 'Saveas', 'off','History','gui'); + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numoferp = 1:numel(Selected_erpset) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==numel(Selected_erpset) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); else - [ERP ERPCOM]= pop_blcerp( ERP , 'Baseline', BaselineMethod, 'Saveas', 'off','History','gui'); - end - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - if Numoferp ==1 - [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - end - - %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. - if ~isempty(BinArray) - ERP_before_bl = ALLERP_advance(Selected_erpset(Numoferp)); - ERP_before_bl.bindata(ChanArray,:,BinArray) = ERP.bindata(ChanArray,:,BinArray); - ERP_before_bl.history = ERP.history; - ERP = ERP_before_bl; - end - - - if numel(Selected_erpset) ==1 - Answer = f_ERP_save_single_file(strcat(ERP.erpname,'-',Suffix_str),ERP.filename,Selected_erpset(Numoferp)); - if isempty(Answer) - beep; - disp('User selectd cancal'); - return; - end - - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ERP.erpname; - elseif ~isempty(fileName_full) - - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - %%----------save the current sdata as-------------------- - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - end - end - end - - if Save_file_label - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - - end%%Loop end for the selected ERset - - erpworkingmemory('f_ERP_BLS_Detrend',{BaselineMethod,0,1}); - %% - % [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1:length(observe_ERPDAT.ALLERP)]; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + else + ERP.saved = 'no'; + ERP.filepath = ''; + ERP.filename = ''; end - - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; + ALLERP(length(ALLERP)+1) = ERP; + end + estudioworkingmemory('f_ERP_BLS_Detrend',{BaselineMethod,0,1}); + observe_ERPDAT.ALLERP = ALLERP; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1; catch Selected_ERP_afd = length(observe_ERPDAT.ALLERP); observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - - observe_ERPDAT.Process_messg =3; - erpworkingmemory('f_ERP_BLS_Detrend',{BaselineMethod,0,1}); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end %%-----------------Setting for save option--------------------------------- - function Reset_blc_dt(~,~) - gui_erp_blc_dt.blc.Value =1; - gui_erp_blc_dt.dt.Value = 0; - gui_erp_blc_dt.pre.Value=1; - gui_erp_blc_dt.post.Value=0; - gui_erp_blc_dt.whole.Value=0; - gui_erp_blc_dt.custom.Value=0; - gui_erp_blc_dt.custom_edit.Enable = 'off'; - if observe_ERPDAT.ERP.times(1)>=0 - CUstom_String = ''; + function Cancel_blc_dt(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=4 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + try + methodtype = gui_erp_blc_dt.ERPTab_baseline_detrend{1}; + catch + methodtype=1; + gui_erp_blc_dt.ERPTab_baseline_detrend{1}=1; + end + if isempty(methodtype) || numel(methodtype)~=1 || (methodtype~=0 && methodtype~=1) + methodtype=1; + gui_erp_blc_dt.ERPTab_baseline_detrend{1}=1; + end + gui_erp_blc_dt.blc.Value =methodtype; + gui_erp_blc_dt.dt.Value = ~methodtype; + if gui_erp_blc_dt.blc.Value==1 + gui_erp_blc_dt.blc_dt_title.String = 'Baseline Period:'; else - CUstom_String = num2str([observe_ERPDAT.ERP.times(1),0]); + gui_erp_blc_dt.blc_dt_title.String = 'Calculate Trend During:'; end - gui_erp_blc_dt.custom_edit.String = CUstom_String; - gui_erp_blc_dt.all_bin_chan.Value = 1; - gui_erp_blc_dt.Selected_bin_chan.Value = 0; + %%baseline period + try + bsperiod = gui_erp_blc_dt.ERPTab_baseline_detrend{2}; + catch + bsperiod=1; + gui_erp_blc_dt.ERPTab_baseline_detrend{2}=1; + end + if isempty(bsperiod) || (numel(bsperiod)~=1 && numel(bsperiod)~=2) + bsperiod=1; + gui_erp_blc_dt.ERPTab_baseline_detrend{2}=1; + end + + if numel(bsperiod)==1 + if bsperiod~=1 && bsperiod~=2 && bsperiod~=3 + bsperiod=1; + gui_erp_blc_dt.ERPTab_baseline_detrend{2}=1; + end + if bsperiod==2 + gui_erp_blc_dt.pre.Value=0; + gui_erp_blc_dt.post.Value=1; + gui_erp_blc_dt.whole.Value=0; + elseif bsperiod==3 + gui_erp_blc_dt.pre.Value=0; + gui_erp_blc_dt.post.Value=0; + gui_erp_blc_dt.whole.Value=1; + else + gui_erp_blc_dt.pre.Value=1; + gui_erp_blc_dt.post.Value=0; + gui_erp_blc_dt.whole.Value=0; + end + gui_erp_blc_dt.custom.Value=0; + gui_erp_blc_dt.custom_edit.Enable = 'off'; + gui_erp_blc_dt.custom_edit.String = ''; + elseif numel(bsperiod)==2 + gui_erp_blc_dt.pre.Value=0; + gui_erp_blc_dt.post.Value=0; + gui_erp_blc_dt.whole.Value=0; + gui_erp_blc_dt.custom.Value=1; + gui_erp_blc_dt.custom_edit.Enable = 'on'; + if any(bsperiod> observe_ERPDAT.ERP.times(end)) || any(bsperiod< observe_ERPDAT.ERP.times(1)) + bsperiod = []; + gui_erp_blc_dt.ERPTab_baseline_detrend{2}=[]; + end + gui_erp_blc_dt.custom_edit.String = num2str(bsperiod); + end + + %%bin & chan selection + try + all_bin_chan = gui_erp_blc_dt.ERPTab_baseline_detrend{3}; + catch + all_bin_chan=1; + end + if isempty(all_bin_chan) || numel(all_bin_chan)~=1 || (all_bin_chan~=0&& all_bin_chan~=1) + gui_erp_blc_dt.ERPTab_baseline_detrend{3}=1; + all_bin_chan=1; + end + gui_erp_blc_dt.all_bin_chan.Value = all_bin_chan; + gui_erp_blc_dt.Selected_bin_chan.Value = ~all_bin_chan; + + estudioworkingmemory('ERPTab_baseline_detrend',0); + gui_erp_blc_dt.apply.BackgroundColor = [ 1 1 1]; + gui_erp_blc_dt.apply.ForegroundColor = [0 0 0]; + ERP_basecorr_detrend_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_blc_dt.Cancel.BackgroundColor = [1 1 1]; + gui_erp_blc_dt.Cancel.ForegroundColor = [0 0 0]; end %%-------------------Setting for the whole panel of fitering based on ALLERP and CURRENTERP-------------- function Count_currentERPChanged(~,~) - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') || ~strcmp(observe_ERPDAT.ERP.datatype,'ERP') + if observe_ERPDAT.Count_currentERP~=11 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag');%%when open advanced wave viewer + if isempty(observe_ERPDAT.ERP) || ~strcmp(observe_ERPDAT.ERP.datatype,'ERP') || ViewerFlag==1 Enable_Label = 'off'; else Enable_Label = 'on'; end - gui_erp_blc_dt.blc.Enable = Enable_Label; gui_erp_blc_dt.dt.Enable = Enable_Label; gui_erp_blc_dt.apply.Enable = Enable_Label; - gui_erp_blc_dt.reset.Enable = Enable_Label; + gui_erp_blc_dt.Cancel.Enable = Enable_Label; gui_erp_blc_dt.pre.Enable= Enable_Label; gui_erp_blc_dt.post.Enable= Enable_Label; gui_erp_blc_dt.whole.Enable= Enable_Label; gui_erp_blc_dt.custom.Enable= Enable_Label; gui_erp_blc_dt.custom_edit.Enable = Enable_Label; gui_erp_blc_dt.apply.Enable = Enable_Label; - gui_erp_blc_dt.reset.Enable = Enable_Label; + gui_erp_blc_dt.Cancel.Enable = Enable_Label; gui_erp_blc_dt.all_bin_chan.Enable = Enable_Label; gui_erp_blc_dt.Selected_bin_chan.Enable = Enable_Label; - if gui_erp_blc_dt.custom.Value==1 gui_erp_blc_dt.custom_edit.Enable = 'on'; else gui_erp_blc_dt.custom_edit.Enable = 'off'; end - + if isempty(observe_ERPDAT.ERP) || ~strcmp(observe_ERPDAT.ERP.datatype,'ERP') + observe_ERPDAT.Count_currentERP=12; + return; + end Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + if isempty(Selected_erpset) || any(Selected_erpset> length(observe_ERPDAT.ALLERP)) + Selected_erpset = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); estudioworkingmemory('selectederpstudio',Selected_erpset); + observe_ERPDAT.CURRENTERP = Selected_erpset; end - S_binchan = estudioworkingmemory('geterpbinchan'); - Check_Selected_erpset = [0 0 0 0 0 0 0]; - if numel(Selected_erpset)>1 - Check_Selected_erpset = S_binchan.checked_ERPset_Index; + if numel(Selected_erpset)>2 + Check_Selected_erpset = f_checkerpsets(observe_ERPDAT.ALLERP,Selected_erpset); end if Check_Selected_erpset(1) ==1 || Check_Selected_erpset(2) == 2 gui_erp_blc_dt.all_bin_chan.Enable = 'on'; @@ -579,7 +701,60 @@ function Count_currentERPChanged(~,~) gui_erp_blc_dt.all_bin_chan.Value = 1; gui_erp_blc_dt.Selected_bin_chan.Value = 0; end + if gui_erp_blc_dt.custom.Value==1 + baseline = str2num(gui_erp_blc_dt.custom_edit.String); + if ~isempty(baseline) + if any(baseline>observe_ERPDAT.ERP.times(end)) || any(baselinelength(observe_ERPDAT.ALLERP) - SelectedIndex =1; -end - -S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedIndex); -estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); -estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - -EStduio_gui_erp_bin_chan = struct(); +ERPTab_bin_chan = struct(); %-----------------------------Name the title---------------------------------------------- % global EStudio_box_bin_chan; [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; if nargin == 0 fig = figure(); % Parent figure - EStudio_box_bin_chan = uiextras.BoxPanel('Parent', fig, 'Title', 'Bin and Channel Selection', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + EStudio_box_bin_chan = uiextras.BoxPanel('Parent', fig, 'Title', 'Bin & Channel Selection', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - EStudio_box_bin_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Bin and Channel Selection', 'Padding', 5,'BackgroundColor',ColorB_def); + EStudio_box_bin_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Bin & Channel Selection', 'Padding', 5,'BackgroundColor',ColorB_def); else - EStudio_box_bin_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Bin and Channel Selection', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + EStudio_box_bin_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Bin & Channel Selection', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); end %-----------------------------Draw the panel------------------------------------- - -observe_ERPDAT.ERP_chan = S_erpbinchan.geterpbinchan.elecs_shown{1}; -observe_ERPDAT.ERP_bin = S_erpbinchan.geterpbinchan.bins{1}; try FonsizeDefault = varargin{2}; catch FonsizeDefault = []; end if isempty(FonsizeDefault) -FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_bin_chan(FonsizeDefault) @@ -72,438 +46,387 @@ function drawui_bin_chan(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; %%--------------------channel and bin setting---------------------- - EStduio_gui_erp_bin_chan.DataSelBox = uiextras.VBox('Parent', EStudio_box_bin_chan,'BackgroundColor',ColorB_def); - EStduio_gui_erp_bin_chan.DataSelGrid = uiextras.Grid('Parent', EStduio_gui_erp_bin_chan.DataSelBox,'BackgroundColor',ColorB_def); - + ERPTab_bin_chan.DataSelBox = uiextras.VBox('Parent', EStudio_box_bin_chan,'BackgroundColor',ColorB_def); + ERPTab_bin_chan.DataSelGrid = uiextras.Grid('Parent', ERPTab_bin_chan.DataSelBox,'BackgroundColor',ColorB_def); % Second column: - uicontrol('Style','text','Parent', EStduio_gui_erp_bin_chan.DataSelGrid,'String','Channels','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1B - Chanlist = observe_ERPDAT.ERP.chanlocs; - Chanlist_name{1} = 'All'; - for Numofchan = 1:length(Chanlist) - Chanlist_name{Numofchan+1} = char(strcat(num2str(Numofchan),'.',32,Chanlist(Numofchan).labels)); - end - EStduio_gui_erp_bin_chan.ElecRange = uicontrol('Parent', EStduio_gui_erp_bin_chan.DataSelGrid,'Style','listbox','min',1,'max',length(Chanlist_name),... - 'String', Chanlist_name,'Callback',@onElecRange,'FontSize',FonsizeDefault,'Enable','on'); % 2B + uicontrol('Style','text','Parent', ERPTab_bin_chan.DataSelGrid,'String','Channels','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1B + Chanlist_name = ['No erpset is available']; + ERPTab_bin_chan.ElecRange = uicontrol('Parent', ERPTab_bin_chan.DataSelGrid,'Style','listbox','min',1,'max',length(Chanlist_name),... + 'String', Chanlist_name,'Callback',@onElecRange,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); % 2B + ERPTab_bin_chan.ElecRange.Value =1; + ERPTab_bin_chan.ElecRange.KeyPressFcn= @erp_binchan_presskey; + % Third column: + uicontrol('Style','text','Parent', ERPTab_bin_chan.DataSelGrid,'String','Bins','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1C - if S_erpbinchan.geterpbinchan.checked_curr_index ==1 || S_erpbinchan.geterpbinchan.checked_ERPset_Index(2) ==2 - EStduio_gui_erp_bin_chan.ElecRange.Enable = 'off'; - end + brange = ['No erpset is available']; + ERPTab_bin_chan.BinRange = uicontrol('Parent', ERPTab_bin_chan.DataSelGrid,'Style','listbox','Min',1,'Max',2,... + 'String', brange,'callback',@onBinChanged,'FontSize',FonsizeDefault,'Enable','off','Value',1,'BackgroundColor',[1 1 1]); % 2C + ERPTab_bin_chan.BinRange.KeyPressFcn= @erp_binchan_presskey; - if numel(S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}) == numel(Chanlist) - EStduio_gui_erp_bin_chan.ElecRange.Value =1; - else - EStduio_gui_erp_bin_chan.ElecRange.Value = S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}+1; - end + set(ERPTab_bin_chan.DataSelGrid, 'ColumnSizes',[ -1.2 -2],'RowSizes',[20 -3]); - % Third column: - uicontrol('Style','text','Parent', EStduio_gui_erp_bin_chan.DataSelGrid,'String','Bins','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1C + %%Cancel and Apply + ERPTab_bin_chan.reset_apply = uiextras.HBox('Parent',ERPTab_bin_chan.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', ERPTab_bin_chan.reset_apply); % 1A + ERPTab_bin_chan.plot_reset = uicontrol('Style', 'pushbutton','Parent',ERPTab_bin_chan.reset_apply,... + 'String','Cancel','callback',@plot_erp_cancel,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); - BinNum = observe_ERPDAT.ERP.nbin; - BinName = observe_ERPDAT.ERP.bindescr; - brange = cell(BinNum+1,1); - brange(1) = {'ALL'}; - for i = 1:BinNum - brange(i+1) = {strcat(num2str(i),'.',32,BinName{i})}; - end - EStduio_gui_erp_bin_chan.BinRange = uicontrol('Parent', EStduio_gui_erp_bin_chan.DataSelGrid,'Style','listbox','Min',1,'Max',BinNum+1,... - 'String', brange,'callback',@onBinChanged,'FontSize',FonsizeDefault); % 2C - if BinNum== numel(S_erpbinchan.geterpbinchan.bins{1}) - EStduio_gui_erp_bin_chan.BinRange.Value =1; - else - EStduio_gui_erp_bin_chan.BinRange.Value = S_erpbinchan.geterpbinchan.bins{1}+1; - end - if S_erpbinchan.geterpbinchan.checked_curr_index ==1 || S_erpbinchan.geterpbinchan.checked_ERPset_Index(1) ==1 - EStduio_gui_erp_bin_chan.BinRange.Enable = 'off'; - end + uiextras.Empty('Parent', ERPTab_bin_chan.reset_apply); % 1A + ERPTab_bin_chan.plot_apply = uicontrol('Style', 'pushbutton','Parent',ERPTab_bin_chan.reset_apply,... + 'String','Apply','callback',@binchan_apply,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); + ERPTab_bin_chan.plot_apply.KeyPressFcn= @erp_binchan_presskey; + uiextras.Empty('Parent', ERPTab_bin_chan.reset_apply); % 1A + set(ERPTab_bin_chan.reset_apply, 'Sizes',[10,-1,30,-1,10]); + set(ERPTab_bin_chan.DataSelBox,'Sizes',[250 30]); - set(EStduio_gui_erp_bin_chan.DataSelGrid, 'ColumnSizes',[ -1.2 -2],'RowSizes',[20 -3]); + estudioworkingmemory('ERPTab_chanbin',0); + ERPTab_bin_chan.ERPFlag = 0; end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% %----------------------------Get the changed channels----------------------* - function onElecRange ( src, ~) - erpworkingmemory('f_ERP_proces_messg','Bin and Channel Selection-select channel(s)'); - observe_ERPDAT.Process_messg =1; - - SelectedERP_Index= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP_Index) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - S_erpbinchan.geterpbinchan = S_erpplot.geterpbinchan; - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_erpbinchan.geterpbinchan= estudioworkingmemory('geterpbinchan'); - if isempty(S_erpbinchan.geterpbinchan) - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - S_erpbinchan.geterpbinchan = S_erpplot.geterpbinchan; - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + function onElecRange (src, ~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==2 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_chanbin',1); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_bin_chan.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [1 1 1]; new_chans = src.Value; if isempty(new_chans) - beep; - disp(['No channel was selected']); return; end [~,y_chan_index_select] = find(new_chans==1); - if isempty(y_chan_index_select) && numel(new_chans) < numel(src.String)-1 %% 'All' is not slected - - if S_erpbinchan.geterpbinchan.checked_ERPset_Index(2) ==2%% the number of channels varied across ERPsets - S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index} = new_chans-1; - S_erpbinchan.geterpbinchan.elec_n(S_erpbinchan.geterpbinchan.Select_index) = numel(new_chans); - S_erpbinchan.geterpbinchan.first_elec(S_erpbinchan.geterpbinchan.Select_index) = new_chans(1)-1; - else - for Numofselecterp = 1:numel(SelectedERP_Index) - S_erpbinchan.geterpbinchan.elecs_shown{Numofselecterp} = new_chans-1; - S_erpbinchan.geterpbinchan.elec_n(Numofselecterp) = numel(new_chans); - S_erpbinchan.geterpbinchan.first_elec(Numofselecterp) = new_chans(1)-1; - end - end - EStduio_gui_erp_bin_chan.ElecRange.Value = new_chans; + if isempty(y_chan_index_select) && numel(new_chans) < length(ERPTab_bin_chan.ElecRange.String)-1 %% 'All' is not slected else%% 'All' is selected and included or all channels are slected except 'ALL' - carray = src.String; - carray(1) = []; - if S_erpbinchan.geterpbinchan.checked_ERPset_Index(2) ==2 - S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index} = [1:numel(carray)]; - S_erpbinchan.geterpbinchan.elec_n(S_erpbinchan.geterpbinchan.Select_index) = numel(carray); - S_erpbinchan.geterpbinchan.first_elec(S_erpbinchan.geterpbinchan.Select_index) = 1; - else - - for Numofselecterp = 1:numel(SelectedERP_Index) - S_erpbinchan.geterpbinchan.elecs_shown{Numofselecterp} = [1:numel(carray)]; - S_erpbinchan.geterpbinchan.elec_n(Numofselecterp) = numel(carray); - S_erpbinchan.geterpbinchan.first_elec(Numofselecterp) = 1; - end - - end - - EStduio_gui_erp_bin_chan.ElecRange.Value = 1; - end - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - observe_ERPDAT.ERP_chan = S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}; - observe_ERPDAT.Process_messg =2; - %%Plot waves - try - try - S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); - S_ws_viewer = S_ws_geterpvalues.Viewer; - catch - S_ws_viewer = 'off'; - end - - if strcmp(S_ws_viewer,'on') - f_redrawERP_mt_viewer(); - else - f_redrawERP(); - end - - catch - f_redrawERP(); + ERPTab_bin_chan.ElecRange.Value = 1; end - % observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; end - %---------------------------get the changed bin---------------------------- - function onBinChanged( src, ~ ) - erpworkingmemory('f_ERP_proces_messg','Bin and Channel Selection-select bin(s)'); - observe_ERPDAT.Process_messg =1; - - SelectedERP_Index= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP_Index) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - S_erpbinchan.geterpbinchan = S_erpplot.geterpbinchan; - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + function onBinChanged(Sources, ~ ) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end - - - S_erpbinchan.geterpbinchan= estudioworkingmemory('geterpbinchan'); - if isempty(S_erpbinchan.geterpbinchan) - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - S_erpbinchan.geterpbinchan = S_erpplot.geterpbinchan; - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==2 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end + estudioworkingmemory('ERPTab_chanbin',1); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [1 1 1]; + EStudio_box_bin_chan.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [1 1 1]; - Bin_label_select = src.Value; - if isempty(Bin_label_select) - beep; - disp(['No bin was selected']); + bin_select = ERPTab_bin_chan.BinRange.Value; + if isempty(bin_select) return; end - - [~,y_bin_index_select] = find(Bin_label_select==1); - if isempty(y_bin_index_select) && numel(Bin_label_select) < numel(src.String)-1 - if S_erpbinchan.geterpbinchan.checked_ERPset_Index(1) ==1% The number of bins varied across the selected erpsets - S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index} = Bin_label_select-1; - S_erpbinchan.geterpbinchan.bin_n(S_erpbinchan.geterpbinchan.Select_index) = numel(Bin_label_select); - else - for Numofselecterp = 1:numel(SelectedERP_Index) - S_erpbinchan.geterpbinchan.bins{Numofselecterp} = Bin_label_select-1; - S_erpbinchan.geterpbinchan.bin_n(Numofselecterp) = numel(Bin_label_select); - end - end - EStduio_gui_erp_bin_chan.BinRange.Value = Bin_label_select; - + [~,y_bin_index_select] = find(bin_select==1); + if isempty(y_bin_index_select) && numel(bin_select) < length(ERPTab_bin_chan.BinRange.String)-1 else% 'All' is selected and inlcuded - carray = src.String; - carray(1) = []; - if S_erpbinchan.geterpbinchan.checked_ERPset_Index(1) ==1% The number of bins varied across the selected erpsets - S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index} = [1:numel(carray)]; - S_erpbinchan.geterpbinchan.bin_n(S_erpbinchan.geterpbinchan.Select_index) = numel(carray); - else - for Numofselecterp = 1:numel(SelectedERP_Index) - S_erpbinchan.geterpbinchan.bins{Numofselecterp} = [1:numel(carray)]; - S_erpbinchan.geterpbinchan.bin_n(Numofselecterp) = numel(carray); - end - end - EStduio_gui_erp_bin_chan.BinRange.Value = 1; - end - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - observe_ERPDAT.ERP_bin = S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}; - observe_ERPDAT.Process_messg =2; - %%Plot waves - try - try - S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); - S_ws_viewer = S_ws_geterpvalues.Viewer; - catch - S_ws_viewer = 'off'; - end - - if strcmp(S_ws_viewer,'on') - f_redrawERP_mt_viewer(); - else - f_redrawERP(); - end - - catch - f_redrawERP(); + ERPTab_bin_chan.BinRange.Value = 1; end - % observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; end -%----------displayed channel label will be midified after channels was selected-------- - function ERP_chan_changed(~,~) - if observe_ERPDAT.Process_messg==0 - return; - end - chanString = EStduio_gui_erp_bin_chan.ElecRange.String; - chanArray = observe_ERPDAT.ERP_chan; - if max(chanArray)> length(chanString)-1 - EStduio_gui_erp_bin_chan.ElecRange.Value =1; - observe_ERPDAT.ERP_chan = [1:length(chanString)-1]; - else - if max(chanArray)>length(chanString)-1 - EStduio_gui_erp_bin_chan.ElecRange.Value =1; - observe_ERPDAT.ERP_chan = [1:length(chanString)-1]; - else - if numel(chanArray) == length(chanString)-1 - EStduio_gui_erp_bin_chan.ElecRange.Value =1; - else - EStduio_gui_erp_bin_chan.ElecRange.Value = chanArray+1; - end - end +%%-------------cancel the previously changed parameters-------------------- + function plot_erp_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end - end - - - -%----------displayed bin label will be midified after different channels was selected-------- - function ERP_bin_changed(~,~) - if observe_ERPDAT.Process_messg==0 - return; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==2 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - binArray = observe_ERPDAT.ERP_bin; - binString = EStduio_gui_erp_bin_chan.BinRange.String; + estudioworkingmemory('f_ERP_proces_messg','Bin & Channel Selection > Cancel'); + observe_ERPDAT.Process_messg =1; - if max(binArray)> length(binString)-1 - EStduio_gui_erp_bin_chan.BinRange.Value =1; - observe_ERPDAT.ERP_bin = [1:length(binString)-1]; + estudioworkingmemory('ERPTab_chanbin',0); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_bin_chan.TitleColor= [ 0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [0 0 0]; + + % + %%setting for channels + ChanArray = estudioworkingmemory('ERP_ChanArray'); + ChaNum = length(ERPTab_bin_chan.ElecRange.String)-1; + if isempty(ChanArray) || any(ChanArray(:)> ChaNum) || any(ChanArray(:)<=0) || numel(ChanArray) == ChaNum + ERPTab_bin_chan.ElecRange.Value = 1; + ChanArray = [1:ChaNum]; else - if max(binArray)>length(binString)-1 - EStduio_gui_erp_bin_chan.BinRange.Value =1; - observe_ERPDAT.ERP_bin = [1:length(binString)-1]; - else - if numel(binArray) == length(binString)-1 - EStduio_gui_erp_bin_chan.BinRange.Value =1; - else - EStduio_gui_erp_bin_chan.BinRange.Value = binArray+1; - end - end + ERPTab_bin_chan.ElecRange.Value = ChanArray+1; + end + estudioworkingmemory('EEG_ChanArray',ChanArray); + + % + %%setting for bins + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = length( ERPTab_bin_chan.BinRange.String)-1; + if isempty(BinArray) || any(BinArray(:)>BinNum) || any(BinArray(:)<=0) || (numel(BinArray)==BinNum) + ERPTab_bin_chan.BinRange.Value=1; + BinArray = [1:BinNum]; + else + ERPTab_bin_chan.BinRange.Value = BinArray+1; end + estudioworkingmemory('ERP_BinArray',BinArray); + estudioworkingmemory('f_ERP_proces_messg','Bin & Channel Selection > Cancel'); + observe_ERPDAT.Process_messg =2; end - -%%--------Settting will be modified if the selected was changed------------ - function Count_currentERPChanged(~,~) - try - ERPloadIndex = estudioworkingmemory('ERPloadIndex'); - catch - ERPloadIndex =0; - end - if ERPloadIndex==1 - ALLERPIN = evalin('base','ALLERP'); - CURRENTERPIN = evalin('base','CURRENTERP'); - observe_ERPDAT.ALLERP = ALLERPIN; - observe_ERPDAT.CURRENTERP =CURRENTERPIN; - try - observe_ERPDAT.ERP = ALLERPIN(CURRENTERPIN); - catch - observe_ERPDAT.ERP = ALLERPIN(end); - observe_ERPDAT.CURRENTERP =length(ALLERPIN); - end +%%---------------------------Apply----------------------------------------- + function binchan_apply(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - S_erpbinchan.geterpbinchan = S_erpplot.geterpbinchan; - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==2 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end + estudioworkingmemory('ERPTab_chanbin',0); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_bin_chan.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [0 0 0]; - S_erpbinchan.geterpbinchan= estudioworkingmemory('geterpbinchan'); - if isempty(S_erpbinchan.geterpbinchan) - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - S_erpbinchan.geterpbinchan = S_erpplot.geterpbinchan; - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - if max(Selectederp_Index(:)) > length(observe_ERPDAT.ALLERP) - beep; - disp(['Max. index of selected ERPsets is greater than the length of ALLERP!!!']); - return; - end - - %The channels and bins will be modified if the ERPset is changed - Chanlist = observe_ERPDAT.ERP.chanlocs; - Chanlist_name{1} = 'All'; - for Numofchan = 1:length(Chanlist) - Chanlist_name{Numofchan+1} = strcat(num2str(Numofchan),'.',32,char(Chanlist(Numofchan).labels)); + estudioworkingmemory('f_ERP_proces_messg','Bin & Channel Selection > Apply'); + observe_ERPDAT.Process_messg =1; + % + %%selected channels + new_chans= ERPTab_bin_chan.ElecRange.Value; + [~,y_chan_index_select] = find(new_chans==1); + ChanNum = length(ERPTab_bin_chan.ElecRange.String)-1; + if isempty(y_chan_index_select) && numel(new_chans) numel(ChanArrayef) + chandiff = setdiff(ChanArray,ChanArrayef); else - EStduio_gui_erp_bin_chan.ElecRange.Enable = 'on'; - end - - EStduio_gui_erp_bin_chan.ElecRange.Min = 1; - EStduio_gui_erp_bin_chan.ElecRange.Max = length(Chanlist_name)+1; - - chanArray_pv = EStduio_gui_erp_bin_chan.ElecRange.Value; - if numel(chanArray_pv)==1 && chanArray_pv ==1 - EStduio_gui_erp_bin_chan.ElecRange.Value =1; - S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index} = 1:(length(Chanlist_name)-1); + chandiff = setdiff(ChanArrayef,ChanArray); + end + if ~isempty(chandiff) + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + % + %%selectd bins + BinArray= ERPTab_bin_chan.BinRange.Value; + BinNum = length( ERPTab_bin_chan.BinRange.String)-1; + [~,y_bin_index_select] = find(BinArray==1); + if isempty(y_bin_index_select) && numel(BinArray) < BinNum + BinArray = BinArray-1; else - if max(chanArray_pv-1)<= (length(Chanlist_name)-1) - S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}= chanArray_pv-1; - else - S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index} = 1:(length(Chanlist_name)-1); - end + BinArray = [1:BinNum]; end - - if numel(S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}) == numel(Chanlist) - EStduio_gui_erp_bin_chan.ElecRange.Value =1; - observe_ERPDAT.ERP_chan = [1:numel(Chanlist)]; + if any(BinArray(:)<=0) + BinArray = [1:BinNum]; + end + BinArraydef = estudioworkingmemory('ERP_BinArray'); + if numel(BinArray)>= numel(BinArraydef) + bindiff = setdiff(BinArray,BinArraydef); else - EStduio_gui_erp_bin_chan.ElecRange.Value = S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}+1; - observe_ERPDAT.ERP_chan= S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}; + bindiff = setdiff(BinArraydef,BinArray); end - - ChanShow = S_erpbinchan.geterpbinchan.elecs_shown{S_erpbinchan.geterpbinchan.Select_index}; - S_erpbinchan.geterpbinchan.elec_n(S_erpbinchan.geterpbinchan.Select_index) = numel(ChanShow); - S_erpbinchan.geterpbinchan.first_elec(S_erpbinchan.geterpbinchan.Select_index) = ChanShow(1); - - estudioworkingmemory('ChanShow',ChanShow); - - %%Setting for display bins - BinNum = observe_ERPDAT.ERP.nbin; - BinName = observe_ERPDAT.ERP.bindescr; - brange = cell(BinNum+1,1); - brange(1) = {'ALL'}; - for i = 1:BinNum - brange(i+1) = {strcat(num2str(i),'.',32,BinName{i})}; - end - EStduio_gui_erp_bin_chan.BinRange.String=brange; - binArray_pv = EStduio_gui_erp_bin_chan.BinRange.Value; - if numel(binArray_pv)==1 && binArray_pv ==1 - EStduio_gui_erp_bin_chan.BinRange.Value =1; - S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index} = 1:BinNum; + if ~isempty(bindiff) + estudioworkingmemory('ERP_BinArray',BinArray); + end + observe_ERPDAT.Count_currentERP=3; + f_redrawERP(); + estudioworkingmemory('f_ERP_proces_messg','Bin & Channel Selection > Apply'); + observe_ERPDAT.Process_messg =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function Count_currentERPChanged(~,~) + if observe_ERPDAT.Count_currentERP~=2 + return; + end + ChangeFlag = estudioworkingmemory('ERPTab_chanbin'); + if ChangeFlag==1 + erp_between_panels_change(); + observe_ERPDAT.Count_currentERP=0; + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + Chanlist_name = 'No erpset is available'; + ERPTab_bin_chan.ElecRange.String = Chanlist_name; + ERPTab_bin_chan.ElecRange.Value=1; + Binlist_name = 'No erpset is available '; + ERPTab_bin_chan.BinRange.String = Binlist_name; + ERPTab_bin_chan.BinRange.Value=1; + ChanArray = []; + BinArray = []; + Enableflag = 'off'; else - if max(binArray_pv-1)<= BinNum - S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}= binArray_pv-1; + Enableflag = 'on'; + % + %%setting for channels + ChanArray = estudioworkingmemory('ERP_ChanArray'); + Chanlist = observe_ERPDAT.ERP.chanlocs; + Chanlist_name{1} = 'All'; + for Numofchan = 1:length(Chanlist) + Chanlist_name{Numofchan+1,1} = strcat(num2str(Numofchan),'.',32,char(Chanlist(Numofchan).labels)); + end + ERPTab_bin_chan.ElecRange.String=Chanlist_name; + ERPTab_bin_chan.ElecRange.Min = 1; + ERPTab_bin_chan.ElecRange.Max = length(Chanlist_name)+1; + ChanArraydef = ERPTab_bin_chan.ElecRange.Value; + if numel(ChanArraydef)==1 && ChanArraydef==1 + ChanArray = [1:length(Chanlist_name)-1]; + end + if isempty(ChanArray) || any(ChanArray(:)<=0) || any(ChanArray(:) >length(Chanlist_name)-1) || numel(ChanArray) == length(Chanlist_name)-1 + ERPTab_bin_chan.ElecRange.Value = 1; + ChanArray = [1:length(Chanlist_name)-1]; + else + ERPTab_bin_chan.ElecRange.Value =ChanArray+1; + end + estudioworkingmemory('ERP_ChanArray',ChanArray); + % + %%setting for bins + bindescr = observe_ERPDAT.ERP.bindescr; + binlist_name{1} = 'All'; + for ii = 1:observe_ERPDAT.ERP.nbin + try + binlist_name{1+ii} = strcat(num2str(ii),'.',32,char(bindescr{ii})); + catch + binlist_name{1+ii} = strcat(num2str(ii),'.',32,'bin',num2str(ii)); + end + end + ERPTab_bin_chan.BinRange.String = binlist_name; + ERPTab_bin_chan.BinRange.Min = 1; + ERPTab_bin_chan.BinRange.Max = length(binlist_name) + 1; + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = observe_ERPDAT.ERP.nbin; + if ERPTab_bin_chan.ERPFlag ==1 + if ERPTab_bin_chan.BinRange.Value==1 + BinArray = 1:BinNum; + end + end + BinArraydef= ERPTab_bin_chan.BinRange.Value; + if numel(BinArraydef)==1 && BinArraydef==1 + BinArray = [1:BinNum]; + end + + if isempty(BinArray) || any(BinArray(:)<=0) || any(BinArray(:)>BinNum) || numel(BinArray) >= BinNum + BinArray = [1:BinNum]; + ERPTab_bin_chan.BinRange.Value=1; else - S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index} = 1:BinNum; + ERPTab_bin_chan.BinRange.Value =BinArray+1; end + estudioworkingmemory('ERP_BinArray',BinArray); + ERPTab_bin_chan.ERPFlag = 1; end - - if numel(S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}) == BinNum - EStduio_gui_erp_bin_chan.BinRange.Value =1; - else - EStduio_gui_erp_bin_chan.BinRange.Value =S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}; + if ViewerFlag==1 + Enableflag = 'off'; end - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') || checked_ERPset_Index_bin_chan(1) ==1 - EStduio_gui_erp_bin_chan.BinRange.Enable = 'off'; - else - EStduio_gui_erp_bin_chan.BinRange.Enable = 'on'; + ERPTab_bin_chan.ElecRange.Enable = Enableflag; + ERPTab_bin_chan.BinRange.Enable = Enableflag; + ERPTab_bin_chan.plot_reset.Enable = Enableflag; + ERPTab_bin_chan.plot_apply.Enable = Enableflag; + observe_ERPDAT.Count_currentERP=3; + end + + + function erp_between_panels_change(~,~) + if isempty(observe_ERPDAT.ALLERP)|| isempty(observe_ERPDAT.ERP) + return; end - EStduio_gui_erp_bin_chan.BinRange.Min = 1; - EStduio_gui_erp_bin_chan.BinRange.Max = length(brange)+1; - - if numel(S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}) == BinNum - EStduio_gui_erp_bin_chan.BinRange.Value =1; - observe_ERPDAT.ERP_bin = [1:BinNum]; + ChangeFlag = estudioworkingmemory('ERPTab_chanbin'); + if ChangeFlag~=1 + return; + end + binchan_apply(); + estudioworkingmemory('ERPTab_chanbin',0); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_bin_chan.TitleColor= [ 0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [0 0 0]; + end + + +%%--------------press return to execute "Apply"---------------------------- + function erp_binchan_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_chanbin'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + binchan_apply(); + estudioworkingmemory('ERPTab_chanbin',0); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_bin_chan.TitleColor= [ 0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [0 0 0]; else - EStduio_gui_erp_bin_chan.BinRange.Value = S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}+1; - observe_ERPDAT.ERP_bin = S_erpbinchan.geterpbinchan.bins{S_erpbinchan.geterpbinchan.Select_index}; + return; end - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - end + +%%---------------reset the parameters for all panels----------------------- + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=2 + return; + end + estudioworkingmemory('ERPTab_chanbin',0); + ERPTab_bin_chan.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_bin_chan.plot_apply.ForegroundColor = [0 0 0]; + EStudio_box_bin_chan.TitleColor= [ 0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_bin_chan.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_bin_chan.plot_reset.ForegroundColor = [0 0 0]; + if isempty(observe_ERPDAT.ERP) + BinArray=[];ChanArray = []; + else + BinArray = [1:observe_ERPDAT.ERP.nbin]; + ChanArray= [1:observe_ERPDAT.ERP.nchan]; + end + ERPTab_bin_chan.BinRange.Value=1; + estudioworkingmemory('ERP_BinArray',BinArray); + ERPTab_bin_chan.ElecRange.Value = 1; + estudioworkingmemory('ERP_ChanArray',ChanArray); + observe_ERPDAT.Reset_erp_paras_panel=3; + end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_binoperation_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_binoperation_GUI.m index c56fd7d8..8ef105a7 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_binoperation_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_binoperation_GUI.m @@ -8,11 +8,9 @@ function varargout = f_ERP_binoperation_GUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@onErpChanged); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); gui_erp_bin_operation = struct(); @@ -21,11 +19,14 @@ [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; if nargin == 0 fig = figure(); % Parent figure - ERP_bin_operation_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'ERP Bin Operations', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_bin_operation_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Bin Operations', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_bin_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Bin Operations', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_bin_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Bin Operations', 'Padding',... + 5,'BackgroundColor',ColorB_def); else - ERP_bin_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Bin Operations', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_bin_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Bin Operations', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def); %'HelpFcn', @binop_help end %-----------------------------Draw the panel------------------------------------- @@ -35,24 +36,17 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_bin_operation(FonsizeDefault); varargout{1} = ERP_bin_operation_gui; function drawui_erp_bin_operation(FonsizeDefault) FontSize_defualt = FonsizeDefault; - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end + Enable_label = 'off'; [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; %%--------------------channel and bin setting---------------------- gui_erp_bin_operation.DataSelBox = uiextras.VBox('Parent', ERP_bin_operation_gui,'BackgroundColor',ColorB_def); - - for ii = 1:100 dsnames{ii,1} = ''; end @@ -64,14 +58,18 @@ function drawui_erp_bin_operation(FonsizeDefault) 'ColumnName' , [], ... 'RowName' , []); set(gui_erp_bin_operation.edit_bineq,'ColumnEditable',true(1,length(dsnames)),'FontSize',FontSize_defualt); - + gui_erp_bin_operation.Paras{1} = gui_erp_bin_operation.edit_bineq.Data; + gui_erp_bin_operation.edit_bineq.KeyPressFcn = @erp_binop_presskey; gui_erp_bin_operation.equation_selection = uiextras.HBox('Parent', gui_erp_bin_operation.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_bin_operation.eq_editor = uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.equation_selection,... - 'String','Eq. Advanced','callback',@eq_advanced,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Advanced','callback',@eq_advanced,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_bin_operation.eq_load = uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.equation_selection,... - 'String','Load Eq.','callback',@eq_load,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Load EQ','callback',@eq_load,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_erp_bin_operation.eq_save = uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.equation_selection,... + 'String','Save EQ','callback',@eq_save,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_bin_operation.eq_clear = uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.equation_selection,... - 'String','Clear Eq.','callback',@eq_clear,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Clear','callback',@eq_clear,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + %%%----------------Mode----------------------------------- gui_erp_bin_operation.mode_1 = uiextras.HBox('Parent', gui_erp_bin_operation.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_bin_operation.mode_modify_title = uicontrol('Style','text','Parent',gui_erp_bin_operation.mode_1 ,... @@ -79,6 +77,8 @@ function drawui_erp_bin_operation(FonsizeDefault) gui_erp_bin_operation.mode_modify = uicontrol('Style','radiobutton','Parent',gui_erp_bin_operation.mode_1 ,... 'String','Modify Existing ERPset','callback',@mode_modify,'Value',1,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F gui_erp_bin_operation.mode_modify.String = 'Modify Existing ERPset
                            (recursive updating)'; + gui_erp_bin_operation.Paras{2} = gui_erp_bin_operation.mode_modify.Value; + gui_erp_bin_operation.mode_modify.KeyPressFcn = @erp_binop_presskey; set(gui_erp_bin_operation.mode_1,'Sizes',[55 -1]); %%--------------For create a new ERPset---------------------------- gui_erp_bin_operation.mode_2 = uiextras.HBox('Parent', gui_erp_bin_operation.DataSelBox,'BackgroundColor',ColorB_def); @@ -87,23 +87,24 @@ function drawui_erp_bin_operation(FonsizeDefault) 'String',{'', ''},'callback',@mode_create,'Value',0,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F gui_erp_bin_operation.mode_create.String = 'Create New ERPset
                            (independent transformations)'; set(gui_erp_bin_operation.mode_2,'Sizes',[55 -1]); + gui_erp_bin_operation.mode_create.KeyPressFcn = @erp_binop_presskey; + + %%-----------------Run--------------------------------------------- gui_erp_bin_operation.run_title = uiextras.HBox('Parent', gui_erp_bin_operation.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_bin_operation.run_title); - uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.run_title,... - 'String','?','callback',@binop_help,'FontSize',16,'Enable','on'); % 2F + gui_erp_bin_operation.cancel= uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.run_title,... + 'String','Cancel','callback',@binop_cancel,'FontSize',FontSize_defualt,'Enable','off','BackgroundColor',[1 1 1]); % 2F uiextras.Empty('Parent', gui_erp_bin_operation.run_title); gui_erp_bin_operation.run = uicontrol('Style','pushbutton','Parent',gui_erp_bin_operation.run_title,... - 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F uiextras.Empty('Parent', gui_erp_bin_operation.run_title); set(gui_erp_bin_operation.run_title, 'Sizes',[15 105 30 105 15]); - gui_erp_bin_operation.note_title = uiextras.HBox('Parent', gui_erp_bin_operation.DataSelBox,'BackgroundColor',ColorB_def); - uicontrol('Style','text','Parent',gui_erp_bin_operation.note_title,... 'String','Note: Operates on all bins and channels','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F - set(gui_erp_bin_operation.DataSelBox,'Sizes',[130,30,35,35,30 30]); + estudioworkingmemory('ERPTab_binop',0); end @@ -112,35 +113,58 @@ function drawui_erp_bin_operation(FonsizeDefault) %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% -% %%------------------help--------------------------------------------- - function binop_help(~,~)%% It seems that it can be ignored - web('https://github.com/lucklab/erplab/wiki/ERP-Bin-Operations','-browser'); - end - - %%-------------------Equation editor--------------------------------------- function eq_advanced(Source_editor,~) - def = erpworkingmemory('pop_binoperator'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_bin_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_bin_operation.run.ForegroundColor = [1 1 1]; + ERP_bin_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_bin_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_binop',1); + def = estudioworkingmemory('pop_binoperator'); if isempty(def) def = { [], 1}; end - binopGUI = erpworkingmemory('binopGUI'); + binopGUI = estudioworkingmemory('binopGUI'); if gui_erp_bin_operation.mode_modify.Value ==1 binopGUI.emode =0; else binopGUI.emode =1; end - erpworkingmemory('binopGUI',binopGUI); + if isfield(binopGUI,'hmode') + hmode = binopGUI.hmode; + if numel(hmode)~=1 || (hmode~=0&& hmode~=1) + binopGUI.hmode = 0; + end + else + binopGUI.hmode = 0; + end + if isfield(binopGUI,'listname') + if ~ischar(binopGUI.listname) + binopGUI.listname = ''; + end + else + binopGUI.listname = ''; + end + estudioworkingmemory('binopGUI',binopGUI); ERP = observe_ERPDAT.ERP; answer = binoperGUI(ERP, def); if isempty(answer) - disp('User selected Cancel') + observe_ERPDAT.Process_messg =2; return end - - binopGUI = erpworkingmemory('binopGUI'); - ModeValue = binopGUI.emode; + binopGUI= estudioworkingmemory('binopGUI'); + try ModeValue = binopGUI.emode;catch ModeValue=0; end if ModeValue ==0 gui_erp_bin_operation.mode_modify.Value =1; gui_erp_bin_operation.mode_create.Value = 0; @@ -152,7 +176,7 @@ function eq_advanced(Source_editor,~) wbmsgon = answer{2}; def = {formulas, wbmsgon}; - erpworkingmemory('pop_binoperator', def); + estudioworkingmemory('pop_binoperator', def); for ii = 1:100 dsnames{ii,1} = ''; end @@ -169,9 +193,25 @@ function eq_advanced(Source_editor,~) %%-------------------Equation Load--------------------------------------- function eq_load(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_bin_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_bin_operation.run.ForegroundColor = [1 1 1]; + ERP_bin_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_bin_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_binop',1); + + [filename, filepath] = uigetfile({'*.txt';'*.*'},'Select a formulas-file'); if isequal(filename,0) - disp('User selected Cancel') return else fullname = fullfile(filepath, filename); @@ -179,25 +219,14 @@ function eq_load(~,~) end fid_formula = fopen( fullname ); - try - formcell = textscan(fid_formula, '%s','delimiter', '\r'); - formulas = char(formcell{:}); - catch - beep; - msgboxText = ['ERP Bin Operations - Please, check your file:\n '... - fullname '\n']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + formcell = textscan(fid_formula, '%s','delimiter', '\r'); + formulas = char(formcell{:}); + if size(formulas,2)>256 - beep; - msgboxText = ['ERP Bin Operations - Formulas length exceed 256 characters.\n'... + msgboxText = ['Bin Operations - Formulas length exceed 256 characters.'... 'Be sure to press [Enter] after you have entered each formula.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end fclose(fid_formula); @@ -205,8 +234,74 @@ function eq_load(~,~) set(gui_erp_bin_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); end +%%-----------------------------Save equation------------------------------- + function eq_save(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + + Eq_Data = gui_erp_bin_operation.edit_bineq.Data; + Formula_str = {}; + count = 0; + for ii = 1:length(Eq_Data) + if ~isempty(Eq_Data{ii}) + count = count +1; + Formula_str{count} = Eq_Data{ii}; + end + end + msgboxText = ['Bin Operations >Save']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg =1; + if isempty(Formula_str) + msgboxText = ['Bin Operations >Save - You have not yet written a formula']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + pathName = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName) + pathName =cd; + end + + [filename, filepath, filterindex] = uiputfile({'*.txt';'*.*'},'Save formulas-file as', pathName); + if isequal(filename,0) + return + else + [px, fname, ext] = fileparts(filename); + ext = '.txt'; + fname = [ fname ext]; + fullname = fullfile(filepath, fname); + fid_list = fopen( fullname , 'w'); + for i=1:length(Formula_str) + fprintf(fid_list,'%s\n', Formula_str{i}); + end + fclose(fid_list); + disp(['Saving equation list at ' fullname '']) + end + observe_ERPDAT.Process_messg =2; + end + + + %%-------------------Equation Clear--------------------------------------- function eq_clear(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_bin_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_bin_operation.run.ForegroundColor = [1 1 1]; + ERP_bin_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_bin_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_binop',1); for ii = 1:100 dsnames{ii,1} = ''; end @@ -218,19 +313,35 @@ function eq_clear(~,~) %%------------------Modify Existing ERPset--------------------------------------- function mode_modify(Source_editor,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_bin_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_bin_operation.run.ForegroundColor = [1 1 1]; + ERP_bin_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_bin_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_binop',1); gui_erp_bin_operation.mode_modify.Value = 1; gui_erp_bin_operation.mode_create.Value = 0; - - FormulaArrayIn = char(gui_erp_bin_operation.edit_bineq.Data); if isempty(FormulaArrayIn) val = 0; - def = erpworkingmemory('pop_binoperator'); + def = estudioworkingmemory('pop_binoperator'); + if isempty(def) + def = { [], 1}; + end FormulaArrayIn_default = def{1}; if ~isempty(FormulaArrayIn_default) [val, formulaArray]= f_testsyntaxtype(FormulaArrayIn_default, 'recu'); def{1} = formulaArray; - erpworkingmemory('pop_binoperator',def); + estudioworkingmemory('pop_binoperator',def); end else [val, formulaArray]= f_testsyntaxtype(FormulaArrayIn, 'recu'); @@ -238,23 +349,40 @@ function mode_modify(Source_editor,~) if val ==1 gui_erp_bin_operation.edit_bineq.Data =formulaArray; set(gui_erp_bin_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); - def = erpworkingmemory('pop_binoperator'); + def = estudioworkingmemory('pop_binoperator'); + if isempty(def) + def = { [], 1}; + end def{1} = formulaArray; - erpworkingmemory('pop_binoperator',def); + estudioworkingmemory('pop_binoperator',def); end end %%------------------Create New ERPset--------------------------------------- function mode_create(Source_create,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_bin_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_bin_operation.run.ForegroundColor = [1 1 1]; + ERP_bin_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_bin_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_binop',1); + gui_erp_bin_operation.mode_modify.Value = 0; gui_erp_bin_operation.mode_create.Value = 1; - - FormulaArrayIn = char(gui_erp_bin_operation.edit_bineq.Data); if isempty(FormulaArrayIn) val = 0; - def = erpworkingmemory('pop_binoperator'); + def = estudioworkingmemory('pop_binoperator'); try FormulaArrayIn_default = def{1}; catch @@ -265,7 +393,7 @@ function mode_create(Source_create,~) if ~isempty(FormulaArrayIn_default) [val, formulaArray]= f_testsyntaxtype(FormulaArrayIn_default, 'norecu'); def{1} = formulaArray; - erpworkingmemory('pop_binoperator',def); + estudioworkingmemory('pop_binoperator',def); end else [val, formulaArray]= f_testsyntaxtype(FormulaArrayIn, 'norecu'); @@ -273,37 +401,39 @@ function mode_create(Source_create,~) if val ==1 gui_erp_bin_operation.edit_bineq.Data =formulaArray; set(gui_erp_bin_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); - def = erpworkingmemory('pop_binoperator'); + def = estudioworkingmemory('pop_binoperator'); + if isempty(def) + def = { [], 1}; + end def{1} = formulaArray; - erpworkingmemory('pop_binoperator',def); + estudioworkingmemory('pop_binoperator',def); end end %%---------------------Run------------------------------------------------- function apply_run(~,~) - pathName_def = erpworkingmemory('ERP_save_folder'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + pathName_def = estudioworkingmemory('EEG_save_folder'); if isempty(pathName_def) pathName_def =cd; end - - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - beep; - msgboxText = ['ERP Bin Operations - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); end - - Eq_Data = gui_erp_bin_operation.edit_bineq.Data; Formula_str = {}; @@ -314,15 +444,19 @@ function apply_run(~,~) Formula_str{count} = Eq_Data{ii}; end end - if isempty(Formula_str) - beep; - msgboxText = ['ERP Bin Operations - You have not yet written a formula']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Bin Operations - You have not yet written a formula']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end + + gui_erp_bin_operation.run.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.run.ForegroundColor = [0 0 0]; + ERP_bin_operation_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_binop',0); %%check the format of equations if gui_erp_bin_operation.mode_modify.Value editormode = 0; @@ -334,155 +468,122 @@ function apply_run(~,~) return end + gui_erp_bin_operation.Paras{1} = gui_erp_bin_operation.edit_bineq.Data; + gui_erp_bin_operation.Paras{2} = gui_erp_bin_operation.mode_modify.Value; + %%%Create a new ERPset for the bin-operated ERPsets - Save_file_label = []; - if gui_erp_bin_operation.mode_create.Value - if numel(Selectederp_Index) > 1 - Answer = f_ERP_save_multi_file(observe_ERPDAT.ALLERP,Selectederp_Index,'_binop'); - if isempty(Answer) - beep; - disp('User selected Cancel'); - return; - end - - if ~isempty(Answer{1}) - ALLERP_out = Answer{1}; - Save_file_label = Answer{2}; - end - elseif numel(Selectederp_Index)== 1 - ALLERP_out = observe_ERPDAT.ALLERP; - ERP = observe_ERPDAT.ALLERP(Selectederp_Index); - ERP.filepath = pathName_def; - Answer = f_ERP_save_single_file(strcat(ERP.erpname,'_binop'),ERP.filename,Selectederp_Index); - if isempty(Answer) - beep; - disp('User selectd cancal'); - return; - end - Save_file_label =0; - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ERP.erpname; - Save_file_label =0; - elseif ~isempty(fileName_full) - - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - Save_file_label =1; - end - end - ALLERP_out(Selectederp_Index) = ERP;clear ERP; + estudioworkingmemory('f_ERP_proces_messg','Bin Operations'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM =''; end; + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + for Numoferp = 1:numel(ERPArray)%%Bin Operations for each selected ERPset + ERP = ALLERP(ERPArray(Numoferp)); + [ERP ERPCOM]= pop_binoperator( ERP, Formula_str, 'Warning', 'on', 'ErrorMsg', 'command', 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; end - elseif gui_erp_bin_operation.mode_modify.Value - ALLERP_out = observe_ERPDAT.ALLERP; end - - if isempty(Save_file_label) - Save_file_label =0; + Save_file_label = 0; + if gui_erp_bin_operation.mode_create.Value + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_binop'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end end - - try - erpworkingmemory('f_ERP_proces_messg','ERP Bin Operations'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - ALLERPCOM = evalin('base','ALLERPCOM'); - for Numofselectederp = 1:numel(Selectederp_Index)%%Bin Operations for each selected ERPset - ERP = ALLERP_out(Selectederp_Index(Numofselectederp)); - [ERP ERPCOM]= pop_binoperator( ERP, Formula_str, 'Warning', 'on', 'ErrorMsg', 'command', 'Saveas', 'off', 'History', 'gui'); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - - if gui_erp_bin_operation.mode_modify.Value%% If select "Modify Existing ERPset (recursive updating)" - ERP.erpname = strcat(ERP.erpname,'_binop'); - observe_ERPDAT.ALLERP(Selectederp_Index(Numofselectederp)) = ERP; - observe_ERPDAT.ERP= observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - elseif gui_erp_bin_operation.mode_create.Value %% If select "Create New ERPset (independent transformations)" - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - if Save_file_label==1 - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ALLERP_out(Selectederp_Index(Numofselectederp)).erpname,... - 'filename', ALLERP_out(Selectederp_Index(Numofselectederp)).filename, 'filepath',ALLERP_out(Selectederp_Index(Numofselectederp)).filepath); + if gui_erp_bin_operation.mode_modify.Value%% If select "Modify Existing ERPset (recursive updating)" + ALLERP(ERPArray) = ALLERP_out; + elseif gui_erp_bin_operation.mode_create.Value %% If select "Create New ERPset (independent transformations)" + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ALLERP_out(Numoferp).erpname,... + 'filename', ALLERP_out(ERPArray(Numoferp)).filename, 'filepath',ALLERP_out(Numoferp).filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end + else + ERP.filename = ''; + ERP.filepath = ''; + ERP.saved = 'no'; end - + ALLERP(length(ALLERP)+1) = ERP; end - - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - if gui_erp_bin_operation.mode_create.Value%%Save the labels of the selected ERPsets - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selectederp_Index)+1:length(observe_ERPDAT.ALLERP)]; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selectederp_Index)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + end + observe_ERPDAT.ALLERP = ALLERP; + if gui_erp_bin_operation.mode_create.Value%%Save the labels of the selected ERPsets + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); end - - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - return; - catch - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - Selected_ERP_afd =observe_ERPDAT.CURRENTERP; estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%% - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('f_ERP_bin_opt',1); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; + return; end - +%%---------------------------cancel---------------------------------------- + function binop_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=7 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_bin_operation.run.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.run.ForegroundColor = [0 0 0]; + ERP_bin_operation_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_binop',0); + + gui_erp_bin_operation.edit_bineq.Data= gui_erp_bin_operation.Paras{1}; + mode_modify = gui_erp_bin_operation.Paras{2}; + gui_erp_bin_operation.mode_modify.Value = mode_modify; + gui_erp_bin_operation.mode_create.Value = ~mode_modify; + end %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - - if isempty(Selectederp_Index) - beep; - msgboxText = ['ERP Bin Operations - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; - end - if isempty(checked_ERPset_Index) - checked_ERPset_Index = f_checkerpsets(observe_ERPDAT.ALLERP,Selectederp_Index); + if observe_ERPDAT.Count_currentERP~=9 + return; end - if checked_curr_index || any(checked_ERPset_Index(:)) + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) Enable_label = 'off'; for ii = 1:100 - if ii==1 + if ii==101 dsnames{ii,1} = 'The number of bins and channles should be the same for the selected ERPset!'; else dsnames{ii,1} = ''; @@ -495,7 +596,8 @@ function Count_currentERPChanged(~,~) binopDataor = gui_erp_bin_operation.edit_bineq.Data; for ii = 1:100 binopDataorcell = char(binopDataor{ii,1}); - if isempty(binopDataorcell) + aa = 'The number of bins and channles should be the same for the selected ERPset!'; + if isempty(binopDataorcell) || strcmpi(binopDataorcell,aa) dsnames{ii,1} = ''; else dsnames{ii,1} = binopDataorcell; @@ -504,12 +606,61 @@ function Count_currentERPChanged(~,~) gui_erp_bin_operation.edit_bineq.Data = dsnames; set(gui_erp_bin_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if ViewerFlag==1 + Enable_label = 'off'; + end gui_erp_bin_operation.mode_modify.Enable=Enable_label; gui_erp_bin_operation.mode_create.Enable=Enable_label; gui_erp_bin_operation.eq_editor.Enable = Enable_label; gui_erp_bin_operation.eq_load.Enable = Enable_label; + gui_erp_bin_operation.eq_save.Enable = Enable_label; gui_erp_bin_operation.eq_clear.Enable = Enable_label; gui_erp_bin_operation.run.Enable = Enable_label; - + gui_erp_bin_operation.cancel.Enable = Enable_label; + observe_ERPDAT.Count_currentERP=10; end + +%%--------------press return to execute "Apply"---------------------------- + function erp_binop_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_binop'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + apply_run(); + gui_erp_bin_operation.run.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.run.ForegroundColor = [0 0 0]; + ERP_bin_operation_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_binop',0); + else + return; + end + end + + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=9 + return; + end + gui_erp_bin_operation.run.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.run.ForegroundColor = [0 0 0]; + ERP_bin_operation_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_bin_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_bin_operation.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_binop',0); + for ii = 1:100 + dsnames{ii,1} = ''; + end + gui_erp_bin_operation.edit_bineq.Data = dsnames; + gui_erp_bin_operation.mode_modify.Value = 1; + gui_erp_bin_operation.mode_create.Value = 0; + observe_ERPDAT.Reset_erp_paras_panel=10; + end + end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_chanoperation_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_chanoperation_GUI.m index 77cc5603..9d18a75b 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_chanoperation_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_chanoperation_GUI.m @@ -2,20 +2,17 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && Nov. 2023 % ERPLAB Studio function varargout = f_ERP_chanoperation_GUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@onErpChanged); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); gui_erp_chan_operation = struct(); - %-----------------------------Name the title---------------------------------------------- % global ERP_chan_operation_gui; try @@ -25,11 +22,14 @@ end if nargin == 0 fig = figure(); % Parent figure - ERP_chan_operation_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'ERP Channel Operations', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_chan_operation_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Channel Operations', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_chan_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Channel Operations', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_chan_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Channel Operations', 'Padding', 5,... + 'BackgroundColor',ColorB_def); else - ERP_chan_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Channel Operations', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_chan_operation_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Channel Operations', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @chanop_help end %-----------------------------Draw the panel------------------------------------- @@ -39,7 +39,7 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_bin_operation(FonsizeDefault); varargout{1} = ERP_chan_operation_gui; @@ -54,13 +54,9 @@ function drawui_erp_bin_operation(FonsizeDefault) if isempty(FontSize_defualt) FontSize_defualt = 12; end - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end + Enable_label = 'off'; %%--------------------channel and bin setting---------------------- - gui_erp_chan_operation.DataSelBox = uiextras.VBox('Parent', ERP_chan_operation_gui); + gui_erp_chan_operation.DataSelBox = uiextras.VBox('Parent', ERP_chan_operation_gui,'BackgroundColor',ColorB_def); for ii = 1:100 dsnames{ii,1} = ''; end @@ -72,93 +68,126 @@ function drawui_erp_bin_operation(FonsizeDefault) 'ColumnName' , [], ... 'RowName' , []); set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,length(dsnames)),'FontSize',FontSize_defualt); + gui_erp_chan_operation.edit_bineq.KeyPressFcn= @erp_chanop_presskey; + gui_erp_chan_operation.Paras{1} = gui_erp_chan_operation.edit_bineq.Data; gui_erp_chan_operation.equation_selection = uiextras.HBox('Parent', gui_erp_chan_operation.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_chan_operation.eq_editor = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.equation_selection,... - 'String','Eq. Advanced','callback',@eq_advanced,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Advanced','callback',@eq_advanced,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_chan_operation.eq_load = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.equation_selection,... - 'String','Load Eq.','callback',@eq_load,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Load EQ','callback',@eq_load,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_erp_chan_operation.eq_save = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.equation_selection,... + 'String','Save EQ','callback',@eq_save,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_chan_operation.eq_clear = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.equation_selection,... - 'String','Clear Eq.','callback',@eq_clear,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Clear','callback',@eq_clear,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_chan_operation.asst_locaInfo = uiextras.HBox('Parent', gui_erp_chan_operation.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_chan_operation.ref_asst = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.asst_locaInfo,... - 'String','Reference Asst','callback',@ref_asst,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Reference Asst','callback',@ref_asst,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_chan_operation.locaInfor = uicontrol('Style','checkbox','Parent',gui_erp_chan_operation.asst_locaInfo,... 'String','Load Eq.','callback',@loca_infor,'FontSize',FontSize_defualt,'Value',1,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F gui_erp_chan_operation.locaInfor.String = 'Try to Preserve
                            Location Information'; + gui_erp_chan_operation.Paras{2} =gui_erp_chan_operation.locaInfor.Value; set(gui_erp_chan_operation.asst_locaInfo,'Sizes',[105 180]); + gui_erp_chan_operation.locaInfor.KeyPressFcn= @erp_chanop_presskey; %%%----------------Mode----------------------------------- gui_erp_chan_operation.mode_1 = uiextras.HBox('Parent', gui_erp_chan_operation.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_chan_operation.mode_modify_title = uicontrol('Style','text','Parent',gui_erp_chan_operation.mode_1 ,... 'String','Mode:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F gui_erp_chan_operation.mode_modify = uicontrol('Style','radiobutton','Parent',gui_erp_chan_operation.mode_1 ,... 'String','Modify Existing ERPset','callback',@mode_modify,'Value',1,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + gui_erp_chan_operation.mode_modify.KeyPressFcn= @erp_chanop_presskey; gui_erp_chan_operation.mode_modify.String = 'Modify Existing ERPset
                            (recursive updating)'; set(gui_erp_chan_operation.mode_1,'Sizes',[55 -1]); + gui_erp_chan_operation.Paras{3} = gui_erp_chan_operation.mode_modify.Value; %%--------------For create a new ERPset---------------------------- gui_erp_chan_operation.mode_2 = uiextras.HBox('Parent', gui_erp_chan_operation.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_chan_operation.mode_2,'BackgroundColor',ColorB_def); gui_erp_chan_operation.mode_create = uicontrol('Style','radiobutton','Parent',gui_erp_chan_operation.mode_2 ,... 'String',{'', ''},'callback',@mode_create,'Value',0,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F gui_erp_chan_operation.mode_create.String = 'Create New ERPset
                            (independent transformations)'; + gui_erp_chan_operation.mode_create.KeyPressFcn= @erp_chanop_presskey; set(gui_erp_chan_operation.mode_2,'Sizes',[55 -1]); %%-----------------Run--------------------------------------------- gui_erp_chan_operation.run_title = uiextras.HBox('Parent', gui_erp_chan_operation.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_chan_operation.run_title,'BackgroundColor',ColorB_def); - uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.run_title,... - 'String','?','callback',@chanop_help,'FontSize',16,'Enable','on'); + gui_erp_chan_operation.cancel = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.run_title,... + 'String','Cancel','callback',@chanop_cancel,'FontSize',FontSize_defualt,'Enable','off','BackgroundColor',[1 1 1]); uiextras.Empty('Parent', gui_erp_chan_operation.run_title,'BackgroundColor',ColorB_def); gui_erp_chan_operation.run = uicontrol('Style','pushbutton','Parent',gui_erp_chan_operation.run_title,... - 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F uiextras.Empty('Parent', gui_erp_chan_operation.run_title,'BackgroundColor',ColorB_def); set(gui_erp_chan_operation.run_title,'Sizes',[15 105 30 105 15]); - gui_erp_chan_operation.note_title = uiextras.HBox('Parent', gui_erp_chan_operation.DataSelBox,'BackgroundColor',ColorB_def); - uicontrol('Style','text','Parent',gui_erp_chan_operation.note_title,... - 'String','Note: Operates on all bins and channels','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + set(gui_erp_chan_operation.DataSelBox,'Sizes',[130,30,35,35,35,30]); - set(gui_erp_chan_operation.DataSelBox,'Sizes',[130,30,35,35,35,30 30]); + estudioworkingmemory('ERPTab_chanop',0); end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% -% %%------------------Edit bin--------------------------------------------- - function chanop_help(~,~)%% It seems that it can be ignored - web('https://github.com/lucklab/erplab/wiki/EEG-and-ERP-Channel-Operations','-browser'); - end - - %%-------------------Equation editor--------------------------------------- - function eq_advanced(Source_editor,~) - def = erpworkingmemory('pop_erpchanoperator'); + function eq_advanced(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); + + def = estudioworkingmemory('pop_erpchanoperator'); if isempty(def) def = { [], 1}; end - chanopGUI = erpworkingmemory('chanopGUI'); + chanopGUI = estudioworkingmemory('chanopGUI'); if gui_erp_chan_operation.mode_modify.Value==1 chanopGUI.emode=0; else chanopGUI.emode=1; end + if isfield(chanopGUI,'hmode') + hmode = chanopGUI.hmode; + if isnumeric(hmode) + if numel(hmode)~=1 || (hmode~=0&& hmode~=1) + chanopGUI.hmode = 0; + end + else + chanopGUI.hmode = 0; + end + else + chanopGUI.hmode = 0; + end + if isfield(chanopGUI,'listname') + if ~ischar(chanopGUI.listname) + chanopGUI.listname = ''; + end + else + chanopGUI.listname = ''; + end localInfor = gui_erp_chan_operation.locaInfor.Value; chanopGUI.keeplocs = localInfor; - erpworkingmemory('chanopGUI',chanopGUI); + estudioworkingmemory('chanopGUI',chanopGUI); ERP = observe_ERPDAT.ERP; answer = chanoperGUI(ERP, def); if isempty(answer) - disp('User selected Cancel') return end - chanopGUI = erpworkingmemory('chanopGUI'); - ModeValue = chanopGUI.emode; + chanopGUI= estudioworkingmemory('chanopGUI'); + try ModeValue = chanopGUI.emode;catch ModeValue=0; end if ModeValue==0 gui_erp_chan_operation.mode_modify.Value=1 ; gui_erp_chan_operation.mode_create.Value = 0; @@ -166,7 +195,7 @@ function eq_advanced(Source_editor,~) gui_erp_chan_operation.mode_modify.Value=0 ; gui_erp_chan_operation.mode_create.Value = 1; end - localInfor = chanopGUI.keeplocs; + try localInfor = chanopGUI.keeplocs;catch localInfor=1; end if localInfor==1 gui_erp_chan_operation.locaInfor.Value=1; else @@ -183,7 +212,7 @@ function eq_advanced(Source_editor,~) end def = {formulas, wbmsgon}; - erpworkingmemory('pop_erpchanoperator', def); + estudioworkingmemory('pop_erpchanoperator', def); for ii = 1:1000 dsnames{ii,1} = ''; end @@ -200,36 +229,40 @@ function eq_advanced(Source_editor,~) end %%-------------------Equation Load--------------------------------------- - function eq_load(~,~) + function eq_load(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); + + [filename, filepath] = uigetfile({'*.txt';'*.*'},'Select a formulas-file'); if isequal(filename,0) - disp('User selected Cancel') return else fullname = fullfile(filepath, filename); disp(['f_ERP_chanoperation_GUI(): For formulas-file, user selected ', fullname]) end - fid_formula = fopen( fullname ); - try - formcell = textscan(fid_formula, '%s','delimiter', '\r'); - formulas = char(formcell{:}); - catch - beep; - msgboxText = ['ERP Channel Operations - Please, check your file:\n '... - fullname '\n']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + formcell = textscan(fid_formula, '%s','delimiter', '\r'); + formulas = char(formcell{:}); + if size(formulas,2)>256 - beep; - msgboxText = ['ERP Channel Operations - Formulas length exceed 256 characters,'... + msgboxText = ['Channel Operations - Formulas length exceed 256 characters,'... 'Be sure to press [Enter] after you have entered each formula.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end fclose(fid_formula); @@ -237,8 +270,74 @@ function eq_load(~,~) set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); end +%%--------------------------Save equations to ----------------------------- + function eq_save(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + Eq_Data = gui_erp_chan_operation.edit_bineq.Data; + Formula_str = {}; + count = 0; + for ii = 1:length(Eq_Data) + if ~isempty(Eq_Data{ii}) + count = count +1; + Formula_str{count} = Eq_Data{ii}; + end + end + msgboxText = ['Channel Operations >Save']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg =1; + if isempty(Formula_str) + msgboxText = ['Channel Operations >Save - You have not yet written a formula']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + pathName = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName) + pathName =cd; + end + + [filename, filepath, filterindex] = uiputfile({'*.txt';'*.*'},'Save formulas-file as', pathName); + if isequal(filename,0) + observe_ERPDAT.Process_messg =2; + return + else + [px, fname, ext] = fileparts(filename); + ext = '.txt'; + fname = [ fname ext]; + fullname = fullfile(filepath, fname); + fid_list = fopen( fullname , 'w'); + for i=1:length(Formula_str) + fprintf(fid_list,'%s\n', Formula_str{i}); + end + fclose(fid_list); + disp(['Saving equation list at ' fullname '']) + end + observe_ERPDAT.Process_messg =2; + end + + %%-------------------Equation Clear--------------------------------------- - function eq_clear(~,~) + function eq_clear(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); + for ii = 1:1000 dsnames{ii,1} = ''; end @@ -247,17 +346,27 @@ function eq_clear(~,~) end %%-------------------Reference assist-------------------------------------- - function ref_asst(~,~) + function ref_asst(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); gui_erp_chan_operation.mode_modify.Value = 0; gui_erp_chan_operation.mode_create.Value = 1; - try - ERPLAB = observe_ERPDAT.ERP; - nchan = ERPLAB.nchan; - catch - ERPLAB.chanlocs = []; - nchan = 1; - end + ERPLAB = observe_ERPDAT.ERP; + nchan = ERPLAB.nchan; listch=[]; if isempty(ERPLAB.chanlocs) for e=1:nchan @@ -272,6 +381,7 @@ function ref_asst(~,~) % open reference wizard formulalist = f_rerefassistantGUI(nchan, listch); if isempty(formulalist) + observe_ERPDAT.Process_messg =2; return; end formulas = char(gui_erp_chan_operation.edit_bineq.Data); @@ -285,7 +395,6 @@ function ref_asst(~,~) [expspliter parts] = regexp(formulalist, '=','match','split'); formulalist{t} = sprintf('%s = %s', strtrim(regexprep(parts{t}{1}, '[^n]*ch','nch','ignorecase')), strtrim(parts{t}{2})); end - % formulalist = char(formulalist); end if isempty(formulas) @@ -302,7 +411,6 @@ function ref_asst(~,~) dsnames{count,1} = formulas{ii}; end end - for ii = 1:length(formulalist) dsnames{count+ii,1} = formulalist{ii}; end @@ -310,31 +418,63 @@ function ref_asst(~,~) gui_erp_chan_operation.edit_bineq.Data =dsnames; end set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); - end %%--------------------Preserve location information------------------------ - function loca_infor(source,~) + function loca_infor(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); Value = source.Value; gui_erp_chan_operation.locaInfor.Value = Value; end - %%------------------Modify Existing ERPset--------------------------------------- - function mode_modify(Source_editor,~) + function mode_modify(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); + gui_erp_chan_operation.mode_modify.Value = 1; gui_erp_chan_operation.mode_create.Value = 0; FormulaArrayIn = gui_erp_chan_operation.edit_bineq.Data; if isempty(FormulaArrayIn) val = 0; - def = erpworkingmemory('pop_erpchanoperator'); + def = estudioworkingmemory('pop_erpchanoperator'); + if isempty(def) + def = { [], 1}; + end FormulaArrayIn_default = def{1}; if ~isempty(FormulaArrayIn_default) [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn_default, 'recu'); def{1} = formulaArray; - erpworkingmemory('pop_erpchanoperator',def); + estudioworkingmemory('pop_erpchanoperator',def); end else [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn, 'recu'); @@ -350,26 +490,48 @@ function mode_modify(Source_editor,~) end gui_erp_chan_operation.edit_bineq.Data =formulaArray; set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); - def = erpworkingmemory('pop_erpchanoperator'); + def = estudioworkingmemory('pop_erpchanoperator'); + if isempty(def) + def = { [], 1}; + end def{1} = formulaArray; - erpworkingmemory('pop_erpchanoperator',def); + estudioworkingmemory('pop_erpchanoperator',def); end - end %%------------------Create New ERPset--------------------------------------- - function mode_create(Source_create,~) + function mode_create(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_chan_operation.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_chan_operation.run.ForegroundColor = [1 1 1]; + ERP_chan_operation_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_chan_operation.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_chanop',1); + + gui_erp_chan_operation.mode_modify.Value = 0; gui_erp_chan_operation.mode_create.Value = 1; FormulaArrayIn = char(gui_erp_chan_operation.edit_bineq.Data); if isempty(FormulaArrayIn) val = 0; - def = erpworkingmemory('pop_erpchanoperator'); + def = estudioworkingmemory('pop_erpchanoperator'); + if isempty(def) + def = { [], 1}; + end FormulaArrayIn_default = def{1}; if ~isempty(FormulaArrayIn_default) [val, formulaArray]= f_chan_testsyntaxtype(FormulaArrayIn_default, 'norecu'); def{1} = formulaArray; - erpworkingmemory('pop_erpchanoperator',def); + estudioworkingmemory('pop_erpchanoperator',def); else for ii = 1:100 formulaArray{ii,1} = ''; @@ -388,39 +550,59 @@ function mode_create(Source_create,~) end gui_erp_chan_operation.edit_bineq.Data =formulaArray; set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); - def = erpworkingmemory('pop_erpchanoperator'); + def = estudioworkingmemory('pop_erpchanoperator'); def{1} = formulaArray; - erpworkingmemory('pop_erpchanoperator',def); + estudioworkingmemory('pop_erpchanoperator',def); end - end +%%------------------------------cancel------------------------------------- + function chanop_cancel(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_chanop',0); + gui_erp_chan_operation.run.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.run.ForegroundColor = [0 0 0]; + ERP_chan_operation_gui.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.cancel.ForegroundColor = [0 0 0]; + + gui_erp_chan_operation.edit_bineq.Data= gui_erp_chan_operation.Paras{1}; + gui_erp_chan_operation.locaInfor.Value=gui_erp_chan_operation.Paras{2}; + mode_modify = gui_erp_chan_operation.Paras{3}; + gui_erp_chan_operation.mode_modify.Value=mode_modify; + gui_erp_chan_operation.mode_create.Value = ~mode_modify; + end + %%---------------------Run------------------------------------------------- - function apply_run(~,~) - pathName_def = erpworkingmemory('ERP_save_folder'); - if isempty(pathName_def) - pathName_def =cd; - end - - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - beep; - msgboxText = ['ERP Channel Operations -No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + function apply_run(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=6 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - Eq_Data = gui_erp_chan_operation.edit_bineq.Data; + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + Eq_Data = gui_erp_chan_operation.edit_bineq.Data; Formula_str = {}; count = 0; for ii = 1:length(Eq_Data) @@ -429,15 +611,19 @@ function apply_run(~,~) Formula_str{count} = Eq_Data{ii}; end end - if isempty(Formula_str) - beep; - msgboxText = ['ERP Channel Operations - You have not yet written a formula']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Channel Operations - You have not yet written a formula']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end + estudioworkingmemory('ERPTab_chanop',0); + gui_erp_chan_operation.run.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.run.ForegroundColor = [0 0 0]; + ERP_chan_operation_gui.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.cancel.ForegroundColor = [0 0 0]; %%check the format of equations if gui_erp_chan_operation.mode_modify.Value @@ -449,157 +635,105 @@ function apply_run(~,~) if goeson==0 return; end - - %%%Create a new ERPset for the bin-operated ERPsets - Save_file_label = []; - if gui_erp_chan_operation.mode_create.Value - - if numel(Selectederp_Index) > 1 - Answer = f_ERP_save_multi_file(observe_ERPDAT.ALLERP,Selectederp_Index,'_chop'); - if isempty(Answer) - beep; - disp('User selected Cancel'); - return; - end - if ~isempty(Answer{1}) - ALLERP_out = Answer{1}; - Save_file_label = Answer{2}; - end - - elseif numel(Selectederp_Index)== 1 - ALLERP_out = observe_ERPDAT.ALLERP; - ERP = observe_ERPDAT.ALLERP(Selectederp_Index); - ERP.filepath = pathName_def; - Answer = f_ERP_save_single_file(strcat(ERP.erpname,'_chop'),ERP.filename,Selectederp_Index); - if isempty(Answer) - beep; - disp('User selectd cancal'); - return; - end - Save_file_label =0; - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ERP.erpname; - Save_file_label =0; - elseif ~isempty(fileName_full) - - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - Save_file_label =1; - end - - end - ALLERP_out(Selectederp_Index) = ERP;clear ERP; - end - elseif gui_erp_chan_operation.mode_modify.Value - ALLERP_out = observe_ERPDAT.ALLERP; - end - - if isempty(Save_file_label) - Save_file_label =0; - end - - if gui_erp_chan_operation.locaInfor.Value + if gui_erp_chan_operation.locaInfor.Value==1 keeplocs =1; else keeplocs =0; end - - try - erpworkingmemory('f_ERP_proces_messg','ERP Bin Operations'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - ALLERPCOM = evalin('base','ALLERPCOM'); - for Numofselectederp = 1:numel(Selectederp_Index)%%Bin Operations for each selected ERPset - ERP = ALLERP_out(Selectederp_Index(Numofselectederp)); - [ERP, ERPCOM] = pop_erpchanoperator(ERP, Formula_str, 'Warning', 'off', 'Saveas', 'off','ErrorMsg', 'command','KeepLocations',keeplocs, 'History', 'gui'); + gui_erp_chan_operation.Paras{1} = gui_erp_chan_operation.edit_bineq.Data; + gui_erp_chan_operation.Paras{2} =gui_erp_chan_operation.locaInfor.Value; + gui_erp_chan_operation.Paras{3} = gui_erp_chan_operation.mode_modify.Value; + + estudioworkingmemory('f_ERP_proces_messg','ERP Bin Operations'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + for Numoferp = 1:numel(ERPArray)%%Bin Operations for each selected ERPset + ERP = ALLERP(ERPArray(Numoferp)); + [ERP, ERPCOM] = pop_erpchanoperator(ERP, Formula_str, 'Warning', 'off', 'Saveas', 'off','ErrorMsg', 'command','KeepLocations',keeplocs, 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - if gui_erp_chan_operation.mode_modify.Value%% If select "Modify Existing ERPset (recursive updating)" - ERP.erpname = strcat(ERP.erpname,'_chop'); - observe_ERPDAT.ALLERP(Selectederp_Index(Numofselectederp)) = ERP; - observe_ERPDAT.ERP= observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - elseif gui_erp_chan_operation.mode_create.Value %% If select "Create New ERPset (independent transformations)" - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - if Save_file_label==1 - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ALLERP_out(Selectederp_Index(Numofselectederp)).erpname,... - 'filename', ALLERP_out(Selectederp_Index(Numofselectederp)).filename, 'filepath',ALLERP_out(Selectederp_Index(Numofselectederp)).filepath); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + end + %%%Create a new ERPset for the bin-operated ERPsets + Save_file_label = 0; + if gui_erp_chan_operation.mode_create.Value==1 + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_chop'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + + if gui_erp_chan_operation.mode_modify.Value%% If select "Modify Existing ERPset (recursive updating)" + ALLERP(ERPArray) = ALLERP_out; + elseif gui_erp_chan_operation.mode_create.Value %% If select "Create New ERPset (independent transformations)" + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ALLERP_out(Numoferp).erpname,... + 'filename', ALLERP_out(ERPArray(Numoferp)).filename, 'filepath',ALLERP_out(Numoferp).filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end + else + ERP.filename = ''; + ERP.filepath = ''; + ERP.saved = 'no'; end + ALLERP(length(ALLERP)+1) = ERP; end - - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - if gui_erp_chan_operation.mode_create.Value%%Save the labels of the selected ERPsets - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selectederp_Index)+1:length(observe_ERPDAT.ALLERP)]; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selectederp_Index)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + end + observe_ERPDAT.ALLERP = ALLERP; + if gui_erp_chan_operation.mode_create.Value==1%%Save the labels of the selected ERPsets + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); end - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - return; - catch - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - Selected_ERP_afd =observe_ERPDAT.CURRENTERP; estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%% - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('f_ERP_bin_opt',1); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; + return; end %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - beep; - msgboxText = ['ERP Channel Operations - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; + if observe_ERPDAT.Count_currentERP~=6 + return; end - - if isempty(checked_ERPset_Index) - checked_ERPset_Index = f_checkerpsets(observe_ERPDAT.ALLERP,Selectederp_Index); + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); end - if checked_curr_index || any(checked_ERPset_Index(:)) + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) Enable_label = 'off'; for ii = 1:100 if ii==1 @@ -611,11 +745,19 @@ function Count_currentERPChanged(~,~) gui_erp_chan_operation.edit_bineq.Data = dsnames; set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); else + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + estudioworkingmemory('selectederpstudio',ERPArray); + end Enable_label = 'on'; chanopDataor = gui_erp_chan_operation.edit_bineq.Data; for ii = 1:100 chanopDataorcell = char(chanopDataor{ii,1}); - if isempty(chanopDataorcell) + aa= 'The number of bins and channles should be the same for the selected ERPset!'; + if isempty(chanopDataorcell) || strcmpi(aa,chanopDataorcell) dsnames{ii,1} = ''; else dsnames{ii,1} = chanopDataorcell; @@ -624,15 +766,60 @@ function Count_currentERPChanged(~,~) gui_erp_chan_operation.edit_bineq.Data = dsnames; set(gui_erp_chan_operation.edit_bineq,'ColumnEditable',true(1,1000),'ColumnWidth',{1000}); end + if ViewerFlag==1 + Enable_label = 'off'; + end gui_erp_chan_operation.mode_modify.Enable=Enable_label; gui_erp_chan_operation.mode_create.Enable=Enable_label; gui_erp_chan_operation.eq_editor.Enable = Enable_label; gui_erp_chan_operation.eq_load.Enable = Enable_label; + gui_erp_chan_operation.eq_save.Enable = Enable_label; gui_erp_chan_operation.eq_clear.Enable = Enable_label; gui_erp_chan_operation.run.Enable = Enable_label; gui_erp_chan_operation.ref_asst.Enable = Enable_label; gui_erp_chan_operation.locaInfor.Enable = Enable_label; - + gui_erp_chan_operation.cancel.Enable = Enable_label; + observe_ERPDAT.Count_currentERP=7; end + +%%--------------press return to execute "Apply"---------------------------- + function erp_chanop_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_chanop'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + apply_run(); + estudioworkingmemory('ERPTab_chanop',0); + gui_erp_chan_operation.run.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.run.ForegroundColor = [0 0 0]; + ERP_chan_operation_gui.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=8 + return; + end + estudioworkingmemory('ERPTab_chanop',0); + gui_erp_chan_operation.run.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.run.ForegroundColor = [0 0 0]; + ERP_chan_operation_gui.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_chan_operation.cancel.BackgroundColor = [1 1 1]; + gui_erp_chan_operation.cancel.ForegroundColor = [0 0 0]; + for ii = 1:1000 + dsnames{ii,1} = ''; + end + gui_erp_chan_operation.edit_bineq.Data = dsnames; + gui_erp_chan_operation.locaInfor.Value=1; + gui_erp_chan_operation.mode_modify.Value = 1; + gui_erp_chan_operation.mode_create.Value = 0; + observe_ERPDAT.Reset_erp_paras_panel=9; + end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_edit_channel_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_edit_channel_GUI.m new file mode 100644 index 00000000..96c4ee05 --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_ERP_edit_channel_GUI.m @@ -0,0 +1,688 @@ +%%This function is to Edit/Delete Channels & Locations + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% Jan. 2024 + + +function varargout = f_ERP_edit_channel_GUI(varargin) + +global observe_ERPDAT; +addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); +%---------------------------Initialize parameters------------------------------------ + +ERP_tab_edit_chan = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global EStudio_erp_box_edit_chan; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + EStudio_erp_box_edit_chan = uiextras.BoxPanel('Parent', fig, 'Title', 'Edit/Delete Channels & Locations', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + EStudio_erp_box_edit_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Edit/Delete Channels & Locations', 'Padding', 5,'BackgroundColor',ColorB_def); +else + EStudio_erp_box_edit_chan = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Edit/Delete Channels & Locations', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_ic_chan_ERP(FonsizeDefault) +varargout{1} = EStudio_erp_box_edit_chan; + + function drawui_ic_chan_ERP(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + FontSize_defualt = FonsizeDefault; + if isempty(FontSize_defualt) + FontSize_defualt = 12; + end + Enable_label = 'off'; + %%--------------------channel and bin setting---------------------- + ERP_tab_edit_chan.DataSelBox = uiextras.VBox('Parent', EStudio_erp_box_edit_chan,'BackgroundColor',ColorB_def); + + %%%----------------Mode----------------------------------- + ERP_tab_edit_chan.mode_1 = uiextras.HBox('Parent', ERP_tab_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + ERP_tab_edit_chan.mode_modify_title = uicontrol('Style','text','Parent',ERP_tab_edit_chan.mode_1 ,... + 'String','Mode:','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + ERP_tab_edit_chan.mode_modify = uicontrol('Style','radiobutton','Parent',ERP_tab_edit_chan.mode_1 ,... + 'String','Modify existing dataset','callback',@mode_modify,'Value',1,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + % ERP_tab_edit_chan.mode_modify.String = 'Modify existing dataset
                            (recursive updating)'; + set(ERP_tab_edit_chan.mode_1,'Sizes',[55 -1]); + %%--------------For create a new ERPset---------------------------- + ERP_tab_edit_chan.mode_2 = uiextras.HBox('Parent', ERP_tab_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', ERP_tab_edit_chan.mode_2,'BackgroundColor',ColorB_def); + ERP_tab_edit_chan.mode_create = uicontrol('Style','radiobutton','Parent',ERP_tab_edit_chan.mode_2 ,... + 'String','Create new dataset','callback',@mode_create,'Value',0,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',ColorB_def); % 2F + % ERP_tab_edit_chan.mode_create.String = 'Create new dataset
                            (independent transformations)'; + set(ERP_tab_edit_chan.mode_2,'Sizes',[55 -1]); + + %%Select channels that will be deleted and renamed + ERP_tab_edit_chan.select_chan_title = uiextras.HBox('Parent', ERP_tab_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',ERP_tab_edit_chan.select_chan_title,... + 'String','Chan:','FontSize',FontSize_defualt,'Enable','on','BackgroundColor',ColorB_def); + ERP_tab_edit_chan.select_edit_chan = uicontrol('Style','edit','Parent',ERP_tab_edit_chan.select_chan_title,... + 'String',' ','callback',@select_edit_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + ERP_tab_edit_chan.browse_chan = uicontrol('Style','pushbutton','Parent',ERP_tab_edit_chan.select_chan_title,... + 'String','Browse','callback',@browse_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + set(ERP_tab_edit_chan.select_chan_title,'sizes',[40 -1 60]) + + %%Delete selected channels && Rename selected channels + ERP_tab_edit_chan.delete_rename = uiextras.HBox('Parent', ERP_tab_edit_chan.DataSelBox,'BackgroundColor',ColorB_def); + ERP_tab_edit_chan.delete_chan = uicontrol('Style','pushbutton','Parent',ERP_tab_edit_chan.delete_rename ,... + 'String','Delete chan','callback',@delete_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + ERP_tab_edit_chan.rename_chan = uicontrol('Style','pushbutton','Parent',ERP_tab_edit_chan.delete_rename ,... + 'String','Rename chan','callback',@rename_chan,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + + %%Add/edit chan locations + ERP_tab_edit_chan.edit_chanlocs = uicontrol('Style','pushbutton','Parent',ERP_tab_edit_chan.delete_rename,... + 'String','Add/edit chanlocs','callback',@edit_chanlocs,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + % set(ERP_tab_edit_chan.interpolate_epoch_title,'Sizes',[160 -1]); + ERP_tab_edit_chan.edit_chanlocs.String = ' Add or edit
                            chan locations'; + ERP_tab_edit_chan.edit_chanlocs.HorizontalAlignment='Center'; + set(ERP_tab_edit_chan.DataSelBox,'sizes',[30 30 30 40]) + estudioworkingmemory('ERPTab_editchan',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%---------------------Modify Existing dataset----------------------------- + function mode_modify(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges();%%execute the other panels if any parameter was changed + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + EStudio_erp_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('ERPTab_editchan',1); + ERP_tab_edit_chan.mode_modify.Value =1; + ERP_tab_edit_chan.mode_create.Value = 0; + end + + +%%---------------------Create new dataset---------------------------------- + function mode_create(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + EStudio_erp_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('ERPTab_editchan',1); + ERP_tab_edit_chan.mode_modify.Value =0; + ERP_tab_edit_chan.mode_create.Value = 1; + end + +%%-----------------------input channels------------------------------------ + function select_edit_chan(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + EStudio_erp_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('ERPTab_editchan',1); + New_chans = str2num(Source.String); + if isempty(New_chans) || any(New_chans(:)<=0) + msgboxText='Edit/Delete Channels & Locations > Index(es) of channels should be positive numbers'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + chanNum = observe_ERPDAT.ERP.nchan; + if any(New_chans(:) > chanNum) + msgboxText=['Edit/Delete Channels & Locations > Index(es) of channels should be smaller than',32,num2str(chanNum)]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + New_chans = vect2colon(New_chans); + New_chans = erase(New_chans,{'[',']'}); + Source.String = New_chans; + end + +%%-----------------------browse channels----------------------------------- + function browse_chan(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + EStudio_erp_box_edit_chan.TitleColor= [0.5137 0.7569 0.9176]; + estudioworkingmemory('ERPTab_editchan',1); + + ERP = observe_ERPDAT.ERP; + for Numofchan = 1:ERP.nchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',ERP.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat('Chan:',32,num2str(Numofchan)); + end + end + chanIgnore = str2num(ERP_tab_edit_chan.select_edit_chan.String); + if isempty(chanIgnore) + indxlistb = ERP.nchan; + else + if min(chanIgnore(:)) >0 && max(chanIgnore(:)) <= ERP.nchan + indxlistb = chanIgnore; + else + indxlistb = ERP.nchan; + end + end + titlename = 'Select Channel(s):'; + chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(chan_label_select) + chan_label_select = vect2colon(chan_label_select); + chan_label_select = erase(chan_label_select,{'[',']'}); + ERP_tab_edit_chan.select_edit_chan.String = chan_label_select; + else + return + end + end + +%%---------------------Delete selected chan-------------------------------- + function delete_chan(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + EStudio_erp_box_edit_chan.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('ERPTab_editchan',0); + + estudioworkingmemory('f_ERP_proces_messg','Edit/Delete Channels & Locations > Delete selected chan'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray <1) + ERPArray = observe_ERPDAT.CURRENTERP;estudioworkingmemory('selectederpstudio',ERPArray); + end + + ChanArray = str2num(ERP_tab_edit_chan.select_edit_chan.String); + if isempty(ChanArray) || any(ChanArray(:)<=0) + msgboxText='Edit/Delete Channels & Locations > Delete selected chan > Indexes of chans should be positive numbers'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + CreateERPFlag = ERP_tab_edit_chan.mode_create.Value; %%create new ERP dataset + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = []; end + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current ERPset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + %%check the selected chans + if any(ChanArray(:) > ERP.nchan) + msgboxText = ['Edit/Delete Channels & Locations > Delete selected chan > Selected channel should be between 1 and ',32, num2str(ERP.nchan)]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + observe_ERPDAT.Process_messg =2; + return; + end + + if numel(ChanArray) == ERP.nchan + msgboxText = ['Edit/Delete Channels & Locations > Delete selected chan > Please clear this ERPset in "ERPsets" panel if you want to delete all channels']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_ERPDAT.Process_messg =2; + return; + end + keeplocs=1; + Formula_str = strcat(['delerpchan(', vect2colon(ChanArray),')']); + + [ERP, ERPCOM] = pop_erpchanoperator(ERP, {Formula_str}, 'Warning', 'off', 'Saveas', 'off','ErrorMsg', 'command','KeepLocations',keeplocs, 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + fprintf( [repmat('-',1,100) '\n']); + end + if CreateERPFlag==1 + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_delchan'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + + if CreateERPFlag==0 + ALLERP(ERPArray) = ALLERP_out; + else + for Numoferp = 1: numel(ERPArray) + ERP= ALLERP_out(Numoferp); + checkfileindex = checkfilexists([ERP.filepath,filesep,ERP.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(ERP.filename); + ERP.filename = [file_name,'.erp']; + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ALLERP = ALLERP; + if CreateERPFlag==1 + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','CURRENTSET',observe_ERPDAT.CURRENTERP); + assignin('base','ALLERP',observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP=1; + observe_ERPDAT.Process_messg =2; + end + + +%%-----------------------Rename selected chan------------------------------ + function rename_chan(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + EStudio_erp_box_edit_chan.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('ERPTab_editchan',0); + + estudioworkingmemory('f_ERP_proces_messg','Edit/Delete Channels & Locations > Rename selected chan'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + ChanArray = str2num(ERP_tab_edit_chan.select_edit_chan.String); + + if isempty(ChanArray) || any(ChanArray(:)<=0) + msgboxText='Edit/Delete Channels & Locations > Delete selected chan > Indexes of chans should be positive numbers'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = observe_ERPDAT.CURRENTERP; estudioworkingmemory('selectederpstudio',ERPArray); + end + + CreateERPFlag = ERP_tab_edit_chan.mode_create.Value; %%create new ERP dataset + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + ALLERPCOM = evalin('base','ALLERPCOM'); + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Rename selected chan*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current ERPset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + + %%check the selected chans + if any(ChanArray(:) > ERP.nchan) + fprintf( ['Edit/Delete Channels & Locations > Rename selected chan: Some of chan indexes exceed',32,num2str(ERP.nchan),32,', we therefore select all channels.\n']); + ChanArray = [1:ERP.nchan]; + end + try + [eloc, Chanlabelsold, theta, radius, indices] = readlocs( ERP.chanlocs); + Chanlabelsold = Chanlabelsold(ChanArray); + catch + fprintf( [repmat('-',1,100) '\n']); + observe_ERPDAT.Process_messg =2; + return; + end + CURRENTSET = ERPArray(Numoferp); + def = estudioworkingmemory('pop_rename2chan'); + if isempty(def) + def = Chanlabelsold; + end + titleName= ['Dataset',32,num2str(CURRENTSET),': ERPLAB Change Channel Name']; + Chanlabelsnew= f_change_chan_name_GUI(Chanlabelsold,def,titleName); + + if isempty(Chanlabelsnew) + fprintf( [repmat('-',1,100) '\n']); + observe_ERPDAT.Process_messg =2; + return + end + estudioworkingmemory('pop_rename2chan',Chanlabelsnew); + + [ERP, ERPCOM] = pop_rename2chan(ALLERP,CURRENTSET,'ChanArray',ChanArray,'Chanlabels',Chanlabelsnew,'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + fprintf( [repmat('-',1,100) '\n']); + end + + + Save_file_label=0; + if CreateERPFlag==0 + ALLERP(ERPArray) = ALLERP_out; + else + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_rnchan'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + if CreateERPFlag==0 + ALLERP(ERPArray) = ERP; + else + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + checkfileindex = checkfilexists([ERP.filepath,filesep,ERP.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(ERP.filename); + ERP.filename = [file_name,'.erp']; + [ERP, ~, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ALLERP = ALLERP; + + if CreateERPFlag==1 + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','CURRENTSET',observe_ERPDAT.CURRENTERP); + assignin('base','ALLERP',observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP=1; + estudioworkingmemory('f_ERP_proces_messg','Edit/Delete Channels & Locations > Rename selected chan'); + observe_ERPDAT.Process_messg =2; + end + + +%%------------------edit channel locations--------------------------------- + function edit_chanlocs(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + [messgStr,ERPpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && ERPpanelIndex~=15 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + EStudio_erp_box_edit_chan.TitleColor= [0.0500 0.2500 0.5000]; + estudioworkingmemory('ERPTab_editchan',0); + + estudioworkingmemory('f_ERP_proces_messg','Edit/Delete Channels & Locations > Add or edit channel locations'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = observe_ERPDAT.CURRENTERP; + end + CreateERPFlag = ERP_tab_edit_chan.mode_create.Value; %%create new ERP dataset + %%loop for the selected ERPsets + ALLERP = observe_ERPDAT.ALLERP; + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + titleName= ['Add or edit channel locations']; + app = feval('f_editchan_gui',observe_ERPDAT.ERP,titleName); + waitfor(app,'Finishbutton',1); + try + ERPoutput = app.output; %NO you don't want to output ERP with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + observe_ERPDAT.Process_messg =2; + return; + end + + if isempty(ERPoutput) + observe_ERPDAT.Process_messg =2; + return; + end + Chanlocs = ERPoutput.chanlocs; + ALLERPCOM = evalin('base','ALLERPCOM'); + ALLERP_out = []; + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*Add or edit all channel locations*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf(['Your current ERPset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + [ERP, ERPCOM] = pop_editdatachanlocs(ALLERP,ERPArray(Numoferp),... + 'ChanArray',ChanArray,'Chanlocs',Chanlocs,'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + fprintf( ['\n',repmat('-',1,100) '\n']); + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + end + + Save_file_label=0; + if CreateERPFlag==1 + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_editchan'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + end + if CreateERPFlag==0 + ALLERP(ERPArray) = ALLERP_out; + else + for Numoferp = 1:numel(ERPArray) + ERP= ALLERP_out(Numoferp); + checkfileindex = checkfilexists([ERP.filepath,filesep,ERP.filename]); + if Save_file_label && checkfileindex==1 + [pathstr, file_name, ext] = fileparts(ERP.filename); + ERP.filename = [file_name,'.erp']; + [ERP, ~, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + end + observe_ERPDAT.ALLERP = ALLERP; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + if CreateERPFlag==1 + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','CURRENTSET',observe_ERPDAT.CURRENTERP); + assignin('base','ALLERP',observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP=1; + observe_ERPDAT.Process_messg =2; + end + + +%%--------Settting will be modified if the selected was changed------------ + function Count_currentERPChanged(~,~) + if observe_ERPDAT.Count_currentERP ~=5 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag');%%when open advanced wave viewer + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || ViewerFlag==1 || (~isempty(observe_ERPDAT.ERP) && isempty(observe_ERPDAT.ERP.chanlocs)) + ERP_tab_edit_chan.mode_modify.Enable ='off'; + ERP_tab_edit_chan.mode_create.Enable = 'off'; + ERP_tab_edit_chan.delete_chan.Enable='off'; + ERP_tab_edit_chan.rename_chan.Enable='off'; + ERP_tab_edit_chan.edit_chanlocs.Enable='off'; + ERP_tab_edit_chan.select_edit_chan.Enable='off'; + ERP_tab_edit_chan.browse_chan.Enable='off'; + observe_ERPDAT.Count_currentERP=6; + return; + end + ERP_tab_edit_chan.mode_modify.Enable ='on'; + ERP_tab_edit_chan.mode_create.Enable = 'on'; + ERP_tab_edit_chan.delete_chan.Enable='on'; + ERP_tab_edit_chan.rename_chan.Enable='on'; + ERP_tab_edit_chan.edit_chanlocs.Enable='on'; + ERP_tab_edit_chan.select_edit_chan.Enable='on'; + ERP_tab_edit_chan.browse_chan.Enable='on'; + observe_ERPDAT.Count_currentERP=6; + end + +%%--------------Reset this panel with the default parameters--------------- + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=5 + return; + end + estudioworkingmemory('ERPTab_editchan',0); + ERP_tab_edit_chan.mode_modify.Value =1; + ERP_tab_edit_chan.mode_create.Value = 0; + ERP_tab_edit_chan.select_edit_chan.String = ''; + observe_ERPDAT.Reset_erp_paras_panel=6; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=0; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr, file_name,'.erp']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This ERP Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end + diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_erpsetsGUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_erpsetsGUI.m index 5e3e3e3b..49453aff 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_erpsetsGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_erpsetsGUI.m @@ -1,42 +1,30 @@ % ERPset selector panel % -% Author: Carter Luck and Guanghui ZHANG +% Author: Guanghui ZHANG && Steven Luck % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2018 & 2022 +% 2022 & 2023 % ERPLAB Toolbox % -% -% Initial setup -% + function varargout = f_ERP_erpsetsGUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@drawui_CB); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); +global EStudio_gui_erp_totl; addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); ERPsetops = struct(); %---------Setting the parameter which will be used in the other panels----------- -CurrentERPSet = evalin('base','CURRENTERP'); - -if isempty(CurrentERPSet) || (CurrentERPSet> length(observe_ERPDAT.ALLERP)) - CurrentERPSet =1; -end - - -estudioworkingmemory('selectederpstudio',CurrentERPSet); - try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch ColorB_def = [0.95 0.95 0.95]; end -datasets = []; % Local data structure + % global box; if nargin == 0 fig = figure(); % Parent figure @@ -48,51 +36,18 @@ end -getDatasets() % Get datasets from ALLERP - -datasets = sortdata(datasets); -datasets = sortdata(datasets); -% global selectedData; -try - cerp = observe_ERPDAT.CURRENTERP; - i = observe_ERPDAT.ALLERP(1,cerp); - [r,~] = size(datasets); - for j = 1:r - if strcmp(i.erpname,cell2mat(datasets(j,1)))&&strcmp(i.filename,cell2mat(datasets(j,4)))&&strcmp(i.filepath,cell2mat(datasets(j,5))) - selectedData = j; - end - end -catch - selectedData = 0; -end - - -sel_path = cd; -estudioworkingmemory('ERP_save_folder',sel_path); -% datasets = {'name', 1, 0, 'Users/***/Documents/Matlab/Test_data/', 'S1.erp';'name2', 2, 1;'name3', 3, 2;'name4', 4, 1;'name5', 5, 4}; % Create datasets. {'Name', datasetNumber, parentNumber, 'filename', 'filepath'} -% Test erpname/filepath/filename against ALLERP to correlate -% No duplicate dataset numbers. If a dataset's parent number is not a valid -% dataset, the dataset will be cleared when dataset = sortdata(datasets) is -% called. erpsetname must contain at least one non-numeric character. -datasets = sortdata(datasets); - - try FonsizeDefault = varargin{2}; catch FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erpset(FonsizeDefault); varargout{1} = box_erpset_gui; - -% Grab local structure from global ERP (update local structure instead of -% replacing it) - % Draw the ui function drawui_erpset(FonsizeDefault) try @@ -100,76 +55,49 @@ function drawui_erpset(FonsizeDefault) catch ColorB_def = [0.95 0.95 0.95]; end - [r, ~] = size(datasets); % Get size of array of datasets. r is # of datasets - % Sort the datasets!!! - datasets = sortdata(datasets); vBox = uiextras.VBox('Parent', box_erpset_gui, 'Spacing', 5,'BackgroundColor',ColorB_def); % VBox for everything panelshbox = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); - % panelshbox = uix.ScrollingPanel('Parent', vBox); panelsv2box = uiextras.VBox('Parent',panelshbox,'Spacing',5,'BackgroundColor',ColorB_def); - %%-----------------------ERPset display--------------------------------------- - dsnames = {}; - if size(datasets,1)==1 - if strcmp(datasets{1},'No ERPset loaded') - dsnames = {''}; - Edit_label = 'off'; - else - dsnames{1} = strcat(num2str(cell2mat(datasets(1,2))),'.',32,datasets{1,1}); - Edit_label = 'on'; - end - else - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(datasets(Numofsub,2))),'.',32,datasets{Numofsub,1})); - end - Edit_label = 'on'; - end - SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - ds_length = length(datasets); - if selectedData == 0 - ERPsetops.butttons_datasets = uicontrol('Parent', panelsv2box, 'Style', 'listbox', 'min', 1,'max',... - ds_length,'String', dsnames,'Value',1,'Callback',@selectdata,'FontSize',FonsizeDefault); - else - ERPsetops.butttons_datasets = uicontrol('Parent', panelsv2box, 'Style', 'listbox', 'min', 1,'max',... - ds_length,'String', dsnames,'Value', SelectedERP,'Callback',@selectdata,'FontSize',FonsizeDefault); - end + ERPlistName = getERPsets(); + Edit_label = 'off'; + + ERPsetops.butttons_datasets = uicontrol('Parent', panelsv2box, 'Style', 'listbox', 'min', 1,'max',... + 2,'String', ERPlistName,'Callback',@selectdata,'FontSize',FonsizeDefault,'Enable',Edit_label,'BackgroundColor',[1 1 1]); + try ERPsetops.butttons_datasets.Value=1; catch end; set(vBox, 'Sizes', 150); %%---------------------Options for ERPsets----------------------------------------------------- ERPsetops.buttons2 = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); ERPsetops.dupeselected = uicontrol('Parent', ERPsetops.buttons2, 'Style', 'pushbutton', 'String', 'Duplicate', ... - 'Callback', @duplicateSelected,'Enable',Edit_label,'FontSize',FonsizeDefault); + 'Callback', @duplicateSelected,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); ERPsetops.renameselected = uicontrol('Parent', ERPsetops.buttons2, 'Style', 'pushbutton', 'String', 'Rename',... - 'Callback', @renamedata,'Enable',Edit_label,'FontSize',FonsizeDefault); + 'Callback', @renamedata,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); ERPsetops.suffix = uicontrol('Parent', ERPsetops.buttons2, 'Style', 'pushbutton', 'String', 'Add Suffix',... - 'Callback', @add_suffix,'Enable',Edit_label,'FontSize',FonsizeDefault); + 'Callback', @add_suffix,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPsetops.refresh_erpset = uicontrol('Parent', ERPsetops.buttons2, 'Style', 'pushbutton', 'String', 'Refresh',... + 'Callback', @refresh_erpset,'Enable','on','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); buttons3 = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); - ERPsetops.importexport = uicontrol('Parent',buttons3, 'Style', 'pushbutton', 'String', 'Import',... - 'Callback', @imp_erp,'FontSize',FonsizeDefault); - ERPsetops.export = uicontrol('Parent',buttons3, 'Style', 'pushbutton', 'String', 'Export', 'Callback', @exp_erp,'Enable',Edit_label,'FontSize',FonsizeDefault); ERPsetops.loadbutton = uicontrol('Parent', buttons3, 'Style', 'pushbutton', 'String', 'Load', ... - 'Callback', @load,'FontSize',FonsizeDefault); - ERPsetops.clearselected = uicontrol('Parent', buttons3, 'Style', 'pushbutton', 'String', 'Clear', 'Callback', @cleardata,'Enable',Edit_label,'FontSize',FonsizeDefault); + 'Callback', @load,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPsetops.clearselected = uicontrol('Parent', buttons3, 'Style', 'pushbutton', 'String', 'Clear', ... + 'Callback', @cleardata,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPsetops.importexport = uicontrol('Parent',buttons3, 'Style', 'pushbutton', 'String', 'Import',... + 'Callback', @imp_erp,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPsetops.export = uicontrol('Parent',buttons3, 'Style', 'pushbutton', 'String', 'Export',... + 'Callback', @exp_erp,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + buttons4 = uiextras.HBox('Parent', vBox, 'Spacing', 5,'BackgroundColor',ColorB_def); - ERPsetops.savebutton = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Save', 'Callback', @savechecked,'Enable',Edit_label,'FontSize',FonsizeDefault); - ERPsetops.saveasbutton = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Save As...', 'Callback', @savecheckedas,'Enable',Edit_label,'FontSize',FonsizeDefault); - ERPsetops.dotstoggle = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Current Folder', 'Callback', @toggledots,'Enable',Edit_label,'FontSize',FonsizeDefault); - set(buttons4,'Sizes',[70 70 115]) + ERPsetops.savebutton = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Save',... + 'Callback', @save_erp,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPsetops.saveasbutton = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Save a Copy', ... + 'Callback', @save_erpas,'Enable',Edit_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPsetops.curr_folder = uicontrol('Parent', buttons4, 'Style', 'pushbutton', 'String', 'Current Folder',... + 'Callback', @curr_folder,'Enable','on','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + set(buttons4,'Sizes',[70 90 95]) end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -177,238 +105,308 @@ function drawui_erpset(FonsizeDefault) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %------------------duplicate the selected ERPsets----------------------------- - function duplicateSelected(source,~)%%The defualt channels and bins that come from "bin and channel" panel but user can select bins and channels. + function duplicateSelected(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end - erpworkingmemory('f_ERP_proces_messg','ERPsets>Duplicate'); + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Duplicate'); observe_ERPDAT.Process_messg =1; - SelectedERP= ERPsetops.butttons_datasets.Value; - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - checked_ERPset_Index_bin_chan = [0 0 0 0 0 0 0]; - try - S_geterpbinchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan = S_geterpbinchan.checked_ERPset_Index; - catch - checked_ERPset_Index_bin_chan = f_checkerpsets(observe_ERPDAT.ALLERP,SelectedERP); + ERPArray= ERPsetops.butttons_datasets.Value; + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); end - BinArray = []; - ChanArray = []; - try - S_geterpbinchan = estudioworkingmemory('geterpbinchan'); - BinArray = S_geterpbinchan.bins{1}; - ChanArray = S_geterpbinchan.elecs_shown{1}; - catch - BinArray = []; - ChanArray = []; + ChanArray= estudioworkingmemory('ERP_ChanArray'); + BinArray= estudioworkingmemory('ERP_BinArray'); + + def = f_ERP_duplicate(observe_ERPDAT.ERP,BinArray,ChanArray); + if isempty(def) + return; end + BinArray = def{1}; + ChanArray =def{2}; + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + ALLERP_out = []; + ALLERP = observe_ERPDAT.ALLERP; + for Numoferp = 1:numel(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + [ERP, ERPCOM] = pop_duplicaterp( ERP, 'ChanArray',ChanArray, 'BinArray',BinArray,... + 'Saveas', 'off', 'History', 'gui'); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1)=ERP; + end + end - try - for Numofselecterp = 1:numel(SelectedERP) - New_ERP = observe_ERPDAT.ALLERP(SelectedERP(Numofselecterp)); - - New_ERP.filename = ''; - New_ERP.erpname = char(strcat(New_ERP.erpname, '_Duplicated')); - if checked_ERPset_Index_bin_chan(1)==1 || checked_ERPset_Index_bin_chan(2) ==2 - BinArray = [1:New_ERP.nbin]; - ChanArray = [1:New_ERP.nchan]; - end - New_ERP = f_ERP_duplicate(New_ERP,length(observe_ERPDAT.ALLERP),BinArray,ChanArray); - if isempty(New_ERP) - beep; - disp('User selected cancal!'); - return; - end - - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = New_ERP; - - datasets = {}; - getDatasets() - datasets = sortdata(datasets); - - - dsnames = {}; - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = char(strcat(num2str(cell2mat(datasets(Numofsub,2))),'.',32,datasets{Numofsub,1})); + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_duplicate'); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numoferp = 1:length(ALLERP_out) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [pathstr, file_name, ext] = fileparts(ERP.filename); + ERP.filename = [file_name,'.erp']; + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==length(ALLERP_out) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - %%Reset the display in ERPset panel - ERPsetops.butttons_datasets.String = dsnames; - ERPsetops.butttons_datasets.Min = 1; - ERPsetops.butttons_datasets.Max = length(datasets); - % ERPsetops.butttons_datasets.Value = observe_ERPDAT.CURRENTERP; - end - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(SelectedERP)+1:length(observe_ERPDAT.ALLERP)]; - ERPsetops.butttons_datasets.Value = Selected_ERP_afd; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(SelectedERP)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - ERPsetops.butttons_datasets.Value = Selected_ERP_afd; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - SelectedERP =Selected_ERP_afd; - estudioworkingmemory('selectederpstudio',SelectedERP); - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_ERP_afd); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - observe_ERPDAT.Process_messg =2; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + ALLERP(length(ALLERP)+1) = ERP; + end + observe_ERPDAT.ALLERP = ALLERP; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('ERPfilter',1); + + ERPlistName = getERPsets(); + %%Reset the display in ERPset panel + ERPsetops.butttons_datasets.String = ERPlistName; + ERPsetops.butttons_datasets.Min = 1; + ERPsetops.butttons_datasets.Max = length(ERPlistName)+1; + + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + ERPsetops.butttons_datasets.Value = Selected_ERP_afd; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; catch - ERPsetops.butttons_datasets.Value = length(observe_ERPDAT.ALLERP); + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + ERPsetops.butttons_datasets.Value = Selected_ERP_afd; observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - SelectedERP =observe_ERPDAT.CURRENTERP; - estudioworkingmemory('selectederpstudio',SelectedERP); - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_ERP_afd); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - observe_ERPDAT.Process_messg =3; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','ALLERP',ALLERP); + assignin('base','CURRENTERP',observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP = 1; end - %%-------------------Rename the selcted files------------------------------ function renamedata(~,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Rename'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Rename'); observe_ERPDAT.Process_messg =1; - SelectedERP= ERPsetops.butttons_datasets.Value; - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= ERPsetops.butttons_datasets.Value; + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); end - for Numofselecterp = 1:length(SelectedERP) - try - ndsns = SelectedERP(Numofselecterp); - [r,~] = size(datasets); - for Numofsub = 1:r - if ismember(datasets{Numofsub,2},ndsns) - - erpName = char(datasets{Numofsub,1}); - new = f_ERP_rename_gui(erpName,SelectedERP(Numofselecterp)); - if isempty(new) - beep; - disp(['User selected cancel']); - return; - end - - datasets{Numofsub,1} = new{1,1}; - clear k - [~,cerp] = size(observe_ERPDAT.ALLERP); - for k = 1:cerp - if strcmp(observe_ERPDAT.ALLERP(1,k).filepath,datasets{Numofsub,5}) && strcmp(observe_ERPDAT.ALLERP(1,k).filename,datasets{Numofsub,4}) - observe_ERPDAT.ALLERP(1,k).erpname = cell2mat(new); - end - end - end - end - datasets = sortdata(datasets); - - dsnames = {}; - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = char(strcat(num2str(datasets{Numofsub,2}),'.',32,datasets{Numofsub,1})); - - end - ERPsetops.butttons_datasets.String = dsnames; - ERPsetops.butttons_datasets.Min = 1; - ERPsetops.butttons_datasets.Max = length(datasets); - observe_ERPDAT.Process_messg =2; - catch - datasets = sortdata(datasets); - dsnames = {}; - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = char(strcat(num2str(datasets{Numofsub,2}),'.',32,char(datasets{Numofsub,1}))); - end - ERPsetops.butttons_datasets.String = dsnames; - ERPsetops.butttons_datasets.Min = 1; - ERPsetops.butttons_datasets.Max = length(datasets); - observe_ERPDAT.Process_messg =3; + app = feval('ERP_Tab_rename_gui',observe_ERPDAT.ALLERP(ERPArray),ERPArray); + waitfor(app,'Finishbutton',1); + try + erpnames = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + if isempty(erpnames) + return; + end + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + ALLERP_out = []; + ALLERP = observe_ERPDAT.ALLERP(ERPArray); + [ALLERP, ERPCOM] = pop_renamerp( ALLERP, 'erpnames',erpnames,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) + return; + end + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(Numoferp); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1)=ERP; end end + + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('ERPfilter',1); + observe_ERPDAT.ALLERP(ERPArray) = ALLERP_out; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + ERPlistName = getERPsets(); + ERPsetops.butttons_datasets.String = ERPlistName; + ERPsetops.butttons_datasets.Min = 1; + ERPsetops.butttons_datasets.Max = length(ERPlistName)+1; + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP = 1; end %%--------------------------------Add Suffix--------------------------------- function add_suffix(~,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Add Suffix'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Add Suffix'); observe_ERPDAT.Process_messg =1; - SelectedERP= ERPsetops.butttons_datasets.Value; - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); + ERPArray= ERPsetops.butttons_datasets.Value; + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); + end + + suffixstr = f_ERP_suffix_gui('Suffix'); + if isempty(suffixstr) return; end - new = f_ERP_suffix_gui('Suffix'); - if ~isempty(new) - for Numofselecterp = 1:length(SelectedERP) - datasets{SelectedERP(Numofselecterp),1} = char(strcat(datasets{SelectedERP(Numofselecterp),1},'_',new{1})); - - [~,cerp] = size(observe_ERPDAT.ALLERP); - for Numoferp = 1:cerp - if strcmp(observe_ERPDAT.ALLERP(1,Numoferp).filepath,char(datasets{SelectedERP(Numofselecterp),5})) && strcmp(observe_ERPDAT.ALLERP(1,Numoferp).filename,char(datasets{SelectedERP(Numofselecterp),4})) - observe_ERPDAT.ALLERP(1,Numoferp).erpname = char(datasets{SelectedERP(Numofselecterp),1}); - end - end - end - observe_ERPDAT.Process_messg =2; - else - beep; - disp('User cancelled'); - observe_ERPDAT.Process_messg =4; + + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + ALLERP_out = []; + ALLERP = observe_ERPDAT.ALLERP(ERPArray); + [ALLERP, ERPCOM] = pop_suffixerp( ALLERP, 'suffixstr',suffixstr,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) return; end - datasets = sortdata(datasets); - dsnames = {}; - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = char(strcat(num2str((datasets{Numofsub,2})),'.',32,char(datasets{Numofsub,1}))); + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(Numoferp); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1)=ERP; + end end - ERPsetops.butttons_datasets.String = dsnames; + + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('ERPfilter',1); + observe_ERPDAT.ALLERP(ERPArray) = ALLERP_out; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + ERPlistName = getERPsets(); + ERPsetops.butttons_datasets.String = ERPlistName; ERPsetops.butttons_datasets.Min = 1; - ERPsetops.butttons_datasets.Max = size(datasets,1); + ERPsetops.butttons_datasets.Max = length(ERPlistName)+1; + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP = 1; end +%%-------------------------------fresh ------------------------------------ + function refresh_erpset(~,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Refresh'); + observe_ERPDAT.Process_messg =1; + try + ALLERP = evalin('base', 'ALLERP'); + catch + ALLERP = []; + end + try + ERP = evalin('base', 'ERP'); + catch + ERP = []; + end + try + CURRENTERP = evalin('base', 'CURRENTERP'); + catch + CURRENTERP = 1; + end + + if isempty(ALLERP) && ~isempty(ALLERP) + ALLERP = ERP; + CURRENTERP =1; + end + if ~isempty(ALLERP) && isempty(ERP) + if isempty(CURRENTERP) || numel(CURRENTERP)~=1 || any(CURRENTERP(:)>length(ALLERP)) + CURRENTERP = length(ALLERP); + end + try + ERP = observe_ERPDAT.ALLERP(CURRENTERP); + catch + ERP = []; + end + end + observe_ERPDAT.ALLERP= ALLERP; + try observe_ERPDAT.ALLERP(CURRENTERP) = ERP;catch end + + observe_ERPDAT.ERP= ERP; + observe_ERPDAT.CURRENTERP= CURRENTERP; + + assignin('base','CURRENTERP',CURRENTERP); + assignin('base','ERP',ERP); + assignin('base','ALLERP',ALLERP); + estudioworkingmemory('selectederpstudio',CURRENTERP); + ERPlistName = getERPsets(); + ERPsetops.butttons_datasets.String = ERPlistName; + ERPsetops.butttons_datasets.Min = 1; + ERPsetops.butttons_datasets.Max = length(ERPlistName)+1; + ERPsetops.butttons_datasets.Value = CURRENTERP; + observe_ERPDAT.Count_currentERP=1; + observe_ERPDAT.Process_messg =2; + end - -%----------------------- Import----------------------------------- +%----------------------- Import-------------------------------------------- function imp_erp( ~, ~ ) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Import'); + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Import'); observe_ERPDAT.Process_messg =1; %-----------Setting for import------------------------------------- try @@ -422,319 +420,259 @@ function imp_erp( ~, ~ ) 'PromptString','Please select a type to import from...','Name','Import','OKString','Select'); set(0,'DefaultUicontrolBackgroundColor',[1 1 1]); - if isempty(ind) - beep; - disp(['User selected cancel']); return; - end - ALLERPCOM = evalin('base','ALLERPCOM'); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end - try - if tf%Import start - %%------------------------------------------------------------------------------- - %%-----------------------Import ERPSS text--------------------------------------- - %%------------------------------------------------------------------------------- - if ind == 1 - % pop_importerpss_studio(); - answer = importERPSS_GUI; %(gui was modified) + if tf%Import start + %%------------------------------------------------------------------------------- + %%-----------------------Import ERPSS text--------------------------------------- + %%------------------------------------------------------------------------------- + if ind == 1 + % pop_importerpss_studio(); + answer = importERPSS_GUI; %(gui was modified) + + if isempty(answer) + return + end + + fname = answer{1}; % filename (+ whole path) + dformat = answer{2}; % data format + dtranspose = answer{3}; % transpose data (Fixed) + if dformat==0 + dformatstr = 'explicit'; % points at columns + else + dformatstr = 'implicit'; % points at rows + end + if dtranspose==0 + orienpoint = 'column'; % points at columns + else + orienpoint = 'row'; % points at rows + end + + [ERP, ALLERP, ERPCOM] = pop_importerpss('Filename', fname, 'Format', dformatstr, 'Pointat', orienpoint, 'History', 'script'); + [ERP, ALLERPCOM]= erphistory(ERP, ALLERPCOM, ERPCOM,2); + + try + Selected_erpset = [length(ALLERP)-length(fname)+1:length(ALLERP)]; + catch + disp('Fail to import the ERPsets, please try again or restart EStudio!'); + return + end + ALLERP = f_erp_remv_Calibrate(ALLERP, Selected_erpset); + Answer = f_ERP_save_multi_file(ALLERP,Selected_erpset,'_erpss'); + if isempty(Answer) + return; + end + Save_file_label = 0; + if ~isempty(Answer{1}) + ALLERP_advance = Answer{1}; + Save_file_label = Answer{2}; + end + if Save_file_label==1 + for Numoferp = 1:length(Selected_erpset) + ERP = ALLERP_advance(Selected_erpset(Numoferp)); + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp==length(Selected_erpset) + [ERP,ALLERPCOM]= erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP,ALLERPCOM]= erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + end + end + observe_ERPDAT.ALLERP=ALLERP_advance; clear ALLERP_advance;clear ALLERP + else + %%------------------------------------------------------------------------ + %%----------------------- Import Universal text----------------------- + %%------------------------------------------------------------------------ + if ind == 2 + + def = estudioworkingmemory('pop_importerp'); + if isempty(def) + def = {'','','',0,1,0,0,1000,[-200 800]}; + end + % + % Call GUI + % + getlista = importerpGUI(def); - if isempty(answer) - disp('User selected Cancel') + if isempty(getlista) return end - fname = answer{1}; % filename (+ whole path) - dformat = answer{2}; % data format - dtranspose = answer{3}; % transpose data (Fixed) - if dformat==0 - dformatstr = 'explicit'; % points at columns + filename = getlista{1}; + filepath = getlista{2}; + ftype = getlista{3}; + includetime = getlista{4}; + timeunit = getlista{5}; + elabel = getlista{6}; + transpose = getlista{7}; + fs = getlista{8}; + xlim = getlista{9}; + + estudioworkingmemory('pop_importerp', {filename, filepath, ftype,includetime,timeunit,elabel,transpose,fs,xlim}); + + filetype = {'text'}; + if includetime==0 + inctimestr = 'off'; else - dformatstr = 'implicit'; % points at rows + inctimestr = 'on'; end - if dtranspose==0 - orienpoint = 'column'; % points at columns + if elabel==0 + elabelstr = 'off'; else - orienpoint = 'row'; % points at rows + elabelstr = 'on'; + end + if transpose==0 + orienpoint = 'column'; % points at columns + else + orienpoint = 'row'; % points at rows end - [ERP, ALLERP, ERPCOM] = pop_importerpss('Filename', fname, 'Format', dformatstr, 'Pointat', orienpoint, 'History', 'script'); - ERP = erphistory(ERP, [], ERPCOM,1); - + % + % Somersault + % + [ERP, ERPCOM] = pop_importerp('Filename', filename, 'Filepath', filepath, 'Filetype', filetype, 'Time', inctimestr,... + 'Timeunit', timeunit, 'Elabel', elabelstr, 'Pointat', orienpoint, 'Srate', fs, 'Xlim', xlim, 'Saveas', 'off',... + 'History', 'gui'); + if length(observe_ERPDAT.ALLERP)==1 && strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + Selected_erpset_indx = 1; + else + Selected_erpset_indx = length(observe_ERPDAT.ALLERP)+1; + end try - Selected_erpset = [length(ALLERP)-length(fname)+1:length(ALLERP)]; + filename = ERP.erpname; catch - beep; - disp('Fail to import the ERPsets, please try again or restart EStudio!'); - return + filename = strcat('Sub',num2str(Selected_erpset_indx),'-universal'); end - ALLERP = f_erp_remv_Calibrate(ALLERP, Selected_erpset); - Answer = f_ERP_save_multi_file(ALLERP,Selected_erpset,'_erpss'); - if isempty(Answer) - beep; - disp('User selected Cancel'); - return; + if isempty(filename) + filename = strcat('Sub',num2str(Selected_erpset_indx),'-universal'); end - Save_file_label = 0; - if ~isempty(Answer{1}) - ALLERP_advance = Answer{1}; - Save_file_label = Answer{2}; - end - if Save_file_label==1 - for Numoferpset = 1:length(Selected_erpset) - ERP = ALLERP_advance(Selected_erpset(Numoferpset)); - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - ERP = erphistory(ERP, [], ERPCOM,1); - end - end - observe_ERPDAT.ALLERP=ALLERP_advance; clear ALLERP_advance;clear ALLERP - - else + ERP.erpname = filename; %%------------------------------------------------------------------------ - %%----------------------- Import Universal text----------------------- + %%------------------------Import Neuroscan (.avg)---------------- %%------------------------------------------------------------------------ - if ind == 2 - - def = erpworkingmemory('pop_importerp'); - if isempty(def) - def = {'','','',0,1,0,0,1000,[-200 800]}; - end - % - % Call GUI - % - getlista = importerpGUI(def); - - if isempty(getlista) - disp('User selected Cancel') - return - end - - filename = getlista{1}; - filepath = getlista{2}; - ftype = getlista{3}; - includetime = getlista{4}; - timeunit = getlista{5}; - elabel = getlista{6}; - transpose = getlista{7}; - fs = getlista{8}; - xlim = getlista{9}; - - erpworkingmemory('pop_importerp', {filename, filepath, ftype,includetime,timeunit,elabel,transpose,fs,xlim}); - - filetype = {'text'}; - if includetime==0 - inctimestr = 'off'; - else - inctimestr = 'on'; - end - if elabel==0 - elabelstr = 'off'; - else - elabelstr = 'on'; - end - if transpose==0 - orienpoint = 'column'; % points at columns - else - orienpoint = 'row'; % points at rows - end - - % - % Somersault - % - [ERP, ERPCOM] = pop_importerp('Filename', filename, 'Filepath', filepath, 'Filetype', filetype, 'Time', inctimestr,... - 'Timeunit', timeunit, 'Elabel', elabelstr, 'Pointat', orienpoint, 'Srate', fs, 'Xlim', xlim, 'Saveas', 'off',... - 'History', 'gui'); - - % [ERP, ERPCOM] = pop_importerp(); - if length(observe_ERPDAT.ALLERP)==1 && strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Selected_erpset_indx = 1; - else - Selected_erpset_indx = length(observe_ERPDAT.ALLERP)+1; - end - try - filename = ERP.erpname; - catch - filename = strcat('Sub',num2str(Selected_erpset_indx),'-universal'); - end - if isempty(filename) - filename = strcat('Sub',num2str(Selected_erpset_indx),'-universal'); - end - ERP.erpname = filename; - %%------------------------------------------------------------------------ - %%------------------------Import Neuroscan (.avg)---------------- - %%------------------------------------------------------------------------ - elseif ind == 3 %% - [filename, filepath] = uigetfile({'*.avg';'Neuroscan average file (*.avg)'},'Select a file (Neuroscan)', 'MultiSelect', 'on'); - if ~iscell(filename) && ~ischar(filename) && filename==0 - disp('User selected Cancel') - return - end - - [ERP, ERPCOM]= pop_importavg(filename, filepath, 'Saveas','off','History', 'gui'); - - [pathstr, file_name, ext] = fileparts(filename{1,1}); - ERP.erpname = file_name; - if length(observe_ERPDAT.ALLERP)==1 && strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Selected_erpset_indx = 1; - else - Selected_erpset_indx = length(observe_ERPDAT.ALLERP)+1; - end - end - ERP = erphistory(ERP, [], ERPCOM,1); - - Answer = f_ERP_save_single_file(ERP.erpname,ERP.filename,Selected_erpset_indx); - if isempty(Answer) - beep; - % disp('User selectd cancal'); - return; + elseif ind == 3 %% + [filename, filepath] = uigetfile({'*.avg';'Neuroscan average file (*.avg)'},'Select a file (Neuroscan)', 'MultiSelect', 'on'); + if ~iscell(filename) && ~ischar(filename) && filename==0 + return end - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ERP.erpname; - elseif ~isempty(fileName_full) - - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - %%----------save the current sdata as-------------------- - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - ERP = erphistory(ERP, [], ERPCOM,1); - end + [ERP, ERPCOM]= pop_importavg(filename, filepath, 'Saveas','off','History', 'gui'); + [pathstr, file_name, ext] = fileparts(filename{1,1}); + ERP.erpname = file_name; + if length(observe_ERPDAT.ALLERP)==1 && strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + Selected_erpset_indx = 1; + else + Selected_erpset_indx = length(observe_ERPDAT.ALLERP)+1; end - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) =ERP; end - end - - [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - - ERPset_default_label = []; - count = 0; - for Numoferpset = 1:size(observe_ERPDAT.ALLERP,2) - if strcmp(observe_ERPDAT.ALLERP(Numoferpset).erpname,'No ERPset loaded') - count = count +1; - ERPset_default_label(count) = Numoferpset; - end - end - - if ~isempty(ERPset_default_label) - observe_ERPDAT.ALLERP(ERPset_default_label)=[]; - end - - datasets = {}; - getDatasets() - datasets = sortdata(datasets); - - dsnames = {}; - if size(datasets,1)==1 - if strcmp(datasets{1},'No ERPset loaded') - dsnames = {''}; - Edit_label = 'off'; - else - dsnames{1} = strcat(num2str(cell2mat(datasets(1,2))),'.',32,datasets{1,1}); - Edit_label = 'on'; + [ERP,ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + + Answer = f_ERP_save_single_file(ERP.erpname,ERP.filename,Selected_erpset_indx); + if isempty(Answer) + return; end - else - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = strcat(num2str(cell2mat(datasets(Numofsub,2))),'.',32,datasets{Numofsub,1}); + + if ~isempty(Answer) + ERPName = Answer{1}; + if ~isempty(ERPName) + ERP.erpname = ERPName; + end + fileName_full = Answer{2}; + if isempty(fileName_full) + ERP.filename = ERP.erpname; + elseif ~isempty(fileName_full) + [pathstr, file_name, ext] = fileparts(fileName_full); + ext = '.erp'; + if strcmp(pathstr,'') + pathstr = cd; + end + ERP.filename = [file_name,ext]; + ERP.filepath = pathstr; + %%----------save the current sdata as-------------------- + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + [ERP,ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + end end - Edit_label = 'on'; + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) =ERP; end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); - observe_ERPDAT.Process_messg =2; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - catch - observe_ERPDAT.Process_messg =3; - disp(['User selected cancel']); - return; end - ERPsetops.butttons_datasets.Value = length(observe_ERPDAT.ALLERP); - ERPsetops.butttons_datasets.String = dsnames; - if strcmp(datasets{1},'No ERPset loaded') + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + + ERPlistName = getERPsets(); + + if isempty(observe_ERPDAT.ALLERP) Edit_label = 'off'; else Edit_label = 'on'; end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + + ERPsetops.butttons_datasets.Value = length(observe_ERPDAT.ALLERP); + ERPsetops.butttons_datasets.String = ERPlistName; ERPsetops.dupeselected.Enable=Edit_label; ERPsetops.renameselected.Enable=Edit_label; ERPsetops.suffix.Enable= Edit_label; + ERPsetops.refresh_erpset.Enable= 'on'; ERPsetops.clearselected.Enable=Edit_label; ERPsetops.savebutton.Enable= Edit_label; ERPsetops.saveasbutton.Enable=Edit_label; - ERPsetops.dotstoggle.Enable=Edit_label; + ERPsetops.curr_folder.Enable='on'; ERPsetops.butttons_datasets.Enable = Edit_label; ERPsetops.export.Enable = Edit_label; - SelectedERP = observe_ERPDAT.CURRENTERP; - estudioworkingmemory('selectederpstudio',SelectedERP); - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray = observe_ERPDAT.CURRENTERP; + estudioworkingmemory('selectederpstudio',ERPArray); ERPsetops.butttons_datasets.Min=1; - if size(datasets,1)<=2 - ERPsetops.butttons_datasets.Max=size(datasets,1)+1; - else - ERPsetops.butttons_datasets.Max=size(datasets,1); - end + ERPsetops.butttons_datasets.Max=length(ERPlistName)+1; observe_ERPDAT.Process_messg =2; - observe_ERPDAT.Count_ERP = observe_ERPDAT.Count_ERP+1; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.Count_currentERP = 1; end - - %-----------------------Export----------------------------------- function exp_erp( ~, ~ ) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Export'); - observe_ERPDAT.Process_messg =1; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end - pathName = estudioworkingmemory('ERP_save_folder'); + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Export'); + observe_ERPDAT.Process_messg =1; + pathName = estudioworkingmemory('EEG_save_folder'); if isempty(pathName) pathName = cd; end - Selected_erpset= ERPsetops.butttons_datasets.Value; - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - if isempty(Selected_erpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= ERPsetops.butttons_datasets.Value; + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); end - checked_ERPset_Index_bin_chan = [0 0 0 0 0 0 0]; - try - S_geterpbinchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan = S_geterpbinchan.checked_ERPset_Index; - catch - checked_ERPset_Index_bin_chan = f_checkerpsets(observe_ERPDAT.ALLERP,Selected_erpset); + + checked_ERPset_Index_bin_chan = f_checkerpsets(observe_ERPDAT.ALLERP,ERPArray); + ChanArray= estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); end - BinArray = []; - ChanArray = []; - try - S_geterpbinchan = estudioworkingmemory('geterpbinchan'); - BinArray = S_geterpbinchan.bins{1}; - ChanArray = S_geterpbinchan.elecs_shown{1}; - catch - BinArray = []; - ChanArray = []; + + BinArray = estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray<=0) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); end + try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch @@ -746,342 +684,268 @@ function exp_erp( ~, ~ ) [ind,tf] = listdlg('ListString',{'ERPSS Text','Universal Text'},'SelectionMode','single','PromptString','Please select a type to export to...','Name','Export ERP to','OKString','Ok'); set(0,'DefaultUicontrolBackgroundColor',[1 1 1]); if isempty(ind) - beep; - disp(['User selected cancel']); return; end ALLERPCOM = evalin('base','ALLERPCOM'); - for Numoferpset = 1:length(Selected_erpset) + for Numoferp = 1:length(ERPArray) - if Selected_erpset(Numoferpset) > length(observe_ERPDAT.ALLERP) - beep; - msgboxText = ['ERPsets>Export: Index of selected ERP is lager than the length of ALLERP']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - ERP_export_erp = observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)); + ERP_export_erp = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); if checked_ERPset_Index_bin_chan(1) ==1 || checked_ERPset_Index_bin_chan(2) ==2 - BinArray = [1:ERP_export_erp.nbin]; - ChanArray = [1:ERP_export_erp.nchan]; - end - - if ind==1 - try - ERP_export_erp.filename =fullfile(pathName,ERP_export_erp.filename); - Answer_erpss = f_erp2ascGUI(ERP_export_erp,BinArray,ChanArray); - if isempty(Answer_erpss) - return; - end - ERP = Answer_erpss{1}; - FileName = Answer_erpss{2}; - - [observe_ERPDAT.ERP, ERPCOM] = pop_erp2asc(ERP,FileName,'History', 'gui'); - [observe_ERPDAT.ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - observe_ERPDAT.Process_messg =2; - catch - beep; - msgboxText = ['ERPsets>Export: cannot be saved as ERPs']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return + BinArray = [1:ERP_export_erp.nbin]; + ChanArray = [1:ERP_export_erp.nchan]; + end + if ind==1 + ERP_export_erp.filename =fullfile(pathName,ERP_export_erp.filename); + Answer_erpss = f_erp2ascGUI(ERP_export_erp,BinArray,ChanArray); + if isempty(Answer_erpss) + return; + end + ERP = Answer_erpss{1}; + FileName = Answer_erpss{2}; + [ERP, ERPCOM] = pop_erp2asc(ERP,FileName,'History', 'gui'); + if Numoferp ==length(ERPArray) + [observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.Count_currentERP = 20; + observe_ERPDAT.Process_messg =2; elseif ind ==2 + ERP_export_erp.filename =fullfile(pathName,ERP_export_erp.filename); + ERP = ERP_export_erp; + def = estudioworkingmemory('f_export2textGUI'); + if isempty(def) + def = {1,1000, 1, 1, 4, ''}; + end - try - ERP_export_erp.filename =fullfile(pathName,ERP_export_erp.filename); - ERP = ERP_export_erp; - def = estudioworkingmemory('f_export2textGUI'); - if isempty(def) - def = {1,1000, 1, 1, 4, ''}; - end - - % - % Call GUI - % - def_x = def; - def_x{6} = ERP.filename; - answer_export = f_export2textGUI(ERP,def_x,BinArray,ChanArray); - if isempty(answer_export) - beep; - disp('User selected cancel'); - return; - end - estudioworkingmemory('f_export2textGUI',answer_export); - istime = answer_export{1}; - tunit = answer_export{2}; - islabeled = answer_export{3}; - transpa = answer_export{4}; - prec = answer_export{5}; - - filename = answer_export{6}; - ERP = answer_export{7}; - binArray = [1:ERP.nbin]; - if istime - time = 'on'; - else - time = 'off'; - end - if islabeled - elabel = 'on'; - else - elabel = 'off'; - end - if transpa - tra = 'on'; - else - tra = 'off'; - end - try - [ERP, ERPCOM] = pop_export2text(ERP, filename, binArray, 'time', time, 'timeunit', tunit, 'electrodes', elabel,... - 'transpose', tra, 'precision', prec, 'History', 'gui'); - [observe_ERPDAT.ERP, ALLERPCOM] = erphistory(ERP_export_erp, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - observe_ERPDAT.Process_messg =2; - catch - beep; - msgboxText = ['ERPsets>Export: Failed to save selected ERPsets']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - catch - observe_ERPDAT.Process_messg =3; + % + % Call GUI + % + def_x = def; + def_x{6} = ERP.filename; + answer_export = f_export2textGUI(ERP,def_x,BinArray,ChanArray); + if isempty(answer_export) return; end + estudioworkingmemory('f_export2textGUI',answer_export); + istime = answer_export{1}; + tunit = answer_export{2}; + islabeled = answer_export{3}; + transpa = answer_export{4}; + prec = answer_export{5}; + filename = answer_export{6}; + ERP = answer_export{7}; + binArray = [1:ERP.nbin]; + if istime + time = 'on'; + else + time = 'off'; + end + if islabeled + elabel = 'on'; + else + elabel = 'off'; + end + if transpa + tra = 'on'; + else + tra = 'off'; + end + [ERP, ERPCOM] = pop_export2text(ERP, filename, binArray, 'time', time, 'timeunit', tunit, 'electrodes', elabel,... + 'transpose', tra, 'precision', prec, 'History', 'gui'); + if Numoferp ==length(ERPArray) + [observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end end - %%%Export data end end - - - %%---------------------Load ERP-------------------------------------------- function load(~,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Load'); - observe_ERPDAT.Process_messg =1; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Load'); + observe_ERPDAT.Process_messg =1; ALLERPCOM = evalin('base','ALLERPCOM'); - [~,bc] = size(observe_ERPDAT.ALLERP); - try - [filename, filepath] = uigetfile({'*.erp','ERP (*.erp)';... - '*.mat','ERP (*.mat)'}, ... - 'Load ERP', ... - 'MultiSelect', 'on'); - if isequal(filename,0) - disp('User selected Cancel'); - return; - end + + [filename, filepath] = uigetfile({'*.erp','ERP (*.erp)';... + '*.mat','ERP (*.mat)'}, ... + 'Load ERP', ... + 'MultiSelect', 'on'); + if isequal(filename,0) + return; + end + + if ischar(filename) - if numel(findobj('tag', 'erpsets')) > 0 - [ERP, ALLERP, ERPCOM] = pop_loaderp('filename', filename, 'filepath', filepath, 'Warning', 'on', 'UpdateMainGui', 'on', 'multiload', 'off',... - 'History', 'gui'); + [ERP, ~, ERPCOM] = pop_loaderp('filename', filename, 'filepath', filepath, 'Warning', 'on', 'UpdateMainGui', 'off', 'multiload', 'off',... + 'History', 'gui'); + ERP.filename = filename; + ERP.filepath = filepath; + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + if isempty(observe_ERPDAT.ALLERP) + observe_ERPDAT.ALLERP = ERP; else - [ERP, ALLERP, ERPCOM] = pop_loaderp('filename', filename, 'filepath', filepath, 'Warning', 'on', 'UpdateMainGui', 'off', 'multiload', 'off',... + observe_ERPDAT.ALLERP(length( observe_ERPDAT.ALLERP)+1) =ERP; + end + elseif iscell(filename) + for numoferp = 1:length(filename) + [ERP, ~, ERPCOM] = pop_loaderp('filename', filename{numoferp}, 'filepath', filepath, 'Warning', 'on', 'UpdateMainGui', 'off', 'multiload', 'off',... 'History', 'gui'); %If eeglab is not open, don't update - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + ERP.filename = filename{numoferp}; + ERP.filepath = filepath; + if numoferp ==length(filename) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(observe_ERPDAT.ALLERP) + observe_ERPDAT.ALLERP = ERP; + else + observe_ERPDAT.ALLERP(length( observe_ERPDAT.ALLERP)+1) =ERP; + end end - catch - return; end - - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); + assignin('base','ALLERP',observe_ERPDAT.ALLERP); assignin('base','ALLERPCOM',ALLERPCOM); assignin('base','ERPCOM',ERPCOM); - observe_ERPDAT.ALLERP = ALLERP; - observe_ERPDAT.ERP = ERP; - ERPset_default_label = []; - if ~isequal([1,bc], size(observe_ERPDAT.ALLERP)) - count = 0; - for Numoferpset = 1:size(observe_ERPDAT.ALLERP,2) - if strcmp(observe_ERPDAT.ALLERP(Numoferpset).erpname,'No ERPset loaded') - count = count +1; - ERPset_default_label(count) = Numoferpset; - end - end - if ~isempty(ERPset_default_label) - observe_ERPDAT.ALLERP(ERPset_default_label)=[]; - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); - observe_ERPDAT.CURRENTERP = size(observe_ERPDAT.ALLERP,2); - end - end - datasets = {}; - getDatasets() - datasets = sortdata(datasets); - % drawui_erpset(); - dsnames = {}; - if size(datasets,1)==1 - if strcmp(datasets{1},'No ERPset loaded') - dsnames = {''}; - Edit_label = 'off'; - else - - dsnames{1} = strcat(num2str(cell2mat(datasets(1,2))),'.',32,datasets{1,1}); - - Edit_label = 'on'; - end + ERPlistName = getERPsets(); + if isempty(observe_ERPDAT.ALLERP) + Edit_label = 'off'; else - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = strcat(num2str(cell2mat(datasets(Numofsub,2))),'.',32,datasets{Numofsub,1}); - end Edit_label = 'on'; end observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - ERPsetops.butttons_datasets.Value = observe_ERPDAT.CURRENTERP; - ERPsetops.butttons_datasets.String = dsnames; - - if strcmp(datasets{1},'No ERPset loaded') - Edit_label = 'off'; - else - Edit_label = 'on'; - end - + ERPsetops.butttons_datasets.String = ERPlistName; ERPsetops.dupeselected.Enable=Edit_label; ERPsetops.renameselected.Enable=Edit_label; ERPsetops.suffix.Enable= Edit_label; + ERPsetops.refresh_erpset.Enable= 'on'; ERPsetops.clearselected.Enable=Edit_label; ERPsetops.savebutton.Enable= Edit_label; ERPsetops.saveasbutton.Enable=Edit_label; - ERPsetops.dotstoggle.Enable=Edit_label; + ERPsetops.curr_folder.Enable='on'; ERPsetops.butttons_datasets.Enable = Edit_label; ERPsetops.export.Enable = Edit_label; - - SelectedERP = observe_ERPDAT.CURRENTERP; estudioworkingmemory('selectederpstudio',SelectedERP); - - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - ERPsetops.butttons_datasets.Min=1; - if size(datasets,1)<=2 - ERPsetops.butttons_datasets.Max=size(datasets,1)+1; - else - ERPsetops.butttons_datasets.Max=size(datasets,1); - end - + ERPsetops.butttons_datasets.Max=length(ERPlistName)+1; observe_ERPDAT.Process_messg =2; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.Count_currentERP = 2; + if EStudio_gui_erp_totl.ERP_autoplot==1 + f_redrawERP(); + end end - - %%----------------------Clear the selected ERPsets------------------------- function cleardata(source,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Clear'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Clear'); observe_ERPDAT.Process_messg =1; - - % global ERPCOM; SelectedERP = ERPsetops.butttons_datasets.Value; - ERPset_remained = setdiff(1:size(datasets,1),SelectedERP); - - if isempty(ERPset_remained) - if numel(findobj('tag', 'erpsets')) > 0 - [observe_ERPDAT.ERP, observe_ERPDAT.ALLERP, ERPCOM] = pop_loaderp('filename', 'dummy.erp', 'Warning', 'on','multiload', 'off',... - 'History', 'implicit'); - else - [observe_ERPDAT.ERP, observe_ERPDAT.ALLERP, ERPCOM] = pop_loaderp('filename', 'dummy.erp', 'Warning', 'on','multiload', 'off',... - 'History', 'implicit'); %If eeglab is not open, don't update - end - %Reset the datasets%%%%% - - datasets = {}; - datasets{1} = observe_ERPDAT.ALLERP(end).erpname; - datasets{2} = 1; - datasets{3} = 0; - datasets{4} = observe_ERPDAT.ALLERP(end).filename; - datasets{5} = observe_ERPDAT.ALLERP(end).filepath; - - observe_ERPDAT.ALLERP = observe_ERPDAT.ALLERP(end); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); - observe_ERPDAT.CURRENTERP = 1; + ALLERP = observe_ERPDAT.ALLERP; + [ALLERP,LASTCOM] = pop_deleterpset(ALLERP,'Erpsets', SelectedERP, 'Saveas', 'off','History', 'gui' ); + if isempty(LASTCOM) + return; + end + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = []; end + ERP1 = observe_ERPDAT.ERP; + [ERP1, ALLERPCOM] = erphistory(ERP1, ALLERPCOM, LASTCOM,2); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',LASTCOM); + if isempty(ALLERP) + observe_ERPDAT.ALLERP = []; + observe_ERPDAT.ERP = []; + observe_ERPDAT.CURRENTERP = 0; assignin('base','ERP',observe_ERPDAT.ERP) else - observe_ERPDAT.ALLERP = observe_ERPDAT.ALLERP(ERPset_remained); + observe_ERPDAT.ALLERP = ALLERP; observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - datasets = {}; - getDatasets(); end - - datasets = sortdata(datasets); - - dsnames = {}; - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = strcat(num2str(cell2mat(datasets(Numofsub,2))),'.',32,datasets{Numofsub,1}); - end - - if strcmp(datasets{1},'No ERPset loaded') && length(observe_ERPDAT.ALLERP)==1 - dsnames = {''}; + ERPlistName = getERPsets(); + if isempty(observe_ERPDAT.ALLERP) Edit_label = 'off'; else Edit_label = 'on'; end - - ERPsetops.butttons_datasets.String = dsnames; - ERPsetops.butttons_datasets.Value = observe_ERPDAT.CURRENTERP; + ERPsetops.butttons_datasets.String = ERPlistName; + if observe_ERPDAT.CURRENTERP>0 + ERPsetops.butttons_datasets.Value = observe_ERPDAT.CURRENTERP; + else + ERPsetops.butttons_datasets.Value=1; + end ERPsetops.dupeselected.Enable=Edit_label; ERPsetops.renameselected.Enable=Edit_label; ERPsetops.suffix.Enable= Edit_label; + ERPsetops.refresh_erpset.Enable= 'on'; ERPsetops.clearselected.Enable=Edit_label; ERPsetops.savebutton.Enable= Edit_label; ERPsetops.saveasbutton.Enable=Edit_label; - ERPsetops.dotstoggle.Enable=Edit_label; + ERPsetops.curr_folder.Enable='on'; ERPsetops.butttons_datasets.Min =1; - ERPsetops.butttons_datasets.Max =length(dsnames)+1; + ERPsetops.butttons_datasets.Max =length(ERPlistName)+1; ERPsetops.butttons_datasets.Enable = Edit_label; ERPsetops.export.Enable = Edit_label; - SelectedERP = observe_ERPDAT.CURRENTERP; estudioworkingmemory('selectederpstudio',SelectedERP); - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); observe_ERPDAT.Process_messg =2; - - observe_ERPDAT.Count_ERP = observe_ERPDAT.Count_ERP+1; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.Count_currentERP = 2; + if EStudio_gui_erp_totl.ERP_autoplot==1 + f_redrawERP(); + end end %-------------------------- Save selected ERPsets------------------------------------------- - function savechecked(source,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Save'); + function save_erp(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Save'); observe_ERPDAT.Process_messg =1; - pathName = estudioworkingmemory('ERP_save_folder'); - if isempty(pathName) - pathName = cd; + pathNamedef = estudioworkingmemory('EEG_save_folder'); + if isempty(pathNamedef) + pathNamedef = cd; end - - Selected_erpset= estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - if isempty(Selected_erpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); end - try ALLERPCOM = evalin('base','ALLERPCOM'); catch @@ -1089,427 +953,316 @@ function savechecked(source,~) assignin('base','ALLERPCOM',ALLERPCOM); end - try - for Numoferpset = 1:length(Selected_erpset) - - if Selected_erpset(Numoferpset) > length(observe_ERPDAT.ALLERP) - beep; - disp(['Index of selected ERP is lager than the length of ALLERP!!!']); - return; + for Numoferp = 1:length(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + pathName = ERP.filepath; + if isempty(pathName) + pathName = pathNamedef; + end + FileName = ERP.filename; + if isempty(FileName) + FileName = ERP.erpname; + end + [pathx, filename, ext] = fileparts(FileName); + filename = [filename '.erp']; + checkfileindex = checkfilexists([pathName,filesep,filename]); + if checkfileindex==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', filename, 'filepath',pathName); + ERPCOM = f_erp_save_history(ERP.erpname,filename,pathName); + if Numoferp==1 + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*ERPsets>Save*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf( [ERPCOM]); + fprintf( ['\n',repmat('-',1,100) '\n']); end - ERP = observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)); - FileName = ERP.filename; - if isempty(FileName) - FileName =ERP.erpname; + if Numoferp == numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - [pathx, filename, ext] = fileparts(FileName); - filename = [filename '.erp']; - [observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)), issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', filename, 'filepath',pathName); - [~, ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)), ALLERPCOM, ERPCOM); - end - - observe_ERPDAT.Process_messg =2; - catch - beep; - observe_ERPDAT.Process_messg =3; - disp(['ERPsets>Save: Cannot save the selected ERPsets.']); - return; - + observe_ERPDAT.ALLERP(ERPArray(Numoferp)) = ERP; end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + try assignin('base','ERPCOM',ERPCOM);catch; end + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end - %------------------------- Save as----------------------------------------- - function savecheckedas(~,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets>Save As'); + function save_erpas(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('f_ERP_proces_messg','ERPsets>Save a Copy'); observe_ERPDAT.Process_messg =1; - pathName = estudioworkingmemory('ERP_save_folder'); + pathName = estudioworkingmemory('EEG_save_folder'); if isempty(pathName) pathName = cd; end - Selected_erpset= estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - if isempty(Selected_erpset) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:)>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); end - - try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = []; assignin('base','ALLERPCOM',ALLERPCOM); end - - for Numoferpset = 1:length(Selected_erpset) - if Selected_erpset(Numoferpset) > length(observe_ERPDAT.ALLERP) - beep; - disp('Index of selected ERP is lager than the length of ALLERP!!!'); - return; + Answer = f_ERP_save_as_GUI(observe_ERPDAT.ALLERP,ERPArray,'_copy',1,pathName); + if isempty(Answer) + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + end + ALLERP = observe_ERPDAT.ALLERP; + for Numoferp = 1:length(ERPArray) + ERP = ALLERP_out(ERPArray(Numoferp)); + if ~isempty(ERP.filename) + filename = ERP.filename; + else + filename = [ERP.erpname,'.erp']; end + [pathstr, erpfilename, ext] = fileparts(filename); + ext = '.erp'; + erpFilename = char(strcat(erpfilename,ext)); + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', erpFilename,... + 'filepath',ERP.filepath); - ERP = observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)); - - [pathstr, namedef, ext] = fileparts(char(ERP.filename)); - [erpfilename, erppathname, indxs] = uiputfile({'*.erp','ERP (*.erp)';... - '*.mat','ERP (*.erp)'}, ... - ['Save "',ERP.erpname,'" as'],... - fullfile(pathName,namedef)); - - if isequal(erpfilename,0) - disp('User selected Cancel') - return + ERPCOM = f_erp_save_history(ERP.erpname,erpFilename,ERP.filepath); + if Numoferp==1 + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*ERPsets>Save a Copy*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf( [ERPCOM]); + fprintf( ['\n',repmat('-',1,100) '\n']); end - - [pathx, filename, ext] = fileparts(erpfilename); - [pathstr, erpfilename, ext] = fileparts(erpfilename) ; - - if indxs==1 - ext = '.erp'; - elseif indxs==2 - ext = '.mat'; + if Numoferp == numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); else - ext = '.erp'; + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - erpFilename = char(strcat(erpfilename,ext)); - [observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)), issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', erpFilename,... - 'filepath',erppathname); - [~, ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)), ALLERPCOM, ERPCOM); - + ALLERP(length(ALLERP)+1) = ERP; end - observe_ERPDAT.Process_messg =2; + observe_ERPDAT.ALLERP = ALLERP; + + ERPlistName = getERPsets(); + %%Reset the display in ERPset panel + ERPsetops.butttons_datasets.String = ERPlistName; + ERPsetops.butttons_datasets.Min = 1; + ERPsetops.butttons_datasets.Max = length(ERPlistName)+1; + + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + ERPsetops.butttons_datasets.Value = Selected_ERP_afd; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + ERPsetops.butttons_datasets.Value = Selected_ERP_afd; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + ERPsetops.butttons_datasets.Value = Selected_ERP_afd; + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end %---------------- Enable/Disable dot structure----------------------------- - function toggledots(~,~) - pathName = erpworkingmemory('ERP_save_folder'); + function curr_folder(~,~) + + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + pathName = estudioworkingmemory('EEG_save_folder'); if isempty(pathName) - pathName =cd; + pathName =[pwd,filesep]; end title = 'Select one forlder for saving files in following procedures'; - sel_path = uigetdir(pathName,title); + sel_path1 = uigetdir(pathName,title); + if isequal(sel_path1,0) + sel_path1 = cd; + end - if isequal(sel_path,0) - sel_path = cd; + cd(sel_path1); + erpcom = sprintf('cd("%s',sel_path1); + erpcom = [erpcom,'");']; + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + if ~isempty(observe_ERPDAT.ERP) + ERP = observe_ERPDAT.ERP; + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*ERPsets>Current Folder*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf( [erpcom]); + fprintf( ['\n',repmat('-',1,100) '\n']); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, erpcom,2); + else + if isempty(ALLERPCOM) + ALLERPCOM{1} = erpcom; + else + ALLERPCOM{length(ALLERPCOM)+1} = erpcom; + end end - userpath(sel_path); - cd(sel_path); - erpworkingmemory('ERP_save_folder',sel_path); + assignin('base','ALLERPCOM',ALLERPCOM); + estudioworkingmemory('EEG_save_folder',sel_path1); + observe_ERPDAT.Count_currentERP = 20; end %-----------------select the ERPset of interest-------------------------- function selectdata(source,~) - erpworkingmemory('f_ERP_proces_messg','ERPsets-select ERPset(s)'); - observe_ERPDAT.Process_messg =1; - - Selected_ERPsetlabel = source.Value; - estudioworkingmemory('selectederpstudio',Selected_ERPsetlabel); - - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_ERPsetlabel); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPArray = source.Value; + estudioworkingmemory('selectederpstudio',ERPArray); - Current_ERP_selected=Selected_ERPsetlabel(1); + Current_ERP_selected=ERPArray(1); observe_ERPDAT.CURRENTERP = Current_ERP_selected; observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_ERP_selected); - - checked_ERPset_Index_bin_chan = S_erpplot.geterpbinchan.checked_ERPset_Index; - - msgboxText = {}; - if checked_ERPset_Index_bin_chan(1) ==1 - msgboxText = ['Number of bins across ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(2)==2 - msgboxText = ['Number of channels across ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(3) ==3 - msgboxText = ['Type of data across ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(4)==4 - msgboxText = ['Number of samples across ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(5)==5 - msgboxText = ['Start time of epoch across ERPsets is different!']; - end - if ischar(msgboxText) - if checked_ERPset_Index_bin_chan(1) ==1 && checked_ERPset_Index_bin_chan(2) ==0 - question = [ '%s\n See details at command window.\n\n',... - ' (a). "Bins" will be deactive on "Bins and Channel Selection".\n\n',... - ' (b). "Plot Scalp Maps" panel will be deactive.\n\n',... - ' (c). "Selected bin and chan" will be deactive on "Baseline correction & Linear detrend".\n\n',... - ' (d). "ERP Channel Operations" panel will be deactive.\n\n',... - ' (e). "ERP Bin Operations" panel will be deactive.\n\n',... - ' (f). "Covert Voltage to CSD" panel will be deactive.\n\n',... - ' (g). "Save values" will be deactive on "ERP Measurement Tool".\n\n',... - ' (h). "Average across ERPsets" will be deactive.\n\n']; - elseif checked_ERPset_Index_bin_chan(1) ==0 && checked_ERPset_Index_bin_chan(2) ==2 - - question = [ '%s\n See details at command window.\n\n',... - ' (a). "Channels" will be deactive on "Bins and Channel Selection".\n\n',... - ' (b). "Plot Scalp Maps" panel will be deactive.\n\n',... - ' (c). "Selected bin and chan" will be deactive on "Baseline correction & Linear detrend".\n\n',... - ' (d). "ERP Channel Operations" panel will be deactive.\n\n',... - ' (e). "ERP Bin Operations" panel will be deactive.\n\n',... - ' (f). "Covert Voltage to CSD" panel will be deactive.\n\n',... - ' (g). "Save values" will be deactive on "ERP Measurement Tool".\n\n',... - ' (h). "Average across ERPsets" will be deactive.\n\n']; - elseif checked_ERPset_Index_bin_chan(1) ==1 && checked_ERPset_Index_bin_chan(2) ==2 - msgboxText = ['Both the number of channels and the number of bins vary across ERPsets!']; - question = [ '%s\n See details at command window.\n\n',... - ' (a). "Channels" and "Bins" will be deactive on "Bins and Channel Selection".\n\n',... - ' (b). "Plot Scalp Maps" panel will be deactive.\n\n',... - ' (c). "Selected bin and chan" will be deactive on "Baseline correction & Linear detrend".\n\n',... - ' (d). "ERP Channel Operations" panel will be deactive.\n\n',... - ' (e). "ERP Bin Operations" panel will be deactive.\n\n',... - ' (f). "Covert Voltage to CSD" panel will be deactive.\n\n',... - ' (g). "Save values" will be deactive on "ERP Measurement Tool".\n\n',... - ' (h). "Average across ERPsets" will be deactive.\n\n']; - else - msgboxText = []; - question = [ ]; - - end - if ~isempty(question) - BackERPLABcolor = [1 0.9 0.3]; - title = 'EStudio: ERPsets'; - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) - button = questdlg(sprintf(question, msgboxText), title,'OK','OK'); - set(0,'DefaultUicontrolBackgroundColor',oldcolor); - end - end - - observe_ERPDAT.Process_messg =2; - observe_ERPDAT.Count_ERP = observe_ERPDAT.Count_ERP+1; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - if numel(source.Value)==1 - observe_ERPDAT.ERP_chan = [1:observe_ERPDAT.ERP.nchan]; - observe_ERPDAT.ERP_bin = [1:observe_ERPDAT.ERP.nbin]; + observe_ERPDAT.Count_currentERP = 2; + if EStudio_gui_erp_totl.ERP_autoplot==1 + f_redrawERP(); end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; end - - -% called datasets = sortdata(datasets), sorts datasets in order based on -% parents - function varargout = sortdata(data) - cinds = []; - ndata = {}; % Sorted data - it = 1; % Iterator for row - for i = data' % Iterate thru all datasets - if cell2mat(i(3)) == 0 % Find base datasets (child of 0 means it's not reliant on another dataset) - [~, ic] = size(cinds); - cinds(1, ic+1) = cell2mat(i(2)); % Append dataset number to list of current indexes - ndata(it,:) = i'; % Put it in - it = it + 1; - end - end - - cond = true; - while cond - ninds = []; % Reset new indexes - for i = data' % Iterate thru all data - for j = cinds % Iterate thru all parents - if cell2mat(i(3)) == j % Check to see if every datapoint is a child of the current layer - [~, nic] = size(ninds); - ninds(1, nic+1) = cell2mat(i(2)); % Append dataset number to the next round of parents - [ndr, ~] = size(ndata); - for v = 1:ndr - if cell2mat(ndata(v, 2)) == j - ndata(v+2:end+1,:) = ndata(v+1:end,:); - ndata(v+1,:) = i'; - end - end - end - end - end - [~, nic] = size(ninds); - if nic == 0 % If we've gone thru all of them, there should be no new indexes - cond = false; - end - clear cinds - cinds = ninds; % Start again with ninds +%%%--------------Up this panel-------------------------------------- + function Count_currentERPChanged(~,~) + if observe_ERPDAT.Count_currentERP~=1 + return; end - varargout{1} = ndata; - end - -% Gets [ind, erp] for input ds where ds is a dataset structure, ind is the -% index of the corresponding ERP, and ERP is the corresponding ERP -% structure. - function varargout = ds2erp(ds) - [~,cvtc] = size(observe_ERPDAT.ALLERP); - for z = 1:cvtc - fp1 = observe_ERPDAT.ALLERP(1,z).filepath; - fp2 = cell2mat(ds(5)); - fp1(regexp(fp1,'[/]')) = []; - fp2(regexp(fp2,'[/]')) = []; - if strcmp(observe_ERPDAT.ALLERP(1,z).erpname,cell2mat(ds(1)))&&strcmp(fp1,fp2) - varargout{1} = z; - varargout{2} = observe_ERPDAT.ALLERP(1,z); + if ~isempty(observe_ERPDAT.ALLERP) && ~isempty(observe_ERPDAT.ERP) + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); end + ERPlistName = getERPsets(); + ERPsetops.butttons_datasets.String = ERPlistName; + ERPsetops.butttons_datasets.Value = ERPArray; + ERPsetops.butttons_datasets.Min=1; + ERPsetops.butttons_datasets.Max=length(ERPlistName)+1; + estudioworkingmemory('selectederpstudio',ERPArray); + ERPsetops.butttons_datasets.Value = ERPArray; + ERPsetops.butttons_datasets.Enable = 'on'; + Edit_label = 'on'; + else + ERPlistName = getERPsets(); + ERPArray =1; + ERPsetops.butttons_datasets.String = ERPlistName; + ERPsetops.butttons_datasets.Value = ERPArray; + ERPsetops.butttons_datasets.Min=1; + ERPsetops.butttons_datasets.Max=length(ERPlistName)+1; + estudioworkingmemory('selectederpstudio',ERPArray); + Edit_label = 'off'; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); end + if ViewerFlag==1 + Edit_label = 'off'; + ERPsetops.importexport.Enable=Edit_label; + ERPsetops.loadbutton.Enable=Edit_label; + else + ERPsetops.importexport.Enable='on'; + ERPsetops.loadbutton.Enable='on'; + end + ERPsetops.dupeselected.Enable=Edit_label; + ERPsetops.renameselected.Enable=Edit_label; + ERPsetops.suffix.Enable= Edit_label; + ERPsetops.refresh_erpset.Enable= 'on'; + ERPsetops.clearselected.Enable=Edit_label; + ERPsetops.savebutton.Enable= Edit_label; + ERPsetops.saveasbutton.Enable=Edit_label; + ERPsetops.curr_folder.Enable='on'; + ERPsetops.butttons_datasets.Enable = Edit_label; + ERPsetops.export.Enable = Edit_label; - end - - - -%%%--------------Up this panel-------------------------------------- - function Count_currentERPChanged(~,~) + assignin('base','ERP',observe_ERPDAT.ERP); + assignin('base','ALLERP',observe_ERPDAT.ALLERP); + assignin('base','CURRENTERP',observe_ERPDAT.CURRENTERP); - Selected_ERP= estudioworkingmemory('selectederpstudio'); - if isempty(Selected_ERP) - Selected_ERP = observe_ERPDAT.CURRENTERP; - if isempty(Selected_ERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_ERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + observe_ERPDAT.Count_currentERP = 2; + if EStudio_gui_erp_totl.ERP_autoplot==1 + f_redrawERP(); end - - [chk, msgboxText] = f_ERP_chckerpindex(observe_ERPDAT.ALLERP, Selected_ERP); - if chk==1 - Selected_ERP = observe_ERPDAT.CURRENTERP; - if isempty(Selected_ERP) - msgboxText = 'No ERPset was imported!!!'; - title = 'EStudio: f_ERP_binoperation_GUI error.'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_ERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_ERP); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - return; + end + +%%------------------get the names of erpsets------------------------------- + function ERPlistName = getERPsets(ALLERP) + if nargin<1 + ALLERP= observe_ERPDAT.ALLERP; end - ERPfilter_label = erpworkingmemory('ERPfilter'); - def_baseline = erpworkingmemory('f_ERP_BLS_Detrend'); - ERP_bin_opertion = erpworkingmemory('f_ERP_bin_opt'); - ERP_simulation = erpworkingmemory('ERP_simulation'); - if isempty(ERPfilter_label) - ERPfilter_label =1; - end - if isempty(def_baseline) - def_baseline{3} =1; - end - if isempty(ERP_bin_opertion) - ERP_bin_opertion =1; - end - if isempty(ERP_simulation) - ERP_simulation =1; - end - if ERPfilter_label ==1 || def_baseline{3}==1 || ERP_bin_opertion==1 || ERP_simulation==1 - erpworkingmemory('ERPfilter',0); - def_baseline{3} = 0; - erpworkingmemory('f_ERP_BLS_Detrend',def_baseline); - erpworkingmemory('f_ERP_bin_opt',0); - erpworkingmemory('ERP_simulation',0); - datasets = {}; - getDatasets() - datasets = sortdata(datasets); - dsnames = {}; - if size(datasets,1)==1 - if strcmp(datasets{1},'No ERPset loaded') - dsnames = {''}; - Edit_label = 'off'; - else - dsnames{1} = strcat(num2str(cell2mat(datasets(1,2))),'.',32,datasets{1,1}); - Edit_label = 'on'; - end - else - for Numofsub = 1:size(datasets,1) - dsnames{Numofsub} = strcat(num2str(cell2mat(datasets(Numofsub,2))),'.',32,datasets{Numofsub,1}); - end - Edit_label = 'on'; - end - ERPsetops.butttons_datasets.String = dsnames; - ERPsetops.butttons_datasets.Value = Selected_ERP; - if strcmp(datasets{1},'No ERPset loaded') - Edit_label = 'off'; - else - Edit_label = 'on'; + ERPlistName = {}; + if ~isempty(ALLERP) + for ii = 1:length(ALLERP) + ERPlistName{ii,1} = char(strcat(num2str(ii),'.',32, ALLERP(ii).erpname)); end - ERPsetops.dupeselected.Enable=Edit_label; - ERPsetops.renameselected.Enable=Edit_label; - ERPsetops.suffix.Enable= Edit_label; - ERPsetops.clearselected.Enable=Edit_label; - ERPsetops.savebutton.Enable= Edit_label; - ERPsetops.saveasbutton.Enable=Edit_label; - ERPsetops.dotstoggle.Enable=Edit_label; - ERPsetops.butttons_datasets.Enable = Edit_label; - ERPsetops.export.Enable = Edit_label; - estudioworkingmemory('selectederpstudio',Selected_ERP); - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_ERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - ERPsetops.butttons_datasets.Min=1; - ERPsetops.butttons_datasets.Max=size(datasets,1)+1; + else + ERPlistName{1} = 'No erpset is available' ; end - ERPsetops.butttons_datasets.Value = Selected_ERP; - observe_ERPDAT.Count_ERP = observe_ERPDAT.Count_ERP+1; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end -%----------------------Get the information of the updated ERPsets---------- - function getDatasets() - if isempty(datasets) - datasets = {}; - end - [s,~] = size(datasets); - del = []; - for i = 1:s - cond = false; - for j = observe_ERPDAT.ALLERP - if strcmp(j.filename, datasets{i,4}) && strcmp(j.filepath, datasets{i,5}) && strcmp(i.erpname, datasets{j,1}) - cond = true; - end - end - if ~cond - del(end+1) = i; - end - end - for i = del - datasets(del,:) = []; + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=1 + return; end - for i = observe_ERPDAT.ALLERP - cond = false; - [s,~] = size(datasets); - for j = 1:s - if strcmp(i.filename, datasets{j,4}) && strcmp(i.filepath, datasets{j,5}) && strcmp(i.erpname, datasets{j,1}); - cond = true; - end - end - if ~cond - datasets{end+1,1} = i.erpname; - [r,~] = size(datasets); - datasets{end,2} = r; - datasets{end,3} = 0; - datasets{end,4} = i.filename; - datasets{end,5} = i.filepath; - end + + if ~isempty(observe_ERPDAT.ALLERP) + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); + ERPsetops.butttons_datasets.Value = observe_ERPDAT.CURRENTERP; end + observe_ERPDAT.Reset_erp_paras_panel=2; end -% function onErpChanged(~,~) -% assignin('base','ERP',observe_ERPDAT.ERP); -% end +end +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%% 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.erp']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This ERP set already exists.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_events_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_events_GUI.m new file mode 100644 index 00000000..2f8c683b --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_ERP_events_GUI.m @@ -0,0 +1,681 @@ +%%This function is operation for EventList + +% *** This function is part of ERPLAB Studio Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + + +function varargout = f_ERP_events_GUI(varargin) + +global observe_ERPDAT; +addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +%---------------------------Initialize parameters------------------------------------ + +erptab_events = struct(); + +%-----------------------------Name the title---------------------------------------------- +% global eegtab_events_box; +[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +if nargin == 0 + fig = figure(); % Parent figure + eegtab_events_box = uiextras.BoxPanel('Parent', fig, 'Title', 'EventList', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + eegtab_events_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EventList', 'Padding', 5,... + 'BackgroundColor',ColorB_def); +else + eegtab_events_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'EventList', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @event_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end + +drawui_erp_events(FonsizeDefault) +varargout{1} = eegtab_events_box; + + function drawui_erp_events(FonsizeDefault) + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + %%--------------------channel and bin setting---------------------- + erptab_events.DataSelBox = uiextras.VBox('Parent', eegtab_events_box,'BackgroundColor',ColorB_def); + EnableFlag= 'off'; + + %%Create Eventlist and Import + erptab_events.create_rt_title = uiextras.HBox('Parent',erptab_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + erptab_events.imp_eventlist = uicontrol('Style', 'pushbutton','Parent', erptab_events.create_rt_title ,... + 'String','Import .txt','callback',@imp_eventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + erptab_events.exp_eventlist = uicontrol('Style', 'pushbutton','Parent', erptab_events.create_rt_title,... + 'String','Export .txt','callback',@exp_eventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + erptab_events.exp_rt = uicontrol('Style', 'pushbutton','Parent', erptab_events.create_rt_title ,... + 'String','Export RTs','callback',@exp_rt,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + %%export eventlist + erptab_events.imp_exp_title = uiextras.HBox('Parent',erptab_events.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + erptab_events.imp_eventlist_exc = uicontrol('Style', 'pushbutton','Parent', erptab_events.imp_exp_title ,... + 'String','Import .xls','callback',@imp_eventlist_exc,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + erptab_events.exp_eventlist_exc = uicontrol('Style', 'pushbutton','Parent', erptab_events.imp_exp_title,... + 'String','Export .xls','callback',@exp_eventlist_exc,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + erptab_events.vieweventlist = uicontrol('Style', 'pushbutton','Parent', erptab_events.imp_exp_title,... + 'String','View ','callback',@vieweventlist,'FontSize',FonsizeDefault,'Enable',EnableFlag,'BackgroundColor',[1 1 1]); + + set(erptab_events.DataSelBox,'Sizes',[30 30]); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%----------------Export reaction times to text file----------------------- + function exp_rt(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','EventList > Export RTs'); + observe_ERPDAT.Process_messg =1; + + if ~isfield(observe_ERPDAT.ERP,'EVENTLIST') + msgboxText = ['EventList > Export RTs: No EVETLIST, please create one first']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + + def = estudioworkingmemory('pop_rt2text'); + if isempty(def) + def = {'' 'basic' 'on' 'off' 1}; + end + + e2 = length(observe_ERPDAT.ERP.EVENTLIST); + + % + % Call Gui + % + param = saveRTGUI(def, e2); + + if isempty(param) + observe_ERPDAT.Process_messg =2; + return + end + filenamei = param{1}; + listformat = param{2}; + header = param{3}; % 1 means include header (name of variables) + arfilt = param{4}; % 1 means filter out RTs with marked flags + indexel = param{5}; % index for eventlist + [pathx, filename, ext] = fileparts(filenamei); + if header==1 + headstr = 'on'; + else + headstr = 'off'; + end + if arfilt==1 + arfilter = 'on'; + else + arfilter = 'off'; + end + estudioworkingmemory('pop_rt2text', {fullfile(pathx, filename), listformat, headstr, arfilter, indexel}); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + + for Numoferp = 1:numel(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + if ~isfield(ERP, 'EVENTLIST') + estudioworkingmemory('f_ERP_proces_messg','EventList > Export RTs:EVENTLIST structure is empty'); + observe_ERPDAT.Process_messg =2; + else + filenameeeg = ERP.filename; + [pathxeeg, filenameeeg, ext] = fileparts(filenameeeg); + if isempty(filenameeeg) + filename = [num2str(ERPArray(Numoferp)),'_',filename,'.txt']; + else + filename = strcat(filenameeeg,'_',filename,'.txt'); + end + filename = fullfile(pathx, filename); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current ERPset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + fprintf(['The exported file name:',32,filename,'\n\n']); + + [ERP,values, ERPCOM] = pop_rt2text(ERP, 'filename', filename, 'listformat', listformat, 'header', headstr,... + 'arfilter', arfilter, 'eventlist', indexel, 'History', 'gui'); + + if ~isempty( values) + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + observe_ERPDAT.ALLERP(ERPArray(Numoferp)) =ERP; + else + fprintf(2,['Cannot export reaction times for:',32,ERP.erpname,'\n']); + fprintf( [repmat('-',1,100) '\n']); + end + end + end + assignin('base','ALLERPCOM',ALLERPCOM); + try assignin('base','ERPCOM',ERPCOM);catch end; + estudioworkingmemory('f_ERP_proces_messg','EventList > Export RTs'); + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP=1; + end + + +%%-------------------View eventlist---------------------------------------- + function vieweventlist(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + estudioworkingmemory('f_ERP_proces_messg','EventList > View EventList'); + observe_ERPDAT.Process_messg =1; + + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + ALLERP = observe_ERPDAT.ALLERP; + [ALLERP, ERPCOM] = pop_erp_eventlist_view( ALLERP, 'ERPArray',ERPArray,... + 'Saveas', 'off', 'History', 'script'); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['*ERP Tab>Eventlist>View*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf([ERPCOM]); + fprintf( ['\n',repmat('-',1,100) '\n']); + for Numoferp = 1:numel(ERPArray) + if Numoferp ==length(ERPArray) + [observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM, ERPCOM,2); + else + [observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(ERPArray(Numoferp)), ALLERPCOM, ERPCOM,1); + end + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP = 20; + observe_ERPDAT.Process_messg =2; + end + + +%%--------------------import EEG eventlist from text file-------------------- + function imp_eventlist(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','EventList > Import'); + observe_ERPDAT.Process_messg =1; + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = ''; end + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + + %% Run pop_ command again with the inputs from the GUI + [filename,pathname] = uigetfile({'*.txt*'},['Select a EVENTLIST file for erpset:',32,num2str(ERPArray(Numoferp))]); + ELfullname = fullfile(pathname, filename); + + if isequal(filename,0) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_ERPDAT.Process_messg =2; + return + else + disp(['For read an EVENTLIST, user selected ', ELfullname]) + end + [ERP, ERPCOM] = pop_importerpeventlist( ERP, ELfullname , 'ReplaceEventList', 'replace', 'Saveas', 'off', 'History', 'gui'); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + fprintf([ERPCOM]); + if Numoferp==1 + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + fprintf( ['\n',repmat('-',1,100) '\n\n']); + end + + Save_file_label = 0; + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray), '_impel'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + if Save_file_label + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + + observe_ERPDAT.ALLERP = ALLERP; + try + Selected_EEG_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_EEG_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_EEG_afd); + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP = 1; + end + + +%%--------------------export EEG eventlist to text file-------------------- + function exp_eventlist(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','EventList > Export eventlist'); + observe_ERPDAT.Process_messg =1; + + if ~isfield(observe_ERPDAT.ERP,'EVENTLIST') || isempty(observe_ERPDAT.ERP.EVENTLIST) + msgboxText = ['EventList >Export eventlist: Please check the current EEG.EVENTLIST']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + + [fname, pathname] = uiputfile({'*.txt*'},'Save EVENTLIST file as (This will be suffix when using EStudio)'); + + if isequal(fname,0) + observe_ERPDAT.Process_messg =2; + return + end + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + [xpath, suffixstr, ext] = fileparts(fname); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + + for Numoferp = 1:numel(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + msgboxText = ''; + if isfield(ERP, 'EVENTLIST') + if isempty(ERP.EVENTLIST) + msgboxText = ['ERP.EVENTLIST structure is empty']; + end + if isfield(ERP.EVENTLIST, 'eventinfo') + if isempty(ERP.EVENTLIST.eventinfo) + msgboxText = ['ERP.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['ERP.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['ERP.EVENTLIST structure is empty']; + end + + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current ERPset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + if isempty(msgboxText) + if numel(ERPArray) >1 + filenameeg = ERP.filename; + [xpatheeg, filenameeg, exteeg] = fileparts(filenameeg); + if isempty(filenameeg) + filenameeg = strcat(num2str(ERPArray(Numoferp)),'_',suffixstr,'.txt'); + else + filenameeg = strcat(filenameeg,'_',suffixstr,'.txt'); + end + else + filenameeg = [suffixstr,'.txt']; + end + filenameeg = fullfile(pathname, filenameeg); + + disp(['For EVENTLIST output user selected ', filenameeg]) + [ERP, ERPCOM] = pop_exporterpeventlist( ERP , 'ELIndex', 1, 'Filename', filenameeg,'History','gui'); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ALLERP(ERPArray(Numoferp)) =ERP; + else + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf(2,['Cannot export eventlist for:',32,ERP.erpname,'\n']); + fprintf( [repmat('-',1,100) '\n']); + end + end + estudioworkingmemory('f_ERP_proces_messg','EventList > Export eventlist'); + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP=1; + end + + +%%--------------------import EEG eventlist from .xls file-------------------- + function imp_eventlist_exc(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','EventList > Import'); + observe_ERPDAT.Process_messg =1; + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = [];end + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current EEGset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + + %% Run pop_ command again with the inputs from the GUI + [filename,pathname] = uigetfile({'*.xls*';'*.xlsx*'},['Select a EVENTLIST file for erpset:',32,num2str(ERPArray(Numoferp))]); + ELfullname = fullfile(pathname, filename); + + if isequal(filename,0) + fprintf( ['\n',repmat('-',1,100) '\n']); + observe_ERPDAT.Process_messg =2; + return + else + disp(['For read an EVENTLIST, user selected ', ELfullname]) + end + + [ERP, ERPCOM] = pop_importerpeventlist( ERP, ELfullname , 'ReplaceEventList', 'replace' , 'Saveas', 'off', 'History', 'gui'); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + if Numoferp==1 + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + end + + + Save_file_label = 0; + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray), '_impel'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + if Save_file_label + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ALLERP = ALLERP; + try + Selected_EEG_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_EEG_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_EEG_afd); + + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP = 1; + end + +%%----------------------------Export eventlist to xls---------------------- + function exp_eventlist_exc(Source,~) + if isempty(observe_ERPDAT.ERP) + Source.Enable= 'off'; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('f_ERP_proces_messg','EventList > Export eventlist to .xls file'); + observe_ERPDAT.Process_messg =1; + + if ~isfield(observe_ERPDAT.ERP,'EVENTLIST') || isempty(observe_ERPDAT.ERP.EVENTLIST) + msgboxText = ['EventList >Export eventlist: Please check the current EEG.EVENTLIST']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + + [fname, pathname] = uiputfile({'*.xls*';'*.xlsx*'},'Save EVENTLIST file as (This will be suffix when using EStudio)'); + if isequal(fname,0) + observe_ERPDAT.Process_messg =2; + return + end + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray(:) > length(observe_ERPDAT.ALLERP)) || any(ERPArray(:) <1) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + [xpath, suffixstr, ext] = fileparts(fname); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + for Numoferp = 1:numel(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + msgboxText = ''; + if isfield(ERP, 'EVENTLIST') + if isempty(ERP.EVENTLIST) + msgboxText = ['ERP.EVENTLIST structure is empty']; + end + if isfield(ERP.EVENTLIST, 'eventinfo') + if isempty(ERP.EVENTLIST.eventinfo) + msgboxText = ['ERP.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['ERP.EVENTLIST.eventinfo structure is empty']; + end + else + msgboxText = ['ERP.EVENTLIST structure is empty']; + end + + fprintf( ['\n\n',repmat('-',1,100) '\n']); + fprintf(['Your current ERPset(No.',num2str(ERPArray(Numoferp)),'):',32,ERP.erpname,'\n\n']); + if isempty(msgboxText) + if numel(ERPArray) >1 + filenameeg = ERP.filename; + [xpatheeg, filenameeg, exteeg] = fileparts(filenameeg); + if isempty(filenameeg) + filenameeg = strcat(num2str(ERPArray(Numoferp)),'_',suffixstr,'.xls'); + else + filenameeg = strcat(filenameeg,'_',suffixstr,'.xls'); + end + else + filenameeg = [suffixstr,'.xls']; + end + filenameeg = fullfile(pathname, filenameeg); + + disp(['For EVENTLIST output user selected ', filenameeg]) + [ERP, ERPCOM] = pop_exporterpeventlist( ERP , 'ELIndex', 1, 'Filename', filenameeg,'History','gui'); + + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ALLERP(ERPArray(Numoferp)) =ERP; + else + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + fprintf(2,['Cannot export eventlist for:',32,ERP.erpname,'\n']); + fprintf( [repmat('-',1,100) '\n']); + end + end + estudioworkingmemory('f_ERP_proces_messg','EventList > Export eventlist'); + observe_ERPDAT.Count_currentERP=1; + observe_ERPDAT.Process_messg =2; + end + + + +%%--------Settting will be modified if the selected was changed------------ + function Count_currentERPChanged(~,~) + if observe_ERPDAT.Count_currentERP ~=15 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || ~isfield(observe_ERPDAT.ERP,'EVENTLIST') || ViewerFlag==1 + EnableFlag = 'off'; + erptab_events.exp_rt.Enable=EnableFlag; + erptab_events.imp_eventlist.Enable=EnableFlag; + erptab_events.exp_eventlist.Enable=EnableFlag; + erptab_events.vieweventlist.Enable=EnableFlag; + erptab_events.imp_eventlist_exc.Enable=EnableFlag; + erptab_events.exp_eventlist_exc.Enable=EnableFlag; + observe_ERPDAT.Count_currentERP=16; + return; + end + + eegtab_events_box.Title = 'EventList'; + eegtab_events_box.ForegroundColor= [1 1 1]; + + if ~isempty(observe_ERPDAT.ERP) + EnableFlag ='on'; + else + EnableFlag ='off'; + end + + %%export reaction times + erptab_events.exp_rt.Enable=EnableFlag; + %%Import and export eventlist + erptab_events.imp_eventlist.Enable=EnableFlag; + erptab_events.imp_eventlist_exc.Enable=EnableFlag; + + if isfield(observe_ERPDAT.ERP,'EVENTLIST') && ~isempty(observe_ERPDAT.ERP.EVENTLIST) + erptab_events.vieweventlist.Enable='on'; + erptab_events.exp_eventlist.Enable='on'; + erptab_events.exp_eventlist_exc.Enable='on'; + else + erptab_events.vieweventlist.Enable='off'; + erptab_events.exp_eventlist.Enable='off'; + erptab_events.exp_eventlist_exc.Enable='off'; + end + observe_ERPDAT.Count_currentERP=16; + end +end + + +%%----------------check if the file already exists------------------------- +function checkfileindex = checkfilexists(filenamex)%%Jan 10 2024 +checkfileindex=1; +[pathstr, file_name, ext] = fileparts(filenamex); +filenamex = [pathstr,filesep, file_name,'.set']; +if exist(filenamex, 'file')~=0 + msgboxText = ['This EEG Data already exist.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if strcmpi(button,'no') + checkfileindex=0; + else + checkfileindex=1; + end +end +end diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_filtering_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_filtering_GUI.m index d54847ab..e0e5703e 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_filtering_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_filtering_GUI.m @@ -1,4 +1,4 @@ -%Author: Guanghui ZHANG--zhang.guanghui@foxmail.com +%Author: Guanghui ZHANG %Center for Mind and Brain %University of California, Davis %Davis, CA, USA @@ -8,30 +8,29 @@ function varargout = f_ERP_filtering_GUI(varargin) -gui_erp_filtering = struct(); -% global gui_erp_filtering; global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@erpschange); -% addlistener(observe_ERPDAT,'ERP_change',@drawui_CB); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); %%---------------------------gui------------------------------------------- try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch - ColorB_def = [0.95 0.95 0.95]; + ColorB_def = [0.702,0.77,0.85]; end if nargin == 0 fig = figure(); % Parent figure - ERP_filtering_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Filtering', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_filtering_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Filtering', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_filtering_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Filtering', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_filtering_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Filtering', 'Padding', 5,... + 'BackgroundColor',ColorB_def); else - ERP_filtering_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Filtering', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_filtering_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Filtering', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @filter_help end - +gui_erp_filtering = struct(); try FonsizeDefault = varargin{2}; @@ -39,7 +38,7 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end erp_filtering_gui(FonsizeDefault); @@ -49,22 +48,15 @@ function erp_filtering_gui(FonsizeDefault) try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch - ColorB_def = [0.95 0.95 0.95]; - end - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; + ColorB_def = [0.702,0.77,0.85]; end - try - nchan = observe_ERPDAT.ERP.nchan; - fs = observe_ERPDAT.ERP.srate; - catch - nchan =1; - end + Enable_label = 'off'; + + nchan =1; + fs = 256; defx = {0 30 2 1:nchan 1 'butter' 0 []}; - def = erpworkingmemory('pop_filterp'); + def = estudioworkingmemory('pop_filterp'); if isempty(def) def = defx; end @@ -80,13 +72,7 @@ function erp_filtering_gui(FonsizeDefault) remove_dc = def{7}; typef = 0; - if strcmpi(fdesign,'butter') % 0 means Butterworth - if filterorder> 8 - filterorder =2; - end - else - filterorder = 2; - end + filterorder=2; if locutoff >= fs/2 || locutoff<=0 locutoff = floor(fs/2)-1; @@ -118,84 +104,55 @@ function erp_filtering_gui(FonsizeDefault) hp_tog_enable = 'on'; lp_tog_enable = 'on'; - if ~strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - - %%High-pass filtering - [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); - if locutoff > 0 && hicutoff ==0 - highpass_toggle_value = 1; - hp_halfamp_enable = 'on'; - lowpass_toggle_value = 0; - lp_halfamp_Enable = 'off'; - hp_halfpow_string =num2str(roundn(frec3dB(1),-2)); - lp_halfpow_string ='---'; - end - %%Low pass filtering - if hicutoff > 0 && locutoff ==0 - highpass_toggle_value = 0; - hp_halfamp_enable = 'off'; - lowpass_toggle_value = 1; - lp_halfamp_Enable = 'on'; - lp_halfpow_string =num2str(roundn(frec3dB,-2)); - hp_halfpow_string ='---'; - end - %%Band pass filtering or notch filtering - if locutoff >0 && hicutoff>0 - highpass_toggle_value = 1; - hp_halfamp_enable = 'on'; - hp_halfpow_string =num2str(roundn(frec3dB(2),-2)); - lowpass_toggle_value = 1; - lp_halfamp_Enable = 'on'; - lp_halfpow_string =num2str(roundn(frec3dB(1),-2)); - end - else - hp_halfamp_enable = 'off'; - lp_halfamp_Enable = 'off'; - Apply_ERP_filter_enable = 'off'; - Advance_ERP_filter_enable = 'off'; - - lp_tog_enable = 'off'; - hp_tog_enable = 'off'; - hp_halfpow_string ='--'; - lp_halfpow_string ='---'; - end + hp_halfamp_enable = 'off'; + lp_halfamp_Enable = 'off'; + Apply_ERP_filter_enable = 'off'; + Advance_ERP_filter_enable = 'off'; + + lp_tog_enable = 'off'; + hp_tog_enable = 'off'; + hp_halfpow_string ='--'; + lp_halfpow_string ='---'; + gui_erp_filtering.filtering = uiextras.VBox('Parent',ERP_filtering_box,'BackgroundColor',ColorB_def); %%-----------------------------Setting for bin and chan-------------------- gui_erp_filtering.bin_chan_title = uiextras.HBox('Parent',gui_erp_filtering.filtering,'BackgroundColor',ColorB_def); uicontrol('Style','text','Parent',gui_erp_filtering.bin_chan_title,'String','Bin and Chan Selection:','FontWeight','bold',... 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_filtering.filter_bin_chan_option = uiextras.HBox('Parent', gui_erp_filtering.filtering,'Spacing',1,'BackgroundColor',ColorB_def); - gui_erp_filtering.all_bin_chan = uicontrol('Style', 'radiobutton','Parent', gui_erp_filtering.filter_bin_chan_option,... 'String','All (Recommended)','callback',@All_bin_chan,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_filtering.all_bin_chan.KeyPressFcn= @erp_filter_presskey; gui_erp_filtering.Selected_bin_chan = uicontrol('Style', 'radiobutton','Parent', gui_erp_filtering.filter_bin_chan_option,... 'String','Selected bin & chan','callback',@Selected_bin_chan,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_filtering.Selected_bin_chan.KeyPressFcn= @erp_filter_presskey; set(gui_erp_filtering.filter_bin_chan_option, 'Sizes',[130 170]); - + gui_erp_filtering.params{1} = gui_erp_filtering.all_bin_chan.Value; %%--------------------------Setting for IIR filter------------------------------ gui_erp_filtering.IIR_title = uiextras.HBox('Parent',gui_erp_filtering.filtering,'BackgroundColor',ColorB_def); uicontrol('Style','text','Parent',gui_erp_filtering.IIR_title,'String','Setting for IIR Butterworth:',... 'FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_filtering.filt_grid = uiextras.Grid('Parent',gui_erp_filtering.filtering,'BackgroundColor',ColorB_def); % first column uiextras.Empty('Parent',gui_erp_filtering.filt_grid); % 1A gui_erp_filtering.hp_tog = uicontrol('Style','checkbox','Parent',gui_erp_filtering.filt_grid,'String','High Pass',... 'callback',@highpass_toggle,'Value',0,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1B + gui_erp_filtering.hp_tog.KeyPressFcn= @erp_filter_presskey; + gui_erp_filtering.params{2} = gui_erp_filtering.hp_tog.Value; gui_erp_filtering.lp_tog = uicontrol('Style','checkbox','Parent',gui_erp_filtering.filt_grid,'String','Low Pass',... 'callback',@lowpass_toggle,'Value',1,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1C - - + gui_erp_filtering.lp_tog.KeyPressFcn= @erp_filter_presskey; + gui_erp_filtering.params{5} = gui_erp_filtering.lp_tog.Value; % second column uicontrol('Style','text','Parent',gui_erp_filtering.filt_grid,'String','Half Amp.','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2A gui_erp_filtering.hp_halfamp = uicontrol('Style','edit','Parent',gui_erp_filtering.filt_grid,... 'callback',@hp_halfamp,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 2B - if strcmp(hp_halfamp_enable,'off'); + gui_erp_filtering.hp_halfamp.KeyPressFcn= @erp_filter_presskey; + gui_erp_filtering.params{3} = str2num(gui_erp_filtering.hp_halfamp.String); + if strcmp(hp_halfamp_enable,'off') if typef<2 gui_erp_filtering.hp_halfamp.String = '0'; else @@ -207,6 +164,8 @@ function erp_filtering_gui(FonsizeDefault) end gui_erp_filtering.lp_halfamp = uicontrol('Style','edit','Parent',gui_erp_filtering.filt_grid,... 'callback',@lp_halfamp,'Enable',lp_halfamp_Enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 2C + gui_erp_filtering.lp_halfamp.KeyPressFcn= @erp_filter_presskey; + gui_erp_filtering.params{6} = str2num(gui_erp_filtering.lp_halfamp.String); if strcmp(lp_halfamp_Enable,'off') gui_erp_filtering.lp_halfamp.String = '20'; else @@ -216,10 +175,10 @@ function erp_filtering_gui(FonsizeDefault) uicontrol('Style','text','Parent',gui_erp_filtering.filt_grid,'String','Half Power','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 3A gui_erp_filtering.hp_halfpow = uicontrol('Style','text','Parent',gui_erp_filtering.filt_grid,... 'String',hp_halfpow_string,'Enable','off','BackgroundColor','y','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 3B - + gui_erp_filtering.params{4} = str2num(gui_erp_filtering.hp_halfpow.String); gui_erp_filtering.lp_halfpow = uicontrol('Style','text','Parent',gui_erp_filtering.filt_grid,... 'String',lp_halfpow_string,'Enable','off','BackgroundColor','y','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 3C - + gui_erp_filtering.params{7} = str2num(gui_erp_filtering.lp_halfpow.String); % fourth column uiextras.Empty('Parent',gui_erp_filtering.filt_grid); % 4A uicontrol('Style','text','Parent',gui_erp_filtering.filt_grid,'String','Hz','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 4B @@ -232,6 +191,8 @@ function erp_filtering_gui(FonsizeDefault) Roll_off = {'12','24','36','48'}; gui_erp_filtering.roll_off = uicontrol('Style','popupmenu','Parent',gui_erp_filtering.rolloff_row,'String',Roll_off,... 'callback',@ERP_filtering_rolloff,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % 2D + gui_erp_filtering.roll_off.KeyPressFcn= @erp_filter_presskey; + gui_erp_filtering.params{8} =gui_erp_filtering.roll_off.Value; if filterorder ==2 gui_erp_filtering.roll_off.Value = 1; elseif filterorder ==4 @@ -246,57 +207,92 @@ function erp_filtering_gui(FonsizeDefault) uicontrol('Style','text','Parent',gui_erp_filtering.rolloff_row,'String','dB/Octave','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 3D - gui_erp_filtering.REMOVE_DC = uiextras.HBox('Parent', gui_erp_filtering.filtering,'BackgroundColor',ColorB_def); - gui_erp_filtering.DC_remove = uicontrol('Style','checkbox','Parent', gui_erp_filtering.REMOVE_DC,... - 'String','Remove DC Offset','Value',0,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def);%,'callback',@remove_dc + gui_erp_filtering.params{9} = 0; % uiextras.Empty('Parent',gui_erp_filtering.REMOVE_DC); - gui_erp_filtering.filt_buttons = uiextras.HBox('Parent', gui_erp_filtering.filtering,'BackgroundColor',ColorB_def); % uiextras.Empty('Parent', gui_erp_filtering.filt_buttons); - uicontrol('Style','pushbutton','Parent',gui_erp_filtering.filt_buttons,'String','?',... - 'callback',@ERP_filter_help,'Enable','on','FontSize',16,'BackgroundColor',[1 1 1]); + gui_erp_filtering.cancel=uicontrol('Style','pushbutton','Parent',gui_erp_filtering.filt_buttons,'String','Cancel',... + 'callback',@ERP_filter_cancel,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); gui_erp_filtering.advanced = uicontrol('Style','pushbutton','Parent',gui_erp_filtering.filt_buttons,'String','Advanced',... 'callback',@advanced_ERP_filter,'Enable',Advance_ERP_filter_enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - gui_erp_filtering.apply = uicontrol('Style','pushbutton','Parent',gui_erp_filtering.filt_buttons,'String','Run',... 'callback',@ERP_filter_apply,'Enable',Apply_ERP_filter_enable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - set( gui_erp_filtering.filtering,'Sizes',[20 20 20 80 20 20 30]); + set( gui_erp_filtering.filtering,'Sizes',[20 20 20 80 20 30]); + estudioworkingmemory('ERPTab_filter',0); end - - %%**************************************************************************************************************************************** %%******************* Subfunctions *************************************************************************************************** %%**************************************************************************************************************************************** -%%---------------------help----------------------------- - - function ERP_filter_help(~,~) - web('https://github.com/lucklab/erplab/wiki/Filtering','-browser'); - - end %%----------------------all bin and all chan------------------------------- function All_bin_chan(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); gui_erp_filtering.all_bin_chan.Value = 1; gui_erp_filtering.Selected_bin_chan.Value = 0; end %%----------------------selected bin and all chan------------------------------- function Selected_bin_chan(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); gui_erp_filtering.all_bin_chan.Value = 0; gui_erp_filtering.Selected_bin_chan.Value = 1; end - - %%--------------------------------High-pass filtering toggle------------------ function highpass_toggle(source,~) - try - fs = observe_ERPDAT.ERP.srate; - catch + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); + + fs = observe_ERPDAT.ERP.srate; locutoff = 0.1; try filterorder = 2*gui_erp_filtering.roll_off.Value; @@ -330,6 +326,23 @@ function highpass_toggle(source,~) %%--------------------------------Low-pass filtering toggle------------------ function lowpass_toggle(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); try fs = observe_ERPDAT.ERP.srate; @@ -363,13 +376,30 @@ function lowpass_toggle(source,~) gui_erp_filtering.lp_halfpow.Enable ='off'; gui_erp_filtering.roll_off.Enable = 'on'; end - end %%---------------------Half amplitude for high pass filtering-------------- function hp_halfamp(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); + try fs = observe_ERPDAT.ERP.srate; catch @@ -386,29 +416,23 @@ function hp_halfamp(Source,~) valueh = str2num(Source.String); if length(valueh)~=1 - beep; - msgboxText = ['Filtring - Invalid input for high-pass filter cutoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid input for high-pass filter cutoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valueh>=fs/2 - beep; - msgboxText = ['Filtring - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valueh<0.001 - beep; - msgboxText = ['Filtring - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end @@ -424,6 +448,23 @@ function hp_halfamp(Source,~) %%---------------------Half amplitude for low pass filtering--------------- function lp_halfamp(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); try fs = observe_ERPDAT.ERP.srate; @@ -438,29 +479,23 @@ function lp_halfamp(Source,~) end valuel = str2num(Source.String); if length(valuel)~=1 || isempty(valuel) - beep; - msgboxText = ['Filtring - Invalid input for low-pass filter cutoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid input for low-pass filter cutoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valuel>=fs/2 - beep; - msgboxText = ['Filtring - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valuel<0.001 - beep; - msgboxText = ['Filtring - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end @@ -472,14 +507,31 @@ function lp_halfamp(Source,~) gui_erp_filtering.lp_halfamp.String = num2str(valuel); gui_erp_filtering.lp_halfpow.String = num2str(frec3dB(1)); gui_erp_filtering.lp_halfpow.Enable ='off'; - end %%----------------------------Setting for roll-off------------------------- function ERP_filtering_rolloff(Source,~) - Source_value = Source.Value; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_filtering.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_filtering.apply.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.cancel.ForegroundColor = [1 1 1]; + gui_erp_filtering.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_filtering.advanced.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_filter',1); + + Source_value = Source.Value; try nchan = observe_ERPDAT.ERP.nchan; fs = observe_ERPDAT.ERP.srate; @@ -494,29 +546,23 @@ function ERP_filtering_rolloff(Source,~) if gui_erp_filtering.lp_tog.Value ==1 if length(valuel)~=1 || isempty(valuel) - beep; - msgboxText = ['Filtring - Invalid input for low-pass filter cutoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid input for low-pass filter cutoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valuel>=fs/2 - beep; - msgboxText = ['Filtring - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if gui_erp_filtering.hp_tog.Value ==0 if valuel<0.001 - beep; - msgboxText = ['Filtring - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end @@ -525,51 +571,40 @@ function ERP_filtering_rolloff(Source,~) if gui_erp_filtering.hp_tog.Value ==1 if length(valueh)~=1 - beep; - msgboxText = ['Filtring - Invalid input for high-pass filter cutoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid input for high-pass filter cutoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valueh>=fs/2 - beep; - msgboxText = ['Filtring - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if gui_erp_filtering.lp_tog.Value ==0 if valueh<0.001 - beep; - msgboxText = ['Filtring - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end end - if gui_erp_filtering.hp_tog.Value ==1 && gui_erp_filtering.lp_tog.Value ==1 if valueh >0 && valueh >0 && valueh >=valuel - beep; - msgboxText = ['Filtring - The lowest bandpass cuttoff is the highest bandpass cuttoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The lowest bandpass cuttoff is the highest bandpass cuttoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if valueh==0 && valuel==0 - beep; - msgboxText = ['Filtring - Either Lowest bandpass cuttoff or the highest bandpass cuttoff or both is larger than 0.01Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Either Lowest bandpass cuttoff or the highest bandpass cuttoff or both is larger than 0.01Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end @@ -585,129 +620,96 @@ function ERP_filtering_rolloff(Source,~) gui_erp_filtering.lp_halfpow.String = num2str(frec3dB(1)); gui_erp_filtering.hp_halfpow.String = num2str(frec3dB(2)); end + end -%-----------------------change for ALLERPs--------------------------------- -% function erpschange(~,~) -% -% -% end - %%------------------Setting for apply option-------------------------------- function ERP_filter_apply(~,~) - try - nchan = observe_ERPDAT.ERP.nchan; - fs = observe_ERPDAT.ERP.srate; - catch + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end - + nchan = observe_ERPDAT.ERP.nchan; + fs = observe_ERPDAT.ERP.srate; defx = {0 30 2 1:nchan 1 'butter' 0 []}; - def = erpworkingmemory('pop_filterp'); + def = estudioworkingmemory('pop_filterp'); if isempty(def) def = defx; end - remove_dc = gui_erp_filtering.DC_remove.Value; + remove_dc = 0; filterorder = 2*gui_erp_filtering.roll_off.Value; locutoff = str2num(gui_erp_filtering.hp_halfamp.String);%% hicutoff = str2num(gui_erp_filtering.lp_halfamp.String); - if isempty(locutoff) locutoff =0; end if isempty(hicutoff) hicutoff =0; end - if gui_erp_filtering.lp_tog.Value ==1 - if length(hicutoff)~=1 || isempty(hicutoff) - beep; - msgboxText = ['Filtring - Invalid input for low-pass filter cutoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid input for low-pass filter cutoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if hicutoff>=fs/2 - beep; - msgboxText = ['Filtring - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The low-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if gui_erp_filtering.hp_tog.Value ==0 if hicutoff<0.001 - beep; - msgboxText = ['Filtring - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - We strongly recommend the low-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end - end if gui_erp_filtering.hp_tog.Value ==1 if length(locutoff)~=1 - beep; - msgboxText = ['Filtring - Invalid input for high-pass filter cutoff']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid input for high-pass filter cutoff']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if locutoff>=fs/2 - beep; - msgboxText = ['Filtring - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - The high-pass filter cutoff should be smaller than',32,num2str(fs/2),'Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if gui_erp_filtering.lp_tog.Value ==0 if locutoff<0.001 - beep; - msgboxText = ['Filtring - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - We strongly recommend the high-pass filter cutoff is larger than 0.001Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end - end - if gui_erp_filtering.hp_tog.Value ==1 && gui_erp_filtering.lp_tog.Value ==1 if locutoff==0 && hicutoff==0 - beep; - msgboxText = ['Filtring - Either Lowest bandpass cuttoff or the highest bandpass cuttoff or both is larger than 0.01Hz']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Either Lowest bandpass cuttoff or the highest bandpass cuttoff or both is larger than 0.01Hz']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end - if remove_dc==1 rdc = 'on'; else rdc = 'off'; end filterallch = def{5}; - if filterallch chanArray = 1:nchan; end - - fdesign = 'butter'; if ~strcmpi(fdesign, 'notch') && locutoff==0 && hicutoff>0 % Butter (IIR) and FIR%% low-pass filter ftype = 'lowpass'; @@ -727,212 +729,145 @@ function ERP_filter_apply(~,~) errorfound(msgboxText, title); return; else - beep; - msgboxText = ['Filtring - Invalid type of filter']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid type of filter']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; - end - erpworkingmemory('pop_filterp', {locutoff,hicutoff,filterorder,chanArray,filterallch,fdesign,remove_dc}); + estudioworkingmemory('pop_filterp', {locutoff,hicutoff,filterorder,chanArray,filterallch,fdesign,remove_dc}); - Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_erpset); + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray> length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan =S_binchan.checked_ERPset_Index; %%-------------loop start for filtering the selected ERPsets----------------------------------- - - erpworkingmemory('f_ERP_proces_messg','Filtering'); + estudioworkingmemory('f_ERP_proces_messg','Filtering'); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - ALLERPCOM = evalin('base','ALLERPCOM'); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + + estudioworkingmemory('ERPTab_filter',0); + gui_erp_filtering.apply.BackgroundColor = [1 1 1]; + gui_erp_filtering.apply.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [1 1 1]; + gui_erp_filtering.cancel.ForegroundColor = [0 0 0]; + gui_erp_filtering.advanced.BackgroundColor = [1 1 1]; + gui_erp_filtering.advanced.ForegroundColor = [0 0 0]; + + gui_erp_filtering.params{1} = gui_erp_filtering.all_bin_chan.Value; + gui_erp_filtering.params{2} = gui_erp_filtering.hp_tog.Value; + gui_erp_filtering.params{5} = gui_erp_filtering.lp_tog.Value; + gui_erp_filtering.params{3} = str2num(gui_erp_filtering.hp_halfamp.String); + gui_erp_filtering.params{6} = str2num(gui_erp_filtering.lp_halfamp.String); + gui_erp_filtering.params{4} = str2num(gui_erp_filtering.hp_halfpow.String); + gui_erp_filtering.params{7} = str2num(gui_erp_filtering.lp_halfpow.String); + gui_erp_filtering.params{8} =gui_erp_filtering.roll_off.Value; + gui_erp_filtering.params{9} = 0; - try - FilterMethod = 'filtered'; - if numel(Selected_erpset)>1 - - Answer = f_ERP_save_multi_file(observe_ERPDAT.ALLERP,Selected_erpset,FilterMethod); - if isempty(Answer) - beep; - disp('User selected Cancel'); - return; - end - - if ~isempty(Answer{1}) - ALLERP_advance = Answer{1}; - Save_file_label = Answer{2}; - end - - elseif numel(Selected_erpset)==1 - Save_file_label =0; - ALLERP_advance = observe_ERPDAT.ALLERP; + BinArray = []; + ChanArray = []; + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + if gui_erp_filtering.all_bin_chan.Value == 1 + BinArray = [1:observe_ERPDAT.ERP.nbin]; + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + else + BinArray = estudioworkingmemory('ERP_BinArray'); + ChanArray = estudioworkingmemory('ERP_ChanArray'); + end + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; end - BinArray = []; - ChanArray = []; - for Numoferp = 1:numel(Selected_erpset) - if Selected_erpset(Numoferp)> length(observe_ERPDAT.ALLERP) - beep; - msgboxText = ['Filtring - No corresponding ERP exists in ALLEERP']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - break; - end - - if (checked_ERPset_Index_bin_chan(1)==1 || checked_ERPset_Index_bin_chan(2)==2) && gui_erp_filtering.Selected_bin_chan.Value ==1 - if checked_ERPset_Index_bin_chan(1) ==1 - msgboxText = ['Number of bins across the selected ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(2)==2 - msgboxText = ['Number of channels across the selected ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(1)==1 && checked_ERPset_Index_bin_chan(2)==2 - msgboxText = ['Number of channels and bins vary across the selected ERPsets']; - end - question = [ '%s\n\n "All" will be active instead of "Selected bin and chan".']; - title = 'EStudio: Filtering'; - button = questdlg(sprintf(question, msgboxText), title,'OK','OK'); - BinArray = []; - ChanArray = []; - end - - ERP = ALLERP_advance(Selected_erpset(Numoferp)); - if (checked_ERPset_Index_bin_chan(1)==0 && checked_ERPset_Index_bin_chan(2)==0) && gui_erp_filtering.Selected_bin_chan.Value ==1 - try - BinArray = S_binchan.bins{1}; - ChanArray = S_binchan.elecs_shown{1}; - [chk, msgboxText] = f_ERP_chckbinandchan(ERP, BinArray, [],1); - if chk(1)==1 - BinArray = [1:ERP.nbin]; - end - [chk, msgboxText] = f_ERP_chckbinandchan(ERP,[], ChanArray,2); - if chk(2)==1 - ChanArray = [1:ERP.nchan]; - end - - catch - BinArray = [1:ERP.nbin]; - ChanArray = [1:ERP.nchan]; - end - end - - if gui_erp_filtering.all_bin_chan.Value == 1 - BinArray = [1:ERP.nbin]; - ChanArray = [1:ERP.nchan]; - end - ERP_AF = ERP; - %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. - [ERP, ERPCOM] = pop_filterp(ERP, chanArray, 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... - 'Saveas', 'off', 'History', 'gui'); - - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - if Numoferp==1 - [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - end - if ~isempty(BinArray)&& ~isempty(ChanArray) - try - ERP_AF.bindata(ChanArray,:,BinArray) = ERP.bindata(ChanArray,:,BinArray); - ERP.bindata = ERP_AF.bindata; - catch - ERP = ERP; - end - end - - if numel(Selected_erpset) ==1 - Answer = f_ERP_save_single_file(char(strcat(ERP.erpname,'_',FilterMethod)),ERP.filename,Selected_erpset(Numoferp)); - if isempty(Answer) - disp('User selected cancel.'); - return; - end - - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ''; - ERP.saved = 'no'; - elseif ~isempty(fileName_full) - - [pathstr, file_name, ext] = fileparts(fileName_full); - - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - ERP.saved = 'yes'; - %%----------save the current sdata as-------------------- - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - end - end - end - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - if Save_file_label - [pathstr, file_name, ext] = fileparts(ERP.filename); - ERP.filename = [file_name,'.erp']; - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - % [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - end - - + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = [1:ERP.nbin]; end - %%close the wait bar - % [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('ERPfilter',1); - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1:length(observe_ERPDAT.ALLERP)]; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. + [ERP, ERPCOM] = pop_filterp(ERP, ChanArray,'binArray',BinArray, 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1)=ERP; + end + end + + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_filt'); + if isempty(Answer) observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numoferp = 1:length(ALLERP_out) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [pathstr, file_name, ext] = fileparts(ERP.filename); + ERP.filename = [file_name,'.erp']; + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==length(ALLERP_out) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + observe_ERPDAT.ALLERP = ALLERP; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('ERPfilter',1); + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - Selected_ERP_afd =observe_ERPDAT.CURRENTERP; - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - erpworkingmemory('ERPfilter',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%%There is erros in processing procedure - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end %%-------------------Setting for advance option--------------------------- function advanced_ERP_filter(~,~) - - try - nchan = observe_ERPDAT.ERP.nchan; - fs = observe_ERPDAT.ERP.srate; - catch - fs = 256; - nchan = 30; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end + nchan = observe_ERPDAT.ERP.nchan; + fs = observe_ERPDAT.ERP.srate; + defx = {0 30 2 1:nchan 1 'butter' 0 []}; - def = erpworkingmemory('pop_filterp'); + def = estudioworkingmemory('pop_filterp'); if isempty(def) def = defx; @@ -953,75 +888,40 @@ function advanced_ERP_filter(~,~) end end - def{7} = gui_erp_filtering.DC_remove.Value; + def{7} = 0; def{8} = []; fdesign = 'butter'; def{3} = 2*gui_erp_filtering.roll_off.Value; def{6} = fdesign; - Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_erpset); + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + observe_ERPDAT.Count_currentERP=1; end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan =S_binchan.checked_ERPset_Index; - - BinArray = []; - ChanArray =[]; - - if checked_ERPset_Index_bin_chan(1) ==1 || checked_ERPset_Index_bin_chan(2) ==2 - BinArray = []; - ChanArray =[]; - def{5} =1; + if gui_erp_filtering.all_bin_chan.Value==0 + BinArray = estudioworkingmemory('ERP_BinArray'); + ChanArray = estudioworkingmemory('ERP_ChanArray'); else - try - BinArray = S_binchan.bins{1}; - ChanArray = S_binchan.elecs_shown{1}; - [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, BinArray, [],1); - if chk(1)==1 - BinArray = [1:observe_ERPDAT.ERP.nbin]; - end - [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP,[], ChanArray,2); - if chk(2)==1 - ChanArray = [1:observe_ERPDAT.ERP.nchan]; - end - - catch - BinArray = [1:observe_ERPDAT.ERP.nbin]; - ChanArray = [1:observe_ERPDAT.ERP.nchan]; - end - def{5} =0; - end - - - if (checked_ERPset_Index_bin_chan(1)==1 && checked_ERPset_Index_bin_chan(2)==2) - BinArray = []; - ChanArray = []; - end - - if (checked_ERPset_Index_bin_chan(1)==0 && checked_ERPset_Index_bin_chan(2)==0) && gui_erp_filtering.all_bin_chan.Value - BinArray = []; - ChanArray = []; + BinArray = 1:observe_ERPDAT.ERP.nbin; + ChanArray = 1:observe_ERPDAT.ERP.nchan; end + def{5} =0; def{9} = BinArray; def{4} = ChanArray; %%call the GUI for advance option answer = f_basicfilterGUI2(observe_ERPDAT.ERP, def); if isempty(answer) - beep; - disp('User selected Cancel') return; end defx = {answer{1},answer{2},answer{3},answer{4},answer{5},answer{6},answer{7},answer{8}}; - erpworkingmemory('pop_filterp',defx); - % erpworkingmemory('filterp_advanced', 1); + estudioworkingmemory('pop_filterp',defx); + locutoff = answer{1}; % for high pass filter hicutoff = answer{2}; % for low pass filter @@ -1032,11 +932,6 @@ function advanced_ERP_filter(~,~) remove_dc = answer{7}; BinArray = answer{9}; - if checked_ERPset_Index_bin_chan(1) ==1 || checked_ERPset_Index_bin_chan(2) ==2 - BinArray = []; - ChanArray =[]; - end - if locutoff >= fs/2 || locutoff< 0 locutoff = floor(fs/2)-1; end @@ -1057,7 +952,7 @@ function advanced_ERP_filter(~,~) gui_erp_filtering.roll_off.Value = filterorder/2; gui_erp_filtering.roll_off.String = {'12','24','36','48'}'; gui_erp_filtering.roll_off.Enable = 'on'; - gui_erp_filtering.DC_remove.Value = remove_dc; + % gui_erp_filtering.DC_remove.Value = remove_dc; %%High-pass filtering [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); if locutoff > 0 && (isempty(hicutoff) || hicutoff ==0 ) @@ -1126,192 +1021,222 @@ function advanced_ERP_filter(~,~) cutoff = hicutoff; elseif ~strcmpi(fdesign, 'notch') && locutoff==0 && hicutoff==0 % Butter (IIR) and FIR - msgboxText = 'I beg your pardon?'; - title = 'EStudio: f_ERP_filtering_GUI() !'; - errorfound(msgboxText, title); + msgboxText = 'Filtering - I beg your pardon?'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; else - beep; - msgboxText = ['Filtring - Invalid type of filter']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering - Invalid type of filter']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if strcmpi(fdesign, 'notch') && locutoff==hicutoff if 3*filterorder>=length(observe_ERPDAT.ERP.times) - beep; - msgboxText = ['Filtring -The length of the data must be more than three times the filter order']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Filtering -The length of the data must be more than three times the filter order']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end - - + gui_erp_filtering.params{1} = gui_erp_filtering.all_bin_chan.Value; + gui_erp_filtering.params{2} = gui_erp_filtering.hp_tog.Value; + gui_erp_filtering.params{5} = gui_erp_filtering.lp_tog.Value; + gui_erp_filtering.params{3} = str2num(gui_erp_filtering.hp_halfamp.String); + gui_erp_filtering.params{6} = str2num(gui_erp_filtering.lp_halfamp.String); + gui_erp_filtering.params{4} = str2num(gui_erp_filtering.hp_halfpow.String); + gui_erp_filtering.params{7} = str2num(gui_erp_filtering.lp_halfpow.String); + gui_erp_filtering.params{8} =gui_erp_filtering.roll_off.Value; + gui_erp_filtering.params{9} = 0; %%-------------loop start for filtering the selected ERPsets----------------------------------- - erpworkingmemory('f_ERP_proces_messg','Filtering (Advanced)'); + estudioworkingmemory('f_ERP_proces_messg','Filtering (Advanced)'); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - ALLERPCOM = evalin('base','ALLERPCOM'); - try - Suffix_label = 1; - FilterMethod_str = char(strcat('filtered')); - if numel(Selected_erpset)>1 - Answer = f_ERP_save_multi_file(observe_ERPDAT.ALLERP,Selected_erpset,FilterMethod_str); - if isempty(Answer) - beep; - disp('User selected Cancel'); - return; - end - - if ~isempty(Answer{1}) - ALLERP_advance = Answer{1}; - Save_file_label = Answer{2}; - end - - elseif numel(Selected_erpset)==1 - Save_file_label =0; - ALLERP_advance = observe_ERPDAT.ALLERP; + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + ALLERP_out = []; + ALLERP = observe_ERPDAT.ALLERP; + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; + end + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = [1:ERP.nbin]; end - for Numoferp = 1:numel(Selected_erpset) - - if Selected_erpset(Numoferp)> length(observe_ERPDAT.ALLERP) - beep; - msgboxText = ['Filtring - No corresponding ERP exists in ALLEERP']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - break; - end - - if (checked_ERPset_Index_bin_chan(1)==1 || checked_ERPset_Index_bin_chan(2)==2) && gui_erp_filtering.Selected_bin_chan.Value ==1 - if checked_ERPset_Index_bin_chan(1) ==1 - msgboxText = ['Number of bins across the selected ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(2)==2 - msgboxText = ['Number of channels across the selected ERPsets is different!']; - elseif checked_ERPset_Index_bin_chan(1)==1 && checked_ERPset_Index_bin_chan(2)==2 - msgboxText = ['Number of channels and bins vary across the selected ERPsets']; - end - question = [ '%s\n\n "All" will be active instead of "Selected bin and chan".']; - title = 'EStudio: Filtering'; - button = questdlg(sprintf(question, msgboxText), title,'OK','OK'); - BinArray = []; - ChanArray = []; - end - - if (checked_ERPset_Index_bin_chan(1)==0 && checked_ERPset_Index_bin_chan(2)==0) && gui_erp_filtering.Selected_bin_chan.Value ==1 - try - BinArray = S_binchan.bins{1}; - ChanArray = S_binchan.elecs_shown{1}; - catch - BinArray = [1:ERP.nbin]; - ChanArray = [1:ERP.nchan]; - end - end - - - ERP = ALLERP_advance(Selected_erpset(Numoferp)); - ERP_before_bl = ERP; - - [ERP, ERPCOM] = pop_filterp(ERP, [1:ERP.nchan], 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... - 'Saveas', 'off', 'History', 'gui'); + [ERP, ERPCOM] = pop_filterp(ERP, ChanArray,'binArray',BinArray, 'Filter',ftype, 'Design', fdesign, 'Cutoff', cutoff, 'Order', filterorder, 'RemoveDC', rdc,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - if Numoferp ==1 - [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - end - %%Only the slected bin and chan were selected to remove baseline and detrending and others are remiained. - if ~isempty(BinArray) && ~isempty(ChanArray) - try - ERP_before_bl.bindata(ChanArray,:,BinArray) = ERP.bindata(ChanArray,:,BinArray); - ERP.bindata = ERP_before_bl.bindata; - catch - ERP = ERP; - end - end - %%Rename single file------------------------------------ - if numel(Selected_erpset) ==1 - Answer = f_ERP_save_single_file(char(strcat(ERP.erpname,'_',FilterMethod_str)),ERP.filename,Selected_erpset(Numoferp)); - if isempty(Answer) - disp('User selected Cancel'); - return; - end - - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ''; - ERP.saved = 'no'; - elseif ~isempty(fileName_full) - [pathstr, file_name, ext] = fileparts(fileName_full); - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - ERP.saved = 'yes'; - %%----------save the current sdata as-------------------- - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - end - end - end - - if Save_file_label - [pathstr, file_name, ext] = fileparts(ERP.filename); - ERP.filename = [file_name,'.erp']; - ERP.saved = 'yes'; - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - else - - ERP.filename = ''; - ERP.saved = 'no'; - end - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; end - % [~, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('ERPfilter',1); - - try - Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1:length(observe_ERPDAT.ALLERP)]; - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(Selected_erpset)+1; - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + if isempty(ALLERP_out) + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + end + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_filt'); + if isempty(Answer) observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numoferp = 1:length(ALLERP_out) + ERP = ALLERP_out(Numoferp); + if Save_file_label==1 + [pathstr, file_name, ext] = fileparts(ERP.filename); + ERP.filename = [file_name,'.erp']; + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + observe_ERPDAT.ALLERP = ALLERP; + + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('ERPfilter',1); + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - Selected_ERP_afd =observe_ERPDAT.CURRENTERP; - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - erpworkingmemory('ERPfilter',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - - observe_ERPDAT.Process_messg =3; + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; + end + + +%%-------------------------------cancel------------------------------------ + function ERP_filter_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=5 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_filter',0); + gui_erp_filtering.apply.BackgroundColor = [1 1 1]; + gui_erp_filtering.apply.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [1 1 1]; + gui_erp_filtering.cancel.ForegroundColor = [0 0 0]; + gui_erp_filtering.advanced.BackgroundColor = [1 1 1]; + gui_erp_filtering.advanced.ForegroundColor = [0 0 0]; + + try allbin_chan = gui_erp_filtering.params{1}; catch allbin_chan=1; gui_erp_filtering.params{1}=1; end; + if isempty(allbin_chan) || numel(allbin_chan)~=1 || (allbin_chan~=0 && allbin_chan~=1) + allbin_chan=1; gui_erp_filtering.params{1}=1; + end + % + %%chans and bins + gui_erp_filtering.all_bin_chan.Value = allbin_chan; + gui_erp_filtering.Selected_bin_chan.Value = ~allbin_chan; + % + %%high-pass filter + try hp_tog= gui_erp_filtering.params{2};catch hp_tog=0; gui_erp_filtering.params{2}=1; end + if isempty(hp_tog) || numel(hp_tog)~=1 || (hp_tog~=0 && hp_tog~=1) + hp_tog=0; gui_erp_filtering.params{2}=1; + end + gui_erp_filtering.hp_tog.Value = hp_tog; + if hp_tog==0 + enableflag = 'off'; + else + enableflag = 'on'; + end + gui_erp_filtering.hp_halfamp.Enable = enableflag; + gui_erp_filtering.hp_halfpow.Enable = 'off'; + % + %%low pass filter + try lp_tog= gui_erp_filtering.params{5}; catch lp_tog=0; gui_erp_filtering.params{5}=0; end + if isempty(lp_tog) || numel(lp_tog)~=1 || (lp_tog~=0 && lp_tog~=1) + lp_tog=0; gui_erp_filtering.params{5}=0; + end + gui_erp_filtering.lp_tog.Value = lp_tog; + if lp_tog==0 + enableflag = 'off'; + else + enableflag = 'on'; + end + gui_erp_filtering.lp_halfpow.Enable = 'off'; + gui_erp_filtering.lp_halfamp.Enable = enableflag; + + try hp_halfamp = gui_erp_filtering.params{3}; catch hp_halfamp=[]; gui_erp_filtering.params{3}=[];end + if ~isnumeric(hp_halfamp) || isempty(hp_halfamp) || numel(hp_halfamp)~=1 + hp_halfamp=[];gui_erp_filtering.params{3}=[]; + end + gui_erp_filtering.hp_halfamp.String = num2str(hp_halfamp); + + try lp_halfamp= gui_erp_filtering.params{6}; catch lp_halfamp=[];gui_erp_filtering.params{6}=[]; end + if ~isnumeric(lp_halfamp) || isempty(lp_halfamp) || numel(lp_halfamp)~=1 + lp_halfamp=[];gui_erp_filtering.params{6}=[]; + end + gui_erp_filtering.lp_halfamp.String = num2str(lp_halfamp); + + try hp_halfpow = gui_erp_filtering.params{4}; catch hp_halfpow=[];gui_erp_filtering.params{4}=[]; end + if ~isnumeric(hp_halfpow) || isempty(hp_halfpow) || numel(hp_halfpow)~=1 + hp_halfpow=[];gui_erp_filtering.params{4}=[]; + end + gui_erp_filtering.hp_halfpow.String = num2str(hp_halfpow); + + try lp_halfpow = gui_erp_filtering.params{4}; catch lp_halfpow=[];gui_erp_filtering.params{7}=[]; end + if ~isnumeric(lp_halfpow) || isempty(lp_halfpow) || numel(lp_halfpow)~=1 + lp_halfpow=[];gui_erp_filtering.params{7}=[]; + end + gui_erp_filtering.lp_halfpow.String = num2str(lp_halfpow); + % + %%roll off? + try roll_off = gui_erp_filtering.params{8}; catch roll_off=1;gui_erp_filtering.params{8}=1; end + if isempty(roll_off) || numel(roll_off)~=1 || any(roll_off<1) || any(roll_off>4) + roll_off=1;gui_erp_filtering.params{8}=1; + end + gui_erp_filtering.roll_off.Value=roll_off; + % + %%remove DC? + try DC_remove = gui_erp_filtering.params{9}; catch DC_remove =1; gui_erp_filtering.params{9}=1; end + if isempty(DC_remove) || numel(DC_remove)~=1 || (DC_remove~=0 && DC_remove~=1) + DC_remove =1; gui_erp_filtering.params{9}=1; + end + end %%-------------------Setting for the whole panel of fitering based on ALLERP and CURRENTERP-------------- function Count_currentERPChanged(~,~) - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') + if observe_ERPDAT.Count_currentERP~=10 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 gui_erp_filtering.apply.Enable = 'off'; gui_erp_filtering.advanced.Enable = 'off'; gui_erp_filtering.roll_off.Enable = 'off'; @@ -1321,8 +1246,12 @@ function Count_currentERPChanged(~,~) gui_erp_filtering.lp_tog.Enable = 'off'; gui_erp_filtering.all_bin_chan.Enable = 'off'; gui_erp_filtering.Selected_bin_chan.Enable = 'off'; + gui_erp_filtering.cancel.Enable = 'off'; + observe_ERPDAT.Count_currentERP=11; + return; else - + % gui_erp_filtering.DC_remove.Enable = 'on'; + gui_erp_filtering.cancel.Enable = 'on'; gui_erp_filtering.all_bin_chan.Enable = 'on'; gui_erp_filtering.Selected_bin_chan.Enable = 'on'; locutoff = str2num(gui_erp_filtering.hp_halfamp.String);%%for high pass filter @@ -1378,7 +1307,6 @@ function Count_currentERPChanged(~,~) lp_halfamp_Enable = 'off'; lp_halfpow_string ='0'; end - gui_erp_filtering.apply.Enable = 'on'; gui_erp_filtering.advanced.Enable = 'on'; gui_erp_filtering.roll_off.Enable = 'on'; @@ -1388,25 +1316,13 @@ function Count_currentERPChanged(~,~) gui_erp_filtering.lp_halfamp.Enable = lp_halfamp_Enable; gui_erp_filtering.hp_tog.Value = highpass_toggle_value; gui_erp_filtering.lp_tog.Value = lowpass_toggle_value; - gui_erp_filtering.hp_tog.Enable = 'on'; gui_erp_filtering.lp_tog.Enable = 'on'; - try - S_ws = evalin('base','S'); - Selected_erpset = S_ws.geterpset.selectederp; - catch - Selected_erpset = observe_ERPDAT.CURRENTERP; - end - + ERPArray = observe_ERPDAT.CURRENTERP; Check_Selected_erpset = [0 0 0 0 0 0 0]; - if numel(Selected_erpset)>1 - try - S_ws = evalin('base','S'); - Check_Selected_erpset = S_binchan.checked_ERPset_Index; - catch - Check_Selected_erpset = f_checkerpsets(observe_ERPDAT.ALLERP,Selected_erpset); - end + if numel(ERPArray)>1 + Check_Selected_erpset = f_checkerpsets(observe_ERPDAT.ALLERP,ERPArray); end if Check_Selected_erpset(1) ==1 || Check_Selected_erpset(2) == 2 gui_erp_filtering.Selected_bin_chan.Value =0; @@ -1414,10 +1330,70 @@ function Count_currentERPChanged(~,~) gui_erp_filtering.all_bin_chan.Value = 1; gui_erp_filtering.all_bin_chan.Enable = 'on'; end - + observe_ERPDAT.Count_currentERP=11; end end +%%--------------press return to execute "Apply"---------------------------- + function erp_filter_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_filter'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + ERP_filter_apply(); + estudioworkingmemory('ERPTab_filter',0); + gui_erp_filtering.apply.BackgroundColor = [1 1 1]; + gui_erp_filtering.apply.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [1 1 1]; + gui_erp_filtering.cancel.ForegroundColor = [0 0 0]; + gui_erp_filtering.advanced.BackgroundColor = [1 1 1]; + gui_erp_filtering.advanced.ForegroundColor = [0 0 0]; + else + return; + end + end + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=7 + return; + end + estudioworkingmemory('ERPTab_filter',0); + gui_erp_filtering.apply.BackgroundColor = [1 1 1]; + gui_erp_filtering.apply.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [ 0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_filtering.cancel.BackgroundColor = [1 1 1]; + gui_erp_filtering.cancel.ForegroundColor = [0 0 0]; + gui_erp_filtering.advanced.BackgroundColor = [1 1 1]; + gui_erp_filtering.advanced.ForegroundColor = [0 0 0]; + gui_erp_filtering.all_bin_chan.Value = 1; + gui_erp_filtering.Selected_bin_chan.Value = 0; + gui_erp_filtering.roll_off.Value=1; + try + fs = observe_ERPDAT.ERP.srate; + catch + fs = 256; + end + if fs <=0 + fs = 256; + end + + typef = 0; + hicutoff = 30; + locutoff = 0; + filterorder = 2*gui_erp_filtering.roll_off.Value; + [bt, at, labelf, v, frec3dB, xdB_at_fx, orderx] = filter_tf(typef, filterorder, hicutoff,locutoff,fs); + gui_erp_filtering.hp_halfpow.String = '---'; + gui_erp_filtering.lp_halfpow.String = num2str(roundn(frec3dB,-2)); + gui_erp_filtering.hp_halfamp.Enable = 'off'; + gui_erp_filtering.lp_halfamp.Enable = 'on'; + gui_erp_filtering.hp_halfamp.String = '0'; + gui_erp_filtering.lp_halfamp.String = '30'; + gui_erp_filtering.hp_tog.Value = 0; + gui_erp_filtering.lp_tog.Value = 1; + observe_ERPDAT.Reset_erp_paras_panel=8; + end end -%Progem end: ERP Measurement tool \ No newline at end of file +%Progem end: \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_grandaverageGUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_grandaverageGUI.m index 99e0061d..8783a2de 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_grandaverageGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_grandaverageGUI.m @@ -2,27 +2,30 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && Nov. 2023 % ERPLAB Studio function varargout = f_ERP_grandaverageGUI(varargin) global observe_ERPDAT; addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); gui_erp_grdavg = struct(); - %-----------------------------Name the title---------------------------------------------- -% global ERP_grdavg_gui; +% global ERP_grdavg_box_gui; [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; if nargin == 0 fig = figure(); % Parent figure - ERP_grdavg_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Average across ERPsets ', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_grdavg_box_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Average Across ERPsets (Grand Average)', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel tool_link elseif nargin == 1 - ERP_grdavg_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Average across ERPsets ', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_grdavg_box_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Average Across ERPsets (Grand Average)',... + 'Padding', 5,'BackgroundColor',ColorB_def); else - ERP_grdavg_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Average across ERPsets ', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_grdavg_box_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Average Across ERPsets (Grand Average)',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @tool_link end %-----------------------------Draw the panel------------------------------------- @@ -32,68 +35,75 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_bin_operation(FonsizeDefault) -varargout{1} = ERP_grdavg_gui; +varargout{1} = ERP_grdavg_box_gui; function drawui_erp_bin_operation(FonsizeDefault) FontSize_defualt = FonsizeDefault; - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end + Enable_label = 'off'; [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; %%--------------------channel and bin setting---------------------- - gui_erp_grdavg.DataSelBox = uiextras.VBox('Parent', ERP_grdavg_gui,'BackgroundColor',ColorB_def); + gui_erp_grdavg.DataSelBox = uiextras.VBox('Parent', ERP_grdavg_box_gui,'BackgroundColor',ColorB_def); %%Parameters gui_erp_grdavg.weigavg_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_grdavg.weigavg = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.weigavg_title,... - 'String','Use weighted average based on trial numbers','Value',0,... + 'String','Use weighted average based on trial numbers','Value',0,'Enable','off',... 'callback',@checkbox_weigavg,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + gui_erp_grdavg.weigavg.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{1} = gui_erp_grdavg.weigavg.Value; gui_erp_grdavg.excldnullbin_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_grdavg.excldnullbin = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.excldnullbin_title,... - 'String','','Value',0,'Enable','off','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + 'callback',@excldnullbin,'String','','Value',1,'Enable','off','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F gui_erp_grdavg.excldnullbin.String = 'Exclude any null bin from non-weighted
                            averaing (recommended)'; - + gui_erp_grdavg.excldnullbin.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{2} = gui_erp_grdavg.excldnullbin.Value; gui_erp_grdavg.jacknife_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_grdavg.jacknife = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.jacknife_title,... - 'String','','Value',0,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + 'String','','callback',@jacknife,'Value',0,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def,'Enable','off'); % 2F gui_erp_grdavg.jacknife.String = 'Include Jackknife subaverages (creates
                            multiple ERPsets)'; - + gui_erp_grdavg.jacknife.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{3} = gui_erp_grdavg.jacknife.Value; gui_erp_grdavg.warn_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_grdavg.warn = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.warn_title,... + gui_erp_grdavg.warn = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.warn_title,'Enable','off',... 'String','','Value',0,'callback',@checkbox_warn,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + gui_erp_grdavg.warn.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{4} = gui_erp_grdavg.warn.Value; gui_erp_grdavg.warn.String = 'Warning if any subjects who exceed
                            the epoch rejection threshold (%) '; - gui_erp_grdavg.warn_edit = uicontrol('Style','edit','Parent', gui_erp_grdavg.warn_title,... + gui_erp_grdavg.warn_edit = uicontrol('Style','edit','Parent', gui_erp_grdavg.warn_title,'Enable','off',... 'String','','callback',@warn_edit,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F - % set(gui_erp_grdavg.hr_title,'Sizes',[210,50]); + gui_erp_grdavg.warn_edit.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{5} = str2num(gui_erp_grdavg.warn_edit.String); set(gui_erp_grdavg.warn_title,'Sizes',[220,70]); gui_erp_grdavg.cmpsd_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_grdavg.cmpsd = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.cmpsd_title,... + gui_erp_grdavg.cmpsd = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.cmpsd_title,'Enable','off',... 'String','Compute point-by-point SEM','Value',1,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F - - + gui_erp_grdavg.cmpsd.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{6} = gui_erp_grdavg.cmpsd.Value; gui_erp_grdavg.cbdatq_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_grdavg.cbdatq = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.cbdatq_title,... + gui_erp_grdavg.cbdatq = uicontrol('Style','checkbox','Parent', gui_erp_grdavg.cbdatq_title,'Enable','off',... 'String','','Value',1,'callback',@checkbox_cbdatq,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F gui_erp_grdavg.cbdatq.String = 'Combine data
                            quality measures '; + gui_erp_grdavg.cbdatq.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{7} = gui_erp_grdavg.cbdatq.Value; - gui_erp_grdavg.cbdatq_def = uicontrol('Style','radiobutton','Parent', gui_erp_grdavg.cbdatq_title,... + gui_erp_grdavg.cbdatq_def = uicontrol('Style','radiobutton','Parent', gui_erp_grdavg.cbdatq_title,'Enable','off',... 'String','defaults','Value',1,'callback',@cbdatq_def,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + gui_erp_grdavg.cbdatq_def.KeyPressFcn = @erp_graverage_presskey; + gui_erp_grdavg.paras{8} = gui_erp_grdavg.cbdatq_def.Value; - gui_erp_grdavg.cbdatq_custom = uicontrol('Style','radiobutton','Parent', gui_erp_grdavg.cbdatq_title,... + gui_erp_grdavg.cbdatq_custom = uicontrol('Style','radiobutton','Parent', gui_erp_grdavg.cbdatq_title,'Enable','off',... 'String','custom combo','Value',0,'callback',@cbdatq_custom,'FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F gui_erp_grdavg.cbdatq_custom.String = 'custom
                            combo '; set(gui_erp_grdavg.cbdatq_title,'Sizes',[120 70 70]); + gui_erp_grdavg.cbdatq_custom.KeyPressFcn = @erp_graverage_presskey; gui_erp_grdavg.cbdatq_custom_option_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_grdavg.cbdatq_custom_option_title); @@ -102,27 +112,40 @@ function drawui_erp_bin_operation(FonsizeDefault) gui_erp_grdavg.location_title = uiextras.HBox('Parent', gui_erp_grdavg.DataSelBox,'BackgroundColor',ColorB_def); uiextras.Empty('Parent',gui_erp_grdavg.location_title); - uicontrol('Style','pushbutton','Parent',gui_erp_grdavg.location_title,... - 'String','?','callback',@tool_link,'FontSize',16,'BackgroundColor',[1 1 1],'Max',10); % 2F + gui_erp_grdavg.cancel = uicontrol('Style','pushbutton','Parent',gui_erp_grdavg.location_title,'Enable','off',... + 'String','Cancel','callback',@average_cancel,'FontSize',FontSize_defualt,'BackgroundColor',[1 1 1],'Max',10); % 2F uiextras.Empty('Parent',gui_erp_grdavg.location_title); - gui_erp_grdavg.run = uicontrol('Style','pushbutton','Parent',gui_erp_grdavg.location_title,... - 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label); + gui_erp_grdavg.run = uicontrol('Style','pushbutton','Parent',gui_erp_grdavg.location_title,'Enable','off',... + 'String','Run','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); uiextras.Empty('Parent',gui_erp_grdavg.location_title); set(gui_erp_grdavg.location_title,'Sizes',[20 95 30 95 20]); set(gui_erp_grdavg.DataSelBox,'Sizes',[25,30,30,30,25,30,25,30]); + estudioworkingmemory('ERPTab_gravg',0); + end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% - - %%---------------checkbox for weighted average----------------------------- function checkbox_weigavg(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; if ~source.Value set(gui_erp_grdavg.excldnullbin,'Enable','on','Value',0); else @@ -130,8 +153,59 @@ function checkbox_weigavg(source,~) end end + function jacknife(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; + end + +%%------------------------------------------------------------------------- + function excldnullbin(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; + end %%-------------------checkbox for warning---------------------------------- function checkbox_warn(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; if ~source.Value gui_erp_grdavg.warn_edit.Enable = 'off'; else @@ -142,6 +216,21 @@ function checkbox_warn(source,~) %%%%----------------checkbox for combining data quality measures----------- function checkbox_cbdatq(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; checkad = source.Value; if checkad gui_erp_grdavg.cbdatq_custom.Value = 0; @@ -157,6 +246,21 @@ function checkbox_cbdatq(source,~) end %%%%----------------default setting for combining data quality measures---- function cbdatq_def(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; gui_erp_grdavg.cbdatq_custom.Value = 0; gui_erp_grdavg.cbdatq_def.Value = 1; gui_erp_grdavg.cbdatq_custom_op.Enable = 'off'; @@ -164,6 +268,21 @@ function cbdatq_def(~,~) %%%%----------------Custom setting for combining data quality measures---- function cbdatq_custom(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; gui_erp_grdavg.cbdatq_custom.Value = 1; gui_erp_grdavg.cbdatq_def.Value = 0; gui_erp_grdavg.cbdatq_custom_op.Enable = 'on'; @@ -171,99 +290,203 @@ function cbdatq_custom(~,~) %%-----------------define the epoch rejection threshold (%) ---------------------------- function warn_edit(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; rejection_peft = str2num(source.String); if isempty(rejection_peft) gui_erp_grdavg.warn_edit.String = ''; - beep; - msgboxText = ['Average across ERPsets - Invalid artifact detection proportion.\n'... + msgboxText = ['Average Across ERPsets (Grand Average) - Invalid artifact detection proportion.',32,... 'Please, enter a number between 0 and 100.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if rejection_peft<0 || rejection_peft>100 gui_erp_grdavg.warn_edit.String = ''; - beep; - msgboxText = ['Average across ERPsets - Invalid artifact detection proportion.\n'... + msgboxText = ['Average Across ERPsets (Grand Average) - Invalid artifact detection proportion.',32,... 'Please, enter a number between 0 and 100.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end %%-----------Setting for custom DQ combo---------------------------------- function cbdatq_custom_op(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',1); + gui_erp_grdavg.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_grdavg.run.ForegroundColor = [1 1 1]; + ERP_grdavg_box_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_grdavg.cancel.ForegroundColor = [1 1 1]; + + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + estudioworkingmemory('selectederpstudio',ERPArray); + end - GAv_combo_defaults.measures = [1, 2, 3]; % Use first 3 DQ measures - GAv_combo_defaults.methods = [2, 2, 2]; % Use the 2nd combo method, Root-Mean Square, for each - GAv_combo_defaults.measure_names = {'Baseline Measure - SD';'Point-wise SEM'; 'aSME'}; - GAv_combo_defaults.method_names = {'Pool ERPSETs, GrandAvg mean','Pool ERPSETs, GrandAvg RMS'}; - GAv_combo_defaults.str = {'Baseline Measure - SD, GrandAvg RMS';'Point-wise SEM, GrandAvg RMS'; 'aSME GrandAvg RMS'}; - custom_spec = grandaverager_DQ(GAv_combo_defaults); + custom_spec = grandaverager_DQ(observe_ERPDAT.ALLERP(ERPArray)); estudioworkingmemory('grandavg_custom_DQ',custom_spec); end -%%---------------------CSD tool link------------------------------------- - function tool_link(~,~) - web('https://github.com/lucklab/erplab/wiki/Averaging-Across-ERPSETS-_-Creating-Grand-Averages','-browser'); - end +%%--------------------------------cancel----------------------------------- + function average_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_gravg',0); + gui_erp_grdavg.run.BackgroundColor = [1 1 1]; + gui_erp_grdavg.run.ForegroundColor = [0 0 0]; + ERP_grdavg_box_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [1 1 1]; + gui_erp_grdavg.cancel.ForegroundColor = [0 0 0]; + try weigavg = gui_erp_grdavg.paras{1}; catch weigavg=0; gui_erp_grdavg.paras{1}=0; end + if isempty(weigavg) || numel(weigavg)~=1 || (weigavg~=0 && weigavg~=1) + gui_erp_grdavg.paras{1}=0;weigavg=0; + end + gui_erp_grdavg.weigavg.Value=weigavg; + if ~weigavg + set(gui_erp_grdavg.excldnullbin,'Enable','on','Value',0); + else + set(gui_erp_grdavg.excldnullbin,'Enable','off','Value',0); + end + try excldnullbin = gui_erp_grdavg.paras{2}; catch excldnullbin=0; gui_erp_grdavg.paras{2}=0; end + if isempty(excldnullbin) || numel(excldnullbin)~=1 || (excldnullbin~=0 && excldnullbin~=1) + gui_erp_grdavg.paras{2}=0;excldnullbin=0; + end + gui_erp_grdavg.excldnullbin.Value=excldnullbin; + + try jacknife = gui_erp_grdavg.paras{3}; catch jacknife=0; gui_erp_grdavg.paras{3}=0; end + if isempty(jacknife) || numel(jacknife)~=1 || (jacknife~=0 && jacknife~=1) + gui_erp_grdavg.paras{3}=0;jacknife=0; + end + gui_erp_grdavg.jacknife.Value =jacknife; + + try warnValue = gui_erp_grdavg.paras{4}; catch warnValue=0; gui_erp_grdavg.paras{4}=0; end + if isempty(warnValue) || numel(warnValue)~=1 || (warnValue~=0 && warnValue~=1) + gui_erp_grdavg.paras{4}=0;warnValue=0; + end + gui_erp_grdavg.warn.Value=warnValue; + if warnValue==1 + gui_erp_grdavg.warn_edit.Enable = 'on'; + else + gui_erp_grdavg.warn_edit.Enable = 'off'; + end + try warn_edit = gui_erp_grdavg.paras{5}; catch warn_edit=[]; gui_erp_grdavg.paras{5}=[]; end + if numel(warn_edit)~=1 || any(warn_edit>100) || any(warn_edit<0) + warn_edit=[]; gui_erp_grdavg.paras{5}=[]; + end + gui_erp_grdavg.warn_edit.String = num2str(warn_edit); + + try cmpsd = gui_erp_grdavg.paras{6}; catch cmpsd=1; gui_erp_grdavg.paras{6}=1; end + if isempty(cmpsd) || numel(cmpsd)~=1 || (cmpsd~=0 && cmpsd~=1) + gui_erp_grdavg.paras{6}=1;cmpsd=1; + end + gui_erp_grdavg.cmpsd.Value =cmpsd; + + try cbdatq = gui_erp_grdavg.paras{7}; catch cbdatq=1; gui_erp_grdavg.paras{7}=1; end + if isempty(cbdatq) || numel(cbdatq)~=1 || (cbdatq~=0 && cbdatq~=1) + gui_erp_grdavg.paras{7}=1;cbdatq=1; + end + gui_erp_grdavg.cbdatq.Value=cbdatq; + + try cbdatq_def = gui_erp_grdavg.paras{8}; catch cbdatq_def=1; gui_erp_grdavg.paras{8}=1; end + if isempty(cbdatq_def) || numel(cbdatq_def)~=1 || (cbdatq_def~=0 && cbdatq_def~=1) + gui_erp_grdavg.paras{8}=0;cbdatq_def=1; + end + gui_erp_grdavg.cbdatq_def.Value=cbdatq_def; + gui_erp_grdavg.cbdatq_custom.Value= ~cbdatq_def; + if cbdatq_def==1 + gui_erp_grdavg.cbdatq_custom_op.Enable = 'off'; + else + gui_erp_grdavg.cbdatq_custom_op.Enable = 'on'; + end + end %%---------------------Run------------------------------------------------- function apply_run(~,~) - pathName_def = erpworkingmemory('ERP_save_folder'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=11 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + pathName_def = estudioworkingmemory('EEG_save_folder'); if isempty(pathName_def) pathName_def =cd; end - - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - beep; - msgboxText = ['Average across ERPsets - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + estudioworkingmemory('selectederpstudio',ERPArray); end - - if numel(Selectederp_Index)<2 - beep; - msgboxText = ['Average across ERPsets - Two ERPsets,at least,were selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if numel(ERPArray)<2 + msgboxText = ['Average Across ERPsets (Grand Average) - Two ERPsets,at least,were selected']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end optioni = 0; %1 means from a filelist, 0 means from erpsets menu - - erpset = Selectederp_Index; + erpset = ERPArray; if gui_erp_grdavg.warn.Value artcrite = str2num(gui_erp_grdavg.warn_edit.String); else artcrite = 100; end - if isempty(artcrite) || artcrite<0 || artcrite>100 - beep; - msgboxText = ['Average across ERPsets - Invalid artifact detection proportion.\n'... + msgboxText = ['Average Across ERPsets (Grand Average) - Invalid artifact detection proportion.',32,... 'Please, enter a number between 0 and 100.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end + estudioworkingmemory('ERPTab_gravg',0); + gui_erp_grdavg.run.BackgroundColor = [1 1 1]; + gui_erp_grdavg.run.ForegroundColor = [0 0 0]; + ERP_grdavg_box_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [1 1 1]; + gui_erp_grdavg.cancel.ForegroundColor = [0 0 0]; %%Send message to Message panel - erpworkingmemory('f_ERP_proces_messg','Average across ERPsets'); + estudioworkingmemory('f_ERP_proces_messg','Average Across ERPsets (Grand Average) '); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. Weightedg = gui_erp_grdavg.weigavg.Value; @@ -272,13 +495,12 @@ function apply_run(~,~) stderror = gui_erp_grdavg.cmpsd.Value; % 0;1 jk = gui_erp_grdavg.jacknife.Value; % 0;1 if jk - Answer = f_ERP_save_single_file(strcat('_jackknife'),'',length(observe_ERPDAT.ALLERP)+1); + Answer = f_ERP_save_single_file(strcat('jackknife'),'',length(observe_ERPDAT.ALLERP)+1); else Answer = f_ERP_save_single_file(strcat('grand'),'',length(observe_ERPDAT.ALLERP)+1); end if isempty(Answer) - beep; - disp('User selectd cancal'); + observe_ERPDAT.Process_messg =2; return; end erpName_new = ''; @@ -295,7 +517,6 @@ function apply_run(~,~) fileName_new = ''; Save_file_label =0; elseif ~isempty(fileName_full) - [pathstr, file_name, ext] = fileparts(fileName_full); ext = '.erp'; if strcmp(pathstr,'') @@ -315,7 +536,6 @@ function apply_run(~,~) jkfilename = ''; % filename for JK grand averages end - GAv_combo_defaults.measures = [1, 2, 3]; % Use first 3 DQ measures GAv_combo_defaults.methods = [2, 2, 2]; % Use the 2nd combo method, Root-Mean Square, for each GAv_combo_defaults.measure_names = {'Baseline Measure - SD';'Point-wise SEM'; 'aSME'}; @@ -323,9 +543,9 @@ function apply_run(~,~) GAv_combo_defaults.str = {'Baseline Measure - SD, GrandAvg RMS';'Point-wise SEM, GrandAvg RMS'; 'aSME GrandAvg RMS'}; if ~gui_erp_grdavg.cbdatq.Value dq_option = 0; % data quality combine option. 0 - off, 1 - on/default, 2 - on/custom + dq_spec = GAv_combo_defaults; elseif gui_erp_grdavg.cbdatq.Value && gui_erp_grdavg.cbdatq_def.Value dq_option = 1; - dq_spec = GAv_combo_defaults; elseif gui_erp_grdavg.cbdatq.Value && gui_erp_grdavg.cbdatq_custom.Value dq_option = 2; @@ -356,97 +576,81 @@ function apply_run(~,~) Weightedstr = 'off'; end - ALLERPCOM = evalin('base','ALLERPCOM'); - try - ALLERP = observe_ERPDAT.ALLERP; - if jk==1 % Jackknife - - [ALLERP, ERPCOM] = pop_jkgaverager(ALLERP, 'Erpsets', erpset, 'Criterion', artcrite,... - 'SEM', stdsstr, 'Weighted', Weightedstr, 'Erpname', jkerpname, 'Filename', jkfilename,... - 'DQ_flag',dq_option,'DQ_spec',dq_spec,'Warning', wavgstr); - Selected_ERP_afd = setdiff([1:length(ALLERP)],[1:length(observe_ERPDAT.ALLERP)]); - observe_ERPDAT.ALLERP = ALLERP; - observe_ERPDAT.CURRENTERP = Selected_ERP_afd(1); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - - if Save_file_label==1 - for Numofselectederp =1:numel(Selected_ERP_afd) - ERP_save = observe_ERPDAT.ALLERP(Selected_ERP_afd(Numofselectederp)); - ERP_save.filepath = pathName_new; - [ERP, issave, ERPCOM] = pop_savemyerp(ERP_save, 'erpname', ERP_save.erpname, 'filename', ERP_save.erpname, 'filepath',ERP_save.filepath); - end - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end; + ALLERP = observe_ERPDAT.ALLERP; + if jk==1 % Jackknife + [ALLERP, ERPCOM] = pop_jkgaverager(ALLERP, 'Erpsets', erpset, 'Criterion', artcrite,... + 'SEM', stdsstr, 'Weighted', Weightedstr, 'Erpname', jkerpname, 'Filename', jkfilename,... + 'DQ_flag',dq_option,'DQ_spec',dq_spec,'Warning', wavgstr); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + + Selected_ERP_afd = setdiff([1:length(ALLERP)],[1:length(observe_ERPDAT.ALLERP)]); + + for Numoferp = 1:numel(Selected_ERP_afd) + if Numoferp ==numel(Selected_ERP_afd) + [ALLERP(Selected_ERP_afd(Numoferp)), ALLERPCOM] = erphistory(ALLERP(Selected_ERP_afd(Numoferp)), ALLERPCOM, ERPCOM,2); + else + [ALLERP(Selected_ERP_afd(Numoferp)), ALLERPCOM] = erphistory(ALLERP(Selected_ERP_afd(Numoferp)), ALLERPCOM, ERPCOM,1); end - - else - [ERP, ERPCOM] = pop_gaverager(ALLERP, 'Erpsets', erpset,'Criterion', artcrite, 'SEM', stdsstr,... - 'ExcludeNullBin', excnullbinstr,'Weighted', Weightedstr, 'Saveas', 'off',... - 'DQ_flag',dq_option,'DQ_spec',dq_spec,'Warning', wavgstr, 'History', 'gui'); - ERP.erpname = erpName_new; - ERP.filename = fileName_new; - ERP.filepath = pathName_new; - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - % [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - if Save_file_label==1 - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + + if Save_file_label==1 + for Numofselectederp =1:numel(Selected_ERP_afd) + ERP_save = observe_ERPDAT.ALLERP(Selected_ERP_afd(Numofselectederp)); + ERP_save.filepath = pathName_new; + [observe_ERPDAT.ALLERP(Selected_ERP_afd(Numofselectederp)), issave, ERPCOM] = pop_savemyerp(ERP_save, 'erpname', ERP_save.erpname, 'filename', ERP_save.erpname, 'filepath',ERP_save.filepath); end + [observe_ERPDAT.ALLERP(Selected_ERP_afd(Numofselectederp)), ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(Selected_ERP_afd(Numofselectederp)), ALLERPCOM, ERPCOM,2); end + observe_ERPDAT.ALLERP = ALLERP; + observe_ERPDAT.CURRENTERP = Selected_ERP_afd(1); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + else + [ERP, ERPCOM] = pop_gaverager(ALLERP, 'Erpsets', erpset,'Criterion', artcrite, 'SEM', stdsstr,... + 'ExcludeNullBin', excnullbinstr,'Weighted', Weightedstr, 'Saveas', 'off',... + 'DQ_flag',dq_option,'DQ_spec',dq_spec,'Warning', wavgstr, 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + ERP.erpname = erpName_new; + ERP.filename = fileName_new; + ERP.filepath = pathName_new; + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - catch - msgboxText = ['Please check all the parameters are correct!!!']; - title = 'EStudio: "Average across ERPsets" panel.'; - errorfound(sprintf(msgboxText), title); - observe_ERPDAT.Process_messg =3; - return; + if Save_file_label==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath,'History','implicit'); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + end + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + estudioworkingmemory('f_ERP_bin_opt',1); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - - if isempty(Selectederp_Index) - beep; - msgboxText = ['Average across ERPsets - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; + if observe_ERPDAT.Count_currentERP~=12 + return; end - - if isempty(checked_ERPset_Index) - checked_ERPset_Index = f_checkerpsets(observe_ERPDAT.ALLERP,Selectederp_Index); + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); end - if checked_curr_index || any(checked_ERPset_Index(:)) + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 Enable_label = 'off'; else Enable_label = 'on'; @@ -474,8 +678,56 @@ function Count_currentERPChanged(~,~) gui_erp_grdavg.cbdatq_custom.Enable = 'off'; gui_erp_grdavg.cbdatq_def.Enable = 'off'; end - gui_erp_grdavg.advanced.Enable = Enable_label; gui_erp_grdavg.run.Enable = Enable_label; + gui_erp_grdavg.cancel.Enable = Enable_label; + gui_erp_grdavg.cmpsd.Enable = Enable_label; + observe_ERPDAT.Count_currentERP=13; end + +%%--------------press return to execute "Apply"---------------------------- + function erp_graverage_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_mesuretool'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + apply_run(); + estudioworkingmemory('ERPTab_gravg',0); + gui_erp_grdavg.run.BackgroundColor = [1 1 1]; + gui_erp_grdavg.run.ForegroundColor = [0 0 0]; + ERP_grdavg_box_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [1 1 1]; + gui_erp_grdavg.cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + + + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=11 + return; + end + estudioworkingmemory('ERPTab_gravg',0); + gui_erp_grdavg.run.BackgroundColor = [1 1 1]; + gui_erp_grdavg.run.ForegroundColor = [0 0 0]; + ERP_grdavg_box_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_grdavg.cancel.BackgroundColor = [1 1 1]; + gui_erp_grdavg.cancel.ForegroundColor = [0 0 0]; + gui_erp_grdavg.weigavg.Value = 0; + gui_erp_grdavg.excldnullbin.Value = 1; + gui_erp_grdavg.jacknife.Value = 0; + gui_erp_grdavg.warn.Value = 0; + gui_erp_grdavg.cmpsd.Value = 1; + gui_erp_grdavg.cbdatq.Value = 1; + gui_erp_grdavg.cbdatq_custom.Value = 0; + gui_erp_grdavg.cbdatq_def.Value = 1; + gui_erp_grdavg.cbdatq_custom_op.Enable = 'off'; + gui_erp_grdavg.cbdatq_def.Enable = 'on'; + gui_erp_grdavg.cbdatq_custom.Enable = 'on'; + observe_ERPDAT.Reset_erp_paras_panel=12; + end + end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_history_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_history_GUI.m index 0b6cd3d7..da7b6320 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_history_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_history_GUI.m @@ -8,16 +8,10 @@ function varargout = f_ERP_history_GUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@onErpChanged); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - - +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); gui_erp_history = struct(); - %-----------------------------Name the title---------------------------------------------- -% global box_erp_history; try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; @@ -41,7 +35,7 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_history(FonsizeDefault); varargout{1} = box_erp_history; @@ -58,17 +52,10 @@ function drawui_erp_history(FonsizeDefault) gui_erp_history.erp_h_all = uicontrol('Style','radiobutton','Parent',gui_erp_history.erp_history_title,'String','Current ERPset',... - 'callback',@ERP_H_ALL,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2F - gui_erp_history.erp_h_EEG = uicontrol('Style','radiobutton','Parent', gui_erp_history.erp_history_title,'String','Current session',... - 'callback',@ERP_H_EEG,'Value',0,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2F - - % gui_erp_history.erp_h_erp = uicontrol('Style','radiobutton','Parent', gui_erp_history.erp_history_title,'String','ERP','callback',@ERP_H_ERP,'Value',0); % 2F - - try - ERP_history = observe_ERPDAT.ERP.history; - catch - ERP_history = []; - end + 'callback',@ERP_H_ALL,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','on'); % 2F + gui_erp_history.erp_h_current = uicontrol('Style','radiobutton','Parent', gui_erp_history.erp_history_title,'String','Current session',... + 'callback',@erp_h_current,'Value',0,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','on'); % 2F + ERP_history = []; if isempty(ERP_history) ERP_history = char('No history exist in the current ERPset'); end @@ -83,11 +70,15 @@ function drawui_erp_history(FonsizeDefault) 'ColumnWidth' , {total_len+2}, ... 'ColumnName' , {'Function call'}, ... 'RowName' , []); - set( gui_erp_history.DataSelBox,'Heights',[40 -1]); + %%save the scripts + gui_erp_history.save_history_title = uiextras.HBox('Parent', gui_erp_history.DataSelBox,'BackgroundColor',ColorB_def); + gui_erp_history.save_script = uicontrol('Style','pushbutton','Parent',gui_erp_history.save_history_title,... + 'String','Save history script','callback',@savescript,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); + gui_erp_history.show_cmd = uicontrol('Style','pushbutton','Parent',gui_erp_history.save_history_title,... + 'String','Show in cmd window','callback',@show_cmd,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); + set(gui_erp_history.DataSelBox,'Sizes',[40 -1 30]); end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% @@ -97,8 +88,7 @@ function drawui_erp_history(FonsizeDefault) function ERP_H_ALL(~,~) Source_value = 1; set(gui_erp_history.erp_h_all,'Value',Source_value); - set(gui_erp_history.erp_h_EEG,'Value',~Source_value); - + set(gui_erp_history.erp_h_current,'Value',~Source_value); %adding the relared history in dispaly panel hiscp_empty =0; try @@ -106,16 +96,6 @@ function ERP_H_ALL(~,~) catch ERP_history = []; end - % if isempty(ERP_history) - % hiscp_empty =1; - % ERP_history = {'No history exist in the current ERPset'}; - % end - % - % if hiscp_empty - % set(gui_erp_history.uitable,'Data', ERP_history); - % else - % set(gui_erp_history.uitable,'Data', strsplit(ERP_history(1,:), '\n')'); - % end if isempty(ERP_history) ERP_history = char('No history exist in the current ERPset'); @@ -125,16 +105,14 @@ function ERP_H_ALL(~,~) ERP_history_display = [ERP_history_display,strsplit(ERP_history(Numofrow,:), '\n')]; end set(gui_erp_history.uitable,'Data', ERP_history_display'); - set(gui_erp_history.DataSelBox,'Heights',[40 -1]); - set(gui_erp_history.DataSelBox,'Heights',[40 -1]); end - function ERP_H_EEG(~,~) + function erp_h_current(~,~) Source_value = 1; set(gui_erp_history.erp_h_all,'Value',~Source_value); - set(gui_erp_history.erp_h_EEG,'Value',Source_value); + set(gui_erp_history.erp_h_current,'Value',Source_value); %adding the relared history in dispaly panel try ERP_history = evalin('base','ALLERPCOM'); @@ -145,44 +123,54 @@ function ERP_H_EEG(~,~) if isempty(ERP_history) ERP_history = {'No command history was found in the current session'}; end - set(gui_erp_history.uitable,'Data',ERP_history); - set(gui_erp_history.DataSelBox,'Heights',[40 -1]); end - - -%%----------------------ALLERPsets change----------------------------------------- - function allErpChanged(~,~) +%%---------------------save history to script------------------------------ + function savescript(~,~) + if gui_erp_history.erp_h_all.Value==1 + if ~isempty(observe_ERPDAT.ERP) + MessageViewer= char(strcat('Save history script for the current ERPset')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=1; + LASTCOM = pop_saveh(observe_ERPDAT.ERP.history); + else + LASTCOM =''; + end + else + MessageViewer= char(strcat('Save history script for the current session')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=1; + try + erp_history = evalin('base','ALLERPCOM'); + erp_history = erp_history'; + catch + return; + end + LASTCOM = pop_saveh(erp_history); + end + fprintf(['\n',LASTCOM,'\n']); + observe_ERPDAT.Process_messg=2; end %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) -% try -% ERPloadIndex = estudioworkingmemory('ERPloadIndex'); -% catch -% ERPloadIndex =0; -% end -% if ERPloadIndex==1 -% ALLERPIN = evalin('base','ALLERP'); -% CURRENTERPIN = evalin('base','CURRENTERP'); -% observe_ERPDAT.ALLERP = ALLERPIN; -% observe_ERPDAT.CURRENTERP =CURRENTERPIN; -% try -% observe_ERPDAT.ERP = ALLERPIN(CURRENTERPIN); -% catch -% observe_ERPDAT.ERP = ALLERPIN(end); -% observe_ERPDAT.CURRENTERP =length(ALLERPIN); -% end -% end - - - %check which option was selected and then update the related - %information based on the current ERPset. + if observe_ERPDAT.Count_currentERP~=20 + return; + end + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') + Enableflag = 'on'; + else + Enableflag = 'on'; + end + gui_erp_history.save_script.Enable = Enableflag; + gui_erp_history.uitable.Enable = Enableflag; + gui_erp_history.erp_h_all.Enable = 'on'; + gui_erp_history.erp_h_current.Enable = 'on'; + gui_erp_history.show_cmd.Enable = Enableflag; if gui_erp_history.erp_h_all.Value ==1 - try ERP_history = observe_ERPDAT.ERP.history; catch @@ -196,9 +184,7 @@ function Count_currentERPChanged(~,~) ERP_history_display = [ERP_history_display,strsplit(ERP_history(Numofrow,:), '\n')]; end set(gui_erp_history.uitable,'Data', ERP_history_display'); - set(gui_erp_history.DataSelBox,'Heights',[40 -1]); else%% ALLERPCOM for current session - try ERP_history = evalin('base','ALLERPCOM'); ERP_history = ERP_history'; @@ -211,12 +197,100 @@ function Count_currentERPChanged(~,~) ERP_history = {'No command history was found in the current section'}; set(gui_erp_history.uitable,'Data',ERP_history); end - - set(gui_erp_history.DataSelBox,'Heights',[40 -1]); + end + if isempty(observe_ERPDAT.ERP) + gui_erp_history.erp_h_all.String = 'Current ERPset'; + else + gui_erp_history.erp_h_all.String = ['Current ERPset (',num2str(observe_ERPDAT.CURRENTERP),')']; + end + end + +%%-------------show history to command window------------------------------ + function show_cmd(~,~) + % if isempty(observe_ERPDAT.ERP) + % return; + % end + MessageViewer= char(strcat('History > Show in cmd window')); + estudioworkingmemory('f_EEG_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=1; + if gui_erp_history.erp_h_all.Value ==1 + try + ERP_history = observe_ERPDAT.ERP.history; + catch + ERP_history = []; + end + if isempty(ERP_history) + disp(['No command history']); + observe_ERPDAT.Process_messg=2; + return; + end + ERP_history_display = {}; + for Numofrow = 1:size(ERP_history,1) + ERP_history_display = [ERP_history_display,strsplit(ERP_history(Numofrow,:), '\n')]; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['**Command history**',32,datestr(datetime('now')),'\n']); + fprintf(['ERP name:',32,observe_ERPDAT.ERP.erpname,'\n\n']); + for ii = 1:length(ERP_history_display) + disp([ERP_history_display{ii}]); + end + fprintf( [repmat('-',1,100) '\n\n']); + else + try + ERP_history = evalin('base','ALLERPCOM'); + catch + ERP_history = ''; + end + if isempty(ERP_history) + disp(['No command history for current session']); + observe_ERPDAT.Process_messg=2; + return; + end + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['**Command history for current session**',32,datestr(datetime('now')),'\n\n']); + for ii = 1:length(ERP_history) + disp([ERP_history{ii}]); + end + fprintf( [repmat('-',1,100) '\n\n']); end + if isempty(observe_ERPDAT.ERP) + gui_erp_history.erp_h_all.String = 'Current ERPset'; + else + gui_erp_history.erp_h_all.String = ['Current ERPset (',num2str(observe_ERPDAT.CURRENTERP),')']; + end + observe_ERPDAT.Process_messg=2; end + + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=17 + return; + end + set(gui_erp_history.erp_h_all,'Value',1); + set(gui_erp_history.erp_h_current,'Value',0); + %adding the relared history in dispaly panel + hiscp_empty =0; + try + ERP_history = observe_ERPDAT.ERP.history; + catch + ERP_history = []; + end + + if isempty(ERP_history) + ERP_history = char('No history exist in the current ERPset'); + end + ERP_history_display = {}; + for Numofrow = 1:size(ERP_history,1) + ERP_history_display = [ERP_history_display,strsplit(ERP_history(Numofrow,:), '\n')]; + end + set(gui_erp_history.uitable,'Data', ERP_history_display'); + if isempty(observe_ERPDAT.ERP) + gui_erp_history.erp_h_all.String = 'Current ERPset'; + else + gui_erp_history.erp_h_all.String = ['Current ERPset (',num2str(observe_ERPDAT.CURRENTERP),')']; + end + end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_meas_basecorr.m b/studio_functions/GUIs/ERP Tab/f_ERP_meas_basecorr.m index ec7c1b53..8ed858c5 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_meas_basecorr.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_meas_basecorr.m @@ -64,8 +64,8 @@ function f_ERP_meas_basecorr_OpeningFcn(hObject, eventdata, handles, varargin) % set(handles.menuerp.Children, 'Enable','off'); % end -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - ERP Measurement Tool']) diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.fig b/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.fig index ccf145b4..8bb28b40 100755 Binary files a/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.fig and b/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.m b/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.m index fc043572..9c95bc86 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_meas_format_path.m @@ -22,7 +22,7 @@ % Edit the above text to modify the response to help f_ERP_meas_format_path -% Last Modified by GUIDE v2.5 07-Aug-2022 18:19:42 +% Last Modified by GUIDE v2.5 19-Feb-2024 15:16:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; @@ -51,10 +51,15 @@ function f_ERP_meas_format_path_OpeningFcn(hObject, eventdata, handles, varargin try foutputstr = varargin{1}; %% 1. long; 0 wide pathName= varargin{2}; - + inclate = varargin{3}; + send2ws = varargin{4}; + binlabop =varargin{5}; catch foutputstr = 1; %% 1. long; 0 wide pathName= cd; + inclate = 0; + send2ws = 0; + binlabop = 0; end handles.output = []; @@ -65,8 +70,8 @@ function f_ERP_meas_format_path_OpeningFcn(hObject, eventdata, handles, varargin set(handles.menuerp.Children, 'Enable','off'); end -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - ERP Measurement Tool']) @@ -80,6 +85,23 @@ function f_ERP_meas_format_path_OpeningFcn(hObject, eventdata, handles, varargin set(handles.radiobutton5_long, 'Value', 1); end set(handles.edit_filename, 'String', pathName); +if inclate==1 + set(handles.checkbox_latency, 'Value', 1); +else + set(handles.checkbox_latency, 'Value', 0); +end +if send2ws==1 + set(handles.checkbox_wks, 'Value', 1); +else + set(handles.checkbox_wks, 'Value', 0); +end + +if binlabop==1 + set(handles.checkbox_binlabel, 'Value', 1); +else + set(handles.checkbox_binlabel, 'Value', 0); +end + % % % Color GUI % % @@ -198,7 +220,6 @@ function pushbutton_browse_Callback(hObject, eventdata, handles) title,pathName); if isequal(filterindex,0) - disp('User selected Cancel'); return; else [px, fname, ext] = fileparts(filename); @@ -220,8 +241,7 @@ function pushbutton_browse_Callback(hObject, eventdata, handles) % --- Executes on button press in pushbutton_Cancel. function pushbutton_Cancel_Callback(hObject, eventdata, handles) handles.output = []; -beep; -disp('User selected Cancel') + % Update handles structure guidata(hObject, handles); uiresume(handles.gui_chassis); @@ -241,17 +261,22 @@ function pushbutton4_okay_Callback(hObject, eventdata, handles) Wide_fromat = (get(handles.radiobutton_wide, 'Value')); - Long_fromat = (get(handles.radiobutton5_long, 'Value')); - if Wide_fromat FileFormat = 1; elseif Long_fromat FileFormat = 0; end -handles.output = {FileFormat, Filename}; +inclate=handles.checkbox_latency.Value; + +send2ws=handles.checkbox_wks.Value; + +binlabop=handles.checkbox_binlabel.Value; + + +handles.output = {FileFormat, Filename,inclate,send2ws,binlabop}; % Update handles structure guidata(hObject, handles); @@ -273,3 +298,30 @@ function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) % The GUI is no longer waiting, just close it delete(handles.gui_chassis); end + + +% --- Executes on button press in checkbox_latency. +function checkbox_latency_Callback(hObject, eventdata, handles) +% hObject handle to checkbox_latency (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 checkbox_latency + + +% --- Executes on button press in checkbox_wks. +function checkbox_wks_Callback(hObject, eventdata, handles) +% hObject handle to checkbox_wks (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 checkbox_wks + + +% --- Executes on button press in checkbox_binlabel. +function checkbox_binlabel_Callback(hObject, eventdata, handles) +% hObject handle to checkbox_binlabel (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 checkbox_binlabel diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_measurement_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_measurement_GUI.m index b1da2e07..b8ab2ff5 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_measurement_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_measurement_GUI.m @@ -5,164 +5,19 @@ %Center for Mind and Brain % University of California, Davis %Davis, CA -% 2022 +% 2022 & Nov. 2023 function varargout = f_ERP_measurement_GUI(varargin) global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@erpschange); -% addlistener(observe_ERPDAT,'ERP_change',@drawui_CB); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); -addlistener(observe_ERPDAT,'ERP_chan_change',@ERP_chan_changed); -addlistener(observe_ERPDAT,'ERP_bin_change',@ERP_bin_changed); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERP_change); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); -%%Get the parameters for pop_geterpvalues used in the last time. -def_erpvalue = erpworkingmemory('pop_geterpvalues'); -try - ALLERP = evalin('base','ALLERP'); - CurrentERPSet = evalin('base','CURRENTERP'); -catch - return; -end - -if isstruct(ALLERP) - if ~iserpstruct(ALLERP(1)) - ALLERP = []; - nbinx = 1; - nchanx = 1; - else - nbinx = ALLERP(1).nbin; - nchanx = ALLERP(1).nchan; - end -else - ALLERP = []; - nbinx = 1; - nchanx = 1; -end - - - -if isempty(def_erpvalue) - if isempty(ALLERP) - inp1 = 1; %from hard drive - CurrentERPSet = []; - else - inp1 = 0; %from erpset menu - CurrentERPSet = 1:length(ALLERP); - end - - def_erpvalue = {inp1,CurrentERPSet,'',0,1:nbinx,1:nchanx,'meanbl',... - 1,3,'pre',1,1,5,0,0.5,0,0,0,'',0,1,1}; - -else - if ~isempty(ALLERP) - if isnumeric(def_erpvalue{2}) % JavierLC 11-17-11 - [uu, mm] = unique_bc2(def_erpvalue{2}, 'first'); - erpset_list_sorted = [def_erpvalue{2}(sort(mm))]; - %def_erpvalue{2} = def_erpvalue{2}(def_erpvalue{2}<=length(ALLERP)); - % non-empty check, axs jul17 - erpset_list = erpset_list_sorted(erpset_list_sorted<=length(ALLERP)); - if isempty(erpset_list) - % if nothing in list, just go with current - def_erpvalue{2} = CurrentERPSet; - else - def_erpvalue{2} = erpset_list; - end - - end - end -end - - -if def_erpvalue{11} == 0 - def_erpvalue{11} = 'off'; -else - def_erpvalue{11} = 'on'; -end - -if def_erpvalue{12} == 0 - def_erpvalue{12} = 'negative'; -else - def_erpvalue{12} = 'positive'; -end - -if def_erpvalue{14}==0 - def_erpvalue{14} = 'NaN'; -else - def_erpvalue{14} = 'absolute'; -end - -if def_erpvalue{16}==0 % Fractional area latency replacement - def_erpvalue{16} = 'NaN'; -else - if ismember_bc2({def_erpvalue{7}}, {'fareatlat', 'fninteglat','fareaplat','fareanlat'}) - def_erpvalue{16} = 'errormsg'; - else - def_erpvalue{16} = 'absolute'; - end -end - -if def_erpvalue{17} == 0 - def_erpvalue{17} = 'off'; -else - def_erpvalue{17} = 'on'; -end - -if def_erpvalue{18} == 0 - def_erpvalue{18} = 'wide'; -else - def_erpvalue{18} = 'long'; -end - - -if def_erpvalue{20} == 0 - def_erpvalue{20} = 'no'; -else - def_erpvalue{20} = 'yes'; -end - -% -S_IN = estudioworkingmemory('geterpvalues'); -if isempty(S_IN) - erpvalues_variables = {'geterpvalues','latency',def_erpvalue{4},... - 'binArray',def_erpvalue{5},... - 'chanArray', def_erpvalue{6},... - 'Erpsets', def_erpvalue{2},... - 'Measure',def_erpvalue{7},... - 'Component',def_erpvalue{8},... - 'Resolution', def_erpvalue{9},... - 'Baseline', def_erpvalue{10},... - 'Binlabel', def_erpvalue{11},... - 'Peakpolarity',def_erpvalue{12},... - 'Neighborhood', def_erpvalue{13},... - 'Peakreplace', def_erpvalue{14},... - 'Filename', def_erpvalue{3},... - 'Warning','on',... - 'SendtoWorkspace', def_erpvalue{17},... - 'Append', '',... - 'FileFormat', def_erpvalue{18},... - 'Afraction',def_erpvalue{15},... - 'Mlabel', def_erpvalue{19},... - 'Fracreplace', def_erpvalue{16},... - 'IncludeLat', def_erpvalue{20},... - 'InterpFactor', def_erpvalue{21},... - 'Viewer', 'off',... - 'PeakOnset',def_erpvalue{22},... - 'History', 'gui'}; - S_OUT = createrplabstudioparameters(S_IN,erpvalues_variables); - estudioworkingmemory('geterpvalues',S_OUT.geterpvalues); - S_IN = S_OUT.geterpvalues; -end -% end - - -EStudio_erp_m_t_p = S_IN; - - -%%---------------------------gui------------------------------------------- +ERPMTops = struct(); +%---------------------------gui------------------------------------------- try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch @@ -170,29 +25,28 @@ end if nargin == 0 fig = figure(); % Parent figure - erp_measurement_box = uiextras.BoxPanel('Parent', fig, 'Title', 'ERP Measurement Tool', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + erp_measurement_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Measurement Tool',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - erp_measurement_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Measurement Tool', 'Padding', 5,'BackgroundColor',ColorB_def); + erp_measurement_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Measurement Tool',... + 'Padding', 5,'BackgroundColor',ColorB_def); else - erp_measurement_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Measurement Tool', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + erp_measurement_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Measurement Tool',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @ERPmeasr_help end -ERPMTops = struct(); - try FonsizeDefault = varargin{2}; catch FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end erp_m_t_gui(FonsizeDefault); - - varargout{1} = erp_measurement_box; -%%********************Draw the GUI for ERP measurement tool***************** +%%********************Draw the GUI for Measurement Tool***************** function erp_m_t_gui(FonsizeDefault) try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; @@ -200,23 +54,8 @@ function erp_m_t_gui(FonsizeDefault) ColorB_def = [0.95 0.95 0.95]; end ERPMTops.mt = uiextras.VBox('Parent',erp_measurement_box,'Spacing',1,'BackgroundColor',ColorB_def); - try - SelectedIndex = EStudio_erp_m_t_p.Erpsets; - catch - SelectedIndex = observe_ERPDAT.CURRENTERP; - end - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; - end - checked_ERPset_Index = f_checkerpsets(observe_ERPDAT.ALLERP,SelectedIndex); - if checked_curr_index || any(checked_ERPset_Index) - Enable_label = 'off'; - else - Enable_label = 'on'; - end + Enable_label = 'off'; %%-----------------------Measurement type setting------------------- ERPMTops.measurement_type = uiextras.Grid('Parent',ERPMTops.mt,'Spacing',1,'BackgroundColor',ColorB_def); @@ -236,293 +75,288 @@ function erp_m_t_gui(FonsizeDefault) ERPMTops.tw_set_title = uicontrol('Style','text','Parent', ERPMTops.measurement_type,'String','Window:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); set(ERPMTops.tw_set_title,'HorizontalAlignment','left'); %%1F - ERPMTops.out_file_title = uicontrol('Style','text','Parent', ERPMTops.measurement_type,'String','File&Path:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPMTops.out_file_title = uicontrol('Style','text','Parent', ERPMTops.measurement_type,'String','Output:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); set(ERPMTops.out_file_title,'HorizontalAlignment','left'); - %%-----------------------------Setting for second column--------------- %%2A - mesurement_type = {'Mean amplitude between two fixed latencies','Local peak amplitude (Negative)','Local peak amplitude (Positive)','Local peak latency (Negative)',... - 'Local peak latency (Positive)','Fractional peak latency (Negative)','Fractional peak latency (Positive)','Fractional area latency: Rectified area (negative values become positive)',... - 'Fractional area latency: Numrical integration (area for negatives substracted from area for positives)',... - 'Fractional area latency: Area for negative waveforms (positive values will be zeroed)','Fractional area latency: Area for positive waveforms (negative values will be zeroed)',... - 'Numerical integration/Area between two fixed latencies: Rectified area (Negative values become positive)',... - 'Numerical integration/Area between two fixed latencies: Numerical intergration (area for negative substracted from area for positive)',... - 'Numerical integration/Area between two fixed latencies: Area for negative waveforms (positive values will be zeroed)',... - 'Numerical integration/Area between two fixed latencies: Area for positive waveforms (negative values will be zeroed)',... - 'Numerical integration/Area between two (automatically detected)zero-crossing latencies: Rectified area (Negative values become positive)',... - 'Numerical integration/Area between two (automatically detected)zero-crossing latencies: Numerical intergration (area for negative substracted from area for positive)',... - 'Numerical integration/Area between two (automatically detected)zero-crossing latencies: Area for negative waveforms (positive values will be zeroed)',... - 'Numerical integration/Area between two (automatically detected)zero-crossing latencies: Area for positive waveforms (negative values will be zeroed)',... - 'Instantaneous amplitude'}; - ERPMTops.m_t_type = uicontrol('Style', 'popup','Parent',ERPMTops.measurement_type,'String',mesurement_type,'callback',@Mesurement_type,'Enable',Enable_label,'FontSize',FonsizeDefault); - if isempty(EStudio_erp_m_t_p.Measure) || ~ischar(EStudio_erp_m_t_p.Measure) - EStudio_erp_m_t_p.Measure = 'meanbl'; - end - switch EStudio_erp_m_t_p.Measure%Find the label of the selected item, the defualt one is 1 (Mean amplitude between two fixed latencies) + mesurement_type = {'Mean Amp',... + 'Positive Peak Amp',... + 'Negative Peak Amp',... + 'Positive Peak Lat',... + 'Negative Peak Lat',... + 'Pos Frac Peak Lat',... + 'Neg Frac Peak Lat',... + 'Frac Area Lat (Rectified)',... + 'Frac Area Lat (Integral)',... + 'Frac Area Lat (Neg Area)',... + 'Frac Area Lat (Pos Area)',... + 'Rectified Area',... + 'Integral',... + 'Positive Area',... + 'Negative Area',... + 'Instantaneous Amp'}; + ERPMTops.m_t_type = uicontrol('Style', 'popup','Parent',ERPMTops.measurement_type,'String',mesurement_type,... + 'callback',@Mesurement_type,'Enable',Enable_label,'FontSize',FonsizeDefault); + %%Get the parameters for pop_geterpvalues used in the last time. + def_erpvalue = estudioworkingmemory('pop_geterpvalues'); + if isempty(def_erpvalue) + def_erpvalue = {0,1,'',0,[],[],'meanbl',... + 1,3,'pre',1,1,5,0,0.5,0,0,0,'',0,1,1}; + else + end + if def_erpvalue{11} == 0%%binlabop + def_erpvalue{11} = 'off'; + else + def_erpvalue{11} = 'on'; + end + + if def_erpvalue{12} == 0%%polpeak + def_erpvalue{12} = 'negative'; + else + def_erpvalue{12} = 'positive'; + end + + if def_erpvalue{14}==-1%%locpeakrep + def_erpvalue{14} = 'errormsg'; + elseif def_erpvalue{14}==0 + def_erpvalue{14} = 'NaN'; + else + def_erpvalue{14} = 'absolute'; + end + + if def_erpvalue{16}==0 % Fractional area latency replacement + def_erpvalue{16} = 'NaN'; + else + if ismember_bc2({def_erpvalue{7}}, {'fareatlat', 'fninteglat','fareanlat','fareaplat'}) + def_erpvalue{16} = 'errormsg'; + else + def_erpvalue{16} = 'absolute'; + end + end + + if def_erpvalue{17} == 0%%send to workspace + def_erpvalue{17} = 'off'; + else + def_erpvalue{17} = 'on'; + end + + if def_erpvalue{18} == 0%% file format + def_erpvalue{18} = 'wide'; + else + def_erpvalue{18} = 'long'; + end + + if def_erpvalue{20} == 0%%include used latency values for measurements like mean, peak, area... + def_erpvalue{20} = 'no'; + else + def_erpvalue{20} = 'yes'; + end + ERPMTops.def_erpvalue = def_erpvalue; + + try + Measure = ERPMTops.def_erpvalue{7}; + catch + Measure = 'meanbl'; + end + try Peakpolarity = ERPMTops.def_erpvalue{12}; catch Peakpolarity=1;end + if isempty(Peakpolarity) ||numel(Peakpolarity)~=1 || (Peakpolarity~=0 && Peakpolarity~=1) + Peakpolarity=1; + end + if Peakpolarity==1 + Polarity= 'positive'; + else + Polarity = 'negative'; + end + switch Measure%Find the label of the selected item, the defualt one is 1 (Mean amplitude between two fixed latencies) case 'meanbl'% Mean amplitude set(ERPMTops.m_t_type,'Value',1); - case 'peakampbl'% Local peak amplitude (P vs. N) - if strcmp(EStudio_erp_m_t_p.Peakpolarity,'positive') - set(ERPMTops.m_t_type,'Value',3); - else + case 'peakampbl'% Peak amplitude (P vs. N) + if strcmp(Polarity,'positive') set(ERPMTops.m_t_type,'Value',2); + else + set(ERPMTops.m_t_type,'Value',3); end case 'peaklatbl'%Peak latency (P vs. N) - if strcmp(EStudio_erp_m_t_p.Peakpolarity,'positive') - set(ERPMTops.m_t_type,'Value',5); - elseif strcmp(EStudio_erp_m_t_p.Peakpolarity,'negative') + if strcmp(Polarity,'positive') set(ERPMTops.m_t_type,'Value',4); + elseif strcmp(Polarity,'negative') + set(ERPMTops.m_t_type,'Value',5); end case 'fpeaklat'%Fractional Peak latency (P vs. N) - if strcmp(EStudio_erp_m_t_p.Peakpolarity,'positive') - set(ERPMTops.m_t_type,'Value',7); - elseif strcmp(EStudio_erp_m_t_p.Peakpolarity,'negative') + if strcmp(Polarity,'positive') set(ERPMTops.m_t_type,'Value',6); + elseif strcmp(Polarity,'negative') + set(ERPMTops.m_t_type,'Value',7); end otherwise%if the measurement type comes from Advanced option - MeasureName_other = {'fareatlat','fninteglat','fareaplat','fareanlat',... - 'areat','ninteg','areap','arean',... - 'areazt','nintegz','areazp','areazn',... - 'instabl'}; - [C,IA] = ismember_bc2({EStudio_erp_m_t_p.Measure}, MeasureName_other); - if any(IA) || isempty(IA) + MeasureName_other = {'fareatlat','fninteglat','fareanlat','fareaplat',... + 'areat','ninteg','areap','arean','instabl'}; + [C,IA] = ismember_bc2({Measure}, MeasureName_other); + if isempty(IA) set(ERPMTops.m_t_type,'Value',1); else set(ERPMTops.m_t_type,'Value',IA+7); end end + ERPMTops.Paras{1} = ERPMTops.m_t_type.Value; %%2B ERPset custom - SelectedERP_Index = estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) || max(SelectedERP_Index)> length(observe_ERPDAT.ALLERP) - ERPMTops.m_t_erpset = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String', '','callback',@erpset_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); % - else - ERPMTops.m_t_erpset = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String', num2str(vect2colon(SelectedERP_Index,'Sort','on')),'callback',@erpset_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); - end + ERPMTops.m_t_erpset = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String', '',... + 'callback',@erpset_custom,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % + ERPMTops.Paras{2} = str2num(ERPMTops.m_t_erpset.String); + ERPMTops.m_t_erpset.KeyPressFcn = @erp_mt_presskey; %%2C - if isempty(EStudio_erp_m_t_p.binArray) - ERP_CURRENT = evalin('base','ERP'); - if isempty(ERP_CURRENT.nbin) || any(ERP_CURRENT.nbin) - ERPMTops.m_t_bin = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String', [],'callback',@binSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); % - else - ERPMTops.m_t_bin = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String', num2str(vect2colon(1:ERP_CURRENT.nbin,'Sort','on')),'callback',@binSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); - end - else - ERPMTops.m_t_bin = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',num2str(vect2colon(EStudio_erp_m_t_p.binArray,'Sort','on')),'callback',@binSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); - end + ERPMTops.m_t_bin = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,... + 'String', '','callback',@binSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); % + ERPMTops.Paras{3} = str2num(ERPMTops.m_t_bin.String); + ERPMTops.m_t_bin.KeyPressFcn = @erp_mt_presskey; %%2D - if isempty(EStudio_erp_m_t_p.chanArray) || ~any(EStudio_erp_m_t_p.chanArray) - try - ERP_CURRENT = evalin('base','ERP'); - if isempty(ERP_CURRENT.chanArray) || any(ERP_CURRENT.chanArray) - ERPMTops.m_t_chan = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',[],'callback',@chanSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault);%vect2colon(observe_ERPDAT.ERP_chan,'Sort', 'on') - else - ERPMTops.m_t_chan = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',num2str(vect2colon(1:ERP_CURRENT.nchan,'Sort','on')),'callback',@chanSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); - end - catch - ERPMTops.m_t_chan = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',[],'callback',@chanSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); - end - else - ERPMTops.m_t_chan = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',num2str(vect2colon(EStudio_erp_m_t_p.chanArray,'Sort','on')),'callback',@chanSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault); - end + ERPMTops.m_t_chan = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,... + 'String','','callback',@chanSelect_custom,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]);%vect2colon(observe_ERPDAT.ERP_chan,'Sort', 'on') + ERPMTops.Paras{4} = str2num(ERPMTops.m_t_chan.String); + ERPMTops.m_t_chan.KeyPressFcn = @erp_mt_presskey; %%2E - if isempty(EStudio_erp_m_t_p.latency) - ERPMTops.m_t_TW = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String','0.000','callback',@t_w_set,'Enable',Enable_label,'FontSize',FonsizeDefault); - else - ERPMTops.m_t_TW = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',num2str(EStudio_erp_m_t_p.latency),'callback',@t_w_set,'Enable',Enable_label,'FontSize',FonsizeDefault); - end + ERPMTops.m_t_TW = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,... + 'String','','callback',@t_w_set,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPMTops.Paras{5} = str2num(ERPMTops.m_t_TW.String); + ERPMTops.m_t_TW.KeyPressFcn = @erp_mt_presskey; %%2F - if isempty(EStudio_erp_m_t_p.Filename) - ERPMTops.m_t_file = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String','','callback',@file_name_set,'Enable',Enable_label,'FontSize',FonsizeDefault); - else - ERPMTops.m_t_file = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,'String',EStudio_erp_m_t_p.Filename,'callback',@file_name_set,'Enable',Enable_label,'FontSize',FonsizeDefault); - end - + ERPMTops.m_t_file = uicontrol('Style', 'edit','Parent',ERPMTops.measurement_type,... + 'String','','callback',@file_name_set,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPMTops.Paras{6} = ERPMTops.m_t_file.String; + ERPMTops.m_t_file.KeyPressFcn = @erp_mt_presskey; %%-----------Setting for third column-------------------------------- %%3A - ERPMTops.m_t_type_ops = uicontrol('Style', 'pushbutton','Parent',ERPMTops.measurement_type,'String','Option','callback',@Mesurement_type_option,'Enable',Enable_label,'FontSize',FonsizeDefault); + ERPMTops.m_t_type_ops = uicontrol('Style', 'pushbutton','Parent',ERPMTops.measurement_type,... + 'String','Options','callback',@Mesurement_type_option,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %%3B - ERPMTops.m_t_erpset_ops = uicontrol('Style','pushbutton','Parent', ERPMTops.measurement_type,'String','Option','callback',@erpsetop,'Enable',Enable_label,'FontSize',FonsizeDefault); + ERPMTops.m_t_erpset_ops = uicontrol('Style','pushbutton','Parent', ERPMTops.measurement_type,... + 'String','Browse','callback',@erpsetop,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %%3C - ERPMTops.m_t_bin_ops = uicontrol('Style','pushbutton','Parent', ERPMTops.measurement_type,'String','Option','callback',@binSelect_label,'Enable',Enable_label,'FontSize',FonsizeDefault); - + ERPMTops.m_t_bin_ops = uicontrol('Style','pushbutton','Parent', ERPMTops.measurement_type,... + 'String','Browse','callback',@binSelect_label,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %%3D - ERPMTops.m_t_chan_ops = uicontrol('Style','pushbutton','Parent', ERPMTops.measurement_type,'String','Option','callback',@chanSelect_label,'Enable',Enable_label,'FontSize',FonsizeDefault); + ERPMTops.m_t_chan_ops = uicontrol('Style','pushbutton','Parent', ERPMTops.measurement_type,... + 'String','Browse','callback',@chanSelect_label,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %%3E - ERPMTops.m_t_TW_ops = uicontrol('Style', 'pushbutton','Parent',ERPMTops.measurement_type,'String','Option','callback',@baseline_set,'Enable',Enable_label,'FontSize',FonsizeDefault); + ERPMTops.m_t_TW_ops = uicontrol('Style', 'pushbutton','Parent',ERPMTops.measurement_type,... + 'String','Baseline','callback',@m_t_TW_ops,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); %%3F - ERPMTops.m_t_file_ops = uicontrol('Style', 'pushbutton','Parent',ERPMTops.measurement_type,'String','Option','callback',@out_file_option,'Enable',Enable_label,'FontSize',FonsizeDefault); + ERPMTops.m_t_file_ops = uicontrol('Style', 'pushbutton','Parent',ERPMTops.measurement_type,... + 'String','Options','callback',@out_file_option,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); set(ERPMTops.measurement_type, 'ColumnSizes',[65 135 65],'RowSizes',[25 25 25 25 25 25]); - - %%-------------------------Setting for Viewer---------------------- - ERPMTops.mt_viewer = uiextras.HBox('Parent',ERPMTops.mt,'Spacing',1,'BackgroundColor',ColorB_def); - ERPMTops.m_t_viewer_title = uicontrol('Style', 'text','Parent', ERPMTops.mt_viewer,'String','Viewer:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - set(ERPMTops.m_t_viewer_title,'HorizontalAlignment','left'); - ERPMTops.m_t_viewer_on = uicontrol('Style', 'radiobutton','Parent', ERPMTops.mt_viewer,'String','On',... - 'callback',@m_t_viewer_on,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - ERPMTops.m_t_viewer_off = uicontrol('Style', 'radiobutton','Parent', ERPMTops.mt_viewer,'String','Off',... - 'callback',@m_t_viewer_off,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - ERPMTops.m_t_viewer_on.Value = 1; - ERPMTops.m_t_viewer_off.Value =0; - elseif strcmp(EStudio_erp_m_t_p.Viewer,'off') - ERPMTops.m_t_viewer_on.Value = 0; - ERPMTops.m_t_viewer_off.Value =1; - - end - uiextras.Empty('Parent', ERPMTops.mt_viewer,'BackgroundColor',ColorB_def); % 1A - set(ERPMTops.mt_viewer,'Sizes',[70 60 60 70]); - %%---------------------------Select ERPsets and Run options----------- ERPMTops.out_file_run = uiextras.HBox('Parent',ERPMTops.mt,'Spacing',1,'BackgroundColor',ColorB_def); - uiextras.Empty('Parent', ERPMTops.out_file_run); - uicontrol('Style', 'pushbutton','Parent',ERPMTops.out_file_run,'String','?','callback',@ERPmeasr_help,'Enable','on','FontSize',16); - uiextras.Empty('Parent', ERPMTops.out_file_run); - ERPMTops.m_t_value = uicontrol('Style', 'pushbutton','Parent',ERPMTops.out_file_run,'String','Save values','callback',@apply_erp_m_t,'Enable',Enable_label,'FontSize',FonsizeDefault); - uiextras.Empty('Parent', ERPMTops.out_file_run); - set(ERPMTops.out_file_run, 'Sizes',[15 105 20 105 15]); + ERPMTops.cancel = uicontrol('Style', 'pushbutton','Parent',ERPMTops.out_file_run,'String','Cancel',... + 'callback',@ERPmeasr_cancel,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPMTops.m_t_value = uicontrol('Style', 'pushbutton','Parent',ERPMTops.out_file_run,'String','Save measures',... + 'callback',@erp_m_t_savalue,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + ERPMTops.apply = uicontrol('Style', 'pushbutton','Parent',ERPMTops.out_file_run,'String','Preview',... + 'callback',@erp_m_t_view,'Enable',Enable_label,'FontSize',FonsizeDefault,'Value',0,'BackgroundColor',[1 1 1]); + set(ERPMTops.out_file_run,'Sizes',[70 -1 70]); %%ERPMTops end - set(ERPMTops.mt,'Sizes',[150 25 30]); + set(ERPMTops.mt,'Sizes',[155 30]); + estudioworkingmemory('ERPTab_mesuretool',0); end %%**************************************************************************************************************************************** %%******************* Subfunctions *************************************************************************************************** %%**************************************************************************************************************************************** -%%-----------------Help------------------------------ - function ERPmeasr_help(~,~) - web('https://github.com/lucklab/erplab/wiki/ERP-Measurement-Tool','-browser'); - end - %%---------------------------Setting for the Measurement type-----------------------------%% function Mesurement_type(source_measure_type,~) - Select_label = source_measure_type.Value; - if isempty(Select_label) - EStudio_erp_m_t_p.Measure = 'meanbl'; - elseif Select_label==1 % Mean amplitude - EStudio_erp_m_t_p.Measure = 'meanbl'; - elseif Select_label==2 %Peak amplitude - EStudio_erp_m_t_p.Measure ='peakampbl'; - EStudio_erp_m_t_p.Peakpolarity = 'negative'; - elseif Select_label==3 % Peak amplitude - EStudio_erp_m_t_p.Measure ='peakampbl'; - EStudio_erp_m_t_p.Peakpolarity = 'positive'; - elseif Select_label==4 % Peak latency - EStudio_erp_m_t_p.Measure = 'peaklatbl'; - EStudio_erp_m_t_p.Peakpolarity = 'negative'; - elseif Select_label==5 %Peak latency - EStudio_erp_m_t_p.Measure = 'peaklatbl'; - EStudio_erp_m_t_p.Peakpolarity = 'positive'; - - elseif Select_label==6 %Fractional Peak latency - EStudio_erp_m_t_p.Measure ='fpeaklat'; - EStudio_erp_m_t_p.Peakpolarity = 'negative'; - elseif Select_label==7 %Fractional Peak latency - EStudio_erp_m_t_p.Measure ='fpeaklat'; - EStudio_erp_m_t_p.Peakpolarity = 'positive'; - else - if Select_label > 7 - MeasureName_other = {'fareatlat','fninteglat','fareanlat','fareaplat',... - 'areat','ninteg','arean','areap',... - 'areazt','nintegz','areazn','areazp',... - 'instabl'}; - EStudio_erp_m_t_p.Measure = MeasureName_other{Select_label-7}; - if 15 < Select_label && Select_label<20 - mnamex = 'Numerical integration/Area between two (automatically detected) zero-crossing latencies'; - question = [ '%s\n\nThis tool is still in alpha phase.\n'... - 'Use it under your responsibility.']; - title = 'ERPLAB Studio: Overwriting Confirmation'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - end - else - EStudio_erp_m_t_p.Measure = 'meanbl'; - end + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_mesuretool',1); + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; - S_ws = estudioworkingmemory('geterpvalues'); - S_ws.Measure = EStudio_erp_m_t_p.Measure; - S_ws.Peakpolarity = EStudio_erp_m_t_p.Peakpolarity; - estudioworkingmemory('geterpvalues',S_ws); - - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - - moption = EStudio_erp_m_t_p.Measure; - latency = EStudio_erp_m_t_p.latency; - if isempty(moption) - beep; - msgboxText = ['ERP Measurement Tool - User must specify a type of measurement']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) - if length(latency)~=1 - beep; - msgboxText = ['ERP Measurement Tool - ',32,moption ' only needs 1 latency value.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - - end - else - if length(latency)~=2 - beep; - msgboxText = ['ERP Measurement Tool - ',32,moption ' only needs 2 latency values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - else - if latency(1)>=latency(2) - beep; - msgboxText = ['ERP Measurement Tool - For latency range, lower time limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + Measure= source_measure_type.Value; + switch Measure%Find the label of the selected item, the defualt one is 1 (Mean amplitude between two fixed latencies) + case 1 + moption = 'meanbl';% Mean amplitude + case 2 + moption = 'peakampbl'; + ERPMTops.def_erpvalue{12} = 'positive'; + case 3 % Peak amplitude (P vs. N) + moption = 'peakampbl'; + ERPMTops.def_erpvalue{12} = 'negative'; + case 4 + moption= 'peaklatbl'; + ERPMTops.def_erpvalue{12} = 'positive'; + case 5 + moption= 'peaklatbl'; + ERPMTops.def_erpvalue{12} = 'negative'; + case 6 + moption= 'fpeaklat'; + ERPMTops.def_erpvalue{12} = 'positive'; + case 7 + moption= 'fpeaklat'; + ERPMTops.def_erpvalue{12} = 'negative'; + otherwise%if the measurement type comes from Advanced option + MeasureName_other = {'fareatlat','fninteglat','fareanlat','fareaplat',... + 'areat','ninteg','areap','arean','instabl'}; + try + moption= MeasureName_other{Measure-7}; + catch + moption= 'meanbl'; + source_measure_type.Value=1; end - end - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end + ERPMTops.def_erpvalue{7} = moption; end %%------------Options for the measurement type----------------------------- function Mesurement_type_option(~,~) - try - S_ws = estudioworkingmemory('geterpvalues'); - EStudio_erp_m_t_p.Measure = S_ws.Measure; - catch - beep; - msgboxText = ['ERP Measurement Tool - None of measure types was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); try - op = S_ws.Measure; + op = ERPMTops.def_erpvalue{7}; catch op= 'meanbl'; end% option: type of measurement ---> instabl, meanbl, peakampbl, peaklatbl, area, areaz, or errorbl. try - dig = S_ws.Resolution; + dig = ERPMTops.def_erpvalue{9}; catch dig =3; end%Resolution try - Binlabel = S_ws.Binlabel; + Binlabel = ERPMTops.def_erpvalue{11}; catch Binlabel = 'off'; end @@ -532,48 +366,62 @@ function Mesurement_type_option(~,~) binlabop = 1; end try - Peakpolarity = S_ws.Peakpolarity; + Peakpolarity = ERPMTops.def_erpvalue{12}; catch Peakpolarity = 'negative'; end if strcmpi(Peakpolarity,'negative') polpeak = 0; else - polpeak = 1; % local peak positive polarity + polpeak = 1; % Peak positive polarity end + %%resolution try - sampeak = S_ws.Neighborhood; % number of samples (one-side) for local peak detection criteria + sampeak = ERPMTops.def_erpvalue{13}; % number of samples (one-side) for Peak detection criteria catch sampeak = 3; end try - Peakreplace = S_ws.Peakreplace; + Peakreplace = ERPMTops.def_erpvalue{14}; catch Peakreplace = 'absolute'; end if strcmpi(Peakreplace,'absolute') locpeakrep = 1; - else + elseif strcmpi(Peakreplace,'Nan') locpeakrep = 0; % 1 abs peak , 0 Nan + elseif strcmpi(Peakreplace,'errormsg') + locpeakrep = -1; end try - frac = S_ws.Afraction; + frac = ERPMTops.def_erpvalue{15}; catch frac = 0.5; end try - Fracreplace = S_ws.Fracreplace; + Fracreplace = ERPMTops.def_erpvalue{16}; catch Fracreplace = 'NaN'; end - if strcmpi(Fracreplace,'NaN') - fracmearep = 0; % def{19}; NaN + if ismember_bc2({op}, {'fareatlat', 'fninteglat','fareanlat','fareaplat'}) + if strcmpi(Fracreplace,'NaN')%% latency : closet 0, NAN 1, error 2 + fracmearep = 0; % NaN + else + fracmearep = 2; + end else - fracmearep = 1; % def{19}; NaN + if strcmpi(Fracreplace,'absolute') + fracmearep = 1; + elseif strcmpi(Fracreplace,'errormsg') + fracmearep = -1; + else + fracmearep = 0; + end end + try - SendtoWorkspace = S_ws.SendtoWorkspace; + SendtoWorkspace = ERPMTops.def_erpvalue{17}; catch SendtoWorkspace = 'off'; end @@ -583,967 +431,1041 @@ function Mesurement_type_option(~,~) send2ws = 1; end try - IncludeLat = S_ws.IncludeLat ; + IncludeLat = ERPMTops.def_erpvalue{20} ; catch IncludeLat = 'off'; end if strcmpi(IncludeLat,'on') - inclate = 1; else inclate = 0; end try - intfactor = S_ws.InterpFactor; + intfactor = ERPMTops.def_erpvalue{21}; catch intfactor = 10; end try - peakonset =S_ws.PeakOnset; + peakonset =ERPMTops.def_erpvalue{22}; catch peakonset = 1; end %%Change the modified parameters after the subfucntion was called - def = { op ,dig,binlabop,polpeak,sampeak,locpeakrep,frac,fracmearep,send2ws,inclate,intfactor,peakonset}; + def = { op ,dig,binlabop,polpeak,sampeak,locpeakrep,frac,... + fracmearep,send2ws,inclate,intfactor,peakonset}; ERP= observe_ERPDAT.ERP; Answer = geterpvaluesparasGUI2(def,ERP); if isempty(Answer) - beep; - disp('User selected cancel'); return; end - S_ws.Measure = Answer{1}; - S_ws.Resolution=Answer{2}; - binlabop = Answer{3}; - if binlabop - S_ws.Binlabel = 'on'; - else - S_ws.Binlabel = 'off'; + Measure = Answer{1}; + + switch Measure%Find the label of the selected item, the defualt one is 1 (Mean amplitude between two fixed latencies) + case 'meanbl'% Mean amplitude + set(ERPMTops.m_t_type,'Value',1); + case 'peakampbl'% Peak amplitude (P vs. N) + if strcmp(Peakpolarity,'positive') + set(ERPMTops.m_t_type,'Value',2); + else + set(ERPMTops.m_t_type,'Value',3); + end + case 'peaklatbl'%Peak latency (P vs. N) + if strcmp(Peakpolarity,'positive') + set(ERPMTops.m_t_type,'Value',4); + elseif strcmp(Peakpolarity,'negative') + set(ERPMTops.m_t_type,'Value',5); + end + case 'fpeaklat'%Fractional Peak latency (P vs. N) + if strcmp(Peakpolarity,'positive') + set(ERPMTops.m_t_type,'Value',6); + elseif strcmp(Peakpolarity,'negative') + set(ERPMTops.m_t_type,'Value',7); + end + otherwise%if the measurement type comes from Advanced option + MeasureName_other = {'fareatlat','fninteglat','fareanlat','fareaplat',... + 'areat','ninteg','areap','arean','instabl'}; + [C,IA] = ismember_bc2({Measure}, MeasureName_other); + if isempty(IA) + set(ERPMTops.m_t_type,'Value',1); + Measure = 'meanbl'; + else + set(ERPMTops.m_t_type,'Value',IA+7); + end end + ERPMTops.def_erpvalue{7} = Measure; + + ERPMTops.def_erpvalue{9} =Answer{2}; - polpeak= Answer{4}; + polpeak= Answer{4};%%polarity if polpeak==0 - S_ws.Peakpolarity = 'negative'; + ERPMTops.def_erpvalue{12} = 'negative'; else - S_ws.Peakpolarity = 'positive'; + ERPMTops.def_erpvalue{12} = 'positive'; end - S_ws.Neighborhood = Answer{5}; + ERPMTops.def_erpvalue{13} = Answer{5};%%Neighborhood + + locpeakrep = Answer{6};%%Peak replacement - locpeakrep = Answer{6}; if locpeakrep==0 - S_ws.Peakreplace = 'NaN'; - else - S_ws.Peakreplace = 'absolute'; + ERPMTops.def_erpvalue{14} = 'NaN'; + elseif locpeakrep==1 + ERPMTops.def_erpvalue{14} = 'absolute'; + elseif locpeakrep==-1 + ERPMTops.def_erpvalue{14} = 'errormsg'; end - S_ws.Afraction = Answer{7}; + ERPMTops.def_erpvalue{15} = Answer{7};%%Afraction - fracmearep= Answer{8}; + fracmearep= Answer{8};%%Fracreplace if fracmearep==0 % Fractional area latency replacement - S_ws.Fracreplace = 'NaN'; - else - if ismember_bc2({S_ws.Measure}, {'fareatlat', 'fninteglat','fareaplat','fareanlat'}) - S_ws.Fracreplace = 'errormsg'; - else - S_ws.Fracreplace = 'absolute'; - end - end - send2ws = Answer{9}; - if send2ws - S_ws.SendtoWorkspace = 'on'; - else - S_ws.SendtoWorkspace = 'off'; - end - inclate = Answer{10}; - if inclate - S_ws.IncludeLat = 'on' ; + ERPMTops.def_erpvalue{16} = 'NaN'; else - S_ws.IncludeLat = 'off' ; - end - S_ws.InterpFactor=Answer{11}; - S_ws.PeakOnset = Answer{12}; - estudioworkingmemory('geterpvalues',S_ws); - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - - moption = EStudio_erp_m_t_p.Measure; - latency = EStudio_erp_m_t_p.latency; - if isempty(moption) - beep; - msgboxText = ['ERP Measurement Tool - User must specify a type of measurement']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) - if length(latency)~=1 - beep; - msgboxText = ['ERP Measurement Tool - ',32,moption ' only needs 1 latency value']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + if ismember_bc2({ERPMTops.def_erpvalue{7}}, {'fareatlat', 'fninteglat','fareanlat','fareaplat'}) + ERPMTops.def_erpvalue{16} = 'errormsg'; else - if length(latency)~=2 - beep; - msgboxText = ['ERP Measurement Tool - ',32,moption ' needs 2 latency values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - else - if latency(1)>=latency(2) - beep; - msgboxText = ['ERP Measurement Tool - For latency range, lower time limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + if fracmearep==1 + ERPMTops.def_erpvalue{16} = 'absolute'; + elseif fracmearep==-1 + ERPMTops.def_erpvalue{16} = 'errormsg'; end end - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end + ERPMTops.def_erpvalue{21} =Answer{11}; + ERPMTops.def_erpvalue{22} = Answer{12}; end %%----------------------------ERPset custom-------------------------------- function erpset_custom(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); ERPsetArray = str2num(Source.String); ERPsetArraydef = estudioworkingmemory('selectederpstudio'); - if isempty(ERPsetArray) || max(ERPsetArray)> length(observe_ERPDAT.ALLERP) - if isempty(ERPsetArraydef) || max(ERPsetArraydef)> length(observe_ERPDAT.ALLERP) + if isempty(ERPsetArray) || any(ERPsetArray> length(observe_ERPDAT.ALLERP)) + if isempty(ERPsetArraydef) || any(ERPsetArraydef> length(observe_ERPDAT.ALLERP)) Source.String = ''; else - Source.String = num2str(vect2colon(ERPsetArraydef,'Sort','on')); + ERPset = vect2colon(ERPsetArraydef,'Sort','on'); + ERPset = erase(ERPset,{'[',']'}); + Source.String = ERPset; end - return; - else - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,ERPsetArray); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - Current_ERP_selected=ERPsetArray(1); - observe_ERPDAT.CURRENTERP = Current_ERP_selected; - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_ERP_selected); - - estudioworkingmemory('selectederpstudio',ERPsetArray); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end - end %%-------------Select bins by user custom---------------------------------- function binSelect_custom(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); binNums = str2num(source.String); [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, binNums, [],1); - if chk(1) - binArray= observe_ERPDAT.ERP_bin; - source.String = num2str(binArray); - - beep; - msgboxText = ['ERP Measurement Tool -',32,msgboxText]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + source.String = ''; + msgboxText = ['Measurement Tool -',32,msgboxText]; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; return; end - if ~isempty(binNums) - binNums = unique_bc2(binNums); - binList = 1:observe_ERPDAT.ERP.nbin; - indxlistb = binNums; - [~,y_check_bin] =find(indxlistb>observe_ERPDAT.ERP.nbin); - if any(y_check_bin) - mnamex = ['Label of one of the imported bins was higher than the number of bins (',num2str(observe_ERPDAT.ERP.nbin),').']; - question = [ '%s\n\n Please input or select bins of interst from "Bin:" on the "ERP Measurement Tool" panel again.\n']; - title = 'EStudio: ERP Measurement Tool'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - return; - end - - indxlistb = indxlistb(indxlistb<=length(binList)); - EStudio_erp_m_t_p.binArray = indxlistb; - S_ws= estudioworkingmemory('geterpvalues'); - if isempty(S_ws) - return; - end - S_ws.binArray = EStudio_erp_m_t_p.binArray; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - %Remark the selected bin in bin and Channel selection - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - SelectedERP_Index = estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',SelectedERP_Index); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - - Bin_label_select = indxlistb; - if isempty(Bin_label_select) - beep; - disp(['No bin was selected']); - return; - end - if S_binchan.checked_ERPset_Index(1) ==1% The number of bins varied across the selected erpsets - S_binchan.bins{Select_index} = Bin_label_select; - S_binchan.bin_n(Select_index) = numel(Bin_label_select); - else - - for Numofselecterp = 1:numel(SelectedERP_Index) - S_binchan.bins{Numofselecterp} = Bin_label_select; - S_binchan.bin_n(Numofselecterp) = numel(Bin_label_select); - end - - end - estudioworkingmemory('geterpbinchan',S_binchan); - end - observe_ERPDAT.ERP_bin = indxlistb; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - end end %%----------------Option for erpset---------------------------------------- function erpsetop(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); + ERPsetArraydef = estudioworkingmemory('selectederpstudio'); - if isempty(ERPsetArraydef) || max(ERPsetArraydef)> length(observe_ERPDAT.ALLERP) - ERPsetArraydef = observe_ERPDAT.CURRENTERP; + if isempty(ERPsetArraydef) || any(ERPsetArraydef> length(observe_ERPDAT.ALLERP)) + ERPsetArraydef = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = ERPsetArraydef; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + end + ERPArray = str2num(ERPMTops.m_t_erpset.String); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = ERPsetArraydef; end for Numoferpset = 1:length(observe_ERPDAT.ALLERP) listname{Numoferpset} = char(strcat(num2str(Numoferpset),'.',observe_ERPDAT.ALLERP(Numoferpset).erpname)); end - indxlistb =ERPsetArraydef; - + indxlistb =ERPArray; titlename = 'Select ERPset(s):'; ERPset_select = browsechanbinGUI(listname, indxlistb, titlename); - if ~isempty(ERPset_select) - ERPMTops.m_t_erpset.String = num2str(vect2colon(ERPset_select,'Sort','on')); - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,ERPset_select); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - Current_ERP_selected=ERPset_select(1); - observe_ERPDAT.CURRENTERP = Current_ERP_selected; - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(Current_ERP_selected); - estudioworkingmemory('selectederpstudio',ERPset_select); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + ERPset = vect2colon(ERPset_select,'Sort','on'); + ERPset = erase(ERPset,{'[',']'}); + ERPMTops.m_t_erpset.String = ERPset; else return; end - end - %%---------------Bins selection from "Option"------------------------------ function binSelect_label(Source,~) - ERP_CURRENT = evalin('base','ERP'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); + + ERP_CURRENT = observe_ERPDAT.ERP; for Numofbin = 1:length(ERP_CURRENT.bindescr) listb{Numofbin} = char(strcat(num2str(Numofbin),'.',ERP_CURRENT.bindescr{Numofbin})); end - try - indxlistb =EStudio_erp_m_t_p.binArray; - catch - indxlistb = 1:ERP_CURRENT.nbin; + indxlistb = str2num(ERPMTops.m_t_bin.String); + if isempty(indxlistb) || any(indxlistb>observe_ERPDAT.ERP.nbin) + indxlistb = 1:observe_ERPDAT.ERP.nbin; end titlename = 'Select Bin(s):'; %----------------judge the number of latency/latencies-------- - if ~isempty(listb) - bin_label_select = browsechanbinGUI(listb, indxlistb, titlename); - if ~isempty(bin_label_select) - EStudio_erp_m_t_p.binArray = bin_label_select; - ERPMTops.m_t_bin.String=num2str(vect2colon(EStudio_erp_m_t_p.binArray,'Sort', 'on')); - else - disp('User selected Cancel'); - return - end + bin_label_select = browsechanbinGUI(listb, indxlistb, titlename); + if ~isempty(bin_label_select) + binset = vect2colon(bin_label_select,'Sort', 'on'); + binset = erase(binset,{'[',']'}); + ERPMTops.m_t_bin.String=binset; else - beep; - msgboxText = ['ERP Measurement Tool - No bin information was found']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end%Program end: Judge the number of latency/latencies - S_ws= estudioworkingmemory('geterpvalues'); - if isempty(S_ws) - return; - end - - S_ws.binArray = EStudio_erp_m_t_p.binArray; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - %Remark the selected bin in bin and Channel selection - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - SelectedERP_Index = estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',SelectedERP_Index); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - - Bin_label_select = bin_label_select; - if isempty(Bin_label_select) - beep; - disp(['No bin was selected']); - return; - end - EStudio_erp_m_t_p.binArray = bin_label_select; - if S_binchan.checked_ERPset_Index(1) ==1% The number of bins varied across the selected erpsets - S_binchan.bins{Select_index} = Bin_label_select; - S_binchan.bin_n(Select_index) = numel(Bin_label_select); - else - for Numofselecterp = 1:numel(SelectedERP_Index) - S_binchan.bins{Numofselecterp} = Bin_label_select; - S_binchan.bin_n(Numofselecterp) = numel(Bin_label_select); - end - end - estudioworkingmemory('geterpbinchan',S_binchan); + return end - observe_ERPDAT.ERP_bin = bin_label_select; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end %%----------------Define the channels of interest---------------------- function chanSelect_custom(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); chanNums = str2num(Source.String); [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, [], chanNums,2); - if chk(2) - chanArray= observe_ERPDAT.ERP_chan; - Source.String = num2str(chanArray); - beep; - msgboxText = ['ERP Measurement Tool -',32,msgboxText]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + Source.String = ''; + msgboxText = ['Measurement Tool -',32,msgboxText]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - - if ~isempty(chanNums) - chanNums = unique_bc2(chanNums); - chanList = 1:observe_ERPDAT.ERP.nchan; - indxlist_chan = chanNums; - - [~,y_check_bin] =find(indxlist_chan>observe_ERPDAT.ERP.nchan); - if any(y_check_bin) - mnamex = ['Label of one of the imported channels was higher than the number of channels (',num2str(observe_ERPDAT.ERP.nchan),').']; - question = [ '%s\n\n Please input or select bins of interst from "Channel:" on the "ERP Measurement Tool" panel again.\n']; - title = 'ERPLAB Studio: ERP Measurement Tool'; - button = questdlg(sprintf(question, mnamex), title,'OK','OK'); - return; - end - - indxlist_chan = indxlist_chan(indxlist_chan<=length(chanList)); - EStudio_erp_m_t_p.chanArray = indxlist_chan; - S_ws= estudioworkingmemory('geterpvalues'); - if isempty(S_ws) - return; - end - S_ws.chanArray = EStudio_erp_m_t_p.chanArray; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - %When the "Viewer" is active on the measurement Tool panel--------- - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - SelectedERP_Index = estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',SelectedERP_Index); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - chan_label_select = indxlist_chan; - - if S_binchan.checked_ERPset_Index(2) ==2%% the number of channels varied across ERPsets - S_binchan.elecs_shown{S_binchan.Select_index} = chan_label_select; - S_binchan.elec_n(Select_index) = numel(chan_label_select); - S_binchan.first_elec(Select_index) = chan_label_select(1); - else - - for Numofselecterp = 1:numel(SelectedERP_Index) - S_binchan.elecs_shown{Numofselecterp} = chan_label_select; - S_binchan.elec_n(Numofselecterp) = numel(chan_label_select); - S_binchan.first_elec(Numofselecterp) = chan_label_select(1); - end - - end - estudioworkingmemory('geterpbinchan',S_binchan); - end - observe_ERPDAT.ERP_chan = indxlist_chan; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - end - end %%----------------Channels selection from option-------------------------------------- function chanSelect_label(Source,~) - ERP_CURRENT = evalin('base','ERP'); - - if isempty(ERP_CURRENT.nchan) || ERP_CURRENT.nchan ==0 - beep; - msgboxText = ['ERP Measurement Tool -No channel information was found']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); - for Numofchan = 1:ERP_CURRENT.nchan - listb{Numofchan}= strcat(num2str(Numofchan),'.',ERP_CURRENT.chanlocs(Numofchan).labels); + for Numofchan = 1:observe_ERPDAT.ERP.nchan + try + listb{Numofchan}= strcat(num2str(Numofchan),'.',observe_ERPDAT.ERP.chanlocs(Numofchan).labels); + catch + listb{Numofchan}= strcat(num2str(Numofchan),'.','chan',num2str(Numofchan)); + end end - try - indxlistb= EStudio_erp_m_t_p.chanArray ; - catch - indxlistb = 1:ERP_CURRENT.nchan; + chanArray = str2num(ERPMTops.m_t_chan.String); + if isempty(chanArray) || any(chanArray>observe_ERPDAT.ERP.nchan) || any(chanArray<1) + chanArray = [1:observe_ERPDAT.ERP.nchan]; end - titlename = 'Select Channel(s):'; - - if ~isempty(listb) - chan_label_select = browsechanbinGUI(listb, indxlistb, titlename); - if ~isempty(chan_label_select) - EStudio_erp_m_t_p.chanArray = chan_label_select; - %%%Save the changed parameters - S_ws= estudioworkingmemory('geterpvalues'); - if isempty(S_ws) - return; - end - - S_ws.chanArray = EStudio_erp_m_t_p.chanArray; - estudioworkingmemory('geterpvalues',S_ws); clear S_ws; - ERPMTops.m_t_chan.String=num2str(vect2colon(EStudio_erp_m_t_p.chanArray,'Sort', 'on')); - else - beep; - disp('User selected Cancel'); - return - end - else - beep; - msgboxText = ['ERP Measurement Tool -No channel information was found']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(listb) + msgboxText = ['Measurement Tool-No channel information was found']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - - %When the "Viewer" is active on the measurement Tool panel--------- - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - SelectedERP_Index = estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',SelectedERP_Index); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - if isempty(chan_label_select) - beep; - disp(['No channel was selected']); - return; - end - if S_binchan.checked_ERPset_Index(2) ==2%% the number of channels varied across ERPsets - S_binchan.elecs_shown{S_binchan.Select_index} = chan_label_select; - S_binchan.elec_n(Select_index) = numel(chan_label_select); - S_binchan.first_elec(Select_index) = chan_label_select(1); - else - - for Numofselecterp = 1:numel(SelectedERP_Index) - S_binchan.elecs_shown{Numofselecterp} = chan_label_select; - S_binchan.elec_n(Numofselecterp) = numel(chan_label_select); - S_binchan.first_elec(Numofselecterp) = chan_label_select(1); - end - end - estudioworkingmemory('geterpbinchan',S_binchan); - end - chanArray = str2num(ERPMTops.m_t_chan.String); - if ~isempty(chanArray) - observe_ERPDAT.ERP_chan = chanArray; + titlename = 'Select Channel(s):'; + chan_label_select = browsechanbinGUI(listb, chanArray, titlename); + if ~isempty(chan_label_select) + chanset = vect2colon(chan_label_select,'Sort', 'on'); + chanset = erase(chanset,{'[',']'}); + ERPMTops.m_t_chan.String=chanset; + else + return end - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end %%-----------------Measurement time-window-------------------------------%% function t_w_set(source_tw,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); if isempty(str2num(source_tw.String)) - beep; - msgboxText = ['ERP Measurement Tool -No measurement window was set']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + source_tw.String = ''; + msgboxText = ['Measurement Tool - No measurement window was set']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; - else - lat_erp = unique_bc2(str2num(source_tw.String)); - EStudio_erp_m_t_p.latency = lat_erp; - moption = EStudio_erp_m_t_p.Measure; - latency = EStudio_erp_m_t_p.latency; - if isempty(moption) - beep; - msgboxText = ['ERP Measurement Tool - User must specify a type of measurement']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + end + Measure= ERPMTops.m_t_type.Value; + switch Measure%Find the label of the selected item, the defualt one is 1 (Mean amplitude between two fixed latencies) + case 1 + moption = 'meanbl';% Mean amplitude + case 2 + moption = 'peakampbl'; + case 3 % Peak amplitude (P vs. N) + moption = 'peakampbl'; + case 4 + moption= 'peaklatbl'; + case 5 + moption= 'peaklatbl'; + case 6 + moption= 'fpeaklat'; + case 7 + moption= 'fpeaklat'; + otherwise%if the measurement type comes from Advanced option + MeasureName_other = {'fareatlat','fninteglat','fareanlat','fareaplat',... + 'areat','ninteg','areap','arean','instabl'}; + try + moption= MeasureName_other{Measure-7}; + catch + moption= 'fareatlat'; + end + end + latency = unique_bc2(str2num(source_tw.String)); + if ismember_bc2({moption}, {'instabl'}) + if length(latency)~=1 + msgboxText = ['Measurement Tool -',32,moption ' only needs 1 latency value']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); observe_ERPDAT.Process_messg =4; return; end - if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) - if length(latency)~=1 - beep; - msgboxText = ['ERP Measurement Tool -',32,moption ' only needs 1 latency value']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + else + if length(latency)~=2 + msgboxText = ['Measurement Tool -',32,moption ' needs 2 latency values']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + source_tw.String = ''; + return; else - if length(latency)~=2 - beep; - msgboxText = ['ERP Measurement Tool -',32,moption ' needs 2 latency values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if latency(1)>=latency(2) + msgboxText = ['Measurement Tool -For latency range, lower time limit must be on the left.',32,... + 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + source_tw.String = ''; return; - else - if latency(1)>=latency(2) - beep; - msgboxText = ['ERP Measurement Tool -For latency range, lower time limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end end end - - - S_ws= estudioworkingmemory('geterpvalues'); - if isempty(S_ws) - return; - end - S_ws.latency = lat_erp; - estudioworkingmemory('geterpvalues',S_ws); clear S_ws; - - end - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; end end %-------------------------Baseline period--------------------------------- - function baseline_set(~,~) + function m_t_TW_ops(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); try - S_ws=estudioworkingmemory('geterpvalues'); - Answer = f_ERP_meas_basecorr(S_ws.Baseline); + Baseline = ERPMTops.def_erpvalue{10}; + Answer = f_ERP_meas_basecorr(Baseline); catch Answer = f_ERP_meas_basecorr('none'); end if isempty(Answer) - beep; - disp('User selected cancel'); return; end ERP_times = observe_ERPDAT.ERP.times; latency = str2num(Answer); if ~isempty(latency) if latency(1)>=latency(2) - beep; - msgboxText = ['ERP Measurement Tool - The first latency should be smaller than the second one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - The first latency should be smaller than the second one']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if latency(1)< ERP_times(1) - beep; - msgboxText = ['ERP Measurement Tool - The defined first latency should be larger than',32, num2str(ERP_times(1)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - The defined first latency should be larger than',32, num2str(ERP_times(1)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if latency(2)> ERP_times(end) - beep; - msgboxText = ['ERP Measurement Tool - The defined second latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - The defined second latency should be smaller than',32, num2str(ERP_times(end)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if latency(1)> ERP_times(end) - beep; - msgboxText = ['ERP Measurement Tool - The defined first latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - The defined first latency should be smaller than',32, num2str(ERP_times(end)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end - - S_ws= estudioworkingmemory('geterpvalues'); - S_ws.Baseline = Answer; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - - if strcmp(EStudio_erp_m_t_p.Viewer,'on') - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - end end %%------------------File name setting for the output file.---------------- function file_name_set(source_file_name,~) - EStudio_erp_m_t_p.Filename = source_file_name.String; - S_ws=estudioworkingmemory('geterpvalues'); - S_ws.Filename = source_file_name.String; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + ERPMTops.apply.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.apply.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); end %%-------------------Path setting to save the measurement results---------- function out_file_option(~,~) - if strcmp(EStudio_erp_m_t_p.FileFormat,'wide') - FileFormat = 0; - else + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPMTops.m_t_value.ForegroundColor = [1 1 1]; + erp_measurement_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + ERPMTops.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_mesuretool',1); + + if strcmp(ERPMTops.def_erpvalue{18},'wide') FileFormat = 1; + else + FileFormat = 0; + end + pathName_folder_default = estudioworkingmemory('EEG_save_folder'); + if isempty(pathName_folder_default) + pathName_folder_default = cd; end - pathName_folder_default = erpworkingmemory('ERP_save_folder'); - FileName = EStudio_erp_m_t_p.Filename; + FileName = ERPMTops.m_t_file.String; [pathNamex, fname, ext] = fileparts(FileName); - Answer = f_ERP_meas_format_path(FileFormat,fullfile(pathName_folder_default,fname)); + if isempty(fname) + fname = 'save_erpvalues'; + end + if isempty(pathNamex) + pathNamex = pathName_folder_default; + end + + try + Binlabel = ERPMTops.def_erpvalue{11}; + catch + Binlabel = 'off'; + end + if strcmpi(Binlabel,'off') + binlabop = 0; % 0: bin# as bin label for table, 1 bin label + else + binlabop = 1; + end + + try + SendtoWorkspace = ERPMTops.def_erpvalue{17}; + catch + SendtoWorkspace = 'off'; + end + if strcmpi(SendtoWorkspace,'off') + send2ws = 0; % 1 send to ws, 0 dont do + else + send2ws = 1; + end + + try + IncludeLat = ERPMTops.def_erpvalue{20} ; + catch + IncludeLat = 'off'; + end + if strcmpi(IncludeLat,'on') + inclate = 1; + else + inclate = 0; + end + Answer = f_ERP_meas_format_path(FileFormat,fullfile(pathNamex,fname),inclate,send2ws,binlabop); if isempty(Answer) - disp('User selected Cancel'); return; - end - if Answer{1}==1 % 1 means "long format"; 0 means "wide format" + if Answer{1}==0 % 0 means "long format"; 1 means "wide format" foutputstr = 'long'; else foutputstr = 'wide'; end + ERPMTops.def_erpvalue{18} = foutputstr; + ERPMTops.m_t_file.String = Answer{2}; - S_ws=estudioworkingmemory('geterpvalues'); - S_ws.Filename = Answer{2}; - S_ws.FileFormat = foutputstr; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - - EStudio_erp_m_t_p.FileFormat = foutputstr; - EStudio_erp_m_t_p.Filename = Answer{2}; - ERPMTops.m_t_file.String = EStudio_erp_m_t_p.Filename; + binlabop = Answer{5};%%Binlabel + if binlabop + ERPMTops.def_erpvalue{11} = 'on'; + else + ERPMTops.def_erpvalue{11} = 'off'; + end - end - - -%%---------------Viewer:ON------------------------------ - function m_t_viewer_on(~,~) - Source_value = 1; - set(ERPMTops.m_t_viewer_on,'Value',Source_value); - set(ERPMTops.m_t_viewer_off,'Value',~Source_value); - EStudio_erp_m_t_p.Viewer = 'on'; - S_ws= estudioworkingmemory('geterpvalues'); - S_ws.Viewer = EStudio_erp_m_t_p.Viewer; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - end - -%%---------------Viewer:Off------------------------------ - function m_t_viewer_off(~,~) - Source_value = 1; - set(ERPMTops.m_t_viewer_off,'Value',Source_value); - set(ERPMTops.m_t_viewer_on,'Value',~Source_value); - EStudio_erp_m_t_p.Viewer = 'off'; - S_ws=estudioworkingmemory('geterpvalues'); - S_ws.Viewer = EStudio_erp_m_t_p.Viewer; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + send2ws = Answer{4}; + if send2ws + ERPMTops.def_erpvalue{17} = 'on'; + else + ERPMTops.def_erpvalue{17} = 'off'; + end + inclate = Answer{3}; + if inclate + ERPMTops.def_erpvalue{20} = 'on' ; + else + ERPMTops.def_erpvalue{20} = 'off' ; + end end %%--------------------Apply the set parameters to selected ERPset---------- - function apply_erp_m_t(~,~) - pathName_folder = erpworkingmemory('ERP_save_folder'); + function erp_m_t_savalue(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); + + pathName_folder = estudioworkingmemory('EEG_save_folder'); if isempty(pathName_folder) pathName_folder = cd; end - - EStudio_erp_m_t_p =estudioworkingmemory('geterpvalues'); - if isempty(EStudio_erp_m_t_p) - EStudio_erp_m_t_p =EStudio_erp_m_t_p; - return; + ERPArraydef = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArraydef) || any(ERPArraydef> length(observe_ERPDAT.ALLERP)) + ERPArraydef = observe_ERPDAT.CURRENTERP; end - - SelectedERP_Index = estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP_Index) - SelectedERP_Index = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP_Index); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',SelectedERP_Index); + ERPsetArray = str2num(ERPMTops.m_t_erpset.String); + if isempty(ERPsetArray) || any(ERPsetArray(:)>length(observe_ERPDAT.ALLERP)) + ERPsetArray = ERPArraydef; end - S_binchan = estudioworkingmemory('geterpbinchan'); - - EStudio_erp_m_t_p.Erpsets = SelectedERP_Index; - - MeasureName = {'meanbl','peakampbl', 'peaklatbl','fareatlat','fpeaklat','fninteglat','fareaplat','fareanlat',... - 'areat','ninteg','areap','arean','areazt','nintegz','areazp','areazn','instabl'}; - [C,IA] = ismember_bc2({EStudio_erp_m_t_p.Measure}, MeasureName); + MeasureName = {'meanbl','peakampbl', 'peaklatbl','fpeaklat','fareatlat','fninteglat','fareanlat','fareaplat',... + 'areat','ninteg','areap','arean','instabl'}; + [C,IA] = ismember_bc2({ERPMTops.def_erpvalue{7}}, MeasureName); if ~any(IA) || isempty(IA) IA =1; end - if isempty(EStudio_erp_m_t_p.Filename) - beep; - msgboxText = ['ERP Measurement Tool - Please set a name for the output file']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(ERPMTops.m_t_file.String) + msgboxText = ['Measurement Tool - Please set a name for the output file']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - - if isempty(EStudio_erp_m_t_p.latency) - beep; - msgboxText = ['ERP Measurement Tool - Please set a Measurement window']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + latency = str2num(ERPMTops.m_t_TW.String); + if isempty(latency) + msgboxText = ['Measurement Tool - Please define the measurement window']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - moption = EStudio_erp_m_t_p.Measure; - latency = EStudio_erp_m_t_p.latency; + moption = ERPMTops.def_erpvalue{7}; + if isempty(moption) - beep; - msgboxText = ['ERP Measurement Tool - User must specify a type of measurement']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - User must specify a type of measurement']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) if length(latency)~=1 - beep; - msgboxText = ['ERP Measurement Tool - ',32, moption ' only needs 1 latency value']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - ',32, moption,32, ' only needs 1 latency value']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end else if length(latency)~=2 - beep; - msgboxText = ['ERP Measurement Tool - ',32,moption ' needs 2 latency values.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - ',32,moption,32, ' needs 2 latency values.']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; else if latency(1)>=latency(2) - beep; - msgboxText = ['ERP Measurement Tool - For latency range, lower time limit must be on the left.\n'... + msgboxText = ['Measurement Tool - For latency range, lower time limit must be on the left.',32,... 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end end - ALLERP = evalin('base','ALLERP'); - - [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, EStudio_erp_m_t_p.binArray, [],1); + binArray = str2num(ERPMTops.m_t_bin.String); + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, binArray, [],1); if chk(1) - beep; - msgboxText = ['ERP Measurement Tool - ',32,msgboxText]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - ',32,msgboxText]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - - [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, [], EStudio_erp_m_t_p.chanArray,2); - + chanArray = str2num(ERPMTops.m_t_chan.String); + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, [],chanArray,2); if chk(2) - beep; - msgboxText = ['ERP Measurement Tool - ',32,msgboxText]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - ',32,msgboxText]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - - FileName = EStudio_erp_m_t_p.Filename; + FileName = ERPMTops.m_t_file.String; [pathNamex, fname, ext] = fileparts(FileName); if isempty(fname) - beep; - msgboxText = ['ERP Measurement Tool - Please give a name to the output file']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Measurement Tool - Please give a name to the output file']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - if isempty(pathNamex) - EStudio_erp_m_t_p.Filename = fullfile(pathName_folder,fname); + ERPMTops.m_t_file.String = fullfile(pathName_folder,fname); end - - - erpworkingmemory('f_ERP_proces_messg',' ERP Measurement Tool (Save values)'); + FileName=ERPMTops.m_t_file.String; + estudioworkingmemory('f_ERP_proces_messg',' Measurement Tool (Save values)'); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + %%check if the file already exists? + [pathtest, filtest, ext] = fileparts(FileName); + FileName = strcat(pathtest, filesep,filtest,'.txt'); + if exist(FileName, 'file')~=0 + msgboxText = ['This file already exists.\n'...; + 'Would you like to overwrite it?']; + title = 'Estudio: WARNING!'; + button = askquest(sprintf(msgboxText), title); + if ~strcmpi(button,'Yes') + return + end + end - try - if ~isempty(EStudio_erp_m_t_p.latency) - % - [ALLERP, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP, EStudio_erp_m_t_p.latency, EStudio_erp_m_t_p.binArray, EStudio_erp_m_t_p.chanArray,... - 'Erpsets', EStudio_erp_m_t_p.Erpsets, 'Measure',MeasureName{IA}, 'Component', EStudio_erp_m_t_p.Component,... - 'Resolution', EStudio_erp_m_t_p.Resolution, 'Baseline', EStudio_erp_m_t_p.Baseline, 'Binlabel', EStudio_erp_m_t_p.Binlabel,... - 'Peakpolarity',EStudio_erp_m_t_p.Peakpolarity, 'Neighborhood', EStudio_erp_m_t_p.Neighborhood, 'Peakreplace', EStudio_erp_m_t_p.Peakreplace,... - 'Filename', EStudio_erp_m_t_p.Filename, 'Warning',EStudio_erp_m_t_p.Warning,'SendtoWorkspace', EStudio_erp_m_t_p.SendtoWorkspace, 'Append', EStudio_erp_m_t_p.Append,... - 'FileFormat', EStudio_erp_m_t_p.FileFormat,'Afraction', EStudio_erp_m_t_p.Afraction, 'Mlabel', EStudio_erp_m_t_p.Mlabel,... - 'Fracreplace', EStudio_erp_m_t_p.Fracreplace,'IncludeLat', EStudio_erp_m_t_p.IncludeLat, 'InterpFactor', EStudio_erp_m_t_p.InterpFactor,... - 'PeakOnset',EStudio_erp_m_t_p.PeakOnset,'History', 'gui'); - %%%------------Save history to current session-------------- - ALLERPCOM = evalin('base','ALLERPCOM'); - [~, ALLERPCOM] = erphistory(observe_ERPDAT.ERP, ALLERPCOM, erpcom); - assignin('base','ALLERPCOM',ALLERPCOM); - - %%---------------save the applied parameters using erpworkingmemory function-------------------- - EStudio_erp_m_t_p_save = EStudio_erp_m_t_p; - if strcmp(EStudio_erp_m_t_p_save.Binlabel,'off') - EStudio_erp_m_t_p_save.Binlabel = 0; - else - EStudio_erp_m_t_p_save.Binlabel = 1; - end - - if strcmp(EStudio_erp_m_t_p_save.Peakpolarity,'negative') - EStudio_erp_m_t_p_save.Peakpolarity = 0; + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); + + ERPMTops.Paras{1} = ERPMTops.m_t_type.Value; + ERPMTops.Paras{2} = str2num(ERPMTops.m_t_erpset.String); + ERPMTops.Paras{3} = str2num(ERPMTops.m_t_bin.String); + ERPMTops.Paras{4} = str2num(ERPMTops.m_t_chan.String); + ERPMTops.Paras{5} = str2num(ERPMTops.m_t_TW.String); + ERPMTops.Paras{6} = ERPMTops.m_t_file.String; + + + ALLERP =observe_ERPDAT.ALLERP; + if ~isempty(latency) + [~, Amp, Lat, erpcom] = pop_geterpvalues(ALLERP, latency, binArray, chanArray,... + 'Erpsets', ERPsetArray, 'Measure',MeasureName{IA}, 'Component', ERPMTops.def_erpvalue{8},... + 'Resolution', ERPMTops.def_erpvalue{9}, 'Baseline', ERPMTops.def_erpvalue{10}, 'Binlabel', ERPMTops.def_erpvalue{11},... + 'Peakpolarity',ERPMTops.def_erpvalue{12}, 'Neighborhood', ERPMTops.def_erpvalue{13}, 'Peakreplace',ERPMTops.def_erpvalue{14},... + 'Filename', FileName, 'Warning','on','SendtoWorkspace', ERPMTops.def_erpvalue{17}, 'Append', 'off',... + 'FileFormat',ERPMTops.def_erpvalue{18},'Afraction', ERPMTops.def_erpvalue{15}, 'Mlabel', ERPMTops.def_erpvalue{19},... + 'Fracreplace', ERPMTops.def_erpvalue{16},'IncludeLat',ERPMTops.def_erpvalue{20}, 'InterpFactor',ERPMTops.def_erpvalue{21},... + 'PeakOnset',ERPMTops.def_erpvalue{22},'History', 'gui'); + %%%------------Save history to current session-------------- + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + for Numoferp = 1:length(ERPsetArray) + if Numoferp ==length(ERPsetArray) + [observe_ERPDAT.ALLERP(ERPsetArray(Numoferp)), ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(ERPsetArray(Numoferp)), ALLERPCOM, erpcom,2); else - EStudio_erp_m_t_p_save.Peakpolarity = 1; + [observe_ERPDAT.ALLERP(ERPsetArray(Numoferp)), ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(ERPsetArray(Numoferp)), ALLERPCOM, erpcom,1); end - - if strcmp(EStudio_erp_m_t_p_save.Peakreplace,'NaN') - EStudio_erp_m_t_p_save.Peakreplace = 0; + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',erpcom); + %%---------------save the applied parameters using estudioworkingmemory function-------------------- + Measure = MeasureName{IA}; + if strcmp(ERPMTops.def_erpvalue{11},'off') + Binlabel = 0; + else + Binlabel = 1; + end + if strcmp(ERPMTops.def_erpvalue{12},'negative') + Peakpolarity = 0; + else + Peakpolarity = 1; + end + + if strcmpi(ERPMTops.def_erpvalue{14},'absolute') + Peakreplace = 1; + elseif strcmpi(ERPMTops.def_erpvalue{14},'NaN') + Peakreplace = 0; % 1 abs peak , 0 Nan + elseif strcmpi(ERPMTops.def_erpvalue{14},'errormsg') + Peakreplace = -1; + end + + %%Fractional area latency replacement + if ismember_bc2({Measure}, {'fareatlat', 'fninteglat','fareanlat','fareaplat'}) % Fractional area latency replacement + if strcmpi(ERPMTops.def_erpvalue{16},'NaN')%% latency : closet 0, NAN 1, error 2 + Fracreplace = 0; % NaN else - EStudio_erp_m_t_p_save.Peakreplace = 1; + Fracreplace = 2; end - - if strcmp(EStudio_erp_m_t_p_save.Fracreplace,'NaN') % Fractional area latency replacement - EStudio_erp_m_t_p_save.Fracreplace = 0; + else + if strcmpi(ERPMTops.def_erpvalue{16},'absolute') + Fracreplace = 1; + elseif strcmpi(ERPMTops.def_erpvalue{16},'errormsg') + Fracreplace = -1; else - EStudio_erp_m_t_p_save.Fracreplace = 1; + Fracreplace = 0; end - - if strcmp(EStudio_erp_m_t_p_save.SendtoWorkspace,'off') - EStudio_erp_m_t_p_save.SendtoWorkspace=0; - else - EStudio_erp_m_t_p_save.SendtoWorkspace=1; + end + + + if strcmp(ERPMTops.def_erpvalue{17},'off') + SendtoWorkspace=0; + else + SendtoWorkspace=1; + end + + if strcmp(ERPMTops.def_erpvalue{18},'wide') + FileFormat = 0; + else + FileFormat = 1; + end + + if strcmp(ERPMTops.def_erpvalue{20},'no') + IncludeLat = 0; + else + IncludeLat = 1; + end + + estudioworkingmemory('pop_geterpvalues', {0, ERPsetArray, FileName, latency,... + binArray, chanArray, Measure, ERPMTops.def_erpvalue{8}, ERPMTops.def_erpvalue{9}, ERPMTops.def_erpvalue{10},... + Binlabel, Peakpolarity,ERPMTops.def_erpvalue{13},Peakreplace,... + ERPMTops.def_erpvalue{15}, Fracreplace,SendtoWorkspace, FileFormat, ERPMTops.def_erpvalue{19},... + IncludeLat, ERPMTops.def_erpvalue{21}, ERPMTops.def_erpvalue{22}}); + end + observe_ERPDAT.Count_currentERP = 20; + observe_ERPDAT.Process_messg =2; + end + +%%---------------------Apply measurement----------------------------------- + function erp_m_t_view(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); + + ERPsetArray = str2num(ERPMTops.m_t_erpset.String); + if isempty(ERPsetArray) || any(ERPsetArray>length(observe_ERPDAT.ALLERP)) + ERPsetArray = ERPArraydef; + end + + MeasureName = {'meanbl','peakampbl', 'peaklatbl','fpeaklat','fareatlat','fninteglat','fareanlat','fareaplat',... + 'areat','ninteg','areap','arean','instabl'}; + [C,IA] = ismember_bc2({ERPMTops.def_erpvalue{7}}, MeasureName); + if ~any(IA) || isempty(IA) + IA =1; + end + + latency = str2num(ERPMTops.m_t_TW.String); + if isempty(latency) + msgboxText = ['Measurement Tool > Preview - Please define the measurement window']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + moption = ERPMTops.def_erpvalue{7}; + + if isempty(moption) + msgboxText = ['Measurement Tool - Preview - User must specify a type of measurement']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) + if length(latency)~=1 + msgboxText = ['Measurement Tool > Preview - ',32, moption,32, ' only needs 1 latency value']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + else + if length(latency)~=2 + msgboxText = ['Measurement Tool > Preview - ',32,moption,32, ' needs 2 latency values.']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + else + if latency(1)>=latency(2) + msgboxText = ['Measurement Tool > Preview - For latency range, lower time limit must be on the left.',32,... + 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; end - - if strcmp(EStudio_erp_m_t_p_save.FileFormat,'wide') - EStudio_erp_m_t_p_save.FileFormat = 0; + end + end + binArray = str2num(ERPMTops.m_t_bin.String); + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, binArray, [],1); + if chk(1) + msgboxText = ['Measurement Tool > Preview - ',32,msgboxText]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + chanArray = str2num(ERPMTops.m_t_chan.String); + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, [],chanArray,2); + if chk(2) + msgboxText = ['Measurement Tool > Preview - ',32,msgboxText]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + FileName = ERPMTops.m_t_file.String; + [pathNamex, fname, ext] = fileparts(FileName); + + FileName=ERPMTops.m_t_file.String; + estudioworkingmemory('f_ERP_proces_messg',' Measurement Tool > Preview'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); + ERPMTops.Paras{1} = ERPMTops.m_t_type.Value; + ERPMTops.Paras{2} = str2num(ERPMTops.m_t_erpset.String); + ERPMTops.Paras{3} = str2num(ERPMTops.m_t_bin.String); + ERPMTops.Paras{4} = str2num(ERPMTops.m_t_chan.String); + ERPMTops.Paras{5} = str2num(ERPMTops.m_t_TW.String); + ERPMTops.Paras{6} = ERPMTops.m_t_file.String; + estudioworkingmemory('ERPTab_mtviewer',1); + + if ~isempty(latency) + %%---------------save the applied parameters using estudioworkingmemory function-------------------- + Measure = MeasureName{IA}; + if strcmp(ERPMTops.def_erpvalue{11},'off') + Binlabel = 0; + else + Binlabel = 1; + end + if strcmp(ERPMTops.def_erpvalue{12},'negative') + Peakpolarity = 0; + else + Peakpolarity = 1; + end + + if strcmpi(ERPMTops.def_erpvalue{14},'absolute') + Peakreplace = 1; + elseif strcmpi(ERPMTops.def_erpvalue{14},'NaN') + Peakreplace = 0; % 1 abs peak , 0 Nan + elseif strcmpi(ERPMTops.def_erpvalue{14},'errormsg') + Peakreplace = -1; + end + + %%Fractional area latency replacement + if ismember_bc2({Measure}, {'fareatlat', 'fninteglat','fareanlat','fareaplat'}) % Fractional area latency replacement + if strcmpi(ERPMTops.def_erpvalue{16},'NaN')%% latency : closet 0, NAN 1, error 2 + Fracreplace = 0; % NaN else - EStudio_erp_m_t_p_save.FileFormat = 1; + Fracreplace = 2; end - - if strcmp(EStudio_erp_m_t_p_save.IncludeLat,'no') - EStudio_erp_m_t_p_save.IncludeLat = 0; + else + if strcmpi(ERPMTops.def_erpvalue{16},'absolute') + Fracreplace = 1; + elseif strcmpi(ERPMTops.def_erpvalue{16},'errormsg') + Fracreplace = -1; else - EStudio_erp_m_t_p_save.IncludeLat = 1; + Fracreplace = 0; end - - erpworkingmemory('pop_geterpvalues', {CurrentERPSet, EStudio_erp_m_t_p_save.Erpsets, EStudio_erp_m_t_p_save.Filename, EStudio_erp_m_t_p_save.latency,... - EStudio_erp_m_t_p_save.binArray, EStudio_erp_m_t_p_save.chanArray, EStudio_erp_m_t_p_save.Measure, EStudio_erp_m_t_p_save.Component, EStudio_erp_m_t_p_save.Resolution, EStudio_erp_m_t_p_save.Baseline,... - EStudio_erp_m_t_p_save.Binlabel, EStudio_erp_m_t_p_save.Peakpolarity,EStudio_erp_m_t_p_save.Neighborhood, EStudio_erp_m_t_p_save.Peakreplace,... - EStudio_erp_m_t_p_save.Afraction, EStudio_erp_m_t_p_save.Fracreplace,EStudio_erp_m_t_p_save.SendtoWorkspace, EStudio_erp_m_t_p_save.FileFormat, EStudio_erp_m_t_p_save.Mlabel,... - EStudio_erp_m_t_p_save.IncludeLat, EStudio_erp_m_t_p_save.InterpFactor, EStudio_erp_m_t_p_save.PeakOnset}); - end - observe_ERPDAT.Process_messg =2; - catch - beep; - msgboxText = ['ERP Measurement Tool - Cannot export the values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - end - - - -%----------displayed channel label will be midified after vaied channels was selected-------- - function ERP_chan_changed(~,~) - ERPMTops.m_t_chan.String = num2str(vect2colon(observe_ERPDAT.ERP_chan,'Sort', 'on')); - S_ws= estudioworkingmemory('geterpvalues'); - S_ws.chanArray = observe_ERPDAT.ERP_chan; - EStudio_erp_m_t_p.chanArray = observe_ERPDAT.ERP_chan; - estudioworkingmemory('geterpvalues',S_ws); clear S_ws; - end - -%----------displayed bin label will be midified after different channels was selected-------- - function ERP_bin_changed(~,~) - ERPMTops.m_t_bin.String = num2str(vect2colon(observe_ERPDAT.ERP_bin,'Sort', 'on')); - S_ws= estudioworkingmemory('geterpvalues'); - S_ws.binArray = observe_ERPDAT.ERP_bin; - EStudio_erp_m_t_p.binArray = observe_ERPDAT.ERP_bin; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; + + if strcmp(ERPMTops.def_erpvalue{17},'off') + SendtoWorkspace=0; + else + SendtoWorkspace=1; + end + if strcmp(ERPMTops.def_erpvalue{18},'wide') + FileFormat = 0; + else + FileFormat = 1; + end + if strcmp(ERPMTops.def_erpvalue{20},'no') + IncludeLat = 0; + else + IncludeLat = 1; + end + + estudioworkingmemory('pop_geterpvalues', {0, ERPsetArray, FileName, latency,... + binArray, chanArray, Measure, ERPMTops.def_erpvalue{8}, ERPMTops.def_erpvalue{9}, ERPMTops.def_erpvalue{10},... + Binlabel, Peakpolarity,ERPMTops.def_erpvalue{13},Peakreplace,... + ERPMTops.def_erpvalue{15}, Fracreplace,SendtoWorkspace, FileFormat, ERPMTops.def_erpvalue{19},... + IncludeLat, ERPMTops.def_erpvalue{21}, ERPMTops.def_erpvalue{22}}); + estudioworkingmemory('ViewerFlag', 1); + observe_ERPDAT.Count_currentERP=1; + estudioworkingmemory('f_ERP_proces_messg','Measurement Tool > Preview: The main ERPLAB Studio window will be frozen until you close the Viewer window for the Measurement Tool'); + observe_ERPDAT.Process_messg =4; %%Marking for the procedure has been started. + + f_erp_viewerGUI(observe_ERPDAT.ALLERP(ERPsetArray),1,binArray,chanArray); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + ERPCOM = ['f_erp_viewerGUI(ALLERP(',vect2colon(ERPsetArray),'),1,',... + vect2colon(binArray),',',vect2colon(chanArray),');']; + ALLERPCOM{end+1} = char(ERPCOM); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + end + estudioworkingmemory('ViewerFlag', 0); + observe_ERPDAT.Count_currentERP=1; + observe_ERPDAT.Process_messg =2; end - %%--------Settting if the current panel is active or not based on the selected ERPsets------------ function Count_currentERP_change(~,~) - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - beep; - msgboxText = ['ERP Measurement Tool - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - ERPMTops.m_t_erpset.String= num2str(vect2colon(Selectederp_Index,'Sort','on'));%%Dec 20 2022 - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; + if observe_ERPDAT.Count_currentERP~=14 + return; end - - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - if checked_curr_index || any(checked_ERPset_Index(:)) - ERPMTops.m_t_value.Enable = 'off'; + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 + Enable_label = 'off'; + else - ERPMTops.m_t_value.Enable = 'on'; + Enable_label = 'on'; end - Enable_label = 'on'; ERPMTops.m_t_type.Enable = Enable_label; ERPMTops.m_t_type_ops.Enable = Enable_label; ERPMTops.m_t_bin.Enable = Enable_label; @@ -1556,24 +1478,187 @@ function Count_currentERP_change(~,~) ERPMTops.m_t_file_ops.Enable = Enable_label; ERPMTops.m_t_viewer.Enable = Enable_label; ERPMTops.m_t_advanced.Enable = Enable_label; - ERPMTops.m_t_viewer_on.Enable = Enable_label; - ERPMTops.m_t_viewer_off.Enable = Enable_label; ERPMTops.m_t_erpset.Enable = Enable_label; ERPMTops.m_t_erpset_ops.Enable = Enable_label; - if checked_ERPset_Index(1)==1 - ERPMTops.m_t_bin.Enable = 'off'; - ERPMTops.m_t_bin_ops.Enable = 'off'; - else - ERPMTops.m_t_bin.Enable = 'on'; - ERPMTops.m_t_bin_ops.Enable = 'on'; + ERPMTops.cancel.Enable = Enable_label; + ERPMTops.apply.Enable = Enable_label; + ERPMTops.m_t_value.Enable = Enable_label; + if strcmpi(Enable_label,'off') + observe_ERPDAT.Count_currentERP=15; + return; + end + + if ~isempty(observe_ERPDAT.ERP) && ~isempty(observe_ERPDAT.ALLERP) + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray> length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + ERPArray = vect2colon(ERPArray,'Sort','on'); + ERPArray = erase(ERPArray,{'[',']'}); + % ERPMTops.m_t_erpset.String= ERPArray;%%Dec 20 2022 + BinArray = estudioworkingmemory('ERP_BinArray'); + ChanArray = estudioworkingmemory('ERP_ChanArray'); + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, BinArray, [],1); + if chk(1)==1 + BinArray = [1:observe_ERPDAT.ERP.nbin]; + end + BinArray = vect2colon(BinArray,'Sort', 'on'); + BinArray = erase(BinArray,{'[',']'}); + + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP,[], ChanArray,2); + if chk(2)==1 + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + end + ChanArray = vect2colon(ChanArray,'Sort', 'on'); + ChanArray = erase(ChanArray,{'[',']'}); + % ERPMTops.m_t_chan.String = ChanArray; + end + observe_ERPDAT.Count_currentERP=15; + end + +%%-----------------------cancel-------------------------------------------- + function ERPmeasr_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end - if checked_ERPset_Index(2)==2 - ERPMTops.m_t_chan.Enable = 'off'; - ERPMTops.m_t_chan_ops.Enable = 'off'; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=10 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); + + m_t_type = ERPMTops.Paras{1} ; + if isempty(m_t_type) || numel(m_t_type)~=1 || any(m_t_type>20) + m_t_type =1; ERPMTops.Paras{1} =1; + end + ERPMTops.m_t_type.Value=m_t_type; + %%erpsets + m_t_erpset = ERPMTops.Paras{2}; + if isempty(m_t_erpset) || any(m_t_erpset> length(observe_ERPDAT.ALLERP)) + m_t_erpset = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = m_t_erpset; + estudioworkingmemory('selectederpstudio',m_t_erpset); + ERPMTops.Paras{2} = m_t_erpset; + end + m_t_erpset = vect2colon(m_t_erpset,'Sort', 'on'); + m_t_erpset = erase(m_t_erpset,{'[',']'}); + ERPMTops.m_t_erpset.String= m_t_erpset; + %%binarray + BinArray= ERPMTops.Paras{3}; + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, BinArray, [],1); + if chk(1)==1 + BinArray = [1:observe_ERPDAT.ERP.nbin]; + ERPMTops.Paras{3} = BinArray; + end + BinArray = vect2colon(BinArray,'Sort', 'on'); + BinArray = erase(BinArray,{'[',']'}); + ERPMTops.m_t_bin.String = BinArray; + %%chanarray + ChanArray=ERPMTops.Paras{4}; + [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP,[], ChanArray,2); + if chk(2)==1 + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + ERPMTops.Paras{4}= ChanArray; + end + ChanArray = vect2colon(ChanArray,'Sort', 'on'); + ChanArray = erase(ChanArray,{'[',']'}); + ERPMTops.m_t_chan.String = ChanArray; + %%latency + latency = ERPMTops.Paras{5}; + if isempty(latency) || any(latencyobserve_ERPDAT.ERP.times(end)) + latency = []; + ERPMTops.Paras{5}=[]; + end + ERPMTops.m_t_TW.String = num2str(latency); + %%path name + try pathanme = ERPMTops.Paras{6}; catch pathanme= ''; ERPMTops.Paras{6}='';end + ERPMTops.m_t_file.String = pathanme; + end + +%%--------------press return to execute "Apply"---------------------------- + function erp_mt_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_mesuretool'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + erp_m_t_view(); + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); else - ERPMTops.m_t_chan.Enable = 'on'; - ERPMTops.m_t_chan_ops.Enable = 'on'; + return; end end -end%Progem end: ERP Measurement tool \ No newline at end of file + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=10 + return; + end + ERPMTops.m_t_value.BackgroundColor = [1 1 1]; + ERPMTops.m_t_value.ForegroundColor = [0 0 0]; + erp_measurement_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + ERPMTops.cancel.BackgroundColor = [1 1 1]; + ERPMTops.cancel.ForegroundColor = [0 0 0]; + ERPMTops.apply.BackgroundColor = [1 1 1]; + ERPMTops.apply.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_mesuretool',0); + ERPMTops.m_t_type.Value=1; + ERPArray= estudioworkingmemory('selectederpstudio'); + if ~isempty(observe_ERPDAT.ALLERP) + if isempty(ERPArray) || any(ERPArray> length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + end + ERPArray = vect2colon(ERPArray,'Sort', 'on'); + ERPArray = erase(ERPArray,{'[',']'}); + ERPMTops.m_t_erpset.String= ERPArray;%%Dec 20 2022 + try + BinArray = [1:observe_ERPDAT.ERP.nbin]; + catch + BinArray = []; + end + BinArray = vect2colon(BinArray,'Sort', 'on'); + BinArray = erase(BinArray,{'[',']'}); + ERPMTops.m_t_bin.String = BinArray; + try + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + catch + ChanArray = []; + end + ChanArray = vect2colon(ChanArray,'Sort', 'on'); + ChanArray = erase(ChanArray,{'[',']'}); + ERPMTops.m_t_chan.String = ChanArray; + ERPMTops.m_t_TW.String = ''; + ERPMTops.m_t_file.String = ''; + ERPMTops.def_erpvalue{18} = 'wide';%%file format + ERPMTops.def_erpvalue{11} = 'off';%%Binlabel + ERPMTops.def_erpvalue{17} = 'off';%%send2ws + ERPMTops.def_erpvalue{20} = 'off' ;%%inclate + observe_ERPDAT.Reset_erp_paras_panel=11; + end + +end%Progem end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_plot_scalp_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_plot_scalp_GUI.m index 964fb78f..c6371c12 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_plot_scalp_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_plot_scalp_GUI.m @@ -2,31 +2,30 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && 2023 Oct. % ERPLAB Studio function varargout = f_ERP_plot_scalp_GUI(varargin) global observe_ERPDAT; -gui_erp_scalp_map = struct(); -% addlistener(observe_ERPDAT,'ALLERP_change',@allErpChanged); -% addlistener(observe_ERPDAT,'ERP_change',@onErpChanged); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); -addlistener(observe_ERPDAT,'ERP_bin_change',@ERP_bin_changed); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); - - +gui_erp_scalp_map = struct(); %-----------------------------Name the title---------------------------------------------- % global ERP_plot_scalp_gui; [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; if nargin == 0 fig = figure(); % Parent figure - ERP_plot_scalp_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Plot Scalp Maps', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_plot_scalp_gui = uiextras.BoxPanel('Parent', fig, 'Title', 'Plot Scalp Maps',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_plot_scalp_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Scalp Maps', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_plot_scalp_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Scalp Maps',... + 'Padding', 5,'BackgroundColor',ColorB_def); else - ERP_plot_scalp_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Scalp Maps', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_plot_scalp_gui = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Scalp Maps',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @scap_help end %-----------------------------Draw the panel------------------------------------- @@ -36,23 +35,14 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_scalp_operation(FonsizeDefault); varargout{1} = ERP_plot_scalp_gui; function drawui_erp_scalp_operation(FonsizeDefault) - % FontSize_defualt = erpworkingmemory('fontsizeGUI'); - % if isempty(FontSize_defualt) - FontSize_defualt = 12; - % end - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end - + Enable_label = 'off'; plegend.binnum = 1; plegend.bindesc = 1; plegend.type = 1; @@ -69,33 +59,59 @@ function drawui_erp_scalp_operation(FonsizeDefault) agif.fname =''; estudioworkingmemory('pscalp_agif',agif); + ERPTab_plotscalp= estudioworkingmemory('ERPTab_plotscalp'); [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; %%--------------------bin and latency setting---------------------- gui_erp_scalp_map.ERPscalpops = uiextras.VBox('Parent', ERP_plot_scalp_gui,'BackgroundColor',ColorB_def); + %%%------------BIN TO PLOT--------------------- - gui_erp_scalp_map.bin_latency_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); - uicontrol('Style', 'text','Parent', gui_erp_scalp_map.bin_latency_title,... - 'String','Bin & Latency:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.measurement_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.measurement = uicontrol('Style', 'popupmenu','Parent', gui_erp_scalp_map.measurement_title,... + 'callback',@measurement_methods, 'String','','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',Enable_label); + measurearray = {'Instantaneous amplitude','Mean amplitude between two fixed latencies',... + 'Instantaneous amplitude Laplacian', 'Mean amplitude Laplacian', 'Root mean square value'}; + set(gui_erp_scalp_map.measurement,'String',measurearray,'Value',2); + ERPTab_plotscalp{10} = gui_erp_scalp_map.measurement.Value; + gui_erp_scalp_map.measurement.KeyPressFcn= @erp_scalps_presskey; + + gui_erp_scalp_map.measurement_title1 = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.measurement_exp = uicontrol('Style', 'text','Parent', gui_erp_scalp_map.measurement_title1,... + 'String','(min max pairs e.g., 300 400 ; 400 500)','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); gui_erp_scalp_map.bin_plot_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); gui_erp_scalp_map.bin_plot = uicontrol('Style','text','Parent',gui_erp_scalp_map.bin_plot_title,... - 'String','Bin(s)','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + 'String','Bin(s)','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2F set(gui_erp_scalp_map.bin_plot,'HorizontalAlignment','left'); gui_erp_scalp_map.bin_plot_edit = uicontrol('Style','edit','Parent',gui_erp_scalp_map.bin_plot_title,... - 'String','','callback',@scalp_bin_edit,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + 'String','','callback',@scalp_bin_edit,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + try binArray = ERPTab_plotscalp{1}; catch binArray = [];ERPTab_plotscalp{1} = [];end + gui_erp_scalp_map.bin_plot_edit.String = num2str(binArray); + + gui_erp_scalp_map.bin_plot_edit.KeyPressFcn= @erp_scalps_presskey; gui_erp_scalp_map.bin_plot_opt = uicontrol('Style','pushbutton','Parent',gui_erp_scalp_map.bin_plot_title,... - 'String','Browse','callback',@scalp_bin_op,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + 'String','Browse','callback',@scalp_bin_op,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F set(gui_erp_scalp_map.bin_plot_title ,'Sizes',[60 150 60]); %%%------------Latency TO PLOT--------------------- gui_erp_scalp_map.latency_plot_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); gui_erp_scalp_map.latency_plot = uicontrol('Style','text','Parent',gui_erp_scalp_map.latency_plot_title,... - 'String','Latency (ms) [min max]','FontSize',FontSize_defualt,'BackgroundColor',ColorB_def); % 2F + 'String','Latency (ms) [min max]','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2F set(gui_erp_scalp_map.latency_plot,'HorizontalAlignment','left'); gui_erp_scalp_map.latency_plot_edit = uicontrol('Style','edit','Parent',gui_erp_scalp_map.latency_plot_title,... - 'String','','callback',@scalp_latency_plot,'FontSize',FontSize_defualt,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + 'String','','callback',@scalp_latency_plot,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + gui_erp_scalp_map.latency_plot_edit.KeyPressFcn= @erp_scalps_presskey; + try Latency = ERPTab_plotscalp{2}; catch Latency = [];ERPTab_plotscalp{2} = [];end + Latencystr = ''; + for ii = 1:size(Latency,1) + if ii==1 + Latencystr = [num2str(Latency(ii,:))]; + else + Latencystr = [Latencystr,';',num2str(Latency(ii,:))]; + end + end + gui_erp_scalp_map.latency_plot_edit.String = Latencystr; %%----------------------------------Map Type------------------------------ gui_erp_scalp_map.map_type_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); @@ -106,19 +122,36 @@ function drawui_erp_scalp_operation(FonsizeDefault) % gui_erp_scalp_map.map_type_2d = uicontrol('Style', 'radiobutton','Parent', gui_erp_scalp_map.map_type,... 'String','2D','callback',@map_type_2d,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.map_type_2d.KeyPressFcn= @erp_scalps_presskey; + try map2d = ERPTab_plotscalp{3}; catch map2d=1;ERPTab_plotscalp{3} = 1;end + if isempty(map2d) || numel(map2d)~=1 || (map2d~=0 && map2d~=1) + map2d=1; + end + gui_erp_scalp_map.map_type_2d.Value= map2d; gui_erp_scalp_map.map_type_3d = uicontrol('Style', 'radiobutton','Parent', gui_erp_scalp_map.map_type,... - 'String','3D','callback',@map_type_3d,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + 'String','3D','callback',@map_type_3d,'Value',~map2d,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.map_type_3d.KeyPressFcn= @erp_scalps_presskey; gui_erp_scalp_map.map_type_2d_type = uicontrol('Style', 'popupmenu','Parent',gui_erp_scalp_map.map_type,... - 'String',{'map','contour','both','fill','blank'},'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + 'callback',@map_type_2d_type,'String',{'map','contour','both','fill','blank'},'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + try twodtyep = ERPTab_plotscalp{4}; catch twodtyep=1;ERPTab_plotscalp{4} = 1;end + if isempty(twodtyep) || numel(twodtyep)~=1 || any(twodtyep>5) || any(twodtyep<1) + twodtyep=1;ERPTab_plotscalp{4} = 1; + end + gui_erp_scalp_map.map_type_2d_type.Value=twodtyep; + gui_erp_scalp_map.map_type_3d_spl = uicontrol('Style', 'pushbutton','Parent',gui_erp_scalp_map.map_type,... 'String','Spline','callback',@map_type_3d_spl,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - gui_erp_scalp_map.map_type_2d_type_outside = uicontrol('Style', 'checkbox','Parent',gui_erp_scalp_map.map_type,... 'String','Outside','Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_scalp_map.map_type); - + try mapoutside = ERPTab_plotscalp{5}; catch mapoutside=0;ERPTab_plotscalp{5} = 0;end + if isempty(mapoutside) || numel(mapoutside)~=1 || (mapoutside~=0 && mapoutside~=1) + mapoutside=0; + ERPTab_plotscalp{5}=0; + end + gui_erp_scalp_map.map_type_2d_type_outside.Value = mapoutside; set(gui_erp_scalp_map.map_type, 'ColumnSizes',[50 130 90],'RowSizes',[25 30]); %%----------------------------------Bar scale------------------------------ @@ -127,20 +160,51 @@ function drawui_erp_scalp_operation(FonsizeDefault) 'String','Color Bar Scale:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); gui_erp_scalp_map.bar_scale = uiextras.HBox('Parent',gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); - gui_erp_scalp_map.max_min = uicontrol('Style', 'radiobutton','Parent', gui_erp_scalp_map.bar_scale,... 'String','Max-Min','callback',@bar_scale_max_min,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.max_min.KeyPressFcn= @erp_scalps_presskey; gui_erp_scalp_map.custom_option = uicontrol('Style', 'radiobutton','Parent',gui_erp_scalp_map.bar_scale,... 'String','Custom (min max:e.g.uv)','callback',@bar_scale_custom_opt,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.custom_option.KeyPressFcn= @erp_scalps_presskey; set(gui_erp_scalp_map.bar_scale ,'Sizes',[100 170]); - gui_erp_scalp_map.bar_scale_2 = uiextras.HBox('Parent',gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); gui_erp_scalp_map.abs_max = uicontrol('Style', 'radiobutton','Parent', gui_erp_scalp_map.bar_scale_2,... 'String','Abs Max','callback',@bar_scale_abs_max,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_scalp_map.abs_max.KeyPressFcn= @erp_scalps_presskey; gui_erp_scalp_map.bar_scale_custom_option_edit = uicontrol('Style', 'edit','Parent',gui_erp_scalp_map.bar_scale_2,... 'String',' ','callback',@bar_scale_custom_edit,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_erp_scalp_map.bar_scale_custom_option_edit.KeyPressFcn= @erp_scalps_presskey; set(gui_erp_scalp_map.bar_scale_2 ,'Sizes',[100 170]); + try barscale = ERPTab_plotscalp{6}; catch barscale=1;ERPTab_plotscalp{65} = 1;end + if isempty(barscale) || (numel(barscale)~=1 && numel(barscale)~=2) + barscale=1; + ERPTab_plotscalp{6}=1; + end + if numel(barscale)==1 + if barscale~=1 && barscale~=2 + barscale=1; + ERPTab_plotscalp{6}=1; + end + if barscale==1 + gui_erp_scalp_map.max_min.Value=1; + gui_erp_scalp_map.abs_max.Value=0; + gui_erp_scalp_map.custom_option.Value=0; + else + gui_erp_scalp_map.max_min.Value=0; + gui_erp_scalp_map.abs_max.Value=1; + gui_erp_scalp_map.custom_option.Value=0; + end + elseif numel(barscale)==2 + gui_erp_scalp_map.max_min.Value=0; + gui_erp_scalp_map.abs_max.Value=0; + gui_erp_scalp_map.custom_option.Value=1; + gui_erp_scalp_map.bar_scale_custom_option_edit.String = num2str(barscale); + else + gui_erp_scalp_map.max_min.Value=1; + gui_erp_scalp_map.abs_max.Value=0; + gui_erp_scalp_map.custom_option.Value=0; + end %%----------------------------------Map Extras------------------------------ gui_erp_scalp_map.map_extras_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); @@ -148,21 +212,29 @@ function drawui_erp_scalp_operation(FonsizeDefault) 'String','Map Extras:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); %%view gui_erp_scalp_map.map_extras_view = uiextras.HBox('Parent',gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); - uicontrol('Style', 'text','Parent', gui_erp_scalp_map.map_extras_view,... 'String','View','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'HorizontalAlignment','left'); - morimenu = {'front', 'back', 'right', 'left', 'top',... 'frontleft', 'frontright', 'backleft', 'backright',... 'custom'}; gui_erp_scalp_map.map_extras_view_ops = uicontrol('Style', 'popupmenu','Parent',gui_erp_scalp_map.map_extras_view,... 'String',morimenu,'callback',@map_extras_view_ops,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - + gui_erp_scalp_map.map_extras_view_ops.KeyPressFcn= @erp_scalps_presskey; gui_erp_scalp_map.map_extras_view_location = uicontrol('Style', 'edit','Parent',gui_erp_scalp_map.map_extras_view,... 'String','','callback',@map_extras_view_location,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - + gui_erp_scalp_map.map_extras_view_location.KeyPressFcn= @erp_scalps_presskey; set(gui_erp_scalp_map.map_extras_view,'Sizes',[70 100 100]); - + if map2d==1 + gui_erp_scalp_map.map_extras_view_ops.Value=1; + ERPTab_plotscalp{7}=1; + else + try mapextrc = ERPTab_plotscalp{7}; catch mapextrc=1;ERPTab_plotscalp{7} = 1;end + if isempty(mapextrc) || numel(mapextrc)~=1 || any(mapextrc<1) || any(mapextrc>10) + mapextrc=1; + ERPTab_plotscalp{7}=1; + end + gui_erp_scalp_map.map_extras_view_ops.Value=mapextrc; + end %%Extras gui_erp_scalp_map.map_extras_cmap_display= uiextras.HBox('Parent',gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); @@ -172,52 +244,97 @@ function drawui_erp_scalp_operation(FonsizeDefault) set(gui_erp_scalp_map.map_extras_cmap,'HorizontalAlignment','left'); cMap_par={'jet','hsv','hot','cool','gray','viridis'}; gui_erp_scalp_map.map_extras_cmap_ops = uicontrol('Style', 'popupmenu','Parent', gui_erp_scalp_map.map_extras_cmap_display,... - 'String',cMap_par,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1,1,1]); + 'String',cMap_par,'callback',@colormap,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1,1,1]); + try clormap = ERPTab_plotscalp{8}; catch clormap=1;ERPTab_plotscalp{8} = 1;end + if isempty(clormap) || numel(clormap)~=1 || any(clormap<1) || any(clormap>6) + clormap=1; + end + gui_erp_scalp_map.map_extras_cmap_ops.Value = clormap; + gui_erp_scalp_map.map_extras_cmap_ops.KeyPressFcn= @erp_scalps_presskey; gui_erp_scalp_map.map_extras_cmapb_disp = uicontrol('Style', 'checkbox','Parent', gui_erp_scalp_map.map_extras_cmap_display,... - 'String','Display color scale bar','Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + 'callback',@dispbar,'String','Display color scale bar','Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); gui_erp_scalp_map.map_extras_cmapb_disp.String = 'Display Color
                            Scale Bar'; + gui_erp_scalp_map.map_extras_cmapb_disp.KeyPressFcn= @erp_scalps_presskey; set(gui_erp_scalp_map.map_extras_cmap_display ,'Sizes',[70 90 110]); - - + try dispbar = ERPTab_plotscalp{9}; catch dispbar=0;ERPTab_plotscalp{9} = 0;end + if isempty(dispbar) || numel(dispbar)~=1 || (dispbar~=0 && dispbar~=1) + dispbar=0;ERPTab_plotscalp{9} = 0; + end + gui_erp_scalp_map.map_extras_cmapb_disp.Value = dispbar; %%-----------------Run--------------------------------------------- gui_erp_scalp_map.run_title = uiextras.HBox('Parent', gui_erp_scalp_map.ERPscalpops,'BackgroundColor',ColorB_def); - uicontrol('Style','pushbutton','Parent',gui_erp_scalp_map.run_title,... - 'String','?','callback',@scap_help,'FontSize',16,'Enable','on'); % 2F + gui_erp_scalp_map.cancel = uicontrol('Style','pushbutton','Parent',gui_erp_scalp_map.run_title,... + 'String','Cancel','callback',@scap_cancel,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_scalp_map.advanced = uicontrol('Style','pushbutton','Parent',gui_erp_scalp_map.run_title,... - 'String','Advanced','callback',@apply_advanced,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F + 'String','Options','callback',@apply_advanced,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F gui_erp_scalp_map.run = uicontrol('Style','pushbutton','Parent',gui_erp_scalp_map.run_title,... - 'String','Apply','callback',@apply_run,'FontSize',FontSize_defualt,'Enable',Enable_label); % 2F - set(gui_erp_scalp_map.ERPscalpops,'Sizes',[20,25,25,25 55 20 30 25 20 25 30 30]); + 'String','Plot','callback',@apply_run,'FontSize',FonsizeDefault,'Enable',Enable_label,'BackgroundColor',[1 1 1]); % 2F + set(gui_erp_scalp_map.ERPscalpops,'Sizes',[25 20 25,25,25 55 20 30 25 20 25 30 30]); + + estudioworkingmemory('ERPTab_topos',0); + estudioworkingmemory('ERPTab_plotscalp',ERPTab_plotscalp); end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% -% %%------------------help--------------------------------------------- - function scap_help(~,~)%% It seems that it can be ignored - web('https://github.com/lucklab/erplab/wiki/Topographic-Mapping','-browser'); + function measurement_methods(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + Value = gui_erp_scalp_map.measurement.Value; + switch Value + case {1,3} + gui_erp_scalp_map.measurement_exp.String='(one or more: e.g. 300 or 100:50:350)'; + case {2,4,5} + gui_erp_scalp_map.measurement_exp.String='(min max pairs: e.g., 300 400 ; 400 500)'; + end end -%%-------------------Input bin number--------------------------------------- +%%-------------------Input bin number-------------------------------------- function scalp_bin_edit(Source,~) - binNums = str2num(Source.String); - [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, binNums, [],1); - - if chk(1) - beep; - msgboxText = ['Plot Scalp Maps>Bins-',msgboxText]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + BinArray = str2num(Source.String); + if isempty(BinArray) || any(BinArray(:)>observe_ERPDAT.ERP.nbin) || any(BinArray(:)<=0) + msgboxText = ['Plot Scalp Maps>Bins-Indexes of bins should be between 1 and',32,num2str(observe_ERPDAT.ERP.nbin)]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_scalp_map.bin_plot_edit.String = ''; return; end @@ -225,6 +342,23 @@ function scalp_bin_edit(Source,~) %%---------------------bin options--------------------------------- function scalp_bin_op(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; ERP_CURRENT = evalin('base','ERP'); for Numofbin = 1:length(ERP_CURRENT.bindescr) @@ -235,102 +369,127 @@ function scalp_bin_op(~,~) catch return; end - titlename = 'Select Bin(s):'; %----------------judge the number of latency/latencies-------- if ~isempty(listb) bin_label_select = browsechanbinGUI(listb, indxlistb, titlename); if ~isempty(bin_label_select) - gui_erp_scalp_map.bin_plot_edit.String=num2str(vect2colon(bin_label_select,'Sort', 'on')); + binset = vect2colon(bin_label_select,'Sort', 'on'); + binset = erase(binset,{'[',']'}); + gui_erp_scalp_map.bin_plot_edit.String=binset; else - disp('User selected Cancel'); return end else msgboxText = ['Plot Scalp Maps>Bins>Browse-No bin information was found',]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end%Program end: Judge the number of latency/latencies - S_ws= estudioworkingmemory('geterpvalues'); - if isempty(S_ws) - return; - end - - S_ws.binArray = bin_label_select; - estudioworkingmemory('geterpvalues',S_ws);clear S_ws; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + % observe_ERPDAT.Count_currentERP = 1; end - %%----------------------Define time window (two latencies)----------------- function scalp_latency_plot(Source,~) - Latecny_scale = str2num(Source.String); - ERP_times = observe_ERPDAT.ERP.times; - if isempty(Latecny_scale) - beep; - msgboxText = ['Plot Scalp Maps>latency-No latency was defined',]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + ERP_times = observe_ERPDAT.ERP.times; + meamenu = gui_erp_scalp_map.measurement.Value; + switch meamenu + case 1 + measurement = 'insta'; + case 2 + measurement = 'mean'; + case 3 + measurement = 'instalapla'; + case 4 + measurement = 'meanlapla'; + case 5 + measurement = 'rms'; + otherwise + measurement = 'insta'; + end - latency = Latecny_scale; - if length(latency)~=2 - beep; - msgboxText = ['Plot Scalp Maps>Latency-Latency needs two values',]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + latencyArray = str2num(gui_erp_scalp_map.latency_plot_edit.String); + if isempty(latencyArray) return; - elseif length(latency)==2 - if latency(1)>=latency(2) - beep; - msgboxText = ['Plot Scalp Maps>Latency-The left edge should be smaller than the seocnd one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latency(1)< ERP_times(1) - beep; - msgboxText = ['Plot Scalp Maps>Latency-The left edge should be larger than the seocnd one',32, num2str(ERP_times(1)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latency(2)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps>Latency-The right edge should be smaller than the seocnd one',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latency(1)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps>Latency-The left edge should be smaller than the seocnd one',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - + end + indxh = find(latencyArray>ERP_times(end),1); + if ~isempty(indxh) + msgboxText = ['Plot Scalp Maps> Latency of ' num2str(latencyArray(indxh)) ' is larger than ERP.xmax = ' num2str(ERP_times(end)) ' msec!']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + gui_erp_scalp_map.latency_plot_edit.String = ''; + return + end + + indxl = find(latencyArray Latency of ' num2str(latencyArray(indxl)) ' is smaller than ERP.xmin = ' num2str(ERP_times(1)) ' msec!']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + gui_erp_scalp_map.latency_plot_edit.String = ''; + return + end + + switch meamenu + case {2, 4, 5} % mean, meanlapla, rms + if size(latencyArray,2)<2 + msgboxText = ['Plot Scalp Maps>latency> You must specify 2 latencies, at least, for getting %s-values.'... + 'For specifying two or more mean value maps, please use semicolon (;) to separate each latency range.'... + 'For instance, to plot mean value maps for 0 to 100 ms AND 400 to 500 ms just write 0 100;400 500']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + + gui_erp_scalp_map.latency_plot_edit.String = ''; + return + end + case {1,3} % insta, instalapla + if size(latencyArray,1)>1 + msgboxText = 'Plot Scalp Maps>latency>For you must specify as many latencies as maps you would like to plot.You cannot use semicolon-separated values.'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end end end - - %%-----------------Dispaly topography with 2D------------------------------ function map_type_2d(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; gui_erp_scalp_map.map_type_2d.Value=1; gui_erp_scalp_map.map_type_3d.Value=0; set(gui_erp_scalp_map.map_type_2d_type,'Enable','on','Value',1); @@ -347,6 +506,23 @@ function map_type_2d(~,~) %%-----------------Dispaly topography with 3D------------------------------ function map_type_3d(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; gui_erp_scalp_map.map_type_2d.Value=0; gui_erp_scalp_map.map_type_3d.Value=1; gui_erp_scalp_map.map_type_3d_spl.Enable = 'on'; @@ -363,183 +539,196 @@ function map_type_3d(~,~) end + function map_type_2d_type(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + end + + %%---------------------Spline setting for 3D------------------------------- function map_type_3d_spl(~,~) - pathName_def = erpworkingmemory('ERP_save_folder'); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + + pathName_def = estudioworkingmemory('EEG_save_folder'); if isempty(pathName_def) pathName_def =cd; end - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index)%%Check indexs of the selected ERPsets - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - msgboxText = 'No ERPset was imported!!!'; - title = 'EStudio: f_ERP_binoperation_GUI error.'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray)%%Check indexs of the selected ERPsets + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); else - [chk, msgboxText] = f_ERP_chckerpindex(observe_ERPDAT.ALLERP, Selectederp_Index); + [chk, msgboxText] = f_ERP_chckerpindex(observe_ERPDAT.ALLERP, ERPArray); if chk==1 - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - msgboxText = 'No ERPset was imported!!!'; - title = 'EStudio: f_ERP_binoperation_GUI error.'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + ERPArray = observe_ERPDAT.CURRENTERP; end end %%Send message to Message panel - erpworkingmemory('f_ERP_proces_messg','Plot Scalp Maps'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - - Selectederp_Index_save = []; count_scalp = 0; - try - erpworkingmemory('f_ERP_proces_messg','Plot Scalp Maps > 3D > Spline'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - ALLERPCOM = evalin('base','ALLERPCOM'); - for Numofselectederp = 1:length(Selectederp_Index) - ERP = observe_ERPDAT.ALLERP(Selectederp_Index(Numofselectederp)); - ERP.filepath = pathName_def; - - try - splnfile = ERP.splinefile; - catch - splnfile = ''; - end - if ~isempty(splnfile) - [pathstr, file_name, ext] = fileparts(splnfile); - splnfile = fullfile(pathName_def,[file_name,ext]); + estudioworkingmemory('f_ERP_proces_messg','Plot Scalp Maps > 3D > Spline'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + ALLERPCOM = evalin('base','ALLERPCOM'); + for Numoferp = 1:length(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + ERP.filepath = pathName_def; + try + splnfile = ERP.splinefile; + catch + splnfile = ''; + end + if ~isempty(splnfile) + [pathstr, file_name, ext] = fileparts(splnfile); + splnfile = fullfile(pathName_def,[file_name,ext]); + end + + %% open splinefilegui + splineinfo = splinefileGUI({splnfile},ERP); + if isempty(splineinfo) + observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; + observe_ERPDAT.Process_messg =2;%% + return + end + splinefile = splineinfo.path; + if isempty(splinefile) + msgboxText = 'Plot Scalp Maps: You must specify a name for the spline file'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + Save_file_label =0; + if splineinfo.save + if isempty(ERP.splinefile) + ERP.splinefile = splinefile; + else + question = ['This ERPset already has spline file info.\n'... + 'Would you like to replace it?']; + title_msg = 'EStudio: spline file'; + button = askquest(sprintf(question), title_msg); + + if ~strcmpi(button,'yes') + return + else + ERP.splinefile = splinefile; + end end - %% open splinefilegui - splineinfo = splinefileGUI({splnfile},ERP); - if isempty(splineinfo) - disp('User selected Cancel'); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%% - return + Answer = f_ERP_save_single_file(strcat(ERP.erpname,'_scalspline'),ERP.filename,ERPArray(Numoferp)); + if isempty(Answer) + observe_ERPDAT.Process_messg =2;%% + return; end - splinefile = splineinfo.path; - - if isempty(splinefile) - msgboxText = 'You must specify a name for the spline file.'; - title = 'EStudio: Plot Scalp Maps inputs'; - errorfound(msgboxText, title); - return - end - Save_file_label =0; - if splineinfo.save - if isempty(ERP.splinefile) - ERP.splinefile = splinefile; - % ERP = pop_savemyerp(ERP, 'gui', 'erplab', 'History', 'off'); - else - question = ['This ERPset already has spline file info.\n'... - 'Would you like to replace it?']; - title_msg = 'EStudio: spline file'; - button = askquest(sprintf(question), title_msg); - - if ~strcmpi(button,'yes') - disp('User selected Cancel') - return - else - ERP.splinefile = splinefile; - end - end - - Answer = f_ERP_save_single_file(strcat(ERP.erpname,'_scalspline'),ERP.filename,Selectederp_Index(Numofselectederp)); - if isempty(Answer) - beep; - disp('User selectd cancal'); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%% - return; + if ~isempty(Answer) + ERPName = Answer{1}; + if ~isempty(ERPName) + ERP.erpname = ERPName; end - - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ERP.erpname; - Save_file_label =0; - elseif ~isempty(fileName_full) - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - Save_file_label =1; + fileName_full = Answer{2}; + if isempty(fileName_full) + ERP.filename = ERP.erpname; + Save_file_label =0; + elseif ~isempty(fileName_full) + [pathstr, file_name, ext] = fileparts(fileName_full); + ext = '.erp'; + if strcmp(pathstr,'') + pathstr = cd; end - + ERP.filename = [file_name,ext]; + ERP.filepath = pathstr; + Save_file_label =1; end - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - count_scalp = count_scalp+1;%%Record the new data; - Selectederp_Index_save(count_scalp) = length(observe_ERPDAT.ALLERP); - splineinfo.save = 0; - observe_ERPDAT.ERP = ERP; - else - ERP.splinefile = splinefile; - observe_ERPDAT.ALLERP(Selectederp_Index(Numofselectederp)) = ERP; - observe_ERPDAT.ERP = ERP; - end - - - if Save_file_label==1 - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - assignin('base','ERPCOM',ERPCOM); - end - end%%end for ERPset loop - - if ~isempty(Selectederp_Index_save) - try - Selected_ERP_afd = Selectederp_Index_save; - observe_ERPDAT.CURRENTERP = Selectederp_Index_save(1); - catch - Selected_ERP_afd = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; + count_scalp = count_scalp+1;%%Record the new data; + Selectederp_Index_save(count_scalp) = ERPArray(Numoferp); + splineinfo.save = 0; + else + ERP.splinefile = splinefile; + observe_ERPDAT.ALLERP(ERPArray(Numoferp)) = ERP; end - assignin('base','ALLERPCOM',ALLERPCOM); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - return; - catch - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + if Save_file_label==1 + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + assignin('base','ERPCOM',ERPCOM); + end + end%%end for ERPset loop + + if ~isempty(Selectederp_Index_save) + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - Selected_ERP_afd =observe_ERPDAT.CURRENTERP; estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - erpworkingmemory('f_ERP_bin_opt',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =3;%% - return; - end%%end for try - + end + assignin('base','ALLERPCOM',ALLERPCOM); + estudioworkingmemory('f_ERP_bin_opt',1); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end %%------------------------------Color bar scale: Max-min---------------------------- function bar_scale_max_min(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.max_min.Value = 1; gui_erp_scalp_map.custom_option.Value = 0; gui_erp_scalp_map.abs_max.Value = 0; @@ -549,6 +738,23 @@ function bar_scale_max_min(~,~) %%------------------------------Color bar scale: abs max---------------------------- function bar_scale_abs_max(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; gui_erp_scalp_map.max_min.Value = 0; gui_erp_scalp_map.custom_option.Value = 0; gui_erp_scalp_map.abs_max.Value = 1; @@ -558,6 +764,24 @@ function bar_scale_abs_max(~,~) %%------------------------------Color bar scale: custom---------------------------- function bar_scale_custom_opt(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; gui_erp_scalp_map.max_min.Value = 0; gui_erp_scalp_map.custom_option.Value = 1; gui_erp_scalp_map.abs_max.Value = 0; @@ -565,15 +789,52 @@ function bar_scale_custom_opt(~,~) end %%-------------------Bar scale custom edit--------------------------------- function bar_scale_custom_edit(Source,~) - - + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + barscale = str2num(Source.String); + if isempty(barscale) || numel(barscale)~=2 + msgboxText = ['Plot Scalp Maps > Color bar scale: it should be two values']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end end - - - %%---------------location selection---------------------------------------- function map_extras_view_ops(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; if gui_erp_scalp_map.map_type_3d.Value%%%If 3D pos = Source.Value; @@ -607,77 +868,199 @@ function map_extras_view_ops(Source,~) set(gui_erp_scalp_map.map_extras_view_location, 'String', vect2colon(mview, 'Delimiter', 'off')) set(gui_erp_scalp_map.map_extras_view_location, 'Enable', 'off') end - end end +%%---------------------------view------------------------------------------ + function map_extras_view_location(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + end + + +%%------------------------color map---------------------------------------- + function colormap(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + end + + +%%------------------------display color bar?------------------------------- + function dispbar(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; + end + + %%---------------------Setting for advanced--------------------------------- function apply_advanced(~,~) - + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_topos',1); + gui_erp_scalp_map.run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_scalp_map.run.ForegroundColor = [1 1 1]; + ERP_plot_scalp_gui.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.cancel.ForegroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_scalp_map.advanced.ForegroundColor = [1 1 1]; is2Dmap = gui_erp_scalp_map.map_type_2d.Value; - pscale_legend = {1,1,1,1,0,'on','off',0,is2Dmap}; - Latecny_scale = str2num(gui_erp_scalp_map.latency_plot_edit.String); - ERP_times = observe_ERPDAT.ERP.times; - if isempty(Latecny_scale) - beep; + latencyArray = str2num(gui_erp_scalp_map.latency_plot_edit.String); + if isempty(latencyArray) msgboxText = ['Plot Scalp Maps - No latency was defined']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - latency = Latecny_scale; - if length(latency)~=2 - beep; - msgboxText = ['Plot Scalp Maps - Latency needs two values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + + ERP_times = observe_ERPDAT.ERP.times; + meamenu = gui_erp_scalp_map.measurement.Value; + switch meamenu + case 1 + measurement = 'insta'; + case 2 + measurement = 'mean'; + case 3 + measurement = 'instalapla'; + case 4 + measurement = 'meanlapla'; + case 5 + measurement = 'rms'; + otherwise + measurement = 'insta'; + end + + latencyArray = str2num(gui_erp_scalp_map.latency_plot_edit.String); + if isempty(latencyArray) + msgboxText = ['Plot Scalp Maps - No latency was defined',]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; - elseif length(latency)==2 - if latency(1)>=latency(2) - beep; - msgboxText = ['Plot Scalp Maps - Left edge of Latency should be smaller than the seocnd one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latency(1)< ERP_times(1) - beep; - msgboxText = ['Plot Scalp Maps - Left edge of Latency should be larger than',32, num2str(ERP_times(1)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latency(2)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps - Right edge of Latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latency(1)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps - Left edge of Latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end end - pagif_legend = {0,[],'',latency}; + indxh = find(latencyArray>ERP_times(end),1); + if ~isempty(indxh) + msgboxText = ['Plot Scalp Maps - Latency of ' num2str(latencyArray(indxh)) ' is greater than ERP.xmax = ' num2str(ERP_times(end)) ' msec!']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + gui_erp_scalp_map.latency_plot_edit.String = ''; + return + end + + indxl = find(latencyArray1 + msgboxText = 'Plot Scalp Maps - For you must specify as many latencies as maps you would like to plot.You cannot use semicolon-separated values.'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return + end + end + + try + pscalp_plegend = estudioworkingmemory('pscalp_plegend'); + pscale_legend{1} = pscalp_plegend.binnum ; + pscale_legend{2} = pscalp_plegend.bindesc; + pscale_legend{3} = pscalp_plegend.type; + pscale_legend{4}= pscalp_plegend.latency ; + pscale_legend{5} = pscalp_plegend.electrodes ; + pscale_legend{6}= pscalp_plegend.elestyle; + pscale_legend{7}= pscalp_plegend.elec3D; + pscale_legend{8}= pscalp_plegend.maximize; + pscale_legend{9}= is2Dmap; + catch + pscale_legend = {1,1,1,1,0,'on','off',0,is2Dmap}; + end + if isempty(pscale_legend) + pscale_legend = {1,1,1,1,0,'on','off',0,is2Dmap}; + end + + try + pscalp_agif = estudioworkingmemory('pscalp_agif'); + pagif_legend{1}= pscalp_agif.value ; + pagif_legend{2}= pscalp_agif.fps ; + pagif_legend{3}=pscalp_agif.fname; + pagif_legend{4}=latencyArray; + catch + pagif_legend = {0,[],'',latencyArray}; + end + if isempty(pagif_legend) + pagif_legend = {0,[],'',latencyArray}; + end + + Answer = f_scalplotadvanceGUI(pscale_legend,pagif_legend); if isempty(Answer) - beep; - disp('User selected cancel.'); return; end %%{binnum, bindesc, type, latency, electrodes, elestyle, elec3D, ismaxim, 2Dvalue} @@ -701,34 +1084,39 @@ function apply_advanced(~,~) %%Save parameters estudioworkingmemory('pscalp_plegend', pscalp_plegend); estudioworkingmemory('pscalp_agif', pscalp_agif); - %%-------------------Plotting scalp mapping----------------------- - %%Send message to Message panel - erpworkingmemory('f_ERP_proces_messg','Plot Scalp Maps'); - observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. - - - pathName_def = erpworkingmemory('ERP_save_folder'); - if isempty(pathName_def) - pathName_def =cd; + end + +%%---------------------Run------------------------------------------------- + function apply_run(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end - - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - - if isempty(Selectederp_Index) - beep; - msgboxText = ['Plot Scalp Maps - No ERPset was selected']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=3 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end + estudioworkingmemory('ERPTab_topos',0); + gui_erp_scalp_map.run.BackgroundColor = [ 1 1 1]; + gui_erp_scalp_map.run.ForegroundColor = [0 0 0]; + ERP_plot_scalp_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [1 1 1]; + gui_erp_scalp_map.cancel.ForegroundColor = [0 0 0]; + gui_erp_scalp_map.advanced.BackgroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.ForegroundColor = [0 0 0]; + %%Send message to Message panel + estudioworkingmemory('f_ERP_proces_messg','Plot Scalp Maps'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP=length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); + end plegend = estudioworkingmemory('pscalp_plegend'); if isempty(plegend) @@ -744,9 +1132,7 @@ function apply_advanced(~,~) plegend.maximize = 0; estudioworkingmemory('pscalp_plegend',plegend); end - agif = estudioworkingmemory('pscalp_agif'); - if isempty(agif) agif.value =0; agif.fps =[]; @@ -757,67 +1143,79 @@ function apply_advanced(~,~) binArray = str2num(gui_erp_scalp_map.bin_plot_edit.String); [chk, msgboxText] = f_ERP_chckbinandchan(observe_ERPDAT.ERP, binArray, [],1); if chk(1) - beep; msgboxText = ['Plot Scalp Maps -',msgboxText]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - latencyArray = str2num(gui_erp_scalp_map.latency_plot_edit.String); + ERP_times = observe_ERPDAT.ERP.times; + meamenu = gui_erp_scalp_map.measurement.Value; + switch meamenu + case 1 + measurement = 'insta'; + case 2 + measurement = 'mean'; + case 3 + measurement = 'instalapla'; + case 4 + measurement = 'meanlapla'; + case 5 + measurement = 'rms'; + otherwise + measurement = 'insta'; + end + + latencyArray = str2num(gui_erp_scalp_map.latency_plot_edit.String); if isempty(latencyArray) - beep; - msgboxText = ['Plot Scalp Maps - No latency was defined']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + msgboxText = ['Plot Scalp Maps - No latency was defined',]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; end - if length(latencyArray)~=2 - beep; - msgboxText = ['Plot Scalp Maps - Latency needs two values']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - elseif length(latencyArray)==2 - if latencyArray(1)>=latencyArray(2) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be smaller than the seocnd one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - - end - - if latencyArray(1)< ERP_times(1) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be larger than',32, num2str(ERP_times(1)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - if latencyArray(2)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps - The right edge of latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - if latencyArray(1)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + + indxh = find(latencyArray>ERP_times(end),1); + if ~isempty(indxh) + msgboxText = ['Plot Scalp Maps - Latency of ' num2str(latencyArray(indxh)) ' is greater than ERP.xmax = ' num2str(ERP_times(end)) ' msec!']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + gui_erp_scalp_map.latency_plot_edit.String = ''; + observe_ERPDAT.Process_messg =2; + return + end + + indxl = find(latencyArray1 + msgboxText = 'Plot Scalp Maps - For you must specify as many latencies as maps you would like to plot.You cannot use semicolon-separated values.'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return + end + end + baseline = 'none'; if gui_erp_scalp_map.max_min.Value maplimit = 'maxmin'; @@ -826,32 +1224,28 @@ function apply_advanced(~,~) elseif gui_erp_scalp_map.custom_option.Value cusca = str2num(gui_erp_scalp_map.bar_scale_custom_option_edit.String); if isempty(cusca) - beep; msgboxText = ['Plot Scalp Maps - No value was defined for "Color Bar Scale"']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; return; else ncusca = length(cusca); if ncusca == 2 if cusca(1)=latencyArray(2) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be smaller than the right one']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latencyArray(1)< ERP_times(1) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be larger than',32, num2str(ERP_times(1)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - if latencyArray(2)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end - - - if latencyArray(1)> ERP_times(end) - beep; - msgboxText = ['Plot Scalp Maps - The left edge of latency should be smaller than',32, num2str(ERP_times(end)),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + estudioworkingmemory('ERPTab_topos',0); + gui_erp_scalp_map.run.BackgroundColor = [ 1 1 1]; + gui_erp_scalp_map.run.ForegroundColor = [0 0 0]; + ERP_plot_scalp_gui.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_scalp_map.cancel.BackgroundColor = [1 1 1]; + gui_erp_scalp_map.cancel.ForegroundColor = [0 0 0]; + gui_erp_scalp_map.advanced.BackgroundColor = [1 1 1]; + gui_erp_scalp_map.advanced.ForegroundColor = [0 0 0]; + + ERPTab_plotscalp=estudioworkingmemory('ERPTab_plotscalp'); + try binArray = ERPTab_plotscalp{1}; catch binArray = [];ERPTab_plotscalp{1} = [];end + nbinum = observe_ERPDAT.ERP.nbin; + if isempty(binArray) || any(binArray<0) || any(binArray>nbinum) + binArray = 1:nbinum; + ERPTab_plotscalp{1} = binArray; end + gui_erp_scalp_map.bin_plot_edit.String = num2str(binArray); - - - measurestr = 'mean'; - baseline = 'none'; - if gui_erp_scalp_map.max_min.Value - maplimit = 'maxmin'; - elseif gui_erp_scalp_map.abs_max.Value - maplimit = 'absmax'; - elseif gui_erp_scalp_map.custom_option.Value - cusca = str2num(gui_erp_scalp_map.bar_scale_custom_option_edit.String); - if isempty(cusca) - beep; - msgboxText = ['Plot Scalp Maps - No value was defined for "Color Bar Scale"']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; + try Latency = ERPTab_plotscalp{2}; catch Latency = [];ERPTab_plotscalp{2} = [];end + if isempty(Latency)|| any(Latency(:)observe_ERPDAT.ERP.times(end)) + Latency = []; + ERPTab_plotscalp{2} = Latency; + end + Latencystr = ''; + for ii = 1:size(Latency,1) + if ii==1 + Latencystr = [num2str(Latency(ii,:))]; else - ncusca = length(cusca); - if ncusca == 2 - if cusca(1)5) || any(twodtyep<1) + twodtyep=1;ERPTab_plotscalp{4} = 1; end - if mapoutside==1 % 'plotrad',mplotrad, - mplotrad = []; - else - mplotrad = 0.55; + gui_erp_scalp_map.map_type_2d_type.Value=twodtyep; + + try mapoutside = ERPTab_plotscalp{5}; catch mapoutside=0;ERPTab_plotscalp{5} = 0;end + if isempty(mapoutside) || numel(mapoutside)~=1 || (mapoutside~=0 && mapoutside~=1) + mapoutside=0; + ERPTab_plotscalp{5}=0; end + gui_erp_scalp_map.map_type_2d_type_outside.Value = mapoutside; - %'jet|hsv|hot|cool|gray' - cMap_par={'jet','hsv','hot','cool','gray','viridis'}; - try - cmap = cMap_par{clrmap}; - catch - cmap = 'jet'; + try barscale = ERPTab_plotscalp{6}; catch barscale=1;ERPTab_plotscalp{65} = 1;end + if isempty(barscale) || (numel(barscale)~=1 && numel(barscale)~=2) + barscale=1; + ERPTab_plotscalp{6}=1; end - if ismoviex==0 - ismoviexx = 'off'; - aff = 'off'; % adjust first frame (aff) - else - if ismoviex==1 - aff = 'off'; % adjust first frame (aff) + if numel(barscale)==1 + if barscale~=1 && barscale~=2 + barscale=1; + ERPTab_plotscalp{6}=1; + end + if barscale==1 + gui_erp_scalp_map.max_min.Value=1; + gui_erp_scalp_map.abs_max.Value=0; + gui_erp_scalp_map.custom_option.Value=0; else - aff = 'on'; + gui_erp_scalp_map.max_min.Value=0; + gui_erp_scalp_map.abs_max.Value=1; + gui_erp_scalp_map.custom_option.Value=0; end - ismoviexx = 'on'; - end - if binleg==1 - binlegx = 'on'; + elseif numel(barscale)==2 + gui_erp_scalp_map.max_min.Value=0; + gui_erp_scalp_map.abs_max.Value=0; + gui_erp_scalp_map.custom_option.Value=1; + gui_erp_scalp_map.bar_scale_custom_option_edit.String = num2str(barscale); else - binlegx = 'off'; + gui_erp_scalp_map.max_min.Value=1; + gui_erp_scalp_map.abs_max.Value=0; + gui_erp_scalp_map.custom_option.Value=0; end - if showelec==1 - showelecx = elestyle; - else - showelecx = 'off'; - end - if ismaxim==1 - maxim = 'on'; + + if map2d==1 + gui_erp_scalp_map.map_extras_view_ops.Value=1; + ERPTab_plotscalp{7}=1; else - maxim = 'off'; + try mapextrc = ERPTab_plotscalp{7}; catch mapextrc=1;ERPTab_plotscalp{7} = 1;end + if isempty(mapextrc) || numel(mapextrc)~=1 || any(mapextrc<1) || any(mapextrc>10) + mapextrc=1; + ERPTab_plotscalp{7}=1; + end + gui_erp_scalp_map.map_extras_view_ops.Value=mapextrc; end - % legend - logstring = ['bn'*binleg '-'*binleg 'bd'*bindesc '-'*bindesc 'me'*vtype '-'*vtype 'la'*vlatency]; - logstring = nonzeros(logstring)'; - mapleg = strtrim(char(logstring)); - - Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_erpset); + try clormap = ERPTab_plotscalp{8}; catch clormap=1;ERPTab_plotscalp{8} = 1;end + if isempty(clormap) || numel(clormap)~=1 || any(clormap<1) || any(clormap>6) + clormap=1; end + gui_erp_scalp_map.map_extras_cmap_ops.Value = clormap; + try dispbar = ERPTab_plotscalp{9}; catch dispbar=0;ERPTab_plotscalp{9} = 0;end + if isempty(dispbar) || numel(dispbar)~=1 || (dispbar~=0 && dispbar~=1) + dispbar=0;ERPTab_plotscalp{9} = 0; + end + gui_erp_scalp_map.map_extras_cmapb_disp.Value = dispbar; - ALLERPCOM = evalin('base','ALLERPCOM'); - try - - for Numofselcerp = 1:numel(Selected_erpset) - ERP = observe_ERPDAT.ALLERP(Selected_erpset(Numofselcerp)); - if strcmpi(mtype, '3d') - - if isempty(ERP.splinefile) && isempty(splineinfo.path) - beep; - msgboxText = ['Plot Scalp Maps -',ERP.erpname,' is not linked to any spline file.\n'... - 'At the Scal plot GUI, use "spline file" button, under the Map type menu, to find/create one.']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - - elseif isempty(ERP.splinefile) && ~isempty(splineinfo.path) - %if splineinfo.new==1 - headplot('setup', ERP.chanlocs, splineinfo.path); %Builds the new spline file. - - elseif ~isempty(ERP.splinefile) && ~isempty(splineinfo.path) - headplot('setup', ERP.chanlocs, splineinfo.path); %Builds the new spline file. - splinefile = splineinfo.path; - - else - %disp('C') - splinefile = ERP.splinefile; - headplot('setup', ERP.chanlocs, splinefile); - end - else - %splinefile = ''; - splinefile = ERP.splinefile; - if strcmpi(mtype, '3d') - headplot('setup', ERP.chanlocs, splinefile); - end - %disp('D') - end - if isempty(binArray) - binArray = [1:ERP.nbin]; - end - [ERP, ERPCOM] = pop_scalplot(ERP, binArray, latencyArray, 'Value', measurestr, 'Blc', baseline, 'Maplimit', maplimit, 'Colorbar', colorbari,... - 'Colormap', cmap,'Animated', ismoviexx, 'AdjustFirstFrame', aff, 'FPS', FPS, 'Filename', fullgifname, 'Legend', mapleg, 'Electrodes', showelecx,... - 'Position', posfig, 'Maptype', mtype, 'Mapstyle', smapstyle, 'Plotrad', mplotrad,'Mapview', mapview, 'Splinefile', splinefile,... - 'Maximize', maxim, 'Electrodes3d', elec3D,'History', 'gui'); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - pause(0.1); - end - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM); - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - observe_ERPDAT.Process_messg =2; %%Marking for the procedure has been started. - catch - observe_ERPDAT.Process_messg =3; %%Marking for the procedure has been started. - return; + %%measurement methods + try MeasValue = ERPTab_plotscalp{10};catch MeasValue=2; end + if isempty(MeasValue) || numel(MeasValue)~=1 || any(MeasValue<1) || any(MeasValue>5) + MeasValue=2; + end + gui_erp_scalp_map.measurement.Value=MeasValue; + ERPTab_plotscalp{10} = MeasValue; + Value = gui_erp_scalp_map.measurement.Value; + switch Value + case {1,3} + gui_erp_scalp_map.measurement_exp.String='(one or more: e.g. 300 or 100:50:350)'; + case {2,4,5} + gui_erp_scalp_map.measurement_exp.String='(min max pairs: e.g., 300 400 ; 400 500)'; end + estudioworkingmemory('ERPTab_plotscalp',ERPTab_plotscalp); end - - %%--------Setting current ERPset/session history based on the current updated ERPset------------ function Count_currentERPChanged(~,~) - - Selectederp_Index= estudioworkingmemory('selectederpstudio'); - if isempty(Selectederp_Index) - Selectederp_Index = observe_ERPDAT.CURRENTERP; - if isempty(Selectederp_Index) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: f_ERP_binoperation_GUI error.'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selectederp_Index); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - - if strcmp(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - checked_curr_index = 1; - else - checked_curr_index = 0; + if observe_ERPDAT.Count_currentERP~=4 + return; end - - if isempty(checked_ERPset_Index) - checked_ERPset_Index = f_checkerpsets(observe_ERPDAT.ALLERP,Selectederp_Index); + ViewerFlag=estudioworkingmemory('ViewerFlag');%%when open advanced wave viewer + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); end - - if any(checked_ERPset_Index([1:2 4]))|| checked_curr_index + if isempty(observe_ERPDAT.ALLERP)|| isempty(observe_ERPDAT.ERP) || ViewerFlag==1 Enable_lab = 'off'; else Enable_lab = 'on'; end + gui_erp_scalp_map.measurement.Enable = Enable_lab; %%bin & latency gui_erp_scalp_map.bin_plot_edit.Enable = Enable_lab; gui_erp_scalp_map.bin_plot_opt.Enable = Enable_lab; @@ -1410,25 +1619,57 @@ function Count_currentERPChanged(~,~) gui_erp_scalp_map.map_type_2d_type.Enable = Enable_lab; gui_erp_scalp_map.map_type_3d_spl.Enable = Enable_lab; gui_erp_scalp_map.map_type_2d_type_outside.Enable = Enable_lab; - %%Color bar scale gui_erp_scalp_map.max_min.Enable = Enable_lab; gui_erp_scalp_map.custom_option.Enable = Enable_lab; gui_erp_scalp_map.abs_max.Enable = Enable_lab; - if gui_erp_scalp_map.custom_option.Value - gui_erp_scalp_map.bar_scale_custom_option_edit.Enable = 'on'; - else - gui_erp_scalp_map.bar_scale_custom_option_edit.Enable = 'off'; - end %%Map extras gui_erp_scalp_map.map_extras_view_ops.Enable= Enable_lab; gui_erp_scalp_map.map_extras_view_location.Enable= Enable_lab; gui_erp_scalp_map.map_extras_cmap_ops.Enable = Enable_lab; gui_erp_scalp_map.map_extras_cmapb_disp.Enable= Enable_lab; gui_erp_scalp_map.map_type_2d_type.Enable= Enable_lab; + set(gui_erp_scalp_map.map_type_2d_type_outside,'Enable',Enable_lab); + %%Run and advanced gui_erp_scalp_map.advanced.Enable= Enable_lab; gui_erp_scalp_map.run.Enable= Enable_lab; + gui_erp_scalp_map.cancel.Enable= Enable_lab; + if isempty(observe_ERPDAT.ALLERP)|| isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP =5; + return; + end + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + estudioworkingmemory('selectederpstudio',ERPArray); + observe_ERPDAT.Count_currentERP =1; + end + + BinArray = estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray>observe_ERPDAT.ERP.nbin) || any(BinArray<=0) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); + observe_ERPDAT.Count_currentERP =2; + end + binset = vect2colon(BinArray,'Sort', 'on'); + binset = erase(binset,{'[',']'}); + gui_erp_scalp_map.bin_plot_edit.String =binset; + + %%check latency + latency= str2num(gui_erp_scalp_map.latency_plot_edit.String); + if numel(latency)~=2 || any(latency(:)>observe_ERPDAT.ERP.times(end)) || any(latency(:)length(observe_ERPDAT.ALLERP) - SelectedIndex =1; - end - - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedIndex); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - S_IN = S_erpbinchan.geterpplot; - - -end - -S_erpplot = S_IN; - -plotops_erp = struct(); -gui_erp_plot = struct; - +ERPTab_plotset = struct(); +[version reldate,ColorB_def,ColorF_def,errorColorF_def,~] = geterplabstudiodef; %-----------------------------Name the title---------------------------------------------- -% global ERP_plotset_box; -[version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - if nargin == 0 fig = figure(); % Parent figure - ERP_plotset_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Plot Setting', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_plotset_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Plot Settings', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_plotset_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Setting', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_plotset_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Settings', 'Padding', 5,'BackgroundColor',ColorB_def); else - ERP_plotset_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Setting', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_plotset_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Plot Settings', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); end %-----------------------------Draw the panel------------------------------------- @@ -69,11 +34,10 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erpplot(FonsizeDefault); varargout{1} = ERP_plotset_box; - function drawui_erpplot(FonsizeDefault) estudioworkingmemory('erp_plot_set',0); @@ -81,813 +45,2315 @@ function drawui_erpplot(FonsizeDefault) %%--------------------x and y axes setting------------------------- [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - gui_erp_plot.plotop = uiextras.VBox('Parent',ERP_plotset_box, 'Spacing',1,'BackgroundColor',ColorB_def); - - % set(gui_erp_plot.time_sel, 'Sizes', [-1 -1 -1 -1 -1]); - uicontrol('Style','text','Parent', gui_erp_plot.plotop,'String','Time Range:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 1B - - gui_erp_plot.ticks = uiextras.HBox('Parent',gui_erp_plot.plotop,'Spacing',1,'BackgroundColor',ColorB_def); - plotops_erp.timet_auto = uicontrol('Style','checkbox','Parent', gui_erp_plot.ticks,'String','Auto','callback',@timet_auto,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2B - uicontrol('Style','text','Parent', gui_erp_plot.ticks,'String','Low','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - plotops_erp.timet_low = uicontrol('Style', 'edit','Parent',gui_erp_plot.ticks,... - 'String',num2str(S_erpplot.timet_low(Select_index)),'callback',@low_ticks_change,'Enable','off','FontSize',FonsizeDefault); - uicontrol('Style','text','Parent', gui_erp_plot.ticks,'String','High','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - plotops_erp.timet_high = uicontrol('Style', 'edit','Parent',gui_erp_plot.ticks,'String',num2str(S_erpplot.timet_high(Select_index)),... - 'callback',@high_ticks_change,'Enable','off','FontSize',FonsizeDefault); - uicontrol('Style','text','Parent', gui_erp_plot.ticks,'String','Step','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - plotops_erp.timet_step = uicontrol('Style', 'edit','Parent',gui_erp_plot.ticks,'String',num2str(S_erpplot.timet_step(Select_index)),... - 'callback',@ticks_step_change,'Enable','off','FontSize',FonsizeDefault); - - set(gui_erp_plot.ticks, 'Sizes', [60 -1 -1 -1 -1 -1 -1]); - - uicontrol('Style','text','Parent', gui_erp_plot.plotop,'String','Y Scale:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - - gui_erp_plot.yscale = uiextras.HBox('Parent',gui_erp_plot.plotop,'Spacing',1,'BackgroundColor',ColorB_def); - plotops_erp.yscale_auto = uicontrol('Style','checkbox','Parent',gui_erp_plot.yscale,'String','Auto',... - 'callback',@yscale_auto,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - tooltiptext = sprintf('Tick Length:\nSize of Y Ticks'); - uicontrol('Style','text','Parent',gui_erp_plot.yscale,'String','Ticks','TooltipString',tooltiptext,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - plotops_erp.yscale_change = uicontrol('Style','edit','Parent',gui_erp_plot.yscale,... - 'String',S_erpplot.yscale(Select_index),'callback',@yscale_change,'Enable','off','FontSize',FonsizeDefault); - tooltiptext = sprintf('Minimum Vertical Spacing:\nSmallest possible distance in inches between zero lines before plots go off the page.'); - uicontrol('Style','text','Parent',gui_erp_plot.yscale,'String','Spacing','TooltipString',tooltiptext,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - plotops_erp.min_vspacing = uicontrol('Style','edit','Parent',gui_erp_plot.yscale,'String',S_erpplot.min_vspacing(Select_index),'callback',@min_vspacing,'Enable','off','FontSize',FonsizeDefault); - tooltiptext = sprintf('Fill Screen:\nDynamically expand plots to fill screen.'); - plotops_erp.fill_screen = uicontrol('Style','checkbox','Parent',gui_erp_plot.yscale,'String','Fill','callback',@fill_screen,... - 'TooltipString',tooltiptext,'Value',S_erpplot.fill(Select_index),'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - - set(gui_erp_plot.yscale, 'Sizes', [50 45 35 50 35 60]); - - - gui_erp_plot.plot_column = uiextras.HBox('Parent',gui_erp_plot.plotop,'Spacing',1,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); - - uicontrol('Style','text','Parent', gui_erp_plot.plot_column,'String','Number of columns:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1E - - ColumnNum = estudioworkingmemory('EStudioColumnNum'); - if isempty(ColumnNum) || numel(ColumnNum)~=1 - ColumnNum =1; + ERPTab_plotset.plotop = uiextras.VBox('Parent',ERP_plotset_box, 'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', ERPTab_plotset.plotop,'String','Time Axis:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); % 1B + %%time range + ERPTab_plotset.timerange = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + ERPTab_plotset.timet_auto = uicontrol('Style','checkbox','Parent', ERPTab_plotset.timerange,'String','Auto',... + 'callback',@timet_auto,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2B + ERPTab_plotset.timet_auto.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.timerange,'String','Range','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPTab_plotset.timet_low = uicontrol('Style', 'edit','Parent',ERPTab_plotset.timerange,'BackgroundColor',[1 1 1],... + 'String','','callback',@low_ticks_change,'Enable','off','FontSize',FonsizeDefault,'Enable','off'); + ERPTab_plotset.timet_low.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.timerange,'String','to','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPTab_plotset.timet_high = uicontrol('Style', 'edit','Parent',ERPTab_plotset.timerange,'String','',... + 'callback',@high_ticks_change,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + ERPTab_plotset.timet_high.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.timerange,'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(ERPTab_plotset.timerange, 'Sizes', [50 50 50 30 50 20]); + %%time ticks + ERPTab_plotset.timeticks = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + ERPTab_plotset.timetick_auto = uicontrol('Style','checkbox','Parent', ERPTab_plotset.timeticks,'String','Auto',... + 'callback',@timetick_auto,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2B + ERPTab_plotset.timetick_auto.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.timeticks,'String','Time ticks, every','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPTab_plotset.timet_step = uicontrol('Style', 'edit','Parent',ERPTab_plotset.timeticks,'String','',... + 'callback',@ticks_step_change,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + ERPTab_plotset.timet_step.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.timeticks,'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(ERPTab_plotset.timeticks, 'Sizes', [50 100 80 20]); + + %%amplitude scale + uicontrol('Style','text','Parent', ERPTab_plotset.plotop,'String','Amplitude Axis:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + ERPTab_plotset.yscale = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + ERPTab_plotset.yscale_auto = uicontrol('Style','checkbox','Parent',ERPTab_plotset.yscale,'String','Auto',... + 'callback',@yscale_auto,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); + ERPTab_plotset.yscale_auto.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent',ERPTab_plotset.yscale,'String','Scale','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPTab_plotset.yscale_low = uicontrol('Style', 'edit','Parent',ERPTab_plotset.yscale,'BackgroundColor',[1 1 1],... + 'String','','callback',@yscale_low,'Enable','off','FontSize',FonsizeDefault,'Enable','off'); + ERPTab_plotset.yscale_low.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.yscale,'String','to','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPTab_plotset.yscale_high = uicontrol('Style', 'edit','Parent',ERPTab_plotset.yscale,'String','',... + 'callback',@yscale_high,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + ERPTab_plotset.yscale_high.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.yscale,'String','uv','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(ERPTab_plotset.yscale, 'Sizes', [50 50 50 30 50 20]); + + %%y ticks + ERPTab_plotset.yscaleticks = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + ERPTab_plotset.ytick_auto = uicontrol('Style','checkbox','Parent', ERPTab_plotset.yscaleticks,'String','Auto',... + 'callback',@ytick_auto,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2B + ERPTab_plotset.ytick_auto.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.yscaleticks,'String','Amp. ticks, every','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + ERPTab_plotset.yscale_step = uicontrol('Style', 'edit','Parent',ERPTab_plotset.yscaleticks,'String','',... + 'callback',@yscale_step,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + ERPTab_plotset.yscale_step.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.yscaleticks,'String','uv','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(ERPTab_plotset.yscaleticks, 'Sizes', [50 100 80 20]); + + + ERPTab_plotset.polarity_waveform = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', ERPTab_plotset.polarity_waveform,'String','Polarity:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1F + + %% polarity + ERPTab_plotset.positive_up = uicontrol('Style','radiobutton','Parent',ERPTab_plotset.polarity_waveform,'String','Positive Up',... + 'callback',@polarity_up,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + ERPTab_plotset.positive_up.KeyPressFcn= @erp_plotsetting_presskey; + ERPTab_plotset.negative_up = uicontrol('Style','radiobutton','Parent', ERPTab_plotset.polarity_waveform,'String','Negative Up',... + 'callback',@polarity_down,'Value',0,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + ERPTab_plotset.negative_up.KeyPressFcn= @erp_plotsetting_presskey; + set(ERPTab_plotset.polarity_waveform, 'Sizes',[60 -1 -1]); + + ERPTab_plotset.bin_chan = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + ERPTab_plotset.pagesel = uicontrol('Parent', ERPTab_plotset.bin_chan, 'Style', 'popupmenu','String',... + {'CHANNELS with BINS overlay','BINS with CHANNELS overlay'},'callback',@pageviewchanged,'FontSize',FonsizeDefault,'Enable','off'); + ERPTab_plotset.pagesel.KeyPressFcn= @erp_plotsetting_presskey; + + + %%standard error for each ERP wave + ERPTab_plotset.SEM_title = uiextras.HBox('Parent', ERPTab_plotset.plotop,'BackgroundColor',ColorB_def); + ERPTab_plotset.show_SEM = uicontrol('Style','checkbox','Parent', ERPTab_plotset.SEM_title ,'String','Show standard error',... + 'callback',@showSEM,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); % + ERPTab_plotset.show_SEM.KeyPressFcn = @erp_plotsetting_presskey; + SMEString = {'0','1','2','3','4','5','6','7','8','9','10'}; + ERPTab_plotset.SEM_custom = uicontrol('Style','popupmenu','Parent', ERPTab_plotset.SEM_title ,'String',SMEString,... + 'callback',@SEMerror,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',2); % + ERPTab_plotset.SEM_custom.KeyPressFcn = @erp_plotsetting_presskey; + set(ERPTab_plotset.SEM_title,'Sizes',[160 80]); + + ERPTab_plotset.SEMtrans_title = uiextras.HBox('Parent', ERPTab_plotset.plotop,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', ERPTab_plotset.SEMtrans_title ,'String','transparency',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'HorizontalAlignment','right'); % + SMEtransString = {'0','0.1','0.2','0.3','0.4','0.5','0.6','0.7','0.8','0.9','1'}; + ERPTab_plotset.SEMtrans_custom = uicontrol('Style','popupmenu','Parent', ERPTab_plotset.SEMtrans_title ,'String',SMEtransString,... + 'callback',@SEMtrans,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',3); % + ERPTab_plotset.SEMtrans_custom.KeyPressFcn = @erp_plotsetting_presskey; + set(ERPTab_plotset.SEMtrans_title,'Sizes',[160 80]); + ERPTab_plotset.SEM_custom.Enable = 'off'; + ERPTab_plotset.SEMtrans_custom.Enable = 'off'; + ERPTab_plotset.show_SEM.Enable = 'off'; + + %%Grid layout + ERPTab_plotset.gridlayout_title = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', ERPTab_plotset.gridlayout_title,'String','Grid Layout:','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1E + + ERPTab_plotset.gridlayout_title2 = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); + ERPTab_plotset.gridlayoutdef = uicontrol('Style','radiobutton','Parent', ERPTab_plotset.gridlayout_title2,... + 'callback',@gridlayoutdef,'String','Default','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',1,'Enable','off'); % 1E + ERPTab_plotset.gridlayoutdef.KeyPressFcn= @erp_plotsetting_presskey; + ERPTab_plotset.chanorder_front = uicontrol('Parent',ERPTab_plotset.gridlayout_title2, 'Style', 'radiobutton', 'String', 'Simple 10/20 system order',... + 'Callback', @chanorder_front,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off','Value',0); + ERPTab_plotset.chanorder_front.KeyPressFcn= @erp_plotsetting_presskey; + set(ERPTab_plotset.gridlayout_title2,'Sizes',[70 -1]); + + ERPTab_plotset.gridlayout_title3 = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); + ERPTab_plotset.gridlayout_custom = uicontrol('Style','radiobutton','Parent', ERPTab_plotset.gridlayout_title3,... + 'callback',@gridlayout_custom,'String','Custom','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); % 1E + ERPTab_plotset.gridlayout_custom.KeyPressFcn= @erp_plotsetting_presskey; + ERPTab_plotset.gridlayout_export = uicontrol('Style','pushbutton','Parent', ERPTab_plotset.gridlayout_title3,... + 'callback',@gridlayout_export,'String','Export','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); % 1E + ERPTab_plotset.gridlayout_import = uicontrol('Style','pushbutton','Parent', ERPTab_plotset.gridlayout_title3,... + 'callback',@gridlayout_import,'String','Import','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); % 1E + set(ERPTab_plotset.gridlayout_title3,'Sizes',[70 60 60]); + + ERPTab_plotset.row_colum_title = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def,'BackgroundColor',ColorB_def); + for ii = 1:256 + rowcolumnString{ii} = num2str(ii); end - plotops_erp.columns = uicontrol('Style','edit','Parent', gui_erp_plot.plot_column,... - 'String',num2str(ColumnNum),'callback',@onElecNbox,'FontSize',FonsizeDefault); % 2E Plot_column - set(gui_erp_plot.plot_column, 'Sizes', [150 -1]); - - - gui_erp_plot.polarity_waveform = uiextras.HBox('Parent',gui_erp_plot.plotop,'Spacing',1,'BackgroundColor',ColorB_def); - - uicontrol('Style','text','Parent', gui_erp_plot.polarity_waveform,'String','Polarity:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1F - - %% second column: - plotops_erp.positive_up = uicontrol('Style','radiobutton','Parent',gui_erp_plot.polarity_waveform,'String','Positive Up','callback',@polarity_up,'Value',1,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2F - plotops_erp.negative_up = uicontrol('Style','radiobutton','Parent', gui_erp_plot.polarity_waveform,'String','Negative Up','callback',@polarity_down,'Value',0,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 2F - - set(gui_erp_plot.polarity_waveform, 'Sizes',[60 -1 -1]); - - gui_erp_plot.bin_chan = uiextras.HBox('Parent',gui_erp_plot.plotop,'Spacing',1,'BackgroundColor',ColorB_def); - - gui_erp_plot.pagesel = uicontrol('Parent', gui_erp_plot.bin_chan, 'Style', 'popupmenu','String',... - {'CHANNELS with BINS overlay','BINS with CHANNELS overlay'},'callback',@pageviewchanged,'FontSize',FonsizeDefault); - - - gui_erp_plot.reset_apply = uiextras.HBox('Parent',gui_erp_plot.plotop,'Spacing',1,'BackgroundColor',ColorB_def); - uiextras.Empty('Parent', gui_erp_plot.reset_apply); % 1A - plotops_erp.plot_reset = uicontrol('Style', 'pushbutton','Parent',gui_erp_plot.reset_apply,... - 'String','Reset','callback',@plot_erp_reset,'FontSize',FonsizeDefault); - uiextras.Empty('Parent', gui_erp_plot.reset_apply); % 1A - plotops_erp.plot_apply = uicontrol('Style', 'pushbutton','Parent',gui_erp_plot.reset_apply,... - 'String','Apply','callback',@plot_erp_apply,'FontSize',FonsizeDefault); - uiextras.Empty('Parent', gui_erp_plot.reset_apply); % 1A - set(gui_erp_plot.reset_apply, 'Sizes',[10 -1 30 -1 10]); - - set(gui_erp_plot.plotop, 'Sizes', [20 25 20 25 25 25 20 30]); - + uicontrol('Style','text','Parent', ERPTab_plotset.row_colum_title,'String','Row(s):','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1E + ERPTab_plotset.rowNum_set = uicontrol('Style','popupmenu','Parent', ERPTab_plotset.row_colum_title,'Enable','off',... + 'String',rowcolumnString,'callback',@rowNum_set,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',1); + ERPTab_plotset.rowNum_set.KeyPressFcn= @erp_plotsetting_presskey; + uicontrol('Style','text','Parent', ERPTab_plotset.row_colum_title,'String','Column(s):','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); % 1E + ERPTab_plotset.columns = uicontrol('Style','popupmenu','Parent', ERPTab_plotset.row_colum_title,'Enable','off',... + 'String',rowcolumnString,'callback',@columNum_select,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',1); % 2E Plot_column + ERPTab_plotset.columns.KeyPressFcn= @erp_plotsetting_presskey; + set(ERPTab_plotset.row_colum_title,'Sizes',[45 75 60 75]); + + %%cancel & apply + ERPTab_plotset.reset_apply = uiextras.HBox('Parent',ERPTab_plotset.plotop,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', ERPTab_plotset.reset_apply); % 1A + ERPTab_plotset.plot_reset = uicontrol('Style', 'pushbutton','Parent',ERPTab_plotset.reset_apply,'Enable','off',... + 'String','Cancel','callback',@plot_erp_reset,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', ERPTab_plotset.reset_apply); % 1A + ERPTab_plotset.plot_apply = uicontrol('Style', 'pushbutton','Parent',ERPTab_plotset.reset_apply,'Enable','off',... + 'String','Apply','callback',@plot_setting_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', ERPTab_plotset.reset_apply); % 1A + set(ERPTab_plotset.reset_apply, 'Sizes',[10 -1 30 -1 10]); + + set(ERPTab_plotset.plotop, 'Sizes', [20 20 20 20 20 20 25 25 20 20 25 20 25 25 30]); + ERPTab_plotset.chanorderIndex = 1; + ERPTab_plotset.chanorder{1,1}=[]; + ERPTab_plotset.chanorder{1,2} = ''; + estudioworkingmemory('ERP_chanorders',{ERPTab_plotset.chanorderIndex,ERPTab_plotset.chanorder}); + estudioworkingmemory('ERPTab_plotset_pars',[]); + estudioworkingmemory('ERPTab_plotset',0); + ERPTab_plotset.timet_auto_reset = 1; + ERPTab_plotset.timeticks_auto_reset = 1; + ERPTab_plotset.gridlayputarray = []; + ERPTab_plotset.paras{1} = ERPTab_plotset.timet_auto.Value; + ERPTab_plotset.paras{2} = ERPTab_plotset.timetick_auto.Value; + ERPTab_plotset.paras{3} = ERPTab_plotset.yscale_auto.Value; + ERPTab_plotset.paras{4} = ERPTab_plotset.ytick_auto.Value; end - - %%**************************************************************************%% %%--------------------------Sub function------------------------------------%% %%**************************************************************************%% %---------------------------------Auto time ticks-------------------------------* function timet_auto( src, ~ ) - estudioworkingmemory('erp_xtickstep',0); - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - - if src.Value == 1 - plotops_erp.timet_low.Enable = 'off'; - plotops_erp.timet_high.Enable = 'off'; - plotops_erp.timet_step.Enable = 'off'; - else - plotops_erp.timet_low.Enable = 'on'; - plotops_erp.timet_high.Enable = 'on'; - plotops_erp.timet_step.Enable = 'on'; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end - plotops_erp.timet_low.String = num2str(floor(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(1)/5)*5); - plotops_erp.timet_high.String = num2str(ceil(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(end)/5)*5); - - - Min_time=floor(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(1)/5)*5; - Max_time = ceil(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(end)/5)*5; - - [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [Min_time,Max_time]); - plotops_erp.timet_step.String = num2str(xstep); - - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - - if any(checked_ERPset_Index(5)) - S_erpplot.timet_low(Select_index) = floor(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(1)/5)*5; - else - S_erpplot.timet_low(1:end) = floor(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(1)/5)*5; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - if any(checked_ERPset_Index(6)) - S_erpplot.timet_high(Select_index) = ceil(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(end)/5)*5; - else - S_erpplot.timet_high(1:end) = ceil(observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).times(end)/5)*5; - end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; - if any(checked_ERPset_Index(6)) || any(checked_ERPset_Index(5)) - S_erpplot.timet_step(Select_index) = xstep; + if src.Value == 1 + ERPTab_plotset.timet_low.Enable = 'off'; + ERPTab_plotset.timet_high.Enable = 'off'; + ERPTab_plotset.timet_low.String = num2str(observe_ERPDAT.ERP.times(1)); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); else - S_erpplot.timet_step(1:end) = xstep; + ERPTab_plotset.timet_low.Enable = 'on'; + ERPTab_plotset.timet_high.Enable = 'on'; end end %%--------------------------Min. interval of time ticks--------------------- function low_ticks_change( src, ~ ) - - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - - xtixlk_min = str2num(src.String); - xtixlk_max = str2num(plotops_erp.timet_high.String); - if isempty(xtixlk_min) - src.String = num2str(S_erpplot.timet_low(Select_index)); - beep; - msgboxText = ['Plot Setting> Time range- Input of left edge must be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; return; end - - - if numel(xtixlk_min)>1 - src.String = num2str(S_erpplot.timet_low(Select_index)); - msgboxText = ['Plot Setting> Time range- nput of left edge must be a single numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - - return; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - - - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - if xtixlk_min < S_erpplot.timet_high(Select_index) - S_erpplot.timet_low(Select_index)=xtixlk_min; - if any(checked_ERPset_Index(5)) - S_erpplot.timet_low(Select_index)=xtixlk_min; - else - S_erpplot.timet_low(1:end)=xtixlk_min; - end - - [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [xtixlk_min,xtixlk_max]); - plotops_erp.timet_step.String = num2str(xstep); - S_erpplot.timet_step(1:end) = xstep; - else - src.String = S_erpplot.min(Select_index); - - msgboxText = ['Plot Setting> Time range- left range must be lower than high tick']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + xtixlk_min = str2num(src.String); + xtixlk_max = str2num(ERPTab_plotset.timet_high.String); + if isempty(xtixlk_min)|| numel(xtixlk_min)~=1 + src.String = num2str(observe_ERPDAT.ERP.times(1)); + msgboxText = ['Plot Settings> Time Axis- Input of low edge must be a single numeric']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; return; end - if S_erpplot.timet_step(Select_index) > S_erpplot.timet_high(Select_index)- S_erpplot.timet_low(Select_index) - plotops_erp.timet_step.String = num2str(S_erpplot.timet_step(Select_index)); - - msgboxText = ['Plot Setting> Time range- Step must be within the time range']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + if any(xtixlk_max<=xtixlk_min) + src.String = num2str(observe_ERPDAT.ERP.times(1)); + msgboxText = ['Plot Settings> Time Axis- Low edge must be smaller than',32,num2str(xtixlk_max(1))]; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; return; end end - - %%----------------------high interval of time ticks--------------------------------* function high_ticks_change( src, ~ ) - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - xtixlk_min = str2num(plotops_erp.timet_low.String); + xtixlk_min = str2num(ERPTab_plotset.timet_low.String); xtixlk_max = str2num(src.String); - if isempty(xtixlk_max) - src.String = num2str(S_erpplot.timet_high(Select_index)); + if isempty(xtixlk_max) || numel(xtixlk_max)~=1 + src.String = num2str(observe_ERPDAT.ERP.times(end)); beep; - msgboxText = ['Plot Setting> Y Scale- Input of ticks edge must be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + msgboxText = ['Plot Settings> Amplitude Axis- Input of ticks edge must be a single numeric']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; - return; end - - if numel(xtixlk_max)>1 - src.String = num2str(S_erpplot.timet_high(Select_index)); - beep; - msgboxText = ['Plot Setting> Y Scale- Input of ticks edge must be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + if any(xtixlk_max < xtixlk_min) + src.String = num2str(observe_ERPDAT.ERP.times(end)); + msgboxText = ['Plot Settings> Time Axis- high edge must be higher than',32,num2str(xtixlk_min),'ms']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; - return; end + end + + +%%---------------------------time ticks automatically---------------------- + function timetick_auto(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end - - checked_ERPset_Index = S_binchan.checked_ERPset_Index; - - if xtixlk_max > xtixlk_min - - if any(checked_ERPset_Index(6)) - S_erpplot.timet_high(Select_index) = xtixlk_max; - else - S_erpplot.timet_high(1:end) = xtixlk_max; + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + if ERPTab_plotset.timetick_auto.Value==1 + timeStart = str2num(ERPTab_plotset.timet_low.String); + if isempty(timeStart) || numel(timeStart)~=1 || timeStart>=observe_ERPDAT.ERP.times(end) %%|| timeStart Time Axis- Time ticks>Auto: left edge of time range must be a single number and smaller than ',32,num2str(observe_ERPDAT.ERP.times(end)),'ms']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg =4; end - [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [xtixlk_min,xtixlk_max]); - plotops_erp.timet_step.String = num2str(xstep); - S_erpplot.timet_step(1:end) = xstep; - + timEnd = str2num(ERPTab_plotset.timet_high.String); + if isempty(timEnd) || numel(timEnd)~=1 || timEnd observe_ERPDAT.ERP.times(end) + timEnd = observe_ERPDAT.ERP.times(end); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + msgboxText = ['Plot Settings> Time Axis- Time ticks>Auto: right edge of time range must be a single number and larger than ',32,num2str(observe_ERPDAT.ERP.times(1)),'ms']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg =4; + end + if timeStart>timEnd + ERPTab_plotset.timet_low.String = num2str(observe_ERPDAT.ERP.times(1)); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + timeStart = observe_ERPDAT.ERP.times(1); + timEnd = observe_ERPDAT.ERP.times(end); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + msgboxText = ['Plot Settings> Time Axis- Time ticks>Auto: left edge of time range must be smaller than right one']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg =4; + end + [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [timeStart,timEnd]); + ERPTab_plotset.timet_step.String = num2str(xstep); + ERPTab_plotset.timet_step.Enable = 'off'; else - src.String = num2str(S_erpplot.timet_high(Select_index)); - beep; - msgboxText = ['Plot Setting> Time range- right edge must be higher than',32,num2str(xtixlk_min),'ms']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; + ERPTab_plotset.timet_step.Enable = 'on'; end - if S_erpplot.timet_step(Select_index) > S_erpplot.timet_high(Select_index) -S_erpplot.timet_low(Select_index) - beep; - plotops_erp.timet_step.String = num2str(S_erpplot.timet_step(Select_index)); - msgboxText = ['Plot Setting> Time range- Step must be within the time range']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end end - %%----------------------Step of time ticks--------------------------------* function ticks_step_change( src, ~ ) - - tick_step = str2num(src.String); - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - - if isempty(tick_step) - src.String = num2str(S_erpplot.timet_step(Select_index)); - beep; - msgboxText = ['Plot Setting> Time range- The input of Step must be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; return; end - - if numel(tick_step)>1 - src.String = num2str(S_erpplot.timet_step(Select_index)); - beep; - msgboxText = ['Plot Setting> Time range- The input of Step must be one numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - if tick_step<=0 %% otherwise, a bug will be displayed - src.String = num2str(S_erpplot.timet_step(Select_index)); - beep; - msgboxText = ['Plot Setting> Time range- Step must be a positive value']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - return; - end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; - checked_ERPset_Index = S_binchan.checked_ERPset_Index; + timeStart = str2num(ERPTab_plotset.timet_low.String); + timEnd = str2num(ERPTab_plotset.timet_high.String); - if tick_step < S_erpplot.timet_high(Select_index) -S_erpplot.timet_low(Select_index) - - if any(checked_ERPset_Index(5)) && any(checked_ERPset_Index(6)) - S_erpplot.timet_step(Select_index) = tick_step; - else - S_erpplot.timet_step(1:end) = tick_step; - end - estudioworkingmemory('erp_xtickstep',1); - - + if ~isempty(timeStart) && ~isempty(timEnd) && numel(timEnd)==1 && numel(timeStart) ==1 && timeStart < timEnd + [def xtickstepdef]= default_time_ticks_studio(observe_ERPDAT.ERP, [timEnd,timeStart]); else - src.String = num2str(S_erpplot.timet_step(Select_index)); - beep; - msgboxText = ['Plot Setting> Time range- Step must be within the time range']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + xtickstepdef = []; + end + tick_step = str2num(src.String); + if isempty(tick_step) || numel(tick_step)~=1 || any(tick_step<=0) + src.String = num2str(xtickstepdef); + msgboxText = ['Plot Settings> Time Axis - The input of Step for time ticks must be a single positive value']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; return; end end -%%---------------------------------Auto y scale---------------------------------* +%%---------------------------------Auto Amplitude Axis---------------------------------* function yscale_auto( src, ~ ) - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - if src.Value == 1 - plotops_erp.yscale_change.Enable = 'off'; - YScale =prctile((observe_ERPDAT.ALLERP(S_selectedERP(Select_index)).bindata(:)*S_erpplot.Positive_up(Select_index)),95)*2/3; - if YScale>= 0&&YScale <=0.1 - YScale = 0.1; - elseif YScale< 0&& YScale > -0.1 - YScale = -0.1; - else - YScale = round(YScale); + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + if ERPTab_plotset.yscale_auto.Value ==1 + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = observe_ERPDAT.ERP.nbin; + if isempty(BinArray) || any(BinArray(:)<=0) || any(BinArray(:)>BinNum) + BinArray = [1:BinNum]; + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; end - plotops_erp.yscale_change.String = YScale; - S_erpplot.yscale(1:end) = YScale; - plotops_erp.min_vspacing.Enable = 'off'; - plotops_erp.min_vspacing.String = 1.5; - S_erpplot.min_vspacing(1:end) =1.5; + ERPTab_plotset.yscale_low.Enable = 'off'; + ERPTab_plotset.yscale_high.Enable = 'off'; + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); else - plotops_erp.yscale_change.Enable = 'on'; - plotops_erp.min_vspacing.Enable = 'on'; + ERPTab_plotset.yscale_low.Enable = 'on'; + ERPTab_plotset.yscale_high.Enable = 'on'; end - end -%%---------------------------------y scale change---------------------------------* - function yscale_change(src, ~ ) - - clear i - val = 1i; - try - val = str2double(src.String); - catch - beep; - msgboxText = ['Plot Setting> y scale - Input of y scale must be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; +%%------------------------left edge of y scale----------------------------- + function yscale_low(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; return; end - if val ~= 1i - if val <= 0 - beep; - msgboxText = ['Plot Setting> y scale - Input must be greater than zero']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - else - S_erpplot.yscale(1:end) = val; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = observe_ERPDAT.ERP.nbin; + if isempty(BinArray) || any(BinArray(:)<=0) || any(BinArray(:)>BinNum) + BinArray = [1:BinNum]; + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; end + Yscales_low = str2num(ERPTab_plotset.yscale_low.String); + Yscales_high = str2num(ERPTab_plotset.yscale_high.String); + if isempty(Yscales_low) || numel(Yscales_low)~=1 + ERPTab_plotset.yscale_low.String = num2str(minydef); + Yscales_low= minydef; + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: You did set left edge of amplitude scale to be a single number and we used the default one '); + observe_ERPDAT.Process_messg =4; + end + if any(Yscales_high<=Yscales_low) + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: Left edge of amplitude scale should be smaller than the right one and we used the default ones '); + observe_ERPDAT.Process_messg =4; + end end -%%-------------------------- Y scale spacing------------------------------- - function min_vspacing( src, ~ ) - clear i - val = 1i; - try - val = str2double(src.String); - catch - beep; - msgboxText = ['Plot Setting> y scale > spacing - Input of spacing must be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); +%%-------------------right edge of y scale--------------------------------- + function yscale_high(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = observe_ERPDAT.ERP.nbin; + if isempty(BinArray) || any(BinArray(:)<=0) || any(BinArray(:)>BinNum) + BinArray = [1:BinNum]; + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; + end + Yscales_low = str2num(ERPTab_plotset.yscale_low.String); + Yscales_high = str2num(ERPTab_plotset.yscale_high.String); + + if isempty(Yscales_high) || numel(Yscales_high)~=1 + ERPTab_plotset.yscale_high.String = num2str(maxydef); + Yscales_high= maxydef; + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: You did set right edge of amplitude scale to be a single number and we used the default one '); observe_ERPDAT.Process_messg =4; - src.String = 1.5; - end - if val ~= 1i - if val <= 0 - beep; - msgboxText = ['Plot Setting> y scale > spacing - Input of spacing must be greater than zero']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - src.String = 1.5; + end + if any(Yscales_high<=Yscales_low) + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: Left edge of amplitude scale should be smaller than the right one and we used the default ones '); + observe_ERPDAT.Process_messg =4; + end + end + +%%------------------y ticks automatically---------------------------------- + function ytick_auto(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = observe_ERPDAT.ERP.nbin; + if isempty(BinArray) || any(BinArray(:)<=0) || any(BinArray(:)>BinNum) + BinArray = [1:BinNum]; + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; + end + + Yscales_low = str2num(ERPTab_plotset.yscale_low.String); + Yscales_high = str2num(ERPTab_plotset.yscale_high.String); + if isempty(Yscales_low) || numel(Yscales_low)~=1 + ERPTab_plotset.yscale_low.String = num2str(minydef); + Yscales_low= minydef; + end + if isempty(Yscales_high) || numel(Yscales_high)~=1 + Yscales_high= maxydef; + ERPTab_plotset.yscale_high.String = num2str(maxydef); + end + if any(Yscales_high<=Yscales_low) + Yscales_high= maxydef; + Yscales_low= minydef; + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); + end + if ERPTab_plotset.ytick_auto.Value==1 + defyticks = default_amp_ticks_viewer([Yscales_low,Yscales_high]); + defyticks = str2num(defyticks); + if ~isempty(defyticks) && numel(defyticks)>=2 + ERPTab_plotset.yscale_step.String = num2str(min(diff(defyticks))); else - S_erpplot.min_vspacing(1:end) = val; + ERPTab_plotset.yscale_step.String = num2str(floor((Yscales_high-Yscales_low)/2)); end + ERPTab_plotset.yscale_step.Enable = 'off'; + else + ERPTab_plotset.yscale_step.Enable = 'on'; end + end -%%-----------------fill screen---------------------------------------------* - function fill_screen( src, ~ ) - S_erpplot.fill(1:end)= src.Value; - end -%%-----------Determing the numbrt of columns------------------------------ - function onElecNbox(source,~) - Values = str2num(source.String); - if isempty(Values) || Values <=0 - source.String = num2str( S_erpplot.Plot_column(1)); - msgboxText = ['Plot Setting> Number of columns - Input for the number of columns must be greater than zero']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; +%%---------------------------------Amplitude Axis change---------------------------------* + function yscale_step(src, ~ ) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; return; end - S_erpplot.Plot_column(1:end) = Values; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + val = str2num(src.String); + if isempty(val) || numel(val)~=1 || any(val(:)<=0) + src.String = ''; + msgboxText = ['Plot Settings> Amplitude Axis - Input must be a positive value']; + estudioworkingmemory('f_ERP_proces_messg',msgboxText); + observe_ERPDAT.Process_messg =4; + end end %------------------Set the polarity of waveform is up or not------------------- function polarity_up(~,~) - source_value_up = 1; - plotops_erp.positive_up.Value =source_value_up; - plotops_erp.negative_up.Value = 0; - S_erpplot.Positive_up(1:end) = source_value_up; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + ERPTab_plotset.positive_up.Value =1; + ERPTab_plotset.negative_up.Value = 0; end %------------------Set the polarity of waveform is up or not------------------- function polarity_down( source, ~) - source_value_down = 1; - plotops_erp.positive_up.Value =0; - plotops_erp.negative_up.Value = source_value_down; - S_erpplot.Positive_up(1:end) = -source_value_down; - end - -%%------------------------------------------------------------------------- - function Count_currentERPChanged(~,~) - erp_plot_set_label = estudioworkingmemory('erp_plot_set'); - if isempty(erp_plot_set_label) - erp_plot_set_label =1; - end - if ~erp_plot_set_label - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - S_erpplot = estudioworkingmemory('geterpplot'); - plotops_erp.timet_auto.Value = 1; % 2B - plotops_erp.timet_low.String = num2str(S_erpplot.timet_low(Select_index)); - plotops_erp.timet_low.Enable = 'off'; - plotops_erp.timet_high.String = num2str(S_erpplot.timet_high(Select_index)); - plotops_erp.timet_high.Enable = 'off'; - try - plotops_erp.timet_step.String = num2str(S_erpplot.timet_step(Select_index)); - catch - plotops_erp.timet_step.String = num2str(floor((S_erpplot.max(Select_index)-S_erpplot.min(Select_index))/5)); - end - plotops_erp.timet_step.Enable = 'off'; - - - plotops_erp.yscale_auto.Value = 1; - - plotops_erp.yscale_change.String = num2str(S_erpplot.yscale(Select_index)); - plotops_erp.yscale_change.Enable = 'off'; - plotops_erp.min_vspacing.String = num2str(S_erpplot.min_vspacing(Select_index)); - plotops_erp.min_vspacing.Enable = 'off'; - plotops_erp.fill_screen.Value = S_erpplot.fill(Select_index); - ColumnNum = estudioworkingmemory('EStudioColumnNum'); - if isempty(ColumnNum) || numel(ColumnNum)~=1 - ColumnNum =1; - end - - plotops_erp.columns.String = num2str(ColumnNum); % 2E Plot_column - plotops_erp.columns.Enable = 'on'; - - if S_erpplot.Positive_up(Select_index) == -1 - plotops_erp.positive_up.Value =0; - plotops_erp.negative_up.Value = 1; - else - plotops_erp.positive_up.Value = 1; - plotops_erp.negative_up.Value = 0; - end - - try - Bin_chan_overlay = S_binchan.bins_chans(1); - catch - Bin_chan_overlay = 0; - end - - set(gui_erp_plot.pagesel,'Value',Bin_chan_overlay+1); - end - estudioworkingmemory('erp_plot_set',0); - - %%---------------Deative the setting for the number of columns when activing ERP viewer - try - S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); - S_ws_viewer = S_ws_geterpvalues.Viewer; - catch - S_ws_viewer = 'off'; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; end - if strcmp(S_ws_viewer,'on') - plotops_erp.columns.Enable = 'off'; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + ERPTab_plotset.positive_up.Value =0; + ERPTab_plotset.negative_up.Value = 1; end - %%----------------------Setting for bin overlay chan--------------------- function pageviewchanged(src,~) - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',S_selectedERP); + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + + BinArray= estudioworkingmemory('ERP_BinArray'); + BinNum = observe_ERPDAT.ERP.nbin; + if isempty(BinArray) || any(BinArray(:)<=0) || any(BinArray(:)>BinNum) + BinArray = [1:BinNum]; + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); end - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - - if src.Value == 1 - if S_binchan.checked_ERPset_Index(1) ==1 || S_binchan.checked_ERPset_Index(2) ==2 - S_binchan.bins_chans(Select_index) = 0; - else - S_binchan.bins_chans(1:end) = 0; + if ERPTab_plotset.pagesel.Value==1 + nplot = numel(ChanArray); + if ERPTab_plotset.chanorder_front.Value ==1 + try + chanindexnew = f_estudio_chan_frontback_left_right(observe_ERPDAT.ERP.chanlocs(sort(ChanArray))); + if ~isempty(chanindexnew) + ChanArray1 = sort(ChanArray); + ChanArray = ChanArray1(chanindexnew); + end + catch + end end + plotarray = ChanArray; + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); else - if S_binchan.checked_ERPset_Index(1) ==1 || S_binchan.checked_ERPset_Index(2) ==2 - S_binchan.bins_chans(Select_index) = 1; - else - S_binchan.bins_chans(1:end) = 1; + nplot = numel(BinArray); + plotarray = BinArray; + labelsdef =observe_ERPDAT.ERP.bindescr; + end + + gridlayputarraydef = cell(ERPTab_plotset.rowNum_set.Value,ERPTab_plotset.columns.Value); + count = 0; + for ii = 1:ERPTab_plotset.rowNum_set.Value + for jj = 1:ERPTab_plotset.columns.Value + count = count+1; + if count>nplot + break; + end + gridlayputarraydef{ii,jj} = labelsdef{plotarray(count)}; end end + if ERPTab_plotset.gridlayoutdef.Value ==1 || ERPTab_plotset.chanorder_front.Value ==1 + rowNum = ceil(sqrt(nplot)); + ERPTab_plotset.rowNum_set.Value=rowNum; + ERPTab_plotset.columns.Value =ceil(nplot/rowNum); + ERPTab_plotset.gridlayputarray = gridlayputarraydef; + end - estudioworkingmemory('geterpbinchan',S_binchan); + if ERPTab_plotset.gridlayout_custom.Value==1 + ERPTab_plotset.gridlayoutdef.Value = 1; + ERPTab_plotset.gridlayout_custom.Value = 0; + ERPTab_plotset.chanorder_front.Value = 0; + ERPTab_plotset.gridlayout_export.Enable ='off'; + ERPTab_plotset.gridlayout_import.Enable ='off'; + ERPTab_plotset.rowNum_set.Enable ='off'; + ERPTab_plotset.columns.Enable ='off'; + end end + function showSEM(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + + if Source.Value ==1 + ERPTab_plotset.SEM_custom.Enable = 'on'; + ERPTab_plotset.SEMtrans_custom.Enable = 'on'; + else + ERPTab_plotset.SEM_custom.Enable = 'off'; + ERPTab_plotset.SEMtrans_custom.Enable = 'off'; + end + end + function SEMerror(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + end -%%--------------Reset the parameters for plotting panel-------------------- - function plot_erp_reset(~,~) - erpworkingmemory('f_ERP_proces_messg','Plot Setting>Reset'); - observe_ERPDAT.Process_messg =1; - - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - try - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('selectederpstudio',S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + + function SEMtrans(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + end + + +%%-----------------channel order-front-back/left-right--------------------- + function chanorder_front(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + + + ERPTab_plotset.gridlayoutdef.Value = 0; + ERPTab_plotset.gridlayout_custom.Value = 0; + ERPTab_plotset.chanorder_front.Value = 1; + ERPTab_plotset.gridlayout_export.Enable ='off'; + ERPTab_plotset.gridlayout_import.Enable ='off'; + ERPTab_plotset.rowNum_set.Enable ='off'; + ERPTab_plotset.columns.Enable ='off'; + + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + BinArray= estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray<=0) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); + end + if ERPTab_plotset.pagesel.Value==1 + nplot = numel(ChanArray); + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); + plotarray = ChanArray; + labelsdef = labelsdef(ChanArray); + else + nplot = numel(BinArray); + labelsdef =observe_ERPDAT.ERP.bindescr(BinArray); + plotarray = BinArray; + end + rowNum = ceil(sqrt(nplot)); + ERPTab_plotset.rowNum_set.Value=rowNum; + ERPTab_plotset.columns.Value =ceil(nplot/rowNum); + gridlayputarray = cell(ERPTab_plotset.rowNum_set.Value,ERPTab_plotset.columns.Value); + + if ERPTab_plotset.pagesel.Value==1 + try + chanlocs = observe_ERPDAT.ERP.chanlocs; + if isempty(chanlocs(1).X) && isempty(chanlocs(1).Y) + MessageViewer= char(strcat('Plot Settings > Simple 10/20 system order:please do "chan locations" first in EEGLAB Tool panel.')); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=4; + end catch - return; + ERPTab_plotset.gridlayoutdef.Value = 1; + ERPTab_plotset.gridlayout_custom.Value = 0; + ERPTab_plotset.chanorder_front.Value = 0; + ERPTab_plotset.gridlayout_export.Enable ='off'; + ERPTab_plotset.gridlayout_import.Enable ='off'; + ERPTab_plotset.rowNum_set.Enable ='off'; + ERPTab_plotset.columns.Enable ='off'; + end + if ERPTab_plotset.chanorder_front.Value==1 + %%check if the channels belong to 10/20 system + [eloc, labels, theta, radius, indices] = readlocs( observe_ERPDAT.ERP.chanlocs); + [Simplabels,simplabelIndex,SamAll] = Simplelabels(labels); + count = 0; + for ii = 1:length(Simplabels) + [xpos,ypos]= find(simplabelIndex==ii); + if ~isempty(ypos) && numel(ypos)>= floor(length(observe_ERPDAT.ERP.chanlocs)/2) + count = count+1; + if count==1 + msgboxText= char(strcat('We cannot use the "Simple 10/20 system order" with your data because your channel labels do not appear to be standard 10/20 names.')); + title = 'Estudio: Plot Settings > Channel order>Simple 10/20 system order:'; + errorfound(msgboxText, title); + break; + end + end + end + if count==1 + ERPTab_plotset.gridlayoutdef.Value = 1; + ERPTab_plotset.gridlayout_custom.Value = 0; + ERPTab_plotset.chanorder_front.Value = 0; + ERPTab_plotset.gridlayout_export.Enable ='off'; + ERPTab_plotset.gridlayout_import.Enable ='off'; + ERPTab_plotset.rowNum_set.Enable ='off'; + ERPTab_plotset.columns.Enable ='off'; + else + [eloc, labels11, theta, radius, indices] = readlocs(observe_ERPDAT.ERP.chanlocs); + ERPTab_plotset.chanorderIndex = 2; + chanindexnew = f_estudio_chan_frontback_left_right(observe_ERPDAT.ERP.chanlocs(plotarray)); + if ~isempty(chanindexnew) + labelsdef = labels11(chanindexnew); + else + labelsdef = labels11(plotarray); + end + end + end + end + count = 0; + for ii = 1:ERPTab_plotset.rowNum_set.Value + for jj = 1:ERPTab_plotset.columns.Value + count = count+1; + if count>nplot + break; + end + gridlayputarray{ii,jj} = labelsdef{count}; end + end + ERPTab_plotset.gridlayputarray = gridlayputarray; + end + + +%%-------------------default layout---------------------------------------- + function gridlayoutdef(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + ERPTab_plotset.gridlayoutdef.Value = 1; + ERPTab_plotset.gridlayout_custom.Value = 0; + ERPTab_plotset.chanorder_front.Value = 0; + ERPTab_plotset.gridlayout_export.Enable ='off'; + ERPTab_plotset.gridlayout_import.Enable ='off'; + ERPTab_plotset.rowNum_set.Enable ='off'; + ERPTab_plotset.columns.Enable ='off'; + + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + BinArray= estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray<=0) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); + end + if ERPTab_plotset.pagesel.Value==1 + nplot = numel(ChanArray); + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); + plotarray = ChanArray; else - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + nplot = numel(BinArray); + labelsdef =observe_ERPDAT.ERP.bindescr; + plotarray = BinArray; end - gui_erp_plot.pagesel.Value = 1; + rowNum = ceil(sqrt(nplot)); + ERPTab_plotset.rowNum_set.Value=rowNum; + ERPTab_plotset.columns.Value =ceil(nplot/rowNum); + gridlayputarray = cell(ERPTab_plotset.rowNum_set.Value,ERPTab_plotset.columns.Value); + count = 0; + for ii = 1:ERPTab_plotset.rowNum_set.Value + for jj = 1:ERPTab_plotset.columns.Value + count = count+1; + if count>nplot + break; + end + gridlayputarray{ii,jj} = labelsdef{plotarray(count)}; + end + end + ERPTab_plotset.gridlayputarray = gridlayputarray; + end + +%%-------------------custom layout----------------------------------------- + function gridlayout_custom(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + + ERPTab_plotset.gridlayoutdef.Value = 0; + ERPTab_plotset.gridlayout_custom.Value = 1; + ERPTab_plotset.chanorder_front.Value = 0; + ERPTab_plotset.gridlayout_export.Enable ='on'; + ERPTab_plotset.gridlayout_import.Enable ='on'; + ERPTab_plotset.rowNum_set.Enable ='on'; + ERPTab_plotset.columns.Enable ='on'; + end + +%%---------------------export layout--------------------------------------- + function gridlayout_export(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + try observe_ERPDAT.Count_currentERP=eegpanelIndex+1; catch end%%call the functions from the other panel + end - erp_plot_set_label = estudioworkingmemory('erp_plot_set'); - if isempty(erp_plot_set_label) - erp_plot_set_label =1; + estudioworkingmemory('f_ERP_proces_messg','Plot Setting > Grid Layout > Export'); + observe_ERPDAT.Process_messg =1; + pathstr = pwd; + namedef ='GridLocations'; + [erpfilename, erppathname, indxs] = uiputfile({'*.tsv'}, ... + ['Save Grid Locations as'],... + fullfile(pathstr,namedef)); + if isequal(erpfilename,0) + return end - if ~erp_plot_set_label - S_selectedERP = estudioworkingmemory('selectederpstudio'); - if isempty(S_selectedERP) - S_selectedERP = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,S_selectedERP); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); + [pathstr, erpfilename, ext] = fileparts(erpfilename) ; + ext = '.tsv'; + erpFilename = char(strcat(erppathname,erpfilename,ext)); + + AllabelArray = ERPTab_plotset.gridlayputarray; + + rowNums = ERPTab_plotset.rowNum_set.Value; + columNums = ERPTab_plotset.columns.Value; + + if isempty(AllabelArray) || rowNums~= size(AllabelArray,1) || columNums~= size(AllabelArray,2) + AllabelArray = reshape(AllabelArray,numel(AllabelArray),1); + AllabelArray_new = cell(rowNums,columNums); + count = 0; + for ii = 1:rowNums + for jj = 1:columNums + count=count+1; + if count<= numel(AllabelArray) + AllabelArray_new{ii,jj} = AllabelArray{count}; + end + end end - - S_binchan = estudioworkingmemory('geterpbinchan'); - Select_index = S_binchan.Select_index; - S_erpplot = estudioworkingmemory('geterpplot'); - plotops_erp.timet_auto.Value = 1; % 2B - plotops_erp.timet_low.String = num2str(S_erpplot.timet_low(Select_index)); - plotops_erp.timet_low.Enable = 'off'; - plotops_erp.timet_high.String = num2str(S_erpplot.timet_high(Select_index)); - plotops_erp.timet_high.Enable = 'off'; - try - plotops_erp.timet_step.String = num2str(S_erpplot.timet_step(Select_index)); - catch - plotops_erp.timet_step.String = num2str(floor((S_erpplot.max(Select_index)-S_erpplot.min(Select_index))/5)); - end - plotops_erp.timet_step.Enable = 'off'; - plotops_erp.yscale_auto.Value = 1; - plotops_erp.yscale_change.String = num2str(S_erpplot.yscale(Select_index)); - plotops_erp.yscale_change.Enable = 'off'; - plotops_erp.min_vspacing.String = num2str(S_erpplot.min_vspacing(Select_index)); - plotops_erp.min_vspacing.Enable = 'off'; - plotops_erp.fill_screen.Value = S_erpplot.fill(Select_index); - ColumnNum = estudioworkingmemory('EStudioColumnNum'); - if isempty(ColumnNum) || numel(ColumnNum)~=1 - ColumnNum =1; + AllabelArray = AllabelArray_new; + end + + fileID = fopen(erpFilename,'w'); + [nrows,ncols] = size(AllabelArray); + formatSpec =''; + for jj = 1:ncols+1 + if jj==ncols+1 + formatSpec = strcat(formatSpec,'%s'); + else + formatSpec = strcat(formatSpec,'%s\t',32); end - - plotops_erp.columns.String = num2str(ColumnNum); % 2E Plot_column - plotops_erp.columns.Enable = 'on'; - - if S_erpplot.Positive_up(Select_index) == -1 - plotops_erp.positive_up.Value =0; - plotops_erp.negative_up.Value = 1; + if jj==1 + columName{1,jj} = ''; else - plotops_erp.positive_up.Value = 1; - plotops_erp.negative_up.Value = 0; + columName{1,jj} = ['Column',num2str(jj-1)]; end - + end + formatSpec = strcat(formatSpec,'\n'); + fprintf(fileID,formatSpec,columName{1,:}); + for row = 1:nrows + rowdata = cell(1,ncols+1); + rowdata{1,1} = char(['Row',num2str(row)]); + for jj = 1:ncols + rowdata{1,jj+1} = AllabelArray{row,jj}; + end + fprintf(fileID,formatSpec,rowdata{1,:}); + end + fclose(fileID); + disp(['The file for ERP Tab Grid layout was created at ' erpFilename '']) + observe_ERPDAT.Process_messg =2; + end + +%%---------------------import layout--------------------------------------- + function gridlayout_import(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + + [filename, filepath] = uigetfile({'*.tsv;*.txt';'*.*'}, ... + 'Plot Setting > Grid Layout > Import'); + if isequal(filename,0) + return; + end + try + DataInput = readtable([filepath,filename], "FileType","text",'PreserveVariableNames',true); + catch + DataInput = readtable([filepath,filename], "FileType","text"); + estudioworkingmemory('f_ERP_proces_messg',['Plot Settings > Grid Layout > Import:','Cannot import:',filepath,filename]); + observe_ERPDAT.Process_messg =4; + return; + end + if isempty(DataInput) + estudioworkingmemory('f_ERP_proces_messg','Plot Settings > Grid Layout > Import is invalid'); + observe_ERPDAT.Process_messg =4; + return; + end + overlapindex = ERPTab_plotset.pagesel.Value; + DataInput = table2cell(DataInput); + + [rows,columns] = size(DataInput); + if columns<=2 + estudioworkingmemory('f_ERP_proces_messg','Plot Settings > Grid Layout > Import is invalid and one column is designed besides the first column that is row title'); + observe_ERPDAT.Process_messg =4; + return; + end + + DataInput = DataInput(:,2:end); + [Griddata, checkflag,labelsIndex ]= f_tranf_check_import_grid(DataInput,overlapindex); + if checkflag==0 + estudioworkingmemory('f_ERP_proces_messg','Plot Settings > Grid Layout > Import is invalid or didnot match with existing labels'); + observe_ERPDAT.Process_messg =4; + return; + end + + ERPTab_plotset.rowNum_set.Value =size(Griddata,1); + ERPTab_plotset.columns.Value =size(Griddata,2); + ERPTab_plotset.gridlayputarray = Griddata;%%save the grid layout + end + +%%--------------------row numbers------------------------------------------ + function rowNum_set(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + end + +%%------------------------column numbers----------------------------------- + function columNum_select(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_plotset',1); + ERPTab_plotset.plot_apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_apply.ForegroundColor = [1 1 1]; + ERP_plotset_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [ 0.5137 0.7569 0.9176]; + ERPTab_plotset.plot_reset.ForegroundColor = [1 1 1]; + end + + +%%--------------Reset the parameters for plotting panel-------------------- + function plot_erp_reset(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + + estudioworkingmemory('ERPTab_plotset',0); + ERPTab_plotset.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_plotset.plot_apply.ForegroundColor = [0 0 0]; + ERP_plotset_box.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_plotset.plot_reset.ForegroundColor = [0 0 0]; + + estudioworkingmemory('f_ERP_proces_messg','Plot Settings>Cancel'); + observe_ERPDAT.Process_messg =1; + % + %%------------------------------time range------------------------- + ERPTab_plotset.timet_auto.Value=ERPTab_plotset.paras{1}; + ERPTab_plotset.timetick_auto.Value=ERPTab_plotset.paras{2}; + + ERPTab_plotset_pars = estudioworkingmemory('ERPTab_plotset_pars'); + timelowdef = observe_ERPDAT.ERP.times(1); + timehighdef= observe_ERPDAT.ERP.times(end); + [def xtickstepdef]= default_time_ticks_studio(observe_ERPDAT.ERP, [timelowdef,timehighdef]); + if ERPTab_plotset.timet_auto_reset==1 + Enablerange = 'off'; + timelow = timelowdef; + timehigh = timehighdef; + else + Enablerange = 'on'; + try + timerange = ERPTab_plotset_pars{1}; + timelow = timerange(1); + timehigh = timerange(2); + catch + timelow = timelowdef; + timehigh = timehighdef; + end + end + if ERPTab_plotset.timetick_auto.Value==1 + xtickstep = xtickstepdef; + Enablerange1 = 'off'; + else try - Bin_chan_overlay = S_binchan.bins_chans(1); + xtickstep = ERPTab_plotset_pars{2}; catch - Bin_chan_overlay = 0; + xtickstep = xtickstepdef; end + Enablerange1 = 'on'; + end + + + if isempty(timelow) || numel(timelow)~=1 || timelow>=timehighdef + timelow = timelowdef; + end + if isempty(timehigh) || numel(timehigh)~=1 || timehigh<=timelowdef + timehigh = timehighdef; + end + if timelow>timehigh + timelow = timelowdef; + timehigh = timehighdef; + end + if isempty(xtickstep) || numel(xtickstep)~=1 || any(xtickstep(:)<=0) || xtickstep>=(timehigh-timelow) + xtickstep = xtickstepdef; + end + ERPTab_plotset.timet_low.Enable = Enablerange; + ERPTab_plotset.timet_high.Enable = Enablerange; + ERPTab_plotset.timet_step.Enable = Enablerange1; + ERPTab_plotset.timet_low.String = num2str(timelow); + ERPTab_plotset.timet_high.String = num2str(timehigh); + ERPTab_plotset.timet_step.String = num2str(xtickstep); + ERPTab_plotset_pars{1} = [timelow,timehigh]; + ERPTab_plotset_pars{2}= xtickstep; + % + %%------------------------Amplitude Axis---------------------------------- + + ERPTab_plotset.yscale_auto.Value = ERPTab_plotset.paras{3}; + ERPTab_plotset.ytick_auto.Value = ERPTab_plotset.paras{4}; + BinArray= estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray<=0) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; + end + try Yscale = ERPTab_plotset_pars{3}; catch Yscale=[]; end + try Yscales_low = Yscale(1);catch Yscales_low=[];end + try Yscales_high = Yscale(2);catch Yscales_high=[];end + if isempty(Yscales_low) || numel(Yscales_low)~=1 + ERPTab_plotset.yscale_low.String = str2num(minydef); + Yscales_low= minydef; + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: You did set left edge of amplitude scale to be a single number and we used the default one '); + observe_ERPDAT.Process_messg =4; + end + if isempty(Yscales_high) || numel(Yscales_high)~=1 + ERPTab_plotset.yscale_high.String = str2num(maxydef); + Yscales_high= maxydef; - set(gui_erp_plot.pagesel,'Value',Bin_chan_overlay+1); end - estudioworkingmemory('erp_plot_set',0); + if any(Yscales_high<=Yscales_low) + ERPTab_plotset.yscale_low.String = str2num(minydef); + ERPTab_plotset.yscale_high.String = str2num(maxydef); + Yscales_high= maxydef; + Yscales_low= minydef; + end - %%---------------Deative the setting for the number of columns when activing ERP viewer + if ERPTab_plotset.yscale_auto.Value==0 + ERPTab_plotset.yscale_low.Enable = 'on'; + ERPTab_plotset.yscale_high.Enable = 'on'; + else + Yscales_high= maxydef; + Yscales_low= minydef; + ERPTab_plotset.yscale_low.Enable = 'off'; + ERPTab_plotset.yscale_high.Enable = 'off'; + end + ERPTab_plotset.yscale_low.String = num2str(Yscales_low); + ERPTab_plotset.yscale_high.String = num2str(Yscales_high); + ERPTab_plotset_pars{3} = [Yscales_low,Yscales_high]; + + + if ERPTab_plotset.ytick_auto.Value==1 + Enableflag = 'off'; + defyticks = default_amp_ticks_viewer([Yscales_low,Yscales_high]); + defyticks = str2num(defyticks); + if ~isempty(defyticks) && numel(defyticks)>=2 + ERPTab_plotset.yscale_step.String = num2str(min(diff(defyticks))); + else + ERPTab_plotset.yscale_step.String = num2str(floor((Yscales_high-Yscales_low)/2)); + end + else + Enableflag = 'on'; + yscale= ERPTab_plotset_pars{4}; + ERPTab_plotset.yscale_step.String = num2str(yscale); + end + ERPTab_plotset.yscale_step.Enable = Enableflag; + + + % + %%Number of columns? + ColumnNum= ERPTab_plotset_pars{5}; + if isempty(ColumnNum) || numel(ColumnNum)~=1 || any(ColumnNum<=0) + ColumnNum =1; + ERPTab_plotset_pars{5}=1; + end + ERPTab_plotset.columns.Value =ColumnNum; % 2E Plot_column + ERPTab_plotset.columns.Enable = 'on'; + + % + %%polarity? + positive_up = ERPTab_plotset_pars{6}; + if isempty(positive_up) || numel(positive_up)~=1 || (positive_up~=0&&positive_up~=1) + positive_up=1; + ERPTab_plotset_pars{6}=1; + end + ERPTab_plotset.positive_up.Value =positive_up; + ERPTab_plotset.negative_up.Value = ~positive_up; + % + %%overlay? + Bin_chan_overlay=ERPTab_plotset_pars{7}; + if isempty(Bin_chan_overlay) || numel(Bin_chan_overlay)~=1 || (Bin_chan_overlay~=0 && Bin_chan_overlay~=1) + Bin_chan_overlay=0; + ERPTab_plotset_pars{7}=0; + end + set(ERPTab_plotset.pagesel,'Value',Bin_chan_overlay+1); + + % + %%channel order + ERP_chanorders= estudioworkingmemory('ERP_chanorders'); try - S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); - S_ws_viewer = S_ws_geterpvalues.Viewer; + chanordervalue = ERP_chanorders{1}; catch - S_ws_viewer = 'off'; + chanordervalue=1; end - if strcmp(S_ws_viewer,'on') - plotops_erp.columns.Enable = 'off'; + + try rowNum = ERPTab_plotset_pars{8};catch rowNum=1;ERPTab_plotset_pars{8}=1; end + ERPTab_plotset.rowNum_set.Value=rowNum; + + + try gridlayoutdef = ERPTab_plotset_pars{9};catch gridlayoutdef =1; ERPTab_plotset_pars{9}=1; end + if isempty(gridlayoutdef) || numel(gridlayoutdef)~=1 || (gridlayoutdef~=0 && gridlayoutdef~=1) + gridlayoutdef =1; ERPTab_plotset_pars{9}=1; + end + ERPTab_plotset.gridlayoutdef.Value=gridlayoutdef;%%default grid layout? + ERPTab_plotset.gridlayout_custom.Value = ~gridlayoutdef; + if gridlayoutdef==3 + EnableFlag= 'on'; + else + EnableFlag= 'off'; + end + ERPTab_plotset.gridlayout_export.Enable =EnableFlag; + ERPTab_plotset.gridlayout_import.Enable =EnableFlag; + ERPTab_plotset.rowNum_set.Enable =EnableFlag; + ERPTab_plotset.columns.Enable =EnableFlag; + + if ERPTab_plotset.pagesel.Value==1 + nplot = numel(ChanArray); + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); + plotarray = sort(ChanArray); + else + nplot = numel(BinArray); + labelsdef =observe_ERPDAT.ERP.bindescr; + plotarray = BinArray; end + if gridlayoutdef==1 + ERPTab_plotset.rowNum_set.Value = ceil(sqrt(nplot)); + ERPTab_plotset.columns.Value = ceil(nplot/ceil(sqrt(nplot))); + end + + gridlayputarraydef = cell(ERPTab_plotset.rowNum_set.Value,ERPTab_plotset.columns.Value); + count = 0; + for ii = 1:ERPTab_plotset.rowNum_set.Value + for jj = 1:ERPTab_plotset.columns.Value + count = count+1; + if count>nplot + break; + end + gridlayputarraydef{ii,jj} = labelsdef{plotarray(count)}; + end + end + if gridlayoutdef==1 + ERPTab_plotset.gridlayputarray=gridlayputarraydef; + end + + try gridlayputarray= ERPTab_plotset_pars{10};catch gridlayputarray= gridlayputarraydef ;ERPTab_plotset_pars{10}=gridlayputarraydef; end + ERPTab_plotset.gridlayputarray=gridlayputarray; + ERPTab_plotset_pars{10} = ERPTab_plotset.gridlayputarray; + + %%-------SEM---------- + try SMEFlag = ERPTab_plotset_pars{11};catch SMEFlag = [0 1 0.2];end + try show_SEM = SMEFlag(1);catch show_SEM=0; end + if isempty(show_SEM) || numel(show_SEM)~=1 ||(show_SEM~=0&& show_SEM~=1) + show_SEM=0; + end + ERPTab_plotset.show_SEM.Value = show_SEM; + if ERPTab_plotset.show_SEM.Value == 1 + ERPTab_plotset.SEM_custom.Enable = 'on'; + ERPTab_plotset.SEMtrans_custom.Enable = 'on'; + else + ERPTab_plotset.SEM_custom.Enable = 'off'; + ERPTab_plotset.SEMtrans_custom.Enable = 'off'; + end + + try SEM_custom = SMEFlag(2);catch SEM_custom = SMEFlag(2); end + if isempty(SEM_custom)|| numel(SEM_custom)~=1 || any(SEM_custom<0) || any(SEM_custom>10) + SEM_custom=1; + end + ERPTab_plotset.SEM_custom.Value = SEM_custom+1; + + try SEMtrans_custom = SMEFlag(3);catch SEMtrans_custom = SMEFlag(3); end + if isempty(SEMtrans_custom)|| numel(SEMtrans_custom)~=1 || any(SEMtrans_custom<0) || any(SEMtrans_custom>1) + SEMtrans_custom=0.2; + end + ERPTab_plotset.SEMtrans_custom.Value = SEMtrans_custom*10+1; + if ERPTab_plotset.show_SEM.Value == 1 + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + ERPTab_plotset_pars{11} = [1,SEM_custom,SEMtrans_custom]; + else + ERPTab_plotset_pars{11} = [0,ERPTab_plotset.SEM_custom.Value-1,(ERPTab_plotset.SEMtrans_custom.Value-1)/10]; + end + + estudioworkingmemory('ERPTab_plotset_pars',ERPTab_plotset_pars); observe_ERPDAT.Process_messg =2; + end + + +%------------Apply current parameters in plotting panel to the selected ERPset--------- + function plot_setting_apply(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=2; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex==1 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end - %%plot the waveforms - try - S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); - S_ws_viewer = S_ws_geterpvalues.Viewer; - - moption = S_ws_geterpvalues.Measure; - latency = S_ws_geterpvalues.latency; - if strcmp(S_ws_viewer,'on') - if isempty(moption) - msgboxText = ['EStudio says: User must specify a type of measurement.']; - title = 'EStudio: ERP measurement tool- "Measurement type".'; - errorfound(msgboxText, title); - return; + estudioworkingmemory('ERPTab_plotset',0); + ERPTab_plotset.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_plotset.plot_apply.ForegroundColor = [0 0 0]; + ERP_plotset_box.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_plotset.plot_reset.ForegroundColor = [0 0 0]; + + estudioworkingmemory('f_ERP_proces_messg','Plot Settings>Apply'); + observe_ERPDAT.Process_messg =1; + ERPTab_plotset.timet_auto_reset = ERPTab_plotset.timet_auto.Value; + ERPTab_plotset.timeticks_auto_reset = ERPTab_plotset.yscale_auto.Value; + % + %%time range + timeStartdef = observe_ERPDAT.ERP.times(1); + timEnddef = observe_ERPDAT.ERP.times(end); + [def xstepdef]= default_time_ticks_studio(observe_ERPDAT.ERP, [observe_ERPDAT.ERP.times(1),observe_ERPDAT.ERP.times(end)]); + timeStart = str2num(ERPTab_plotset.timet_low.String); + if isempty(timeStart) || numel(timeStart)~=1 || timeStart>=observe_ERPDAT.ERP.times(end) + timeStart = timeStartdef; + ERPTab_plotset.timet_low.String = num2str(observe_ERPDAT.ERP.times(1)); + MessageViewer= char(['Plot Settings > Apply: Low edge of the time range should be smaller',32,num2str(observe_ERPDAT.ERP.times(end)),32,... + 'we therefore set to be',32,num2str(timeStart)]); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=4; + end + + timEnd = str2num(ERPTab_plotset.timet_high.String); + if isempty(timEnd) || numel(timEnd)~=1 || timEnd<=observe_ERPDAT.ERP.times(1) + timEnd = timEnddef; + ERPTab_plotset.timet_high.String = num2str(timEnd); + MessageViewer= char(['Plot Settings > Apply: High edge of the time range should be larger',32,num2str(timeStartdef),32,... + 'we therefore set to be',32,num2str(timEnddef)]); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=4; + end + + if timeStart>= timEnd + timEnd = timEnddef; + timeStart = timeStartdef; + ERPTab_plotset.timet_low.String = num2str(timeStart); + ERPTab_plotset.timet_high.String = num2str(timEnd); + MessageViewer= char(['Plot Settings > Apply: Low edge of the time range should be smaller than the high one and we therefore used the defaults']); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=4; + end + ERPTab_plotset_pars{1} = [timeStart,timEnd]; + + xtickstep = str2num(ERPTab_plotset.timet_step.String); + if isempty(xtickstep) || numel(xtickstep)~=1 || any(xtickstep<=0) + xtickstep = xstepdef; + ERPTab_plotset.timet_step.String = num2str(xtickstep); + MessageViewer= char(['Plot Settings > Apply: the step of the time ticks should be a positive number that belows',32,num2str(floor((timEnd-timeStart)/2))]); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=4; + end + ERPTab_plotset_pars{2} = xtickstep; + + % + %%Amplitude Axis + BinArray= estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray<=0) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; + end + Yscales_low = str2num(ERPTab_plotset.yscale_low.String); + Yscales_high = str2num(ERPTab_plotset.yscale_high.String); + if isempty(Yscales_low) || numel(Yscales_low)~=1 + ERPTab_plotset.yscale_low.String = num2str(minydef); + Yscales_low= minydef; + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: You did set left edge of amplitude scale to be a single number and we used the default one '); + observe_ERPDAT.Process_messg =4; + end + if isempty(Yscales_high) || numel(Yscales_high)~=1 + ERPTab_plotset.yscale_high.String = num2str(maxydef); + Yscales_high= maxydef; + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: You did set right edge of amplitude scale to be a single number and we used the default one '); + observe_ERPDAT.Process_messg =4; + end + if any(Yscales_high<=Yscales_low) + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); + Yscales_high= maxydef; + Yscales_low= minydef; + estudioworkingmemory('f_ERP_proces_messg','Plot Settings> Amplitude Axis: Left edge of amplitude scale should be smaller than the right one and we used the default ones '); + observe_ERPDAT.Process_messg =4; + end + ERPTab_plotset_pars{3} = [Yscales_low,Yscales_high]; + ERPTab_plotset_pars{4} = str2num(ERPTab_plotset.yscale_step.String); + + %%Number of columns + columNum = round(ERPTab_plotset.columns.Value); + if isempty(columNum) || numel(columNum)~=1 || any(columNum<=0) + columNum =1; + ERPTab_plotset.columns.String = '1'; + MessageViewer= char(['Plot Settings > Apply: the number of columns should be a positive value']); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg=4; + end + ERPTab_plotset_pars{5} =columNum; + + % + %%polarity (positive up?) + ERPTab_plotset_pars{6} =ERPTab_plotset.positive_up.Value; + % + %%overlay? + if ERPTab_plotset.pagesel.Value==1 + ERPTab_plotset_pars{7} =0; + else + ERPTab_plotset_pars{7} = 1; + end + + ERPTab_plotset_pars{8} = ERPTab_plotset.rowNum_set.Value;%%number of rows + if ERPTab_plotset.gridlayoutdef.Value==1 + gridlayoutdef=1; + elseif ERPTab_plotset.chanorder_front.Value==1 + gridlayoutdef=2; + else + gridlayoutdef=3; + end + + ERPTab_plotset_pars{9} = gridlayoutdef;%%default grid layout? + if ERPTab_plotset.pagesel.Value==1 + [~,plotArraystr] = readlocs(observe_ERPDAT.ERP.chanlocs(ChanArray)); + else + plotArraystr= observe_ERPDAT.ERP.bindescr{BinArray}; + end + rowNum = ERPTab_plotset_pars{8} ; + gridlayputarraydef = cell(rowNum,columNum); + count = 0; + for ii = 1:rowNum + for jj = 1:columNum + count = count+1; + if count<= length(plotArraystr) + try gridlayputarraydef{ii,jj} = plotArraystr{count};catch end; end - if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) - if length(latency)~=1 - msgboxText = ['ERPLAB says: ' moption ' only needs 1 latency value.']; - title = 'EStudio: ERP measurement tool- "Measurement type".'; - errorfound(msgboxText, title); - return; - end + end + end + if ERPTab_plotset.gridlayoutdef.Value==1 || size(ERPTab_plotset.gridlayputarray,1)~=rowNum || size(ERPTab_plotset.gridlayputarray,2)~=columNum + ERPTab_plotset.gridlayputarray = gridlayputarraydef; + end + [Griddata, checkflag,labelsIndex]= f_tranf_check_import_grid(ERPTab_plotset.gridlayputarray,ERPTab_plotset.pagesel.Value); + if checkflag==1 + if ERPTab_plotset.pagesel.Value==1 + estudioworkingmemory('ERP_ChanArray',labelsIndex); + ChanArray = labelsIndex; + else + estudioworkingmemory('ERP_BinArray',labelsIndex); + BinArray = labelsIndex; + end + else + ERPTab_plotset.gridlayputarray = gridlayputarraydef; + end + if ERPTab_plotset.chanorder_front.Value==1 + try + [eloc, labels, theta, radius, indices] = readlocs(observe_ERPDAT.ERP.chanlocs); + ERPTab_plotset.chanorderIndex = 2; + chanindexnew = f_estudio_chan_frontback_left_right(observe_ERPDAT.ERP.chanlocs(sort(ChanArray))); + if isempty(chanindexnew) + chanindexnew = ChanArray; else - if length(latency)~=2 - msgboxText = ['EStudio says: ' moption ' needs 2 latency values.']; - title = 'EStudio: ERP measurement tool- "Measurement type".'; - errorfound(msgboxText, title); - return; - else - if latency(1)>=latency(2) - msgboxText = ['For latency range, lower time limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; - title = 'EStudio: ERP measurement tool-Measurement window'; - errorfound(sprintf(msgboxText), title); - return + ChanArray = sort(ChanArray); + chanindexnew = ChanArray(chanindexnew); + end + catch + chanindexnew = ChanArray; + end + else + chanindexnew = ChanArray; + end + if ERPTab_plotset.chanorder_front.Value==1 + gridlayputarraydef = cell(rowNum,columNum); + count = 0; + for ii = 1:rowNum + for jj = 1:columNum + count = count+1; + if count<= length(plotArraystr) + if ERPTab_plotset.pagesel.Value==1 + try + gridlayputarraydef{ii,jj} = observe_ERPDAT.ERP.chanlocs(chanindexnew(count)).labels; + catch + gridlayputarraydef{ii,jj} = ['Chan',32,num2str(chanindexnew(count))]; + end + else + try gridlayputarraydef{ii,jj} = observe_ERPDAT.ERP.bindescr{BinArray(count)};catch end; end end end - f_redrawERP_mt_viewer(); - else - f_redrawERP(); end - catch - f_redrawERP(); + estudioworkingmemory('ERP_ChanArray',chanindexnew); + ERPTab_plotset.gridlayputarray=gridlayputarraydef; + end + + ERPTab_plotset_pars{10} = ERPTab_plotset.gridlayputarray; + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + if ERPTab_plotset.show_SEM.Value == 1 + ERPTab_plotset.SEM_custom.Enable = 'on'; + ERPTab_plotset.SEMtrans_custom.Enable = 'on'; + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + ERPTab_plotset_pars{11} = [1,SEM_custom,SEMtrans_custom]; + else + ERPTab_plotset_pars{11} = [0,SEM_custom,SEMtrans_custom]; end + estudioworkingmemory('ERPTab_plotset_pars',ERPTab_plotset_pars);%%save the changed paras to memory file + %%channel orders + + ERPTab_plotset.paras{1} = ERPTab_plotset.timet_auto.Value; + ERPTab_plotset.paras{2} = ERPTab_plotset.timetick_auto.Value; + ERPTab_plotset.paras{3} = ERPTab_plotset.yscale_auto.Value; + ERPTab_plotset.paras{4} = ERPTab_plotset.ytick_auto.Value; + observe_ERPDAT.Count_currentERP=1; end -%------------Apply current parameters in plotting panel to the selected ERPset--------- - function plot_erp_apply(~,~) - erpworkingmemory('f_ERP_proces_messg','Plot Setting>Apply'); - observe_ERPDAT.Process_messg =1; + +%%------------------------------------------------------------------------- + function Count_currentERPChanged(~,~) + if observe_ERPDAT.Count_currentERP~=3 + return; + end + ChangeFlag = estudioworkingmemory('ERPTab_plotset'); + if ~isempty(ChangeFlag) && ChangeFlag==1 + erp_between_panels_change(); + observe_ERPDAT.Count_currentERP=0; + return; + end - estudioworkingmemory('geterpplot',S_erpplot); - estudioworkingmemory('erp_plot_set',1); - ColumnNum = str2num(plotops_erp.columns.String); - if isempty(ColumnNum) && numel(ColumnNum)~=1 - ColumnNum = 1; + ViewerFlag=estudioworkingmemory('ViewerFlag');%%when open advanced wave viewer + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ALLERP)|| isempty(observe_ERPDAT.ERP) || ViewerFlag==1 + enbaleflag = 'off'; + else + enbaleflag = 'on'; + end + ERPTab_plotset.timet_auto.Enable =enbaleflag; + ERPTab_plotset.timet_low.Enable =enbaleflag; + ERPTab_plotset.timet_high.Enable =enbaleflag; + ERPTab_plotset.timetick_auto.Enable =enbaleflag; + ERPTab_plotset.timet_step.Enable =enbaleflag; + ERPTab_plotset.yscale_auto.Enable =enbaleflag; + ERPTab_plotset.yscale_low.Enable =enbaleflag; + ERPTab_plotset.yscale_high.Enable =enbaleflag; + ERPTab_plotset.ytick_auto.Enable =enbaleflag; + ERPTab_plotset.yscale_step.Enable =enbaleflag; + ERPTab_plotset.columns.Enable =enbaleflag; + ERPTab_plotset.positive_up.Enable =enbaleflag; + ERPTab_plotset.negative_up.Enable =enbaleflag; + ERPTab_plotset.pagesel.Enable =enbaleflag; + ERPTab_plotset.SEM_custom.Enable = enbaleflag; + ERPTab_plotset.SEMtrans_custom.Enable = enbaleflag; + ERPTab_plotset.show_SEM.Enable = enbaleflag; + ERPTab_plotset.plot_reset.Enable =enbaleflag; + ERPTab_plotset.plot_apply.Enable =enbaleflag; + ERPTab_plotset.gridlayoutdef.Enable =enbaleflag; + ERPTab_plotset.chanorder_front.Enable =enbaleflag; + ERPTab_plotset.gridlayout_custom.Enable =enbaleflag; + ERPTab_plotset.gridlayout_export.Enable =enbaleflag; + ERPTab_plotset.gridlayout_import.Enable =enbaleflag; + ERPTab_plotset.rowNum_set.Enable =enbaleflag; + ERPTab_plotset.columns.Enable =enbaleflag; + if isempty(observe_ERPDAT.ALLERP)|| isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP =4; + return; end - estudioworkingmemory('EStudioColumnNum',ColumnNum); - % observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - %%plot the waveforms - try - S_ws_geterpvalues = estudioworkingmemory('geterpvalues'); - S_ws_viewer = S_ws_geterpvalues.Viewer; - - moption = S_ws_geterpvalues.Measure; - latency = S_ws_geterpvalues.latency; - if strcmp(S_ws_viewer,'on') - if isempty(moption) - msgboxText = ['EStudio says: User must specify a type of measurement.']; - title = 'EStudio: ERP measurement tool- "Measurement type".'; - errorfound(msgboxText, title); - return; + % + %%time range + if ERPTab_plotset.timet_auto.Value == 1 + ERPTab_plotset.timet_low.String = num2str(observe_ERPDAT.ERP.times(1)); + ERPTab_plotset.timet_low.Enable = 'off'; + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + ERPTab_plotset.timet_high.Enable = 'off'; + end + timeStart = str2num(ERPTab_plotset.timet_low.String); + if isempty(timeStart) || numel(timeStart)~=1 || timeStart>observe_ERPDAT.ERP.times(end) %%|| timeStart observe_ERPDAT.ERP.times(end) + timEnd = observe_ERPDAT.ERP.times(end); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + end + if timeStart>timEnd + ERPTab_plotset.timet_low.String = num2str(observe_ERPDAT.ERP.times(1)); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + timeStart = observe_ERPDAT.ERP.times(1); + timEnd = observe_ERPDAT.ERP.times(end); + end + ERPTab_plotset_pars{1} = [timeStart,timEnd]; + [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [timeStart,timEnd]); + if ERPTab_plotset.timetick_auto.Value==1 + ERPTab_plotset.timet_step.String = num2str(xstep); + ERPTab_plotset.timet_step.Enable = 'off'; + end + xtickstep = str2num(ERPTab_plotset.timet_step.String); + if isempty(xtickstep) || numel(xtickstep)~=1 || xtickstep> floor((timEnd-timeStart)/2) + xtickstep= xstep; + ERPTab_plotset.timet_step.String = num2str(xstep); + end + ERPTab_plotset_pars{2} = xtickstep; + % + %%Amplitude Axis + %%Yscale + BinArray= estudioworkingmemory('ERP_BinArray'); + if isempty(BinArray) || any(BinArray<=0) || any(BinArray>observe_ERPDAT.ERP.nbin) + BinArray = [1:observe_ERPDAT.ERP.nbin]; + estudioworkingmemory('ERP_BinArray',BinArray); + end + ChanArray=estudioworkingmemory('ERP_ChanArray'); + if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>observe_ERPDAT.ERP.nchan) + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + estudioworkingmemory('ERP_ChanArray',ChanArray); + end + if ERPTab_plotset.gridlayoutdef.Value==1 + ChanArray = sort(ChanArray); + end + ERP1 = observe_ERPDAT.ERP; + ERP1.bindata = ERP1.bindata(ChanArray,:,:); + [def, minydef, maxydef] = default_amp_ticks(ERP1, BinArray); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; + end + if ERPTab_plotset.yscale_auto.Value ==1 + ERPTab_plotset.yscale_low.Enable = 'off'; + ERPTab_plotset.yscale_high.Enable = 'off'; + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); + end + Yscales_low = str2num(ERPTab_plotset.yscale_low.String); + Yscales_high = str2num(ERPTab_plotset.yscale_high.String); + if isempty(Yscales_low) || numel(Yscales_low)~=1 + ERPTab_plotset.yscale_low.String = num2str(minydef); + Yscales_low= minydef; + end + if isempty(Yscales_high) || numel(Yscales_high)~=1 + ERPTab_plotset.yscale_high.String = num2str(maxydef); + Yscales_high= maxydef; + end + + if any(Yscales_high<=Yscales_low) + ERPTab_plotset.yscale_low.String = num2str(minydef); + Yscales_low= minydef; + ERPTab_plotset.yscale_high.String = num2str(maxydef); + Yscales_high= maxydef; + end + ERPTab_plotset_pars{3} = [Yscales_low,Yscales_high]; + + if ERPTab_plotset.ytick_auto.Value==1 + defyticks = default_amp_ticks_viewer([Yscales_low,Yscales_high]); + defyticks = str2num(defyticks); + if ~isempty(defyticks) && numel(defyticks)>=2 + ERPTab_plotset.yscale_step.String = num2str(min(diff(defyticks))); + else + ERPTab_plotset.yscale_step.String = num2str(floor((Yscales_high-Yscales_low)/2)); + end + ERPTab_plotset.yscale_step.Enable = 'off'; + end + + ERPTab_plotset_pars{4} = str2num(ERPTab_plotset.yscale_step.String); + + if ERPTab_plotset.pagesel.Value==1 + nplot = numel(ChanArray); + plotarray = ChanArray; + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); + else + nplot = numel(BinArray); + plotarray = BinArray; + labelsdef =observe_ERPDAT.ERP.bindescr; + end + if ERPTab_plotset.gridlayoutdef.Value ==1 || ERPTab_plotset.chanorder_front.Value==1 + EnableFlag = 'off'; + rowNum = ceil(sqrt(nplot)); + ERPTab_plotset.rowNum_set.Value=rowNum; + ERPTab_plotset.columns.Value =ceil(nplot/rowNum); + else + EnableFlag = 'on'; + end + rowNum = ERPTab_plotset.rowNum_set.Value; + gridlayputarraydef = cell(ERPTab_plotset.rowNum_set.Value,ERPTab_plotset.columns.Value); + count = 0; + for ii = 1:ERPTab_plotset.rowNum_set.Value + for jj = 1:ERPTab_plotset.columns.Value + count = count+1; + if count>nplot + break; + end + gridlayputarraydef{ii,jj} = labelsdef{plotarray(count)}; + end + end + ERPTab_plotset.gridlayout_export.Enable =EnableFlag; + ERPTab_plotset.gridlayout_import.Enable =EnableFlag; + ERPTab_plotset.rowNum_set.Enable =EnableFlag; + ERPTab_plotset.columns.Enable =EnableFlag; + + %%Number of columns + columNum = round(ERPTab_plotset.columns.Value); + if isempty(columNum) || numel(columNum)~=1 || any(columNum<=0) + columNum =1; + ERPTab_plotset.columns.Value = 1; + end + ERPTab_plotset_pars{5} =columNum; + %%polarity (positive up?) + ERPTab_plotset_pars{6} =ERPTab_plotset.positive_up.Value; + + %%overlay? + if ERPTab_plotset.pagesel.Value==1 + ERPTab_plotset_pars{7} =0; + else + ERPTab_plotset_pars{7} = 1; + end + ERPTab_plotset_pars{8} = ERPTab_plotset.rowNum_set.Value;%%number of rows + if ERPTab_plotset.gridlayoutdef.Value==1 + gridlayoutdef=1; + elseif ERPTab_plotset.chanorder_front.Value==1 + gridlayoutdef=2; + else + gridlayoutdef=3; + end + + ERPTab_plotset_pars{9} = gridlayoutdef;%%default grid layout? + if ERPTab_plotset.chanorder_front.Value==1 + try + [eloc, labels, theta, radius, indices] = readlocs(observe_ERPDAT.ERP.chanlocs); + ERPTab_plotset.chanorderIndex = 2; + chanindexnew = f_estudio_chan_frontback_left_right(observe_ERPDAT.ERP.chanlocs(sort(ChanArray))); + if ~isempty(chanindexnew) + ChanArray = sort(ChanArray); + chanindexnew = ChanArray(chanindexnew); + else + chanindexnew = ChanArray; end - if ismember_bc2({moption}, {'instabl', 'areazt','areazp','areazn', 'nintegz'}) - if length(latency)~=1 - msgboxText = ['ERPLAB says: ' moption ' only needs 1 latency value.']; - title = 'EStudio: ERP measurement tool- "Measurement type".'; - errorfound(msgboxText, title); - return; + catch + chanindexnew = ChanArray; + end + else + chanindexnew = ChanArray; + end + if ERPTab_plotset.chanorder_front.Value==1 + gridlayputarraydef = cell(rowNum,columNum); + count = 0; + for ii = 1:rowNum + for jj = 1:columNum + count = count+1; + if count<= length(plotarray) + if ERPTab_plotset.pagesel.Value==1 + try + gridlayputarraydef{ii,jj} = observe_ERPDAT.ERP.chanlocs(chanindexnew(count)).labels; + catch + gridlayputarraydef{ii,jj} = ['Chan',32,num2str(chanindexnew(count))]; + end + else + gridlayputarraydef{ii,jj} = observe_ERPDAT.ERP.bindescr{BinArray(count)}; + end end + end + + end + estudioworkingmemory('ERP_ChanArray',chanindexnew); + ERPTab_plotset.gridlayputarray=gridlayputarraydef; + elseif ERPTab_plotset.gridlayoutdef.Value ==1 + ERPTab_plotset.gridlayputarray= gridlayputarraydef; + end + + ERPTab_plotset_pars{10} = ERPTab_plotset.gridlayputarray; + if isempty(observe_ERPDAT.ERP.binerror) + ERPTab_plotset.show_SEM.Value=0; + ERPTab_plotset.show_SEM.Enable = 'off'; + else + ERPTab_plotset.show_SEM.Enable = 'on'; + end + %%standard error + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + if ERPTab_plotset.show_SEM.Value == 1 + ERPTab_plotset.SEM_custom.Enable = 'on'; + ERPTab_plotset.SEMtrans_custom.Enable = 'on'; + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + ERPTab_plotset_pars{11} = [1,SEM_custom,SEMtrans_custom]; + else + ERPTab_plotset_pars{11} = [0,SEM_custom,SEMtrans_custom]; + ERPTab_plotset.SEM_custom.Enable = 'off'; + ERPTab_plotset.SEMtrans_custom.Enable = 'off'; + end + estudioworkingmemory('ERPTab_plotset_pars',ERPTab_plotset_pars); + ERPTab_plotset.paras{1} = ERPTab_plotset.timet_auto.Value; + ERPTab_plotset.paras{2} = ERPTab_plotset.timetick_auto.Value; + ERPTab_plotset.paras{3} = ERPTab_plotset.yscale_auto.Value; + ERPTab_plotset.paras{4} = ERPTab_plotset.ytick_auto.Value; + observe_ERPDAT.Count_currentERP=4; + end + + + function erp_between_panels_change(~,~) + if isempty(observe_ERPDAT.ALLERP)|| isempty(observe_ERPDAT.ERP) + return; + end + ChangeFlag = estudioworkingmemory('ERPTab_plotset'); + if ChangeFlag~=1 + return; + end + plot_setting_apply(); + estudioworkingmemory('ERPTab_plotset',0); + ERPTab_plotset.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_plotset.plot_apply.ForegroundColor = [0 0 0]; + ERP_plotset_box.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_plotset.plot_reset.ForegroundColor = [0 0 0]; + end + + +%%--------------press return to execute "Apply"---------------------------- + function erp_plotsetting_presskey(hObject, eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_plotset'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + plot_setting_apply(); + estudioworkingmemory('ERPTab_plotset',0); + ERPTab_plotset.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_plotset.plot_apply.ForegroundColor = [0 0 0]; + ERP_plotset_box.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_plotset.plot_reset.ForegroundColor = [0 0 0]; + else + return; + end + end + + +%%-----------------------check out the imported lay out-------------------- + function [Griddata, checkflag,labelsIndex]= f_tranf_check_import_grid(DataInput,overlapindex) + checkflag = 0; + Griddata = cell(size(DataInput)); + if overlapindex==1 + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); + else + labelsdef =observe_ERPDAT.ERP.bindescr; + end + count = 0; + labelsIndex = []; + for ii = 1:size(DataInput,1) + for jj = 1:size(DataInput,2) + if ~ischar(DataInput{ii,jj}) || strcmpi(DataInput{ii,jj},'none') || isempty(DataInput{ii,jj}) else - if length(latency)~=2 - msgboxText = ['EStudio says: ' moption ' needs 2 latency values.']; - title = 'EStudio: ERP measurement tool- "Measurement type".'; - errorfound(msgboxText, title); - return; + [C,IA] = ismember_bc2(DataInput{ii,jj},labelsdef); + if IA~=0 + Griddata{ii,jj} = labelsdef{IA}; + checkflag =1; + count = count+1; + labelsIndex(count) = IA; else - if latency(1)>=latency(2) - msgboxText = ['For latency range, lower time limit must be on the left.\n'... - 'Additionally, lower time limit must be at least 1/samplerate seconds lesser than the higher one.']; - title = 'EStudio: ERP measurement tool-Measurement window'; - errorfound(sprintf(msgboxText), title); - return + if overlapindex==1 + disp([DataInput{ii,jj},32,'didnot match with any channel labels']); + else + disp([DataInput{ii,jj},32,'didnot match with any bin labels']); end end end - f_redrawERP_mt_viewer(); + end + end + end + + +%%---------------reset the parameters for all panels----------------------- + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=3 + return; + end + estudioworkingmemory('ERPTab_plotset',0); + ERPTab_plotset.plot_apply.BackgroundColor = [ 1 1 1]; + ERPTab_plotset.plot_apply.ForegroundColor = [0 0 0]; + ERP_plotset_box.TitleColor= [0.0500 0.2500 0.5000];%% the default is [0.0500 0.2500 0.5000] + ERPTab_plotset.plot_reset.BackgroundColor = [1 1 1]; + ERPTab_plotset.plot_reset.ForegroundColor = [0 0 0]; + ERPTab_plotset.timet_auto.Value=1; + ERPTab_plotset.timet_low.Enable = 'off'; + ERPTab_plotset.timet_high.Enable = 'off'; + try + ERPTab_plotset.timet_low.String = num2str(observe_ERPDAT.ERP.times(1)); + ERPTab_plotset.timet_high.String = num2str(observe_ERPDAT.ERP.times(end)); + catch + ERPTab_plotset.timet_low.String = ''; + ERPTab_plotset.timet_high.String = ''; + end + ERPTab_plotset.timetick_auto.Value=1; + ERPTab_plotset.ytick_auto.Value=1; + ERPTab_plotset.yscale_auto.Value=1; + if ~isempty(observe_ERPDAT.ERP) + [def xstep]= default_time_ticks_studio(observe_ERPDAT.ERP, [observe_ERPDAT.ERP.times(1),observe_ERPDAT.ERP.times(end)]); + ERPTab_plotset.timet_step.String = num2str(xstep); + [def, minydef, maxydef] = default_amp_ticks(observe_ERPDAT.ERP, [1:observe_ERPDAT.ERP.nbin]); + minydef = floor(minydef); + maxydef = ceil(maxydef); + if ~isempty(minydef) && ~isempty(maxydef) + if minydef==maxydef + minydef=-1; + maxydef=1; + end + elseif isempty(minydef) || isempty(maxydef) + minydef=-1; + maxydef=1; + end + ERPTab_plotset.yscale_low.String = num2str(minydef); + ERPTab_plotset.yscale_high.String = num2str(maxydef); + defyticks = default_amp_ticks_viewer([minydef,maxydef]); + defyticks = str2num(defyticks); + if ~isempty(defyticks) && numel(defyticks)>=2 + ERPTab_plotset.yscale_step.String = num2str(min(diff(defyticks))); else - f_redrawERP(); + ERPTab_plotset.yscale_step.String = num2str(floor((Yscales_high-Yscales_low)/2)); end + else + xstep = []; + ERPTab_plotset.timet_step.String = ''; + ERPTab_plotset.yscale_low.String = ''; + ERPTab_plotset.yscale_high.String = ''; + ERPTab_plotset.yscale_step.String = ''; + minydef = []; + maxydef = []; + end + ERPTab_plotset.yscale_low.Enable = 'off'; + ERPTab_plotset.yscale_high.Enable = 'off'; + ERPTab_plotset.yscale_step.Enable = 'off'; + ERPTab_plotset.positive_up.Value =1; + ERPTab_plotset.negative_up.Value = 0; + ERPTab_plotset.pagesel.Value = 1; + + + ERPTab_plotset.gridlayoutdef.Value = 1; + ERPTab_plotset.chanorder_front.Value=0; + ERPTab_plotset.gridlayout_custom.Value = 0; + ERPTab_plotset.gridlayout_export.Enable ='off'; + ERPTab_plotset.gridlayout_import.Enable ='off'; + ERPTab_plotset.rowNum_set.Enable ='off'; + ERPTab_plotset.columns.Enable ='off'; + try + ERPTab_plotset_pars{1} = [observe_ERPDAT.ERP.times(1),observe_ERPDAT.ERP.times(end)]; catch - f_redrawERP(); + ERPTab_plotset_pars{1} = []; + end + ERPTab_plotset_pars{2} = xstep; + ERPTab_plotset_pars{3} = [minydef,maxydef]; + ERPTab_plotset_pars{4} = str2num(ERPTab_plotset.yscale_step.String); + ERPTab_plotset_pars{6} =ERPTab_plotset.positive_up.Value; + ERPTab_plotset_pars{7} =0; + try + ChanArray = [1:observe_ERPDAT.ERP.nchan]; + catch + ChanArray = 1; + end + rowNum = ceil(sqrt(numel(ChanArray))); + ERPTab_plotset.rowNum_set.Value=rowNum; + ERPTab_plotset.columns.Value =ceil(numel(ChanArray)/rowNum); + gridlayputarraydef = cell(ERPTab_plotset.rowNum_set.Value,ERPTab_plotset.columns.Value); + if ~isempty(observe_ERPDAT.ERP) + [~, labelsdef, ~, ~, ~] = readlocs(observe_ERPDAT.ERP.chanlocs); + count = 0; + for ii = 1:ERPTab_plotset.rowNum_set.Value + for jj = 1:ERPTab_plotset.columns.Value + count = count+1; + if count>numel(ChanArray) + break; + end + gridlayputarraydef{ii,jj} = labelsdef{count}; + end + end + else + gridlayputarraydef = []; + labelsdef = []; + end + ERPTab_plotset.gridlayputarray = gridlayputarraydef; + ERPTab_plotset_pars{5} =ERPTab_plotset.columns.Value; + ERPTab_plotset_pars{8} = ERPTab_plotset.rowNum_set.Value;%%number of rows + ERPTab_plotset_pars{9} = ERPTab_plotset.gridlayoutdef.Value ;%%default grid layout? + ERPTab_plotset_pars{10} = gridlayputarraydef; + try show_SEM = ERPTab_plotset_pars{11};catch show_SEM=[0,1,0.2];end; + try ERPTab_plotset.show_SEM.Value =show_SEM(1); catch ERPTab_plotset.show_SEM.Value=0; end; + + try SEM_custom = show_SEM(2); catch SEM_custom=1; end + if isempty(SEM_custom) || numel(SEM_custom)~=1 || any(SEM_custom<0) || any(SEM_custom>10) + SEM_custom=1; + end + ERPTab_plotset.SEM_custom.Value = SEM_custom+1; + + try SEMtrans_custom = show_SEM(3); catch SEMtrans_custom = 0.2; end + if isempty(SEMtrans_custom) || numel(SEMtrans_custom)~=1 || any(SEMtrans_custom<0) || any(SEMtrans_custom>1) + SEMtrans_custom=0.2; + end + ERPTab_plotset.SEMtrans_custom.Value = SEMtrans_custom*10+1; + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + if ERPTab_plotset.show_SEM.Value == 1 + SEM_custom = ERPTab_plotset.SEM_custom.Value-1; + SEMtrans_custom = (ERPTab_plotset.SEMtrans_custom.Value-1)/10; + ERPTab_plotset_pars{11} = [1,SEM_custom,SEMtrans_custom]; + ERPTab_plotset.SEM_custom.Enable = 'on'; + ERPTab_plotset.SEMtrans_custom.Enable = 'on'; + else + ERPTab_plotset_pars{11} = [0,SEM_custom,SEMtrans_custom]; + ERPTab_plotset.SEM_custom.Enable = 'off'; + ERPTab_plotset.SEMtrans_custom.Enable = 'off'; + end + + ERPTab_plotset.paras{1} = ERPTab_plotset.timet_auto.Value; + ERPTab_plotset.paras{2} = ERPTab_plotset.timetick_auto.Value; + ERPTab_plotset.paras{3} = ERPTab_plotset.yscale_auto.Value; + ERPTab_plotset.paras{4} = ERPTab_plotset.ytick_auto.Value; + estudioworkingmemory('ERPTab_plotset_pars',ERPTab_plotset_pars); + observe_ERPDAT.Reset_erp_paras_panel=4; + end +end + + + +function IA = f_chanlabel_check(Checklabel,allabels) +IA = 0; +for ii = 1:length(allabels) + if strcmpi(strtrim(Checklabel),strtrim(allabels{ii})) + IA = ii; + break; + end +end +end + + +%%--------------------------check the labels------------------------------- +function [Simplabels,simplabelIndex,SamAll] = Simplelabels(labels) +labelsrm = ['[']; +for ii=1:1000 + labelsrm = char([labelsrm,',',num2str(ii)]); +end +labelsrm = char([labelsrm,',z,Z]']); + +SamAll = 0; +for ii = 1:length(labels) + labelcell = labels{ii}; + labelcell(regexp(labelcell,labelsrm))=[]; + labelsNew{ii} = labelcell; +end + +%%get the simple +[~,X,Z] = unique(labelsNew,'stable'); +Simplabels = labelsNew(X); +if length(Simplabels)==1 + SamAll = 1; +end + +simplabelIndex = zeros(1,length(labels)); +count = 0; +for jj = 1:length(Simplabels) + for kk = 1:length(labelsNew) + if strcmp(Simplabels{jj},labelsNew{kk}) + count = count+1; + simplabelIndex(kk) = jj; end end +end +end -end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_rename_gui.fig b/studio_functions/GUIs/ERP Tab/f_ERP_rename_gui.fig deleted file mode 100755 index 5dc9e8af..00000000 Binary files a/studio_functions/GUIs/ERP Tab/f_ERP_rename_gui.fig and /dev/null differ diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_resample_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_resample_GUI.m new file mode 100644 index 00000000..9c128175 --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_ERP_resample_GUI.m @@ -0,0 +1,677 @@ +%Author: Guanghui ZHANG +%Center for Mind and Brain +%University of California, Davis +%Davis, CA, USA +% Dec. 2023 + +% ERPLAB Studio + +function varargout = f_ERP_resample_GUI(varargin) +global observe_ERPDAT; +addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); + +gui_erp_resample = struct(); + +%-----------------------------Name the title---------------------------------------------- +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; +catch + ColorB_def = [0.95 0.95 0.95]; +end + +if nargin == 0 + fig = figure(); % Parent figure + box_erp_resample = uiextras.BoxPanel('Parent', fig, 'Title', 'Sampling Rate & Epoch', 'Padding', 5,... + 'BackgroundColor',ColorB_def); % Create boxpanel +elseif nargin == 1 + box_erp_resample = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Sampling Rate & Epoch', 'Padding', 5,... + 'BackgroundColor',ColorB_def); +else + box_erp_resample = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Sampling Rate & Epoch', 'Padding', 5,... + 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @resample_help +end + +%-----------------------------Draw the panel------------------------------------- +try + FonsizeDefault = varargin{2}; +catch + FonsizeDefault = []; +end +if isempty(FonsizeDefault) + FonsizeDefault = f_get_default_fontsize(); +end +drawui_erp_resample(FonsizeDefault); +varargout{1} = box_erp_resample; + + function drawui_erp_resample(FonsizeDefault) + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.702,0.77,0.85]; + end + + gui_erp_resample.DataSelBox = uiextras.VBox('Parent', box_erp_resample,'BackgroundColor',ColorB_def); + + %%------------------current sampling rate-------------------------- + gui_erp_resample.csrate_title = uiextras.HBox('Parent', gui_erp_resample.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', gui_erp_resample.csrate_title,'String','Current sampling rate:',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_resample.csrate_edit = uicontrol('Style','edit','Parent', gui_erp_resample.csrate_title,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + uicontrol('Style','text','Parent', gui_erp_resample.csrate_title,'String','Hz',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_erp_resample.csrate_title,'Sizes',[130 110 30]); + + %%---------------------new sampling rate--------------------------- + gui_erp_resample.nwsrate_title = uiextras.HBox('Parent', gui_erp_resample.DataSelBox,'BackgroundColor',ColorB_def); + gui_erp_resample.nwsrate_checkbox = uicontrol('Style','checkbox','Parent', gui_erp_resample.nwsrate_title,'String','New sampling rate:',... + 'callback',@nwsrate_checkbox,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); + gui_erp_resample.nwsrate_checkbox.KeyPressFcn = @erp_resample_presskey; + gui_erp_resample.Paras{1} = gui_erp_resample.nwsrate_checkbox.Value; + gui_erp_resample.nwsrate_edit = uicontrol('Style','edit','Parent', gui_erp_resample.nwsrate_title,'String','',... + 'callback',@nwsrate_edit,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_erp_resample.Paras{2} = str2num(gui_erp_resample.nwsrate_edit.String); + gui_erp_resample.nwsrate_edit.KeyPressFcn = @erp_resample_presskey; + uicontrol('Style','text','Parent', gui_erp_resample.nwsrate_title,'String','Hz',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_erp_resample.nwsrate_title,'Sizes',[130 110 30]); + + %%----------------current time-window------------------------------ + gui_erp_resample.ctimewindow_title = uiextras.HBox('Parent', gui_erp_resample.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent',gui_erp_resample.ctimewindow_title,... + 'String','Current epoch','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_resample.ctimewindow_editleft = uicontrol('Style','edit','Parent', gui_erp_resample.ctimewindow_title,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + uicontrol('Style', 'text','Parent',gui_erp_resample.ctimewindow_title,... + 'String','ms, to','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_resample.ctimewindow_editright = uicontrol('Style','edit','Parent', gui_erp_resample.ctimewindow_title,'String','',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + uicontrol('Style', 'text','Parent',gui_erp_resample.ctimewindow_title,... + 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_erp_resample.ctimewindow_title,'Sizes',[90 55 40 55 25]); + + %%--------------------new time window-------------------------------- + gui_erp_resample.nwtimewindow_title = uiextras.HBox('Parent', gui_erp_resample.DataSelBox,'BackgroundColor',ColorB_def); + gui_erp_resample.nwtimewindow_checkbox= uicontrol('Style', 'checkbox','Parent',gui_erp_resample.nwtimewindow_title,... + 'callback',@nwtimewindow_checkbox,'String','New epoch','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Value',0,'Enable','off'); + gui_erp_resample.Paras{3} = gui_erp_resample.nwtimewindow_checkbox.Value; + gui_erp_resample.nwtimewindow_checkbox.KeyPressFcn = @erp_resample_presskey; + gui_erp_resample.nwtimewindow_editleft = uicontrol('Style','edit','Parent', gui_erp_resample.nwtimewindow_title,'String','',... + 'callback',@nwtimewindow_editleft,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_erp_resample.Paras{4} = str2num(gui_erp_resample.nwtimewindow_editleft.String); + gui_erp_resample.nwtimewindow_editleft.KeyPressFcn = @erp_resample_presskey; + uicontrol('Style', 'text','Parent',gui_erp_resample.nwtimewindow_title,... + 'String','ms, to','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_resample.nwtimewindow_editright = uicontrol('Style','edit','Parent', gui_erp_resample.nwtimewindow_title,'String','',... + 'callback',@nwtimewindow_editright,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','off'); % 2F + gui_erp_resample.Paras{5} = str2num(gui_erp_resample.nwtimewindow_editright.String); + gui_erp_resample.nwtimewindow_editright.KeyPressFcn = @erp_resample_presskey; + uicontrol('Style', 'text','Parent',gui_erp_resample.nwtimewindow_title,... + 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + set(gui_erp_resample.nwtimewindow_title,'Sizes',[90 55 40 55 25]); + + %%------------------------cancel & apply----------------------------- + gui_erp_resample.advance_help_title = uiextras.HBox('Parent',gui_erp_resample.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', gui_erp_resample.advance_help_title); + gui_erp_resample.resample_cancel= uicontrol('Style', 'pushbutton','Parent',gui_erp_resample.advance_help_title,... + 'String','Cancel','callback',@resample_cancel,'Enable','off','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_erp_resample.advance_help_title); + + gui_erp_resample.resample_run = uicontrol('Style', 'pushbutton','Parent',gui_erp_resample.advance_help_title,'String','Apply',... + 'callback',@resample_run,'FontSize',FonsizeDefault,'Enable','off','BackgroundColor',[1 1 1]); + uiextras.Empty('Parent', gui_erp_resample.advance_help_title); + set(gui_erp_resample.advance_help_title,'Sizes',[15 105 30 105 15]); + set(gui_erp_resample.DataSelBox,'Sizes',[30 30 30 30 30]); + estudioworkingmemory('ERPTab_resample',0); + end + +%%**************************************************************************%% +%%--------------------------Sub function------------------------------------%% +%%**************************************************************************%% + +%%-------------------checkbox for new sampling rate------------------------ + function nwsrate_checkbox(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + gui_erp_resample.nwsrate_edit.BackgroundColor = [1 1 1]; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_resample',1); + gui_erp_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_run.ForegroundColor = [1 1 1]; + box_erp_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_cancel.ForegroundColor = [1 1 1]; + + if Source.Value==1 + gui_erp_resample.nwsrate_edit.Enable = 'on'; + Newsrate = str2num(gui_erp_resample.nwsrate_edit.String); + if isempty(Newsrate) || numel(Newsrate)~=1 || any(Newsrate<=0) + try gui_erp_resample.nwsrate_edit.String = str2num(observe_ERPDAT.ERP.srate); catch end + end + else + gui_erp_resample.nwsrate_edit.Enable = 'off'; + end + end + + +%%-------------------------edit new sampling rate-------------------------- + function nwsrate_edit(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_resample',1); + gui_erp_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_run.ForegroundColor = [1 1 1]; + box_erp_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_cancel.ForegroundColor = [1 1 1]; + Newsrate = str2num(gui_erp_resample.nwsrate_edit.String); + if isempty(Newsrate) || numel(Newsrate)~=1 ||any(Newsrate<=0) + msgboxText='Sampling Rate & Epoch: New sampling rate must be a positive value'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + end + end + +%%-------------------checkbox for new time window-------------------------- + function nwtimewindow_checkbox(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + gui_erp_resample.nwtimewindow_editleft.BackgroundColor = [1 1 1]; + gui_erp_resample.nwtimewindow_editright.BackgroundColor = [1 1 1]; + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_resample',1); + gui_erp_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_run.ForegroundColor = [1 1 1]; + box_erp_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_cancel.ForegroundColor = [1 1 1]; + if Source.Value==1 + gui_erp_resample.nwtimewindow_editleft.Enable ='on'; + gui_erp_resample.nwtimewindow_editright.Enable = 'on'; + NewStart = str2num(gui_erp_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 || any(NewStart>=observe_ERPDAT.ERP.times(end)) + gui_erp_resample.nwtimewindow_editleft.String = num2str(observe_ERPDAT.ERP.times(1)); + end + Newend = str2num(gui_erp_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 || any(Newend<=observe_ERPDAT.ERP.times(1)) + gui_erp_resample.nwtimewindow_editright.String = num2str(observe_ERPDAT.ERP.times(end)); + end + else + gui_erp_resample.nwtimewindow_editleft.Enable ='off'; + gui_erp_resample.nwtimewindow_editright.Enable = 'off'; + end + end + +%%--------------------------new epoch start-------------------------------- + function nwtimewindow_editleft(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_resample',1); + gui_erp_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_run.ForegroundColor = [1 1 1]; + box_erp_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_cancel.ForegroundColor = [1 1 1]; + NewStart = str2num(gui_erp_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 + msgboxText='Sampling Rate & Epoch: the left edge for the new time window must be a single value'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if NewStart>= observe_ERPDAT.ERP.times(end) + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than',32,num2str(observe_ERPDAT.ERP.times(end)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if NewStart< observe_ERPDAT.ERP.times(1) + msgboxText=['Sampling Rate & Epoch: we will set 0 for the additional time range because the left edge for the new time window is smaller than',32,num2str(observe_ERPDAT.ERP.times(1)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + end + if NewStart>= 0 + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than 0 ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + + end + + +%%---------------------------new epoch stop-------------------------------- + function nwtimewindow_editright(Source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_resample',1); + gui_erp_resample.resample_run.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_run.ForegroundColor = [1 1 1]; + box_erp_resample.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_resample.resample_cancel.ForegroundColor = [1 1 1]; + Newend = str2num(gui_erp_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 + msgboxText='Sampling Rate & Epoch: the right edge for the new time window must be a single value'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if Newend<= observe_ERPDAT.ERP.times(1) + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than',32,num2str(observe_ERPDAT.ERP.times(1)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + if Newend> observe_ERPDAT.ERP.times(end) + msgboxText=['Sampling Rate & Epoch: we will set 0 for the additional time range because the right edge for the new time window is larger than',32,num2str(observe_ERPDAT.ERP.times(end)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + end + + if Newend<=0 + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than 0 ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + Source.String = ''; + return; + end + + + end + +%%--------------------------cancel----------------------------------------- + function resample_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + estudioworkingmemory('ERPTab_resample',0); + gui_erp_resample.resample_run.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_run.ForegroundColor = [0 0 0]; + box_erp_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_cancel.ForegroundColor = [0 0 0]; + + gui_erp_resample.csrate_edit.String = num2str(observe_ERPDAT.ERP.srate); + gui_erp_resample.ctimewindow_editleft.String = num2str(observe_ERPDAT.ERP.times(1)); + gui_erp_resample.ctimewindow_editright.String = num2str(observe_ERPDAT.ERP.times(end)); + %%------------------new sampling rate-------------------------- + nwsrate_checkboxValue = gui_erp_resample.Paras{1}; + if isempty(nwsrate_checkboxValue) || numel(nwsrate_checkboxValue)~=1 || (nwsrate_checkboxValue~=0 && nwsrate_checkboxValue~=1) + gui_erp_resample.Paras{1}=0; + nwsrate_checkboxValue=0; + end + gui_erp_resample.nwsrate_checkbox.Value=nwsrate_checkboxValue; + if nwsrate_checkboxValue==1 + gui_erp_resample.nwsrate_edit.Enable = 'on'; + else + gui_erp_resample.nwsrate_edit.Enable = 'off'; + end + gui_erp_resample.nwsrate_edit.String = num2str(gui_erp_resample.Paras{2}); + %%------------------------new-time window------------------------- + newtwcheckboxValue = gui_erp_resample.Paras{3}; + if isempty(newtwcheckboxValue) || numel(newtwcheckboxValue)~=1 || (newtwcheckboxValue~=0 && newtwcheckboxValue~=1) + gui_erp_resample.Paras{3}=0; + newtwcheckboxValue=0; + end + gui_erp_resample.nwtimewindow_checkbox.Value=newtwcheckboxValue; + if newtwcheckboxValue==1 + gui_erp_resample.nwtimewindow_editleft.Enable ='on'; + gui_erp_resample.nwtimewindow_editright.Enable = 'on'; + else + gui_erp_resample.nwtimewindow_editleft.Enable ='off'; + gui_erp_resample.nwtimewindow_editright.Enable = 'off'; + end + gui_erp_resample.nwtimewindow_editleft.String = num2str(gui_erp_resample.Paras{4}); + gui_erp_resample.nwtimewindow_editright.String = num2str(gui_erp_resample.Paras{5}); + end + +%%--------------------------Run-------------------------------------------- + function resample_run(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=14 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + if gui_erp_resample.nwsrate_checkbox.Value==0 && gui_erp_resample.nwtimewindow_checkbox.Value==0 + msgboxText='Sampling Rate & Epoch: Please select "New sampling rate" or "New epoch"'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + return; + end + %%Send message to Message panel + estudioworkingmemory('f_ERP_proces_messg','Sampling Rate & Epoch'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + + %%--------------------check new sampling rate---------------------- + Freq2resamp = str2num(gui_erp_resample.nwsrate_edit.String); + if gui_erp_resample.nwsrate_checkbox.Value==1 + if isempty(Freq2resamp) || numel(Freq2resamp)~=1 ||any(Freq2resamp<=0) + msgboxText='Sampling Rate & Epoch: New sampling rate must be a positive value'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + else + Freq2resamp = []; + end + + %%----------------------------check new time window---------------- + if gui_erp_resample.nwtimewindow_checkbox.Value==1 + NewStart = str2num(gui_erp_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 + msgboxText='Sampling Rate & Epoch: the left edge for the new time window must be a single value'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + if NewStart>= observe_ERPDAT.ERP.times(end) + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than',32,num2str(observe_ERPDAT.times(end)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + + if NewStart>=0 + msgboxText=['Sampling Rate & Epoch: the left edge for the new time window should be smaller than 0 ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + Newend = str2num(gui_erp_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 + msgboxText='Sampling Rate & Epoch: the right edge for the new time window must be a single value'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + if Newend<= observe_ERPDAT.ERP.times(1) + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than',32,num2str(observe_ERPDAT.times(1)),'ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + + if Newend<= 0 + msgboxText=['Sampling Rate & Epoch: the right edge for the new time window should be larger than 0 ms']; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + observe_ERPDAT.Process_messg =2; + return; + end + else + NewStart = []; + Newend = []; + end + + estudioworkingmemory('ERPTab_resample',0); + gui_erp_resample.resample_run.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_run.ForegroundColor = [0 0 0]; + box_erp_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_cancel.ForegroundColor = [0 0 0]; + gui_erp_resample.Paras{1} = gui_erp_resample.nwsrate_checkbox.Value; + gui_erp_resample.Paras{2} = str2num(gui_erp_resample.nwsrate_edit.String); + gui_erp_resample.Paras{3} = gui_erp_resample.nwtimewindow_checkbox.Value; + gui_erp_resample.Paras{4} = str2num(gui_erp_resample.nwtimewindow_editleft.String); + gui_erp_resample.Paras{5} = str2num(gui_erp_resample.nwtimewindow_editright.String); + + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; + estudioworkingmemory('selectederpstudio',ERPArray); + end + + estudioworkingmemory('f_ERP_proces_messg','Sampling Rate & Epoch'); + observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + ALLERP = observe_ERPDAT.ALLERP; + ALLERP_out = []; + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + if gui_erp_resample.nwsrate_checkbox.Value==0 + Freq2resamp = ERP.srate; + end + if gui_erp_resample.nwtimewindow_checkbox.Value==0 + TimeRange = [ERP.times(1),ERP.times(end)]; + else + TimeRange = [NewStart,Newend]; + end + [ERP, ERPCOM] = pop_resamplerp(ERP, 'Freq2resamp',Freq2resamp, 'TimeRange',TimeRange,... + 'Saveas', 'off', 'History', 'gui'); + if isempty(ERPCOM) + observe_ERPDAT.Process_messg =2; + return; + end + if Numoferp == numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + if Numoferp==1 + ALLERP_out = ERP; + else + ALLERP_out(length(ALLERP_out)+1) = ERP; + end + end + + Answer = f_ERP_save_multi_file(ALLERP_out,1:numel(ERPArray),'_resampled'); + if isempty(Answer) + observe_ERPDAT.Process_messg =2; + return; + end + if ~isempty(Answer{1}) + ALLERP_out = Answer{1}; + Save_file_label = Answer{2}; + end + for Numoferp = 1:numel(ERPArray) + ERP = ALLERP_out(Numoferp); + if Save_file_label + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + ERPCOM = f_erp_save_history(ERP.erpname,ERP.filename,ERP.filepath); + if Numoferp == numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + else + ERP.filename = ''; + ERP.saved = 'no'; + ERP.filepath = ''; + end + ALLERP(length(ALLERP)+1) = ERP; + end + observe_ERPDAT.ALLERP = ALLERP; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + try + Selected_ERP_afd = [length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1:length(observe_ERPDAT.ALLERP)]; + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP)-numel(ERPArray)+1; + catch + Selected_ERP_afd = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',Selected_ERP_afd); + + observe_ERPDAT.Process_messg =2; + observe_ERPDAT.Count_currentERP = 1; + end + + +%%--------Setting current ERPset/session history based on the current updated ERPset------------ + function Count_currentERPChanged(~,~) + if observe_ERPDAT.Count_currentERP~=8 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 + Enableflag = 'off'; + else + Enableflag = 'on'; + end + if ~isempty(observe_ERPDAT.ERP) + gui_erp_resample.csrate_edit.String = num2str(observe_ERPDAT.ERP.srate); + gui_erp_resample.ctimewindow_editleft.String = num2str(observe_ERPDAT.ERP.times(1)); + gui_erp_resample.ctimewindow_editright.String = num2str(observe_ERPDAT.ERP.times(end)); + else + gui_erp_resample.csrate_edit.String = ''; + gui_erp_resample.ctimewindow_editleft.String = ''; + gui_erp_resample.ctimewindow_editright.String = ''; + end + %%----------------------new sampling rate-------------------------- + gui_erp_resample.nwsrate_checkbox.Enable = Enableflag; + gui_erp_resample.nwsrate_edit.Enable = Enableflag; + if strcmp(Enableflag,'on') && gui_erp_resample.nwsrate_checkbox.Value==1 + gui_erp_resample.nwsrate_edit.Enable = 'on'; + Newsrate = str2num(gui_erp_resample.nwsrate_edit.String); + if isempty(Newsrate) || numel(Newsrate)~=1 || any(Newsrate<=0) + try gui_erp_resample.nwsrate_edit.String = str2num(observe_ERPDAT.ERP.srate); catch end + end + else + gui_erp_resample.nwsrate_edit.Enable = 'off'; + end + + %%--------------------new tiem window------------------------------ + gui_erp_resample.nwtimewindow_checkbox.Enable = Enableflag; + gui_erp_resample.nwtimewindow_editleft.Enable = Enableflag; + gui_erp_resample.nwtimewindow_editright.Enable = Enableflag; + gui_erp_resample.resample_run.Enable = Enableflag; + gui_erp_resample.resample_cancel.Enable = Enableflag; + if strcmp(Enableflag,'on') && gui_erp_resample.nwtimewindow_checkbox.Value==1 + gui_erp_resample.nwtimewindow_editleft.Enable ='on'; + gui_erp_resample.nwtimewindow_editright.Enable = 'on'; + NewStart = str2num(gui_erp_resample.nwtimewindow_editleft.String); + if isempty(NewStart) || numel(NewStart)~=1 || any(NewStart>=observe_ERPDAT.ERP.times(end)) + gui_erp_resample.nwtimewindow_editleft.String = num2str(observe_ERPDAT.ERP.times(1)); + end + Newend = str2num(gui_erp_resample.nwtimewindow_editright.String); + if isempty(Newend) || numel(Newend)~=1 || any(Newend<=observe_ERPDAT.ERP.times(1)) + gui_erp_resample.nwtimewindow_editright.String = num2str(observe_ERPDAT.ERP.times(end)); + end + else + gui_erp_resample.nwtimewindow_editleft.Enable ='off'; + gui_erp_resample.nwtimewindow_editright.Enable = 'off'; + end + gui_erp_resample.Paras{1} = gui_erp_resample.nwsrate_checkbox.Value; + gui_erp_resample.Paras{2} = str2num(gui_erp_resample.nwsrate_edit.String); + gui_erp_resample.Paras{3} = gui_erp_resample.nwtimewindow_checkbox.Value; + gui_erp_resample.Paras{4} = str2num(gui_erp_resample.nwtimewindow_editleft.String); + gui_erp_resample.Paras{5} = str2num(gui_erp_resample.nwtimewindow_editright.String); + observe_ERPDAT.Count_currentERP=9; + end + +%%--------------press return to execute "Apply"---------------------------- + function erp_resample_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_resample'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + resample_run(); + estudioworkingmemory('ERPTab_resample',0); + gui_erp_resample.resample_run.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_run.ForegroundColor = [0 0 0]; + box_erp_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_cancel.ForegroundColor = [0 0 0]; + else + return; + end + end + +%%--------------reset this panel with the default parameters--------------- + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=13 + return; + end + estudioworkingmemory('ERPTab_resample',0); + gui_erp_resample.resample_run.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_run.ForegroundColor = [0 0 0]; + box_erp_resample.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_resample.resample_cancel.BackgroundColor = [1 1 1]; + gui_erp_resample.resample_cancel.ForegroundColor = [0 0 0]; + if ~isempty(observe_ERPDAT.ERP) + gui_erp_resample.csrate_edit.String = num2str(observe_ERPDAT.ERP.srate); + gui_erp_resample.ctimewindow_editleft.String = num2str(observe_ERPDAT.ERP.times(1)); + gui_erp_resample.ctimewindow_editright.String = num2str(observe_ERPDAT.ERP.times(end)); + else + gui_erp_resample.csrate_edit.String = ''; + gui_erp_resample.ctimewindow_editleft.String = ''; + gui_erp_resample.ctimewindow_editright.String = ''; + end + gui_erp_resample.nwsrate_checkbox.Value=0; + gui_erp_resample.nwsrate_edit.Enable = 'off'; + gui_erp_resample.nwsrate_edit.String=''; + gui_erp_resample.nwtimewindow_editleft.Enable ='off'; + gui_erp_resample.nwtimewindow_editright.Enable = 'off'; + gui_erp_resample.nwtimewindow_checkbox.Value=0; + gui_erp_resample.nwtimewindow_editleft.String =''; + gui_erp_resample.nwtimewindow_editright.String = ''; + observe_ERPDAT.Reset_erp_paras_panel=14; + end + +end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_as_GUI.fig b/studio_functions/GUIs/ERP Tab/f_ERP_save_as_GUI.fig new file mode 100644 index 00000000..26720d2f Binary files /dev/null and b/studio_functions/GUIs/ERP Tab/f_ERP_save_as_GUI.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_as_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_save_as_GUI.m new file mode 100644 index 00000000..60e1e9d9 --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_ERP_save_as_GUI.m @@ -0,0 +1,481 @@ +function varargout = f_ERP_save_as_GUI(varargin) +% F_ERP_SAVE_AS_GUI MATLAB code for f_ERP_save_as_GUI.fig +% F_ERP_SAVE_AS_GUI, by itself, creates a new F_ERP_SAVE_AS_GUI or raises the existing +% singleton*. +% +% H = F_ERP_SAVE_AS_GUI returns the handle to a new F_ERP_SAVE_AS_GUI or the handle to +% the existing singleton*. +% +% F_ERP_SAVE_AS_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_ERP_SAVE_AS_GUI.M with the given input arguments. +% +% F_ERP_SAVE_AS_GUI('Property','Value',...) creates a new F_ERP_SAVE_AS_GUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_ERP_save_as_GUI_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_ERP_save_as_GUI_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 f_ERP_save_as_GUI + +% Last Modified by GUIDE v2.5 17-Mar-2024 15:42:33 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_ERP_save_as_GUI_OpeningFcn, ... + 'gui_OutputFcn', @f_ERP_save_as_GUI_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 f_ERP_save_as_GUI is made visible. +function f_ERP_save_as_GUI_OpeningFcn(hObject, eventdata, handles, varargin) +% Choose default command line output for f_ERP_save_as_GUI + +try + ALLERP = varargin{1}; + EEGArray = varargin{2}; + suffix = varargin{3}; + +catch + suffix = ''; + EEGLAB = []; + EEGLAB.erpname = 'No erpset was selected'; + EEGLAB.filename ='No erpset was selected'; + EEGLAB.event = []; + EEGLAB.chanlocs = []; + EEGLAB.nbchan = 0; + ALLERP(1) = EEGLAB; + EEGArray = 1; + +end +try + ERPIndex = varargin{4}; +catch + ERPIndex=1; +end +try + filepath = varargin{5}; +catch + filepath = [cd,filesep]; +end +handles.filepath = filepath; +handles.ERPIndex = ERPIndex; +% handles.erpnameor = erpname; +handles.output = []; +handles.suffix = suffix; + +handles.ALLERP = ALLERP; +handles.EEGArray =EEGArray; + +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save erpsets as GUI']) + + +% set(handles.checkbox1_suffix,'Value',1); +set(handles.edit_suffix_name,'String',suffix); +set(handles.checkbox2_save_label,'Value',1); +set(handles.checkbox2_save_label,'Enable','off'); +ColumnName_table = {'ERP name','File name'}; + +set(handles.uitable1_erpset_table,'ColumnName',cellstr(ColumnName_table)); +set(handles.uitable1_erpset_table,'RowName',cellstr(num2str(EEGArray'))); +handles.uitable1_erpset_table.ColumnEditable(1) = true; +handles.uitable1_erpset_table.ColumnEditable(2) = true; +for Numoferpset = 1:numel(EEGArray) + if ERPIndex==1 + DataString{Numoferpset,1} = strcat(ALLERP(EEGArray(Numoferpset)).erpname,suffix); + else + DataString{Numoferpset,1} = strcat(ALLERP(EEGArray(Numoferpset)).setname,suffix); + end + if ERPIndex==1 + DataString{Numoferpset,2} = [strcat(ALLERP(EEGArray(Numoferpset)).erpname,suffix),'.erp']; + else + DataString{Numoferpset,2} = [strcat(ALLERP(EEGArray(Numoferpset)).setname,suffix),'.set']; + end +end + +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); +set(handles.uitable1_erpset_table,'Enable','on'); +set(handles.checkbox3_filename_erpname,'Enable','on','Value',1); +set(handles.edit_path,'Enable','on','String',filepath); +set(handles.pushbutton_path_browse,'Enable','on'); + + +% handles.uitable1_erpset_table.DisplayDataChangedFcn = {@tableDisplayDataChangedFcn,hObject,handles}; +% +% % Color GUI +% % +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + +% Update handles structure +guidata(hObject, handles); +handles.uitable1_erpset_table.BackgroundColor = [1 1 1]; +handles.checkbox1_suffix.BackgroundColor = [1 1 1]; +% handles.checkbox3_filename_erpname.BackgroundColor = [1 1 1]; +% UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) +uiwait(handles.gui_chassis); + + + + +% --- Outputs from this function are returned to the command line. +function varargout = f_ERP_save_as_GUI_OutputFcn(hObject, eventdata, handles) + +% Get default command line output from handles structure +try + varargout{1} = handles.output; +catch + varargout{1} = []; +end + +delete(handles.gui_chassis); +pause(0.1) + + + +% --- Executes on button press in checkbox1_suffix. +function checkbox1_suffix_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +EEGArray = handles.EEGArray; +suffix_edit = handles.edit_suffix_name.String; + +DataString_before = handles.uitable1_erpset_table.Data; +for Numoferpset = 1:numel(EEGArray) + DataString{Numoferpset,1} = strcat( ALLERP(EEGArray(Numoferpset)).erpname,suffix_edit); + if handles.checkbox3_filename_erpname.Value==1 + DataString{Numoferpset,2} = [DataString{Numoferpset,1},'.erp']; + else + DataString{Numoferpset,2} = DataString_before{Numoferpset,2}; + end +end +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +% set(handles.uitable1_erpset_table,'ColumnWidth',{248 248}); +set(handles.uitable1_erpset_table,'Enable','on'); + + + + +function edit_suffix_name_Callback(hObject, eventdata, handles) + + + + +% --- Executes during object creation, after setting all properties. +function edit_suffix_name_CreateFcn(hObject, eventdata, handles) + +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + + + +% --- Executes on button press in checkbox2_save_label. +function checkbox2_save_label_Callback(hObject, eventdata, handles) + +Values = handles.checkbox2_save_label.Value; + +if Values + set(handles.checkbox3_filename_erpname,'Enable','on'); + ALLERP = handles.ALLERP; + EEGArray = handles.EEGArray; + DataString_before = handles.uitable1_erpset_table.Data; + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = ALLERP(EEGArray(Numoferpset)).filename; + [pathstr, file_name, ext] = fileparts(fileName); + + DataString{Numoferpset,2} = [file_name,'.erp']; + end + set(handles.uitable1_erpset_table,'Data',DataString); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; +else + set(handles.checkbox3_filename_erpname,'Enable','off'); + DataString_before = handles.uitable1_erpset_table.Data; + for Numoferpset = 1:size(DataString_before,1) + DataString_before{Numoferpset,2} = ''; + end + set(handles.uitable1_erpset_table,'Data',DataString_before); + set(handles.uitable1_erpset_table,'Enable','on'); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = false; +end +if handles.checkbox2_save_label.Value + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','on'); + set(handles.pushbutton_path_browse,'Enable','on'); +else + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','off'); + set(handles.pushbutton_path_browse,'Enable','off'); +end + + + +% --- Executes on button press in checkbox3_filename_erpname. +function checkbox3_filename_erpname_Callback(hObject, eventdata, handles) +Value_filename_erpname = handles.checkbox3_filename_erpname.Value; + +% set(handles.uitable1_erpset_table,'Enable','off'); +DataString_before = handles.uitable1_erpset_table.Data; + +for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.erp'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.erp']; + else + file_name = [file_name,'.erp']; + end + DataString{Numoferpset,2} = file_name; +end + +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +% set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); + +handles.uitable1_erpset_table.ColumnEditable(1) = true; +handles.uitable1_erpset_table.ColumnEditable(2) = true; + + + + +% --- Executes when entered data in editable cell(s) in uitable1_erpset_table. +function uitable1_erpset_table_CellEditCallback(hObject, eventdata, handles) + +DataString = handles.uitable1_erpset_table.Data; +EEGArray = handles.EEGArray; +if size(DataString,1) < numel(EEGArray) + msgboxText = 'EEG name and filename for one of erpsets are empty at least! Please give name to eegname and filename'; + title = 'EStudio: f_ERP_save_as_GUI empty erpname'; + errorfound(msgboxText, title); + return +end + +for Numofselected = 1:numel(EEGArray) + if isempty(DataString{Numofselected,1}) + msgboxText = 'Erpname for one of erpsets is empty at least! Please give name to that erpset'; + title = 'EStudio: f_ERP_save_as_GUI empty eegname'; + errorfound(msgboxText, title); + return + end +end + +if handles.checkbox3_filename_erpname.Value==1 + DataString_before = handles.uitable1_erpset_table.Data; + + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.erp'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.erp']; + else + file_name = [file_name,'.erp']; + end + DataString{Numoferpset,2} = file_name; + end + + set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); +end +guidata(hObject, handles); + + + +% --- Executes on button press in pushbutton_Cancel. +function pushbutton_Cancel_Callback(hObject, eventdata, handles) +handles.output = []; +guidata(hObject, handles); +uiresume(handles.gui_chassis); + + + + +% --- Executes on button press in pushbutton4_okay. +function pushbutton4_okay_Callback(hObject, eventdata, handles) + +Data_String =handles.uitable1_erpset_table.Data; +ALLERP = handles.ALLERP; +EEGArray = handles.EEGArray; + +if size(Data_String,1)< numel(EEGArray)% + msgboxText = 'ERP name for one of erpsets is empty at least! Please give a name'; + title = 'EStudio: f_ERP_save_as_GUI empty eegname'; + errorfound(msgboxText, title); + return +end + + +if size(Data_String,1)> numel(EEGArray)% + msgboxText = 'More eegname is given. Please delect it!!!'; + title = 'EStudio: f_ERP_save_as_GUI empty erpname'; + errorfound(msgboxText, title); + return +end + +for Numofselected = 1:numel(EEGArray) + if isempty(Data_String{Numofselected,1}) + msgboxText = 'Erpname for one of erpsets is empty at least! Please give name to that erpset'; + title = 'EStudio: f_ERP_save_as_GUI empty erpname'; + errorfound(msgboxText, title); + return + end + +end + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end + +for Numoferpset = 1:numel(EEGArray) + if handles.ERPIndex==1 + ALLERP(EEGArray(Numoferpset)).erpname = Data_String{Numoferpset,1}; + else + ALLERP(EEGArray(Numoferpset)).setname = Data_String{Numoferpset,1}; + end + fileName = char(Data_String{Numoferpset,2}); + if isempty(fileName) + fileName = Data_String{Numoferpset,1}; + end + + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.erp']; + else + file_name = [file_name,'.erp']; + end + + ALLERP(EEGArray(Numoferpset)).filename = file_name; + if handles.checkbox2_save_label.Value + ALLERP(EEGArray(Numoferpset)).filepath = pathName; + end + + if handles.checkbox2_save_label.Value + ALLERP(EEGArray(Numoferpset)).saved = 'yes'; + else + ALLERP(EEGArray(Numoferpset)).saved = 'no'; + end + +end + +FilePath = handles.checkbox2_save_label.Value; + +handles.output = {ALLERP, FilePath}; +% Update handles structure +guidata(hObject, handles); + +uiresume(handles.gui_chassis); + + + +% ----------------------------------------------------------------------- +function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.gui_chassis, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.gui_chassis); +else + % The GUI is no longer waiting, just close it + delete(handles.gui_chassis); +end + + + +function edit_path_Callback(hObject, eventdata, handles) + + +PathName = handles.edit_path.String; +handles.filepath = PathName; + + + + +% --- Executes during object creation, after setting all properties. +function edit_path_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_path (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 + + +% --- Executes on button press in pushbutton_path_browse. +function pushbutton_path_browse_Callback(hObject, eventdata, handles) + + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end +title = 'Select one forlder for saving files in following procedures'; +select_path = uigetdir(pathName,title); + +if isequal(select_path,0) + select_path = [cd,filesep]; +end +handles.filepath = select_path; +handles.edit_path.String = select_path; + + +% --- Executes on button press in pushbutton_reset. +function pushbutton_reset_Callback(hObject, eventdata, handles) + +suffix = handles.suffix; + +ALLERP = handles.ALLERP; +EEGArray = handles.EEGArray; +ERPIndex = handles.ERPIndex; +set(handles.checkbox3_filename_erpname,'Enable','on','Value',1); +for Numoferpset = 1:numel(EEGArray) + if ERPIndex==1 + DataString{Numoferpset,1} = strcat(ALLERP(EEGArray(Numoferpset)).erpname,suffix); + else + DataString{Numoferpset,1} = strcat(ALLERP(EEGArray(Numoferpset)).setname,suffix); + end + if ERPIndex==1 + DataString{Numoferpset,2} = [strcat(ALLERP(EEGArray(Numoferpset)).erpname,suffix),'.erp']; + else + DataString{Numoferpset,2} = [strcat(ALLERP(EEGArray(Numoferpset)).setname,suffix),'.set']; + end +end +set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.fig b/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.fig old mode 100755 new mode 100644 index e7351ed6..948249d1 Binary files a/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.fig and b/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.m b/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.m old mode 100755 new mode 100644 index 726cf919..7b3bd893 --- a/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_save_multi_file.m @@ -22,7 +22,7 @@ % Edit the above text to modify the response to help f_ERP_save_multi_file -% Last Modified by GUIDE v2.5 13-Jun-2022 18:55:22 +% Last Modified by GUIDE v2.5 16-Jan-2024 19:20:46 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; @@ -50,30 +50,38 @@ function f_ERP_save_multi_file_OpeningFcn(hObject, eventdata, handles, varargin) try ALLERP = varargin{1}; - Selected_ERP_label = varargin{2}; + EEGArray = varargin{2}; suffix = varargin{3}; + catch suffix = ''; - ERPLAB = []; - ERPLAB.erpname = 'No erpset was selected'; - ERPLAB.filename ='No erpset was selected'; - ERPLAB.event = []; - ERPLAB.chanlocs = []; - ERPLAB.nbchan = 0; - ALLERP(1) = ERPLAB; - Selected_ERP_label = 1; + EEGLAB = []; + EEGLAB.erpname = 'No erpset was selected'; + EEGLAB.filename ='No erpset was selected'; + EEGLAB.event = []; + EEGLAB.chanlocs = []; + EEGLAB.nbchan = 0; + ALLERP(1) = EEGLAB; + EEGArray = 1; + end - +try + ERPIndex = varargin{4}; +catch + ERPIndex=1; +end +handles.ERPIndex = ERPIndex; % handles.erpnameor = erpname; handles.output = []; handles.suffix = suffix; handles.ALLERP = ALLERP; -handles.Selected_ERP_label =Selected_ERP_label; +handles.EEGArray =EEGArray; + -erplab_studio_default_values; -version = erplabstudiover; -set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save multiple Erpsets GUI']) +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save multiple erpsets GUI']) % set(handles.checkbox1_suffix,'Value',1); @@ -83,19 +91,27 @@ function f_ERP_save_multi_file_OpeningFcn(hObject, eventdata, handles, varargin) ColumnName_table = {'ERP name','File name'}; set(handles.uitable1_erpset_table,'ColumnName',cellstr(ColumnName_table)); -set(handles.uitable1_erpset_table,'RowName',cellstr(num2str(Selected_ERP_label'))); - - -for Numofselectederp = 1:numel(Selected_ERP_label) - DataString{Numofselectederp,1} = strcat(ALLERP(Selected_ERP_label(Numofselectederp)).erpname,suffix); - DataString{Numofselectederp,2} = ''; +set(handles.uitable1_erpset_table,'RowName',cellstr(num2str(EEGArray'))); +handles.uitable1_erpset_table.ColumnEditable(1) = true; +handles.uitable1_erpset_table.ColumnEditable(2) = false; +for Numoferpset = 1:numel(EEGArray) + if ERPIndex==1 + DataString{Numoferpset,1} = strcat(ALLERP(EEGArray(Numoferpset)).erpname,suffix); + else + DataString{Numoferpset,1} = strcat(ALLERP(EEGArray(Numoferpset)).setname,suffix); + end + DataString{Numoferpset,2} = ''; end set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); -set(handles.uitable1_erpset_table,'ColumnWidth',{248 248}); +set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); set(handles.uitable1_erpset_table,'Enable','on'); set(handles.checkbox3_filename_erpname,'Enable','off'); +set(handles.edit_path,'Enable','off','String',''); +set(handles.pushbutton_path_browse,'Enable','off'); + +% handles.uitable1_erpset_table.DisplayDataChangedFcn = {@tableDisplayDataChangedFcn,hObject,handles}; % % % Color GUI % % @@ -108,8 +124,9 @@ function f_ERP_save_multi_file_OpeningFcn(hObject, eventdata, handles, varargin) % Update handles structure guidata(hObject, handles); - - +handles.uitable1_erpset_table.BackgroundColor = [1 1 1]; +handles.checkbox1_suffix.BackgroundColor = [1 1 1]; +% handles.checkbox3_filename_erpname.BackgroundColor = [1 1 1]; % UIWAIT makes savemyerpGUI wait for user response (see UIRESUME) uiwait(handles.gui_chassis); @@ -134,56 +151,28 @@ function f_ERP_save_multi_file_OpeningFcn(hObject, eventdata, handles, varargin) % --- Executes on button press in checkbox1_suffix. function checkbox1_suffix_Callback(hObject, eventdata, handles) ALLERP = handles.ALLERP; -Selected_ERP_label = handles.Selected_ERP_label; +EEGArray = handles.EEGArray; suffix_edit = handles.edit_suffix_name.String; -if isempty(suffix_edit) - msgboxText = 'You must enter a suffix at least!'; - title = 'EStudio: f_ERP_save_multi_file() error'; - errorfound(msgboxText, title); - return -end - - DataString_before = handles.uitable1_erpset_table.Data; -for Numofselectederp = 1:numel(Selected_ERP_label) - DataString{Numofselectederp,1} = strcat(ALLERP(Selected_ERP_label(Numofselectederp)).erpname,suffix_edit); - DataString{Numofselectederp,2} = DataString_before{Numofselectederp,2}; +for Numoferpset = 1:numel(EEGArray) + DataString{Numoferpset,1} = strcat(DataString_before{Numoferpset,1},suffix_edit); + if handles.checkbox3_filename_erpname.Value==0 + DataString{Numoferpset,2} = DataString_before{Numoferpset,2}; + else + DataString{Numoferpset,2} = [DataString{Numoferpset,1},'.erp']; + end end set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); -set(handles.uitable1_erpset_table,'ColumnWidth',{248 248}); -if handles.checkbox2_save_label.Value - set(handles.uitable1_erpset_table,'Enable','off'); -else - set(handles.uitable1_erpset_table,'Enable','on'); -end +set(handles.uitable1_erpset_table,'Enable','on'); function edit_suffix_name_Callback(hObject, eventdata, handles) -% Suffix_string = handles.edit_suffix_name.String; -% if isempty(Suffix_string) -% msgboxText = 'You must enter a suffix at least!'; -% title = 'EStudio: f_ERP_save_multi_file() error'; -% errorfound(msgboxText, title); -% return -% end -% -% if handles.checkbox1_suffix.Value -% -% DataString_before = handles.uitable1_erpset_table.Data; -% for Numofselectederp = 1:size(DataString_before,1) -% DataString{Numofselectederp,1} = char(strcat(DataString_before{Numofselectederp,1},'-',char(Suffix_string))); -% DataString{Numofselectederp,2} = DataString_before{Numofselectederp,2}; -% end -% -% set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); -% set(handles.uitable1_erpset_table,'ColumnWidth',{248 248}); -% set(handles.uitable1_erpset_table,'Enable','off'); -% handles.suffix=Suffix_string; -% end + + % --- Executes during object creation, after setting all properties. function edit_suffix_name_CreateFcn(hObject, eventdata, handles) @@ -204,26 +193,37 @@ function checkbox2_save_label_Callback(hObject, eventdata, handles) if Values set(handles.checkbox3_filename_erpname,'Enable','on'); ALLERP = handles.ALLERP; - Selected_ERP_label = handles.Selected_ERP_label; + EEGArray = handles.EEGArray; DataString_before = handles.uitable1_erpset_table.Data; - for Numofselectederp = 1:size(DataString_before,1) - DataString{Numofselectederp,1} = DataString_before{Numofselectederp,1}; - DataString{Numofselectederp,2} = char(ALLERP(Selected_ERP_label(Numofselectederp)).filename); + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = ALLERP(EEGArray(Numoferpset)).filename; + [pathstr, file_name, ext] = fileparts(fileName); + + DataString{Numoferpset,2} = [file_name,'.erp']; end set(handles.uitable1_erpset_table,'Data',DataString); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; else set(handles.checkbox3_filename_erpname,'Enable','off'); DataString_before = handles.uitable1_erpset_table.Data; - for Numofselectederp = 1:size(DataString_before,1) - DataString_before{Numofselectederp,2} = ''; + for Numoferpset = 1:size(DataString_before,1) + DataString_before{Numoferpset,2} = ''; end set(handles.uitable1_erpset_table,'Data',DataString_before); set(handles.uitable1_erpset_table,'Enable','on'); + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = false; end if handles.checkbox2_save_label.Value - set(handles.uitable1_erpset_table,'Enable','off'); + set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','on'); + set(handles.pushbutton_path_browse,'Enable','on'); else set(handles.uitable1_erpset_table,'Enable','on'); + set(handles.edit_path,'Enable','off'); + set(handles.pushbutton_path_browse,'Enable','off'); end @@ -232,27 +232,33 @@ function checkbox2_save_label_Callback(hObject, eventdata, handles) function checkbox3_filename_erpname_Callback(hObject, eventdata, handles) Value_filename_erpname = handles.checkbox3_filename_erpname.Value; -set(handles.uitable1_erpset_table,'Enable','off'); +% set(handles.uitable1_erpset_table,'Enable','off'); DataString_before = handles.uitable1_erpset_table.Data; -for Numofselectederp = 1:size(DataString_before,1) - - DataString{Numofselectederp,1} = DataString_before{Numofselectederp,1}; - fileName = char(DataString_before{Numofselectederp,1}); +for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); if isempty(fileName) - fileName = strcat(num2str(Numofselectederp),'erp'); + fileName = strcat(num2str(Numoferpset),'.erp'); end [pathstr, file_name, ext] = fileparts(fileName); if isempty(file_name) - file_name = [num2str(Selected_ERP_label(Numofselectederp)),'_ERP.erp']; + file_name = [num2str(EEGArray(Numoferpset)),'.erp']; else - file_name = [file_name,'.erp']; + file_name = [file_name,'.erp']; end - DataString{Numofselectederp,2} = file_name; + DataString{Numoferpset,2} = file_name; end set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); -set(handles.uitable1_erpset_table,'ColumnWidth',{248 248}); +% set(handles.uitable1_erpset_table,'ColumnWidth',{350 350}); +if handles.checkbox3_filename_erpname.Value==0 + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = false; +else + handles.uitable1_erpset_table.ColumnEditable(1) = true; + handles.uitable1_erpset_table.ColumnEditable(2) = true; +end @@ -262,31 +268,50 @@ function checkbox3_filename_erpname_Callback(hObject, eventdata, handles) function uitable1_erpset_table_CellEditCallback(hObject, eventdata, handles) DataString = handles.uitable1_erpset_table.Data; -Selected_ERP_label = handles.Selected_ERP_label; -if size(DataString,1) < numel(Selected_ERP_label) - msgboxText = 'Erpname and filename for one of erpsets are empty at least! Please give name to erpname and filename'; +EEGArray = handles.EEGArray; +if size(DataString,1) < numel(EEGArray) + msgboxText = 'EEG name and filename for one of erpsets are empty at least! Please give name to eegname and filename'; title = 'EStudio: f_ERP_save_multi_file empty erpname'; errorfound(msgboxText, title); return end -for Numofselected = 1:numel(Selected_ERP_label) +for Numofselected = 1:numel(EEGArray) if isempty(DataString{Numofselected,1}) msgboxText = 'Erpname for one of erpsets is empty at least! Please give name to that erpset'; - title = 'EStudio: f_ERP_save_multi_file empty erpname'; + title = 'EStudio: f_ERP_save_multi_file empty eegname'; errorfound(msgboxText, title); return end +end + +if handles.checkbox3_filename_erpname.Value==1 + DataString_before = handles.uitable1_erpset_table.Data; + + for Numoferpset = 1:size(DataString_before,1) + DataString{Numoferpset,1} = DataString_before{Numoferpset,1}; + fileName = char(DataString_before{Numoferpset,1}); + if isempty(fileName) + fileName = strcat(num2str(Numoferpset),'.erp'); + end + [pathstr, file_name, ext] = fileparts(fileName); + if isempty(file_name) + file_name = [num2str(EEGArray(Numoferpset)),'.erp']; + else + file_name = [file_name,'.erp']; + end + DataString{Numoferpset,2} = file_name; + end + set(handles.uitable1_erpset_table,'Data',cellstr(DataString)); end +guidata(hObject, handles); % --- Executes on button press in pushbutton_Cancel. function pushbutton_Cancel_Callback(hObject, eventdata, handles) handles.output = []; -% beep; -disp('User selected Cancel.'); % Update handles structure guidata(hObject, handles); uiresume(handles.gui_chassis); @@ -296,38 +321,27 @@ function pushbutton_Cancel_Callback(hObject, eventdata, handles) % --- Executes on button press in pushbutton4_okay. function pushbutton4_okay_Callback(hObject, eventdata, handles) -% suffix = strtrim(get(handles.edit_suffix_name, 'String')); -% if handles.checkbox1_suffix.Value -% if isempty(suffix) -% msgboxText = 'You must enter suffix at least!'; -% title = 'EStudio: f_ERP_save_multi_file empty erpname'; -% errorfound(msgboxText, title); -% return -% end -% end Data_String =handles.uitable1_erpset_table.Data; ALLERP = handles.ALLERP; -Selected_ERP_label = handles.Selected_ERP_label; +EEGArray = handles.EEGArray; -if size(Data_String,1)< numel(Selected_ERP_label)% - msgboxText = 'Erpname for one of erpsets is empty at least! Please give a name'; - title = 'EStudio: f_ERP_save_multi_file empty erpname'; +if size(Data_String,1)< numel(EEGArray)% + msgboxText = 'ERP name for one of erpsets is empty at least! Please give a name'; + title = 'EStudio: f_ERP_save_multi_file empty eegname'; errorfound(msgboxText, title); return end -if size(Data_String,1)> numel(Selected_ERP_label)% - msgboxText = 'More erpname is given. Please delect it!!!'; +if size(Data_String,1)> numel(EEGArray)% + msgboxText = 'More eegname is given. Please delect it!!!'; title = 'EStudio: f_ERP_save_multi_file empty erpname'; errorfound(msgboxText, title); return end - - -for Numofselected = 1:numel(Selected_ERP_label) +for Numofselected = 1:numel(EEGArray) if isempty(Data_String{Numofselected,1}) msgboxText = 'Erpname for one of erpsets is empty at least! Please give name to that erpset'; title = 'EStudio: f_ERP_save_multi_file empty erpname'; @@ -337,31 +351,38 @@ function pushbutton4_okay_Callback(hObject, eventdata, handles) end +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end - -for Numofselectederp = 1:numel(Selected_ERP_label) - ALLERP(Selected_ERP_label(Numofselectederp)).erpname = Data_String{Numofselectederp,1}; - fileName = char(Data_String{Numofselectederp,2}); +for Numoferpset = 1:numel(EEGArray) + if handles.ERPIndex==1 + ALLERP(EEGArray(Numoferpset)).erpname = Data_String{Numoferpset,1}; + else + ALLERP(EEGArray(Numoferpset)).setname = Data_String{Numoferpset,1}; + end + fileName = char(Data_String{Numoferpset,2}); if isempty(fileName) - fileName = Data_String{Numofselectederp,1}; + fileName = Data_String{Numoferpset,1}; end [pathstr, file_name, ext] = fileparts(fileName); if isempty(file_name) - file_name = [num2str(Selected_ERP_label(Numofselectederp)),'_ERP.erp']; + file_name = [num2str(EEGArray(Numoferpset)),'.erp']; else - file_name = [file_name,'.erp']; + file_name = [file_name,'.erp']; end - ALLERP(Selected_ERP_label(Numofselectederp)).filename = file_name; + ALLERP(EEGArray(Numoferpset)).filename = file_name; if handles.checkbox2_save_label.Value - ALLERP(Selected_ERP_label(Numofselectederp)).filepath = cd; + ALLERP(EEGArray(Numoferpset)).filepath = pathName; end if handles.checkbox2_save_label.Value - ALLERP(Selected_ERP_label(Numofselectederp)).saved = 'yes'; + ALLERP(EEGArray(Numoferpset)).saved = 'yes'; else - ALLERP(Selected_ERP_label(Numofselectederp)).saved = 'no'; + ALLERP(EEGArray(Numoferpset)).saved = 'no'; end end @@ -389,3 +410,43 @@ function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) % The GUI is no longer waiting, just close it delete(handles.gui_chassis); end + + + +function edit_path_Callback(hObject, eventdata, handles) + + +PathName = handles.edit_path.String; + + + + + +% --- Executes during object creation, after setting all properties. +function edit_path_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit_path (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 + + +% --- Executes on button press in pushbutton_path_browse. +function pushbutton_path_browse_Callback(hObject, eventdata, handles) + + +pathName = handles.edit_path.String; +if isempty(pathName) + pathName =cd; +end +title = 'Select one forlder for saving files in following procedures'; +select_path = uigetdir(pathName,title); + +if isequal(select_path,0) + select_path = cd; +end +handles.edit_path.String = select_path; diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_single_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_save_single_GUI.m deleted file mode 100755 index 7dfaffce..00000000 --- a/studio_functions/GUIs/ERP Tab/f_ERP_save_single_GUI.m +++ /dev/null @@ -1,231 +0,0 @@ -%%This function is GUI that is used to save single ERP - - - - - - - -function ERP_OUT = f_ERP_save_single_GUI(ERP_In) - - -global observe_ERPDAT; - -try - % % ERP_In = evalin('base','ERP'); - ERP_In = ERP_In; - % % Suffix = varargin{2}; -catch - ERP_In = evalin('base','ERP'); -end - - -% varargout = {}; -f_ERP_save_single = figure( 'Name', 'Save ERPset GUI for single file', ... - 'NumberTitle', 'off', ... - 'MenuBar', 'none', ... - 'Toolbar', 'none', ... - 'HandleVisibility', 'off'); -f_ERP_save_single.Position(3:4) = [600 200]; - -% global gui_erp_save_single; -ERP_OUT = []; -% varargout{1} = f_ERP_save_single; - -erp_blc_dt_adv_gui(ERP_In); -% varargout{1} = ERP_basecorr_detrend_box; -%%********************Draw the GUI for ERP measurement tool***************** - function erp_blc_dt_adv_gui(ERP_In) - gui_erp_save_single.erp_file_name = uiextras.VBox('Parent',f_ERP_save_single,'Spacing',1); - - gui_erp_save_single.erpname_title = uiextras.HBox('Parent',gui_erp_save_single.erp_file_name,'Spacing',1); - uicontrol('Style', 'text','Parent', gui_erp_save_single.erpname_title,... - 'String',['Your active erpset is #', num2str(observe_ERPDAT.CURRENTERP)],'fontsize',16); - - - gui_erp_save_single.erpname_sec = uiextras.Grid('Parent',gui_erp_save_single.erp_file_name,'Spacing',1); - gui_erp_save_single.erpname_save = uicontrol('Style', 'radiobutton','Parent', gui_erp_save_single.erpname_sec,... - 'String','ERPname','callback',@erpname_radio,'Value',1); - % uiextras.Empty('Parent', gui_erp_save_single.erpname_sec); - gui_erp_save_single.erpname_str = uicontrol('Style', 'edit','Parent', gui_erp_save_single.erpname_sec,... - 'String',ERP_In.erpname,'callback',@erpname_str); - - gui_erp_save_single.erpname_filename = uicontrol('Style', 'pushbutton','Parent', gui_erp_save_single.erpname_sec,... - 'String','save as filename','callback',@erpname_filename,'Enable','off'); - - set(gui_erp_save_single.erpname_sec, 'ColumnSizes',[80 400 115],'RowSizes',[40]); - - - - - %%Save as - gui_erp_save_single.filename_sec = uiextras.Grid('Parent',gui_erp_save_single.erp_file_name,'Spacing',1); - gui_erp_save_single.filename_save = uicontrol('Style', 'radiobutton','Parent', gui_erp_save_single.filename_sec,... - 'String','Save ERP as','callback',@filename_radio,'Value',0); - gui_erp_save_single.filename_str = uicontrol('Style', 'edit','Parent', gui_erp_save_single.filename_sec,... - 'String','','Enable','off'); - - gui_erp_save_single.filename_browse = uicontrol('Style', 'pushbutton','Parent', gui_erp_save_single.filename_sec,... - 'String','Browse','callback',@filename_browse,'Enable','off'); - - set(gui_erp_save_single.filename_sec, 'ColumnSizes',[100 410 85],'RowSizes',[40]); - - - %%Cancel and Run - - gui_erp_save_single.other_option = uiextras.HBox('Parent',gui_erp_save_single.erp_file_name,'Spacing',1); - uiextras.Empty('Parent', gui_erp_save_single.other_option); - gui_erp_save_single.cancel = uicontrol('Style','pushbutton','Parent',gui_erp_save_single.other_option,... - 'String','Cancel','callback',@cancel_blc_dt); - uiextras.Empty('Parent', gui_erp_save_single.other_option); - gui_erp_save_single.run = uicontrol('Parent',gui_erp_save_single.other_option,'Style','pushbutton',... - 'String','Ok','callback',@run_blc_dt); - uiextras.Empty('Parent', gui_erp_save_single.other_option); - set(gui_erp_save_single.other_option,'Sizes',[80 170 100 170 80]); - - set(gui_erp_save_single.erp_file_name,'Sizes',[30 60 60 40]); - end - -%%------------------------------------------------------------------------%% -%%----------------------------Subfunction---------------------------------%% -%%------------------------------------------------------------------------%% - -%%----------------Setting for 'save ERPname" Radio----------------------------------------- - function erpname_radio(~,~) - gui_erp_save_single.erpname_save.Value = 1; - end - - -%%---------------Setting for filename-------------------------------------- - function erpname_str(Source,~) - if gui_erp_save_single.filename_save.Value ==1 - gui_erp_save_single.filename_str.String = gui_erp_save_single.erpname_str.String; - else - gui_erp_save_single.filename_str.String = ''; - end - end - -%%--------------Save erpname as filename----------------------------------- - function erpname_filename(~,~) - fileName = gui_erp_save_single.filename_str.String; - [px, fname, ext] = fileparts(fileName); - gui_erp_save_single.erpname_str.String = fname; - end - - -%%--------------------Select "Save ERP as"----------------------------------- - function filename_radio(Source,~) - if Source.Value == 0 - gui_erp_save_single.filename_str.String = ''; - gui_erp_save_single.filename_str.Enable = 'off'; - gui_erp_save_single.filename_browse.Enable = 'off'; - gui_erp_save_single.erpname_filename.Enable = 'off'; - else - gui_erp_save_single.filename_str.String = gui_erp_save_single.erpname_str.String; - gui_erp_save_single.filename_str.Enable = 'on'; - gui_erp_save_single.filename_browse.Enable = 'on'; - gui_erp_save_single.erpname_filename.Enable = 'on'; - end - end - - - -%%--------------------------Path------------------------------------------- - - function filename_browse(~,~) - fileName = gui_erp_save_single.filename_str.String; - if ~isempty(fileName) - [px, fname1, ext] = fileparts(fileName); - - [filename, filepath,filterindex] = uiputfile({'*.erp'; '*.mat'}, ... - 'Save Output file as',fname1); - else - [filename, filepath] = uiputfile({'*.erp'; '*.mat'}, ... - 'Save Output file as'); - end - - if isequal(filename,0) - disp('User selected Cancel'); - return - else - [px, fname, ext] = fileparts(filename); - if strcmp(ext,'') - if filterindex==1 || filterindex==3 - ext = '.erp'; - else - ext = '.mat'; - end - end - gui_erp_save_single.filename_str.String =[filepath,fname ext]; - end - end - - - - - - -%%-----------------------Cancel section----------------------------------- - function cancel_blc_dt(Source_localp_cancel,~) - Values_localp_cancel = Source_localp_cancel.Value; - if ~isempty(Values_localp_cancel) - beep; - disp('User selected Cancel'); - ERP_OUT = ERP_In; - close(f_ERP_save_single); - - ERPName = ERP_In.erpname; - px_fn = ERP_In.filepath; - fileName_save = ERP_In.filename; - erpworkingmemory('f_ERP_save_single_file',{ERPName,fileName_save,px_fn,0}); - return; - end - end - -%%-----------------------Run selection------------------------------------- - function run_blc_dt(Source_localp_run,~) - Values_localp_run = Source_localp_run.Value; - if ~isempty(Values_localp_run) - ERPName = gui_erp_save_single.erpname_str.String; - - if isempty(ERPName) - ERP_In.erpname = ERP_In.erpname; - ERPName = ERP_In.erpname; - else - ERP_In.erpname = ERPName; - end - - if gui_erp_save_single.filename_save.Value ==1 - FileName = gui_erp_save_single.filename_str.String; - [px_fn, fname_fn, ext_fn] = fileparts(FileName); - - fileName_save = [fname_fn ext_fn]; - - if strcmp(ext_fn,'.erp') - ERP_In.filename = fileName_save; - ERP = ERP_In; - [ERP, issave, erpcom] = pop_savemyerp( ERP,'filename', fileName_save, 'filepath', px_fn); - - elseif strcmp(ext_fn,'.mat') - ERP = ERP_In; - save([px_fn,filesep,fileName_save],'ERP'); - end - fileName_save = [fname_fn '.erp']; - else - px_fn = ERP_In.filepath; - fileName_save = ERP_In.filename; - end - - - - erpworkingmemory('f_ERP_save_single_file',{ERPName,fileName_save,px_fn,1}); - ERP_OUT = ERP_In; - close(f_ERP_save_single); - - return; - end - end - - - -end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.fig b/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.fig index 24128fe2..6e1db5ec 100755 Binary files a/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.fig and b/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.m b/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.m index 1ff500a1..c369e5d8 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_save_single_file.m @@ -69,8 +69,8 @@ function f_ERP_save_single_file_OpeningFcn(hObject, eventdata, handles, varargin set(handles.menuerp.Children, 'Enable','off'); end -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - Save single Erpset GUI']) set(handles.edit_erpname, 'String', erpname); set(handles.radio_erpname,'Value',1); @@ -87,14 +87,12 @@ function f_ERP_save_single_file_OpeningFcn(hObject, eventdata, handles, varargin set(handles.edit_filename, 'String', ''); set(handles.radiobutton_saveas, 'Value', 0); set(handles.filename_erpname, 'Enable', 'off'); - set(handles.erpname_filename, 'Enable', 'off'); set(handles.pushbutton_browse, 'Enable', 'off'); else set(handles.edit_filename, 'String', ''); set(handles.radiobutton_saveas, 'Value', 0); set(handles.edit_filename, 'Enable', 'off'); set(handles.filename_erpname, 'Enable', 'off'); - set(handles.erpname_filename, 'Enable', 'off'); set(handles.pushbutton_browse, 'Enable', 'off'); end % @@ -156,20 +154,6 @@ function edit_erpname_CreateFcn(hObject, eventdata, handles) end -% --- Executes on button press in erpname_filename. -function erpname_filename_Callback(hObject, eventdata, handles) - -fname = get(handles.edit_filename, 'String'); -% -if strcmp(fname,'') - msgboxText = 'You must enter a filename first!'; - title = 'ERPLAB: f_ERP_save_single GUI empty filename'; - errorfound(msgboxText, title); - return -end -[pathstr, fname, ext] = fileparts(fname); -erpname = fname; -set(handles.edit_erpname, 'String', erpname); % --- Executes on button press in radiobutton_saveas. @@ -179,12 +163,11 @@ function radiobutton_saveas_Callback(hObject, eventdata, handles) set(handles.edit_filename, 'Enable', 'on'); set(handles.filename_erpname, 'Enable', 'on'); set(handles.pushbutton_browse, 'Enable', 'on'); - set(handles.erpname_filename, 'Enable', 'on'); + else set(handles.edit_filename, 'Enable', 'off'); set(handles.filename_erpname, 'Enable', 'off'); set(handles.pushbutton_browse, 'Enable', 'off'); - set(handles.erpname_filename, 'Enable', 'off'); set(handles.edit_filename, 'String', ''); end @@ -225,8 +208,10 @@ function filename_erpname_Callback(hObject, eventdata, handles) return end [pathstr, fname, ext] = fileparts(fname); -erpname = fname; -set(handles.edit_filename, 'String', erpname); +erpname = [fname,'.erp']; +fileName = handles.edit_filename.String; +[pathstr, ~, ~] = fileparts(fileName); +set(handles.edit_filename, 'String', fullfile(pathstr,erpname)); @@ -240,13 +225,12 @@ function pushbutton_browse_Callback(hObject, eventdata, handles) fndefault); if isequal(fname,0) - disp('User selected Cancel') +% disp('User selected Cancel') guidata(hObject, handles); handles.owfp = 0; % over write file permission guidata(hObject, handles); else set(handles.edit_filename,'String', fullfile(pathname, fname)); - % disp(['To save ERP, user selected ', fullfile(pathname, fname)]) handles.owfp = 1; % over write file permission guidata(hObject, handles); end diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_simulation_panel.m b/studio_functions/GUIs/ERP Tab/f_ERP_simulation_panel.m old mode 100644 new mode 100755 index 5b18461e..a062ba7e --- a/studio_functions/GUIs/ERP Tab/f_ERP_simulation_panel.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_simulation_panel.m @@ -10,20 +10,22 @@ % global gui_erp_simulation; global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@erpschange); -% addlistener(observe_ERPDAT,'ERP_change',@drawui_CB); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); +global EStudio_gui_erp_totl; addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); %%---------------------------gui------------------------------------------- [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; if nargin == 0 fig = figure(); % Parent figure - ERP_simulation_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Create Artificial ERP Waveform', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + ERP_simulation_box = uiextras.BoxPanel('Parent', fig, 'Title', 'Create Artificial ERP Waveform',... + 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - ERP_simulation_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Create Artificial ERP Waveform', 'Padding', 5,'BackgroundColor',ColorB_def); + ERP_simulation_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Create Artificial ERP Waveform',... + 'Padding', 5,'BackgroundColor',ColorB_def); else - ERP_simulation_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Create Artificial ERP Waveform', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + ERP_simulation_box = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Create Artificial ERP Waveform',... + 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def);%, 'HelpFcn', @simuerp_help end gui_erp_simulation = struct(); @@ -40,18 +42,11 @@ %%********************Draw the GUI for ERP measurement tool***************** function erp_blc_dt_gui(FonsizeDefault) [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end - - def = erpworkingmemory('pop_ERP_simulation'); + Enable_label = 'off'; + def = estudioworkingmemory('pop_ERP_simulation'); if isempty(def) def = {1,1,100,50,0,-200,799,1,1000,0,1,0,1,0,1,10}; end - try BasFunLabel = def{1}; catch @@ -63,15 +58,11 @@ function erp_blc_dt_gui(FonsizeDefault) if numel(BasFunLabel)~=1 BasFunLabel=BasFunLabel(1); end - gui_erp_simulation.bsfun_box = uiextras.VBox('Parent',ERP_simulation_box,'Spacing',1,'BackgroundColor',ColorB_def); - - %%-----------------------Plot axis--------------------------------- gui_erp_simulation.plotasix_op = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.plot_erp = axes( 'Parent', gui_erp_simulation.plotasix_op);%, 'ActivePositionProperty', 'Position' - % %%----------------------information for Real data------------------ gui_erp_simulation.realdata_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); @@ -81,16 +72,18 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.realdatamatch_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.realerp_check = uicontrol('Style', 'checkbox','Parent', gui_erp_simulation.realdatamatch_title,... 'callback',@erpcheckbox,'String','Compare with Real Data','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def,'Value',0); + gui_erp_simulation.realerp_check.KeyPressFcn= @erp_simuls_presskey; uiextras.Empty('Parent', gui_erp_simulation.realdatamatch_title); set(gui_erp_simulation.realdatamatch_title, 'Sizes',[200 70]); - + gui_erp_simulation.Paras{1}=gui_erp_simulation.realerp_check.Value; %%ERPset for real data gui_erp_simulation.erpset_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uicontrol('Style', 'text','Parent', gui_erp_simulation.erpset_title,... 'String','ERPset:','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); gui_erp_simulation.erpsetedit = uicontrol('Style', 'edit','Parent', gui_erp_simulation.erpset_title,... 'callback',@erpsetedit,'String','','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1],'Enable','off'); - + gui_erp_simulation.Paras{2} = str2num(gui_erp_simulation.erpsetedit.String); + gui_erp_simulation.erpsetedit.KeyPressFcn= @erp_simuls_presskey; gui_erp_simulation.erpsetpopup = uicontrol('Style', 'pushbutton','Parent', gui_erp_simulation.erpset_title,... 'callback',@erpsetpopup,'String','Browse','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1],'Enable','off'); @@ -100,22 +93,22 @@ function erp_blc_dt_gui(FonsizeDefault) 'String','Channel:','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); gui_erp_simulation.channeledit = uicontrol('Style', 'edit','Parent', gui_erp_simulation.erpsetchan_title,... 'callback',@channeledit,'String','','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1],'Enable','off'); + gui_erp_simulation.channeledit.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{3} = str2num(gui_erp_simulation.channeledit.String); gui_erp_simulation.channelpopup = uicontrol('Style', 'pushbutton','Parent', gui_erp_simulation.erpsetchan_title,... 'callback',@channelpopup,'String','Browse','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1],'Enable','off'); - - %%bin for real data gui_erp_simulation.erpsetbin_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uicontrol('Style', 'text','Parent', gui_erp_simulation.erpsetbin_title,... 'String','Bin:','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); gui_erp_simulation.binedit = uicontrol('Style', 'edit','Parent', gui_erp_simulation.erpsetbin_title,... 'callback',@binedit,'String','','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1],'Enable','off'); - + gui_erp_simulation.binedit.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{4} = str2num(gui_erp_simulation.binedit.String); gui_erp_simulation.binpopup = uicontrol('Style', 'pushbutton','Parent', gui_erp_simulation.erpsetbin_title,... 'callback',@binpopup,'String','Browse','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1],'Enable','off'); - - if length(observe_ERPDAT.ALLERP)==1 && strcmpi(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + if isempty(observe_ERPDAT.ALLERP) gui_erp_simulation.realerp_check.Value =0; EnableFlag = 'off'; gui_erp_simulation.realerp_check.Enable = EnableFlag; @@ -124,10 +117,7 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.asif_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uicontrol('Style', 'text','Parent', gui_erp_simulation.asif_title,... 'String','Basic Information for Simulation','FontWeight','bold','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); - - gui_erp_simulation.epoch_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); - uicontrol('Style', 'text','Parent', gui_erp_simulation.epoch_title,... 'String','Epoch: Start','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); try @@ -137,7 +127,8 @@ function erp_blc_dt_gui(FonsizeDefault) end gui_erp_simulation.epoch_start = uicontrol('Style', 'edit','Parent', gui_erp_simulation.epoch_title,... 'callback',@epochstart,'String',num2str(epochStart),'FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1]); - + gui_erp_simulation.epoch_start.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{5} = str2num(gui_erp_simulation.epoch_start.String); uicontrol('Style', 'text','Parent', gui_erp_simulation.epoch_title,... 'String','Stop','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); try @@ -145,10 +136,10 @@ function erp_blc_dt_gui(FonsizeDefault) catch epochStop = 799; end - gui_erp_simulation.epoch_stop = uicontrol('Style', 'edit','Parent', gui_erp_simulation.epoch_title,... 'callback',@epocstop,'String',num2str(epochStop),'FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1]); - + gui_erp_simulation.epoch_stop.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{6} = str2num(gui_erp_simulation.epoch_stop.String); uicontrol('Style', 'text','Parent', gui_erp_simulation.epoch_title,... 'String','ms','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); set(gui_erp_simulation.epoch_title, 'Sizes',[80 60 40 60 25]); @@ -158,10 +149,11 @@ function erp_blc_dt_gui(FonsizeDefault) catch srateop = 1; end - gui_erp_simulation.srate_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.srate=uicontrol('Style', 'radiobutton','Parent', gui_erp_simulation.srate_title,... 'callback',@srateop,'String','Sampling rate','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); + gui_erp_simulation.Paras{7} = gui_erp_simulation.srate.Value; + gui_erp_simulation.srate.KeyPressFcn= @erp_simuls_presskey; try srate = def{9}; catch @@ -169,6 +161,8 @@ function erp_blc_dt_gui(FonsizeDefault) end gui_erp_simulation.srateedit =uicontrol('Style', 'edit','Parent', gui_erp_simulation.srate_title,... 'callback',@srateedit,'String', '','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1]); + gui_erp_simulation.srateedit.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{8} = str2num(gui_erp_simulation.srateedit.String); if srateop==1 gui_erp_simulation.srate.Value =1; gui_erp_simulation.srateedit.Enable = 'on'; @@ -179,19 +173,18 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.srateedit.String = num2str(1000/srate); end - uicontrol('Style', 'text','Parent', gui_erp_simulation.srate_title,... 'String','Hz','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.srate_title); set(gui_erp_simulation.srate_title, 'Sizes',[120 80 25 40]); - gui_erp_simulation.speriod_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); - gui_erp_simulation.srateperiod=uicontrol('Style', 'radiobutton','Parent', gui_erp_simulation.speriod_title,... 'callback',@srateperiod,'String','Sampling period','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); + gui_erp_simulation.srateperiod.KeyPressFcn= @erp_simuls_presskey; gui_erp_simulation.srateperiodedit =uicontrol('Style', 'edit','Parent', gui_erp_simulation.speriod_title,... 'callback',@srateperiodedit,'String', '','FontSize',FonsizeDefault ,'BackgroundColor',[1 1 1]); + gui_erp_simulation.srateperiodedit.KeyPressFcn= @erp_simuls_presskey; if srateop==1 gui_erp_simulation.srateperiod.Value =0; gui_erp_simulation.srateperiodedit.Enable = 'off'; @@ -201,7 +194,6 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.srateperiodedit.Enable = 'on'; gui_erp_simulation.srateperiodedit.String = num2str(srate); end - uicontrol('Style', 'text','Parent', gui_erp_simulation.speriod_title,... 'String','ms','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.speriod_title); @@ -217,6 +209,9 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.exguafun_option = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.exgua_op = uicontrol('Style', 'radiobutton','Parent', gui_erp_simulation.exguafun_option,... 'String','ExGaussian','callback',@exguass_op,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.exgua_op.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{9} = gui_erp_simulation.exgua_op.Value; + if BasFunLabel==1 gui_erp_simulation.exgua_op.Value =1; ExgauEnable = 'on'; @@ -241,7 +236,8 @@ function erp_blc_dt_gui(FonsizeDefault) 'String',num2str(Exgau_amp),'callback',@exgau_peakamp,'Enable',ExgauEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); uicontrol('Style', 'text','Parent', gui_erp_simulation.exguafun_option,... 'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_simulation.exgua_peakamp.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{10} = str2num(gui_erp_simulation.exgua_peakamp.String); uiextras.Empty('Parent', gui_erp_simulation.exguafun_option); set(gui_erp_simulation.exguafun_option, 'Sizes',[90 90 60 30 15]); @@ -259,7 +255,8 @@ function erp_blc_dt_gui(FonsizeDefault) end gui_erp_simulation.exgua_mean = uicontrol('Style', 'edit','Parent', gui_erp_simulation.exguafun_setting,... 'String',num2str(Exgau_mean),'callback',@exgau_mean,'Enable',ExgauEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - + gui_erp_simulation.exgua_mean.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{11} = str2num(gui_erp_simulation.exgua_mean.String); uicontrol('Style', 'text','Parent', gui_erp_simulation.exguafun_setting,... 'String','SD','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); try @@ -273,14 +270,12 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.exgua_sd = uicontrol('Style', 'edit','Parent', gui_erp_simulation.exguafun_setting,... 'String',num2str(ExGauSD),'callback',@exgau_sd,'Enable',ExgauEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); set(gui_erp_simulation.exguafun_setting, 'Sizes',[15 90 50 40 50]); - - + gui_erp_simulation.exgua_sd.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{12} = str2num(gui_erp_simulation.exgua_sd.String); gui_erp_simulation.exguafun_setting1 = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.exguafun_setting1); - uicontrol('Style', 'text','Parent', gui_erp_simulation.exguafun_setting1,... 'String','Exponential tau','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - try ExGauTau = def{5}; catch @@ -294,7 +289,8 @@ function erp_blc_dt_gui(FonsizeDefault) uiextras.Empty('Parent', gui_erp_simulation.exguafun_setting1); uiextras.Empty('Parent', gui_erp_simulation.exguafun_setting1); set(gui_erp_simulation.exguafun_setting1, 'Sizes',[15 90 50 40 50]); - + gui_erp_simulation.exgua_tau.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{13} = str2num(gui_erp_simulation.exgua_tau.String); %%Impulse function gui_erp_simulation.impulse_option = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.impulse_op = uicontrol('Style', 'radiobutton','Parent', gui_erp_simulation.impulse_option,... @@ -302,19 +298,20 @@ function erp_blc_dt_gui(FonsizeDefault) if BasFunLabel==2 ImpulseEnable ='on'; gui_erp_simulation.impulse_op.Value =1; - else ImpulseEnable = 'off'; gui_erp_simulation.impulse_op.Value =0; end - + gui_erp_simulation.impulse_op.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{14} = gui_erp_simulation.impulse_op.Value; uicontrol('Style', 'text','Parent', gui_erp_simulation.impulse_option,... 'String','Peak amplitude','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_simulation.impulse_peakamp = uicontrol('Style', 'edit','Parent', gui_erp_simulation.impulse_option,... 'String','','callback',@impulse_peakamp,'Enable',ImpulseEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); uicontrol('Style', 'text','Parent', gui_erp_simulation.impulse_option,... 'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.impulse_peakamp.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{15} = str2num(gui_erp_simulation.impulse_peakamp.String); if BasFunLabel==2 try impulsePeakamp = def{2}; @@ -328,16 +325,15 @@ function erp_blc_dt_gui(FonsizeDefault) end uiextras.Empty('Parent', gui_erp_simulation.impulse_option); set( gui_erp_simulation.impulse_option, 'Sizes',[80 100 60 30 15]); - gui_erp_simulation.impulse_setting = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.impulse_setting); uicontrol('Style', 'text','Parent', gui_erp_simulation.impulse_setting,... 'String','Latency','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_simulation.impulse_latency = uicontrol('Style', 'edit','Parent', gui_erp_simulation.impulse_setting,... 'String','','callback',@impulse_latency,'Enable',ImpulseEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - uicontrol('Style', 'text','Parent', gui_erp_simulation.impulse_setting,... - 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', gui_erp_simulation.impulse_setting,'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.impulse_latency.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{16} = str2num(gui_erp_simulation.impulse_latency.String); if BasFunLabel==2 try impulselat = def{3}; @@ -349,17 +345,16 @@ function erp_blc_dt_gui(FonsizeDefault) end gui_erp_simulation.impulse_latency.String = num2str(impulselat); end - uiextras.Empty('Parent', gui_erp_simulation.impulse_setting); set(gui_erp_simulation.impulse_setting, 'Sizes',[80 100 60 30 15]); - %%Boxcar function gui_erp_simulation.square_option = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.square_op = uicontrol('Style', 'radiobutton','Parent', gui_erp_simulation.square_option,... 'String','Boxcar','callback',@square_op,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_simulation.square_op.KeyPressFcn= @erp_simuls_presskey; uicontrol('Style', 'text','Parent', gui_erp_simulation.square_option,... 'String','Peak amplitude','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.Paras{17} =gui_erp_simulation.square_op.Value; if BasFunLabel==3 squareEnable = 'on'; else @@ -370,6 +365,8 @@ function erp_blc_dt_gui(FonsizeDefault) uicontrol('Style', 'text','Parent', gui_erp_simulation.square_option,... 'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.square_option); + gui_erp_simulation.square_peakamp.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{18} =str2num(gui_erp_simulation.square_peakamp.String); if BasFunLabel==3 try sqaurePeakamp = def{2}; @@ -385,16 +382,15 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.square_op.Value =0; end set( gui_erp_simulation.square_option, 'Sizes',[80 100 60 30 15]); - gui_erp_simulation.square_setting = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.square_setting); uicontrol('Style', 'text','Parent', gui_erp_simulation.square_setting,... 'String','Onset','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_simulation.square_onset = uicontrol('Style', 'edit','Parent', gui_erp_simulation.square_setting,... 'String','','callback',@square_onset,'Enable',squareEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - uicontrol('Style', 'text','Parent', gui_erp_simulation.square_setting,... - 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', gui_erp_simulation.square_setting,'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.square_onset.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{19} =str2num(gui_erp_simulation.square_onset.String); if BasFunLabel==3 try Onsetlat = def{3}; @@ -406,15 +402,13 @@ function erp_blc_dt_gui(FonsizeDefault) end gui_erp_simulation.square_onset.String = num2str(Onsetlat); end - - uicontrol('Style', 'text','Parent', gui_erp_simulation.square_setting,... 'String','Offset','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - gui_erp_simulation.square_offset = uicontrol('Style', 'edit','Parent', gui_erp_simulation.square_setting,... 'String','','callback',@square_offset,'Enable',squareEnable,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); - uicontrol('Style', 'text','Parent', gui_erp_simulation.square_setting,... - 'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', gui_erp_simulation.square_setting,'String','ms','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.square_offset.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{20} =str2num(gui_erp_simulation.square_offset.String); if BasFunLabel==3 try Offsetlat = def{4}; @@ -428,20 +422,18 @@ function erp_blc_dt_gui(FonsizeDefault) end set( gui_erp_simulation.square_setting, 'Sizes',[15 40 60 25 40 60 25]); - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%-----------------------noise ------------------------------------ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% gui_erp_simulation.noisefun_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uicontrol('Style', 'text','Parent', gui_erp_simulation.noisefun_title,... 'String','Noise Function for Simulation','FontWeight','bold','FontSize',FonsizeDefault ,'BackgroundColor',ColorB_def); - - %%sin noise gui_erp_simulation.sin_option = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.sin_op = uicontrol('Style', 'checkbox','Parent', gui_erp_simulation.sin_option ,... 'String','Sinusoidal','callback',@sinoise_op,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.sin_op.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{21} = gui_erp_simulation.sin_op.Value; try sinop = def{14}; catch @@ -457,9 +449,10 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.sin_op.Value=0; sinEnable = 'off'; end - gui_erp_simulation.sin_amp = uicontrol('Style', 'edit','Parent', gui_erp_simulation.sin_option ,... 'String',' ','callback',@sin_amp,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',sinEnable); + gui_erp_simulation.sin_amp.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{22} = str2num(gui_erp_simulation.sin_amp.String); try sinamp = def{15}; catch @@ -475,7 +468,8 @@ function erp_blc_dt_gui(FonsizeDefault) 'String',' ','callback',@sinoise_fre,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',sinEnable); uicontrol('Style', 'text','Parent', gui_erp_simulation.sin_option,... 'String','Hz','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - + gui_erp_simulation.sin_fre.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{23} = str2num(gui_erp_simulation.sin_fre.String); try sinfre = def{16}; catch @@ -486,11 +480,12 @@ function erp_blc_dt_gui(FonsizeDefault) end gui_erp_simulation.sin_fre.String = num2str(sinfre); set(gui_erp_simulation.sin_option, 'Sizes',[90 60 30 60 30]); - %%white noise gui_erp_simulation.white_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.white_op = uicontrol('Style', 'checkbox','Parent', gui_erp_simulation.white_title ,... 'String','White','callback',@whitenoise_op,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.white_op.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{24} = gui_erp_simulation.white_op.Value; try whiteop =def{10}; catch @@ -506,14 +501,13 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.white_op.Value =0; whitEnable = 'off'; end - gui_erp_simulation.white_amp = uicontrol('Style', 'edit','Parent', gui_erp_simulation.white_title ,... 'String',' ','callback',@white_amp,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',whitEnable); - - uicontrol('Style', 'text','Parent', gui_erp_simulation.white_title,... - 'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.white_amp.KeyPressFcn= @erp_simuls_presskey; + uicontrol('Style', 'text','Parent', gui_erp_simulation.white_title,'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.white_title); uiextras.Empty('Parent', gui_erp_simulation.white_title); + gui_erp_simulation.Paras{25} = str2num(gui_erp_simulation.white_amp.String); try whiteamp =def{11}; catch @@ -529,6 +523,8 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.pink_title = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_simulation.pink_op = uicontrol('Style', 'checkbox','Parent', gui_erp_simulation.pink_title ,... 'String','Pink','callback',@pinknoise_op,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_simulation.pink_op.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{26} = gui_erp_simulation.pink_op.Value; try pinkeop =def{12}; catch @@ -544,75 +540,82 @@ function erp_blc_dt_gui(FonsizeDefault) gui_erp_simulation.pink_op.Value =0; pinkEnable = 'off'; end - gui_erp_simulation.pink_amp = uicontrol('Style', 'edit','Parent', gui_erp_simulation.pink_title ,... 'String',' ','callback',@pink_amp,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable',pinkEnable); + gui_erp_simulation.pink_amp.KeyPressFcn= @erp_simuls_presskey; + gui_erp_simulation.Paras{27} = str2num(gui_erp_simulation.pink_amp.String); try pinkAmp = def{13}; catch pinkAmp=0; end gui_erp_simulation.pink_amp.String = num2str(pinkAmp); - uicontrol('Style', 'text','Parent', gui_erp_simulation.pink_title,... - 'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + uicontrol('Style', 'text','Parent', gui_erp_simulation.pink_title,'String','μV','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.pink_title); uiextras.Empty('Parent', gui_erp_simulation.pink_title); set(gui_erp_simulation.pink_title, 'Sizes',[90 60 30 60 30]); %%update noise if needed New Noise %%seeds for white and pink noise - gui_erp_simulation.SimulationSeed = erpworkingmemory('SimulationSeed'); + gui_erp_simulation.SimulationSeed = estudioworkingmemory('SimulationSeed'); rng(1,'twister'); SimulationSeed = rng; - erpworkingmemory('SimulationSeed',SimulationSeed); + estudioworkingmemory('SimulationSeed',SimulationSeed); %phase for sin noise - gui_erp_simulation.SimulationPhase = erpworkingmemory('SimulationPhase'); + gui_erp_simulation.SimulationPhase = estudioworkingmemory('SimulationPhase'); SimulationPhase = 0; - erpworkingmemory('SimulationPhase',SimulationPhase); + estudioworkingmemory('SimulationPhase',SimulationPhase); gui_erp_simulation.newnoise_option = uiextras.HBox('Parent', gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.newnoise_option); gui_erp_simulation.newnoise_op = uicontrol('Style', 'pushbutton','Parent', gui_erp_simulation.newnoise_option ,... 'String','Re-randomize noise','callback',@newnoise_op,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Value',0); - % uiextras.Empty('Parent', gui_erp_simulation.newnoise_option); - % uiextras.Empty('Parent', gui_erp_simulation.newnoise_option); uiextras.Empty('Parent', gui_erp_simulation.newnoise_option); set(gui_erp_simulation.newnoise_option, 'Sizes',[70 130 70]); - %%Cancel and advanced gui_erp_simulation.other_option = uiextras.HBox('Parent',gui_erp_simulation.bsfun_box,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_simulation.other_option,'BackgroundColor',ColorB_def); - gui_erp_simulation.simulation_help = uicontrol('Parent',gui_erp_simulation.other_option,'Style','pushbutton',... - 'String','?','FontWeight','bold','callback',@simulation_help,'FontSize',14,'BackgroundColor',[1 1 1]); + gui_erp_simulation.simulation_cancel = uicontrol('Parent',gui_erp_simulation.other_option,'Style','pushbutton',... + 'String','Cancel','callback',@simulation_cancel,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); uiextras.Empty('Parent', gui_erp_simulation.other_option); gui_erp_simulation.apply = uicontrol('Style','pushbutton','Parent',gui_erp_simulation.other_option,... - 'String','Apply','callback',@simulation_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + 'String','Create ERPset','callback',@simulation_apply,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); uiextras.Empty('Parent', gui_erp_simulation.other_option); set(gui_erp_simulation.other_option, 'Sizes',[15 105 30 105 15]); set(gui_erp_simulation.bsfun_box, 'Sizes',[200 20 25 25 25 25 20 25 25 25 20 25 25 25 25 25 25 25 20 25 25 25 25 25]); plot_erp_simulation(); + + estudioworkingmemory('ERPTab_stimulation',0); end - - - %%**************************************************************************************************************************************** %%******************* Subfunctions *************************************************************************************************** %%**************************************************************************************************************************************** - %%---------------------Match with real ERP?-------------------------------- function erpcheckbox(Str,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + + Value = Str.Value; if Value ==1 EnableFlag = 'on'; else EnableFlag = 'off'; end - if length(observe_ERPDAT.ALLERP)==1 && strcmpi(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) Str.Enable = 'off'; EnableFlag = 'off'; - gui_erp_simulation.erpsetedit.Enable = EnableFlag; gui_erp_simulation.erpsetpopup.Enable = EnableFlag; gui_erp_simulation.channeledit.Enable = EnableFlag; @@ -632,7 +635,6 @@ function erpcheckbox(Str,~) else EnableFlagn = 'on'; end - gui_erp_simulation.epoch_start.Enable = EnableFlagn; gui_erp_simulation.epoch_stop.Enable = EnableFlagn; gui_erp_simulation.srate.Enable = EnableFlagn; @@ -657,17 +659,27 @@ function erpcheckbox(Str,~) %%------------------------ERPset edit-------------------------------------- function erpsetedit(Str,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); ERPArray = str2num(Str.String); if ~isempty(observe_ERPDAT.ALLERP) - if ~isempty(ERPArray) && min(ERPArray)>0 + if ~isempty(ERPArray) && any(ERPArray>0) if numel(ERPArray) ~=1 ERPArray = ERPArray(1); end if ERPArray> length(observe_ERPDAT.ALLERP) msgboxText = 'Create Artificial ERP Waveform -Real ERP: Input should be smaller than the length of ALLERP'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = ''; return; end @@ -694,9 +706,8 @@ function erpsetedit(Str,~) end else msgboxText = 'Create Artificial ERP Waveform -Real ERP: Index of ERPset should be a positive numeric'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = ''; return; end @@ -711,9 +722,8 @@ function erpsetedit(Str,~) gui_erp_simulation.binedit.Enable = EnableFlag; gui_erp_simulation.binpopup.Enable = EnableFlag; msgboxText = 'Create Artificial ERP Waveform -Real ERP: ALLERPset is empty and cannot match simulation with it'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = ''; return; end @@ -723,6 +733,17 @@ function erpsetedit(Str,~) %%-----------------------ERPset popup-------------------------------------- function erpsetpopup(~,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); ERPArray = str2num(gui_erp_simulation.erpsetedit.String); if ~isempty(ERPArray) if numel(ERPArray)~=1 @@ -775,9 +796,8 @@ function erpsetpopup(~,~) end else%%the user did not select one ERPset msgboxText = 'Create Artificial ERP Waveform -Real ERP: User selected cancel'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end @@ -789,13 +809,24 @@ function erpsetpopup(~,~) %%------------------------channel edit------------------------------------- function channeledit(Str,~) + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + channelArray = str2num(Str.String); if ~isempty(observe_ERPDAT.ALLERP) if isempty(channelArray) msgboxText = 'Create Artificial ERP Waveform -Real ERP: Please input one positive numeric for "Channel"'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '1'; return; end @@ -804,9 +835,8 @@ function channeledit(Str,~) end if channelArray<=0 msgboxText = 'Create Artificial ERP Waveform -Real ERP: Please input one positive numeric for "Channel"'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '1'; return; end @@ -822,9 +852,8 @@ function channeledit(Str,~) gui_erp_simulation.binedit.Enable = EnableFlag; gui_erp_simulation.binpopup.Enable = EnableFlag; msgboxText = 'Create Artificial ERP Waveform -Real ERP: ALLERPset is empty and cannot match simulation with it'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '1'; return; end @@ -833,9 +862,21 @@ function channeledit(Str,~) %%------------------------channel popup------------------------------------ function channelpopup(~,~) - if length(observe_ERPDAT.ALLERP)==1 && strcmpi(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + if ~isempty(observe_ERPDAT.ALLERP) ERPsetArray = str2num(gui_erp_simulation.erpsetedit.String); if ~isempty(ERPsetArray) @@ -874,9 +915,8 @@ function channelpopup(~,~) gui_erp_simulation.channeledit.String = num2str(channelArray); else msgboxText = 'Create Artificial ERP Waveform-Real ERP: User selected cancel'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end end @@ -886,14 +926,27 @@ function channelpopup(~,~) %%------------------------bin edit----------------------------------------- function binedit(Str,~) + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + Str.Enable = 'off'; + return; + end + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + binArray = str2num(Str.String); if ~isempty(observe_ERPDAT.ALLERP) if isempty(binArray) msgboxText = 'Create Artificial ERP Waveform -Real ERP: Please input one positive numeric for "Bin"'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - % Str.String = '1'; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if numel(binArray)~=1 @@ -901,9 +954,8 @@ function binedit(Str,~) end if binArray<=0 msgboxText = 'Create Artificial ERP Waveform -Real ERP: Please input one positive numeric for "Bin"'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '1'; return; end @@ -919,9 +971,8 @@ function binedit(Str,~) gui_erp_simulation.binedit.Enable = EnableFlag; gui_erp_simulation.binpopup.Enable = EnableFlag; msgboxText = 'Create Artificial ERP Waveform -Real ERP: ALLERPset is empty and cannot match simulation with it'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '1'; return; end @@ -930,10 +981,22 @@ function binedit(Str,~) %%-----------------------bin popup----------------------------------------- - function binpopup(~,~) - if length(observe_ERPDAT.ALLERP)==1 && strcmpi(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + function binpopup(Str,~) + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + Str.Enable = 'off'; return; end + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + if ~isempty(observe_ERPDAT.ALLERP) ERPsetArray = str2num(gui_erp_simulation.erpsetedit.String); if ~isempty(ERPsetArray) @@ -971,10 +1034,6 @@ function binpopup(~,~) end gui_erp_simulation.binedit.String = num2str(binArray); else - msgboxText = 'Create Artificial ERP Waveform-Real ERP: User selected cancel'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; return; end end @@ -989,9 +1048,8 @@ function binpopup(~,~) gui_erp_simulation.binedit.Enable = EnableFlag; gui_erp_simulation.binpopup.Enable = EnableFlag; msgboxText = 'Create Artificial ERP Waveform -Real ERP: ALLERPset is empty and cannot match simulation with it'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '1'; return; end @@ -1001,14 +1059,23 @@ function binpopup(~,~) %%----------------------------epoch start---------------------------------- function epochstart(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + epochStart = str2num( gui_erp_simulation.epoch_start.String); epochStop = str2num( gui_erp_simulation.epoch_stop.String); if epochStart>=epochStop - beep; msgboxText = ['Create Artificial ERP Waveform - The value for epoch start should be smaller than epoch stop']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = ''; return; end @@ -1017,15 +1084,23 @@ function epochstart(Str,~) %%----------------------------epoch stop----------------------------------- function epocstop(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + epochStart = str2num( gui_erp_simulation.epoch_start.String); epochStop = str2num( gui_erp_simulation.epoch_stop.String); if epochStart>=epochStop - beep; msgboxText = ['Create Artificial ERP Waveform - The value for epoch start should be smaller than epoch stop']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; - Str.String = ''; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end plot_erp_simulation(); @@ -1033,6 +1108,16 @@ function epocstop(Str,~) %%---------------------Sampling rate option-------------------------------- function srateop(~,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); gui_erp_simulation.srate.Value =1; gui_erp_simulation.srateedit.Enable = 'on'; gui_erp_simulation.srateperiod.Value =0; @@ -1043,14 +1128,24 @@ function srateop(~,~) %%--------------Edit sampling rate----------------------------------------- function srateedit(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + srate = str2num(Str.String); if ~isempty(srate) && numel(srate)==1 && srate>0 gui_erp_simulation.srateperiodedit.String = num2str(1000/srate); else msgboxText = ['Create Artificial ERP Waveform>sampling rate- the input should be a positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateperiodedit.String = ''; return; end @@ -1059,6 +1154,17 @@ function srateedit(Str,~) %%---------------------Sampling period------------------------------------- function srateperiod(~,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + gui_erp_simulation.srate.Value =0; gui_erp_simulation.srateedit.Enable = 'off'; gui_erp_simulation.srateperiod.Value =1; @@ -1068,14 +1174,23 @@ function srateperiod(~,~) %%----------------------Edit sampling period------------------------------- function srateperiodedit(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); srateperiod = str2num(Str.String); if ~isempty(srateperiod) && numel(srateperiod)==1 && srateperiod>0 gui_erp_simulation.srateedit.String = num2str(1000/srateperiod); else msgboxText = ['Create Artificial ERP Waveform>sampling period- the input should be a positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateedit.String = ''; return; end @@ -1084,16 +1199,24 @@ function srateperiodedit(Str,~) %%--------------------------------Select ex-gaussian function-------------- function exguass_op(~,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); gui_erp_simulation.exgua_op.Value =1; gui_erp_simulation.exgua_peakamp.Enable = 'on'; gui_erp_simulation.exgua_mean.Enable = 'on'; gui_erp_simulation.exgua_sd.Enable = 'on'; gui_erp_simulation.exgua_tau.Enable = 'on'; - gui_erp_simulation.impulse_op.Value = 0; gui_erp_simulation.impulse_peakamp.Enable = 'off'; gui_erp_simulation.impulse_latency.Enable = 'off'; - gui_erp_simulation.square_op.Value = 0; gui_erp_simulation.square_onset.Enable = 'off'; gui_erp_simulation.square_offset.Enable = 'off'; @@ -1104,12 +1227,21 @@ function exguass_op(~,~) %%---------------Peak amplitude for ex-Gaussian function------------------- function exgau_peakamp(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); PeakAmp = str2num(Str.String); if isempty(PeakAmp) || numel(PeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> peak amplitude for Ex-Gaussian should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1118,12 +1250,21 @@ function exgau_peakamp(Str,~) %%------------------Guasssian mean----------------------------------------- function exgau_mean(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); Mean = str2num(Str.String); if isempty(Mean) || numel(Mean)~=1 msgboxText = ['Create Artificial ERP Waveform> Gaussian mean for Ex-Gaussian should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1132,12 +1273,21 @@ function exgau_mean(Str,~) %%-----------------SD for Ex-Gaussian function----------------------------- function exgau_sd(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); SD = str2num(Str.String); if isempty(SD) || numel(SD)~=1 msgboxText = ['Create Artificial ERP Waveform> SD for Ex-Gaussian should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1147,12 +1297,21 @@ function exgau_sd(Str,~) %%----------------Tau for Ex-Gaussian function----------------------------- function exgau_tau(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); Tau = str2num(Str.String); if isempty(Tau) || numel(Tau)~=1 msgboxText = ['Create Artificial ERP Waveform> Exponential tau for Ex-Gaussian should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1162,12 +1321,21 @@ function exgau_tau(Str,~) %%--------------------------------impulse function------------------------- function impulse_op(~,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); gui_erp_simulation.exgua_op.Value =0; gui_erp_simulation.exgua_peakamp.Enable = 'off'; gui_erp_simulation.exgua_mean.Enable = 'off'; gui_erp_simulation.exgua_sd.Enable = 'off'; gui_erp_simulation.exgua_tau.Enable = 'off'; - gui_erp_simulation.impulse_op.Value = 1; gui_erp_simulation.impulse_peakamp.Enable = 'on'; gui_erp_simulation.impulse_latency.Enable = 'on'; @@ -1180,12 +1348,21 @@ function impulse_op(~,~) %%-------------Impulse peak amplitude-------------------------------------- function impulse_peakamp(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); peakAmp = str2num(Str.String); if isempty(peakAmp) msgboxText = ['Create Artificial ERP Waveform>Impulse- peak amplitude should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1194,12 +1371,21 @@ function impulse_peakamp(Str,~) %%-------------------Latency for impluse----------------------------------- function impulse_latency(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); peakLat = str2num(Str.String); if isempty(peakLat) msgboxText = ['Create Artificial ERP Waveform>Impulse- Latency should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1208,12 +1394,21 @@ function impulse_latency(Str,~) %%--------------------------------square function-------------------------- function square_op(~,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); gui_erp_simulation.exgua_op.Value =0; gui_erp_simulation.exgua_peakamp.Enable = 'off'; gui_erp_simulation.exgua_mean.Enable = 'off'; gui_erp_simulation.exgua_sd.Enable = 'off'; gui_erp_simulation.exgua_tau.Enable = 'off'; - gui_erp_simulation.impulse_op.Value = 0; gui_erp_simulation.impulse_peakamp.Enable = 'off'; gui_erp_simulation.impulse_latency.Enable = 'off'; @@ -1227,12 +1422,21 @@ function square_op(~,~) %%--------------Peak amplitude for square function------------------------- function square_peakamp(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); peakAmp = str2num(Str.String); if isempty(peakAmp) msgboxText = ['Create Artificial ERP Waveform>Square- peak amplitude should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1241,21 +1445,29 @@ function square_peakamp(Str,~) %%------------------Square onset latency----------------------------------- function square_onset(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); onsetlat = str2num(Str.String); if isempty(onsetlat) msgboxText = ['Create Artificial ERP Waveform>Boxcar- Onset latency should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end offsetLat = str2num(gui_erp_simulation.square_offset.String); if onsetlat>offsetLat msgboxText = ['Create Artificial ERP Waveform>Boxcar- Onset latency should be smaller than',32,num2str(offsetLat)]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1264,21 +1476,29 @@ function square_onset(Str,~) %%------------------Boxcar offset latency---------------------------------- function square_offset(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); offsetlat = str2num(Str.String); if isempty(offsetlat) msgboxText = ['Create Artificial ERP Waveform>Boxcar- Offset latency should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end onsetlat = str2num(gui_erp_simulation.square_onset.String); if offsetlatBoxcar- Offset latency should be larger than',32,num2str(onsetlat)]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1287,13 +1507,22 @@ function square_offset(Str,~) %%-----------------update new noise if needed------------------------------ function newnoise_op(~,~) - + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); %%reset the phase for sin signal SimulationPhase = rand(1); - erpworkingmemory('SimulationPhase',SimulationPhase); + estudioworkingmemory('SimulationPhase',SimulationPhase); %%reset seeds for white or pink noise - SimulationSeed = erpworkingmemory('SimulationSeed'); + SimulationSeed = estudioworkingmemory('SimulationSeed'); try SimulationSeed.Type = 'philox'; SimulationSeed.Seed = SimulationSeed.Seed+1; @@ -1301,7 +1530,7 @@ function newnoise_op(~,~) SimulationSeed.Type = 'twister'; SimulationSeed.Seed = 1; end - erpworkingmemory('SimulationSeed',SimulationSeed); + estudioworkingmemory('SimulationSeed',SimulationSeed); gui_erp_simulation.SimulationSeed = SimulationSeed; gui_erp_simulation.SimulationPhase = SimulationPhase; plot_erp_simulation(); @@ -1309,6 +1538,17 @@ function newnoise_op(~,~) %%-----------------check box of sin function------------------------------- function sinoise_op(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + Value = Str.Value; if Value==1 Enable = 'on'; @@ -1322,12 +1562,21 @@ function sinoise_op(Str,~) %%---------------Peak amplitude for sin noise------------------------------ function sin_amp(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); peakAmp = str2num(Str.String); if isempty(peakAmp) msgboxText = ['Create Artificial ERP Waveform>Sinusoidal noise- peak amplitude should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1336,12 +1585,21 @@ function sin_amp(Str,~) %%------------------Frequency for sin noise-------------------------------- function sinoise_fre(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); Fresin = str2num(Str.String); if isempty(Fresin) || Fresin<=0 msgboxText = ['Create Artificial ERP Waveform>Sinusoidal noise- frequency should be a positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = ''; return; end @@ -1350,6 +1608,16 @@ function sinoise_fre(Str,~) %%------------checkbox for white noise------------------------------------- function whitenoise_op(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); if Str.Value ==1 gui_erp_simulation.white_amp.Enable ='on'; else @@ -1360,12 +1628,22 @@ function whitenoise_op(Str,~) %%-------------------Peak amplitude for white noise------------------------ function white_amp(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + peakAmp = str2num(Str.String); if isempty(peakAmp) msgboxText = ['Create Artificial ERP Waveform>White noise- peak amplitude should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1374,6 +1652,16 @@ function white_amp(Str,~) %%--------------------check box for pink noise----------------------------- function pinknoise_op(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); if Str.Value ==1 gui_erp_simulation.pink_amp.Enable = 'on'; else @@ -1384,12 +1672,22 @@ function pinknoise_op(Str,~) %%------------------peak amplitude of pink noise--------------------------- function pink_amp(Str,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + peakAmp = str2num(Str.String); if isempty(peakAmp) msgboxText = ['Create Artificial ERP Waveform>Pink noise- peak amplitude should be a numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); Str.String = '0'; return; end @@ -1397,14 +1695,157 @@ function pink_amp(Str,~) end %%-----------------------Help---------------------------------------------- - function simulation_help(~,~) + function simulation_cancel(~,~) + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 1 1 1]; + gui_erp_simulation.apply.ForegroundColor = [0 0 0]; + ERP_simulation_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [1 1 1]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_stimulation',0); + + + try gui_erp_simulation.realerp_check.Value = gui_erp_simulation.Paras{1};catch gui_erp_simulation.realerp_check.Value=0; end + gui_erp_simulation.erpsetedit.String = num2str(gui_erp_simulation.Paras{2}); + if gui_erp_simulation.realerp_check.Value==0 + Enable1 = 'off'; + Enable2 = 'on'; + else + Enable1 = 'on'; + Enable2 = 'off'; + end + %%chan + gui_erp_simulation.erpsetpopup.Enable = Enable1; + gui_erp_simulation.erpsetedit.Enable = Enable1; + gui_erp_simulation.channeledit.String = num2str(gui_erp_simulation.Paras{3}); + gui_erp_simulation.channeledit.Enable = Enable1; + gui_erp_simulation.channelpopup.Enable = Enable1; + %%bin + gui_erp_simulation.binedit.String= num2str(gui_erp_simulation.Paras{4}); + gui_erp_simulation.binedit.Enable = Enable1; + gui_erp_simulation.binpopup.Enable = Enable1; + %%start and end for the epoch + gui_erp_simulation.epoch_start.String = num2str(gui_erp_simulation.Paras{5}); + gui_erp_simulation.epoch_stop.String = num2str(gui_erp_simulation.Paras{6}); + gui_erp_simulation.epoch_start.Enable = Enable2; + gui_erp_simulation.epoch_stop.Enable = Enable2; + %%sampling rate + gui_erp_simulation.srate.Value = gui_erp_simulation.Paras{7}; + gui_erp_simulation.srateedit.String = num2str( gui_erp_simulation.Paras{8}); + if gui_erp_simulation.srate.Value==1 + gui_erp_simulation.srateedit.Enable = 'on'; + gui_erp_simulation.srateperiod.Value=0; + if ~isempty(gui_erp_simulation.Paras{8}) && gui_erp_simulation.Paras{8}~=0 + gui_erp_simulation.srateperiodedit = num2str(1000/gui_erp_simulation.Paras{8}); + end + else + gui_erp_simulation.srateedit.Enable = 'off'; + gui_erp_simulation.srateperiod.Value=1; + if ~isempty(gui_erp_simulation.Paras{8}) && gui_erp_simulation.Paras{8}~=0 + gui_erp_simulation.srateperiodedit.String = num2str(1000/gui_erp_simulation.Paras{8}); + end + end + if gui_erp_simulation.realerp_check.Value==1 + gui_erp_simulation.srate.Enable = Enable2; + gui_erp_simulation.srateedit.Enable = Enable2; + gui_erp_simulation.srateperiod.Enable = Enable2; + gui_erp_simulation.srateperiodedit.Enable = Enable2; + end + %%exgaussian + gui_erp_simulation.exgua_op.Value= gui_erp_simulation.Paras{9}; + if gui_erp_simulation.exgua_op.Value==1 + Enableflag = 'on'; + else + Enableflag = 'off'; + end + gui_erp_simulation.exgua_peakamp.String = num2str(gui_erp_simulation.Paras{10}); + gui_erp_simulation.exgua_mean.String = num2str(gui_erp_simulation.Paras{11}); + gui_erp_simulation.exgua_sd.String= num2str(gui_erp_simulation.Paras{12}); + gui_erp_simulation.exgua_tau.String= num2str(gui_erp_simulation.Paras{13}); + gui_erp_simulation.exgua_peakamp.Enable = Enableflag; + gui_erp_simulation.exgua_mean.Enable = Enableflag; + gui_erp_simulation.exgua_sd.Enable = Enableflag; + gui_erp_simulation.exgua_tau.Enable = Enableflag; + + %%impulse + gui_erp_simulation.impulse_op.Value = gui_erp_simulation.Paras{14}; + if gui_erp_simulation.impulse_op.Value==1 + Enableflag = 'on'; + else + Enableflag = 'off'; + end + gui_erp_simulation.impulse_peakamp.String = num2str(gui_erp_simulation.Paras{15}); + gui_erp_simulation.impulse_latency.String=num2str(gui_erp_simulation.Paras{16}); + gui_erp_simulation.impulse_peakamp.Enable = Enableflag; + gui_erp_simulation.impulse_latency.Enable = Enableflag; + + %%boxcar + gui_erp_simulation.square_op.Value=gui_erp_simulation.Paras{17}; + gui_erp_simulation.square_peakamp.String = num2str(gui_erp_simulation.Paras{18}); + gui_erp_simulation.square_onset.String= num2str(gui_erp_simulation.Paras{19}); + gui_erp_simulation.square_offset.String= num2str(gui_erp_simulation.Paras{20}); + if gui_erp_simulation.square_op.Value==1 + Enableflag = 'on'; + else + Enableflag = 'off'; + end + gui_erp_simulation.square_peakamp.Enable = Enableflag; + gui_erp_simulation.square_onset.Enable = Enableflag; + gui_erp_simulation.square_offset.Enable = Enableflag; + + %%sinusoidal signal + gui_erp_simulation.sin_op.Value = gui_erp_simulation.Paras{21}; + gui_erp_simulation.sin_amp.String =num2str(gui_erp_simulation.Paras{22}); + gui_erp_simulation.sin_fre.String=num2str(gui_erp_simulation.Paras{23}); + if gui_erp_simulation.sin_op.Value + Enableflag = 'on'; + else + Enableflag = 'off'; + end + gui_erp_simulation.sin_amp.Enable = Enableflag; + gui_erp_simulation.sin_fre.Enable = Enableflag; + %%white noise + gui_erp_simulation.white_op.Value=gui_erp_simulation.Paras{24}; + gui_erp_simulation.white_amp.String = num2str(gui_erp_simulation.Paras{25}); + if gui_erp_simulation.white_op.Value==1 + gui_erp_simulation.white_amp.Enable = 'on'; + else + gui_erp_simulation.white_amp.Enable = 'off'; + end + + %%pink noise + gui_erp_simulation.pink_op.Value=gui_erp_simulation.Paras{26}; + gui_erp_simulation.pink_amp.String = num2str(gui_erp_simulation.Paras{27}); + if gui_erp_simulation.pink_op.Value==1 + gui_erp_simulation.pink_amp.Enable = 'on'; + else + gui_erp_simulation.pink_amp.Enable = 'off'; + end end %%----------------------apply---------------------------------------------- function simulation_apply(~,~) - erpworkingmemory('f_ERP_proces_messg','Create Artificial ERP waveform'); + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=13 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_simulation.apply.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_simulation.apply.ForegroundColor = [1 1 1]; + ERP_simulation_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_stimulation',1); + + estudioworkingmemory('f_ERP_proces_messg','Create Artificial ERP waveform'); observe_ERPDAT.Process_messg =1; %%Marking for the procedure has been started. ALLERPCOM = evalin('base','ALLERPCOM'); @@ -1414,17 +1855,15 @@ function simulation_apply(~,~) Srate = str2num(gui_erp_simulation.srateedit.String); if isempty(Srate) || numel(Srate)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for sampling rate']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateedit.String = ''; return; end if Srate<=0 msgboxText = ['Create Artificial ERP Waveform>Sampling rate must be a positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateedit.String = ''; return; end @@ -1432,16 +1871,14 @@ function simulation_apply(~,~) Speriod = str2num(gui_erp_simulation.srateperiodedit.String); if isempty(Speriod) || numel(Speriod)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for sampling period']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateperiodedit.String = ''; return; end if Speriod<=0 msgboxText = ['Create Artificial ERP Waveform>Sampling period must be a positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); + estudioworkingmemory('f_ERP_proces_messg',msgboxText); observe_ERPDAT.Process_messg =4; gui_erp_simulation.srateperiodedit.String = ''; return; @@ -1450,30 +1887,26 @@ function simulation_apply(~,~) end if isempty(EpochStart) || numel(EpochStart)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for epoch start']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if isempty(EpochStop) || numel(EpochStop)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for epoch stop']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if EpochStop<=EpochStart msgboxText = ['Create Artificial ERP Waveform> Start time of epoch must be smaller than stop time of epoch']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if 1000/Srate>= (EpochStop-EpochStart) msgboxText = ['Create Artificial ERP Waveform> Please sampling period must be much smaller than ',32,num2str(EpochStop-EpochStart)]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end %%---------------------------Simulated signal------------------------------ @@ -1485,33 +1918,29 @@ function simulation_apply(~,~) BasPeakAmp = str2num(gui_erp_simulation.exgua_peakamp.String); if isempty(BasPeakAmp) || numel(BasPeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "peak amplitude" of ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end MeanLatOnset = str2num(gui_erp_simulation.exgua_mean.String); if isempty(MeanLatOnset) || numel(MeanLatOnset)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "Gaussian mean" of Ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end ExGauTau = str2num(gui_erp_simulation.exgua_tau.String); if isempty(ExGauTau) || numel(ExGauTau)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "Tau" of Ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end SDOffset = str2num(gui_erp_simulation.exgua_sd.String); if isempty(SDOffset) || numel(SDOffset)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "SD" of Ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end elseif gui_erp_simulation.impulse_op.Value ==1 @@ -1519,17 +1948,15 @@ function simulation_apply(~,~) BasPeakAmp = str2num(gui_erp_simulation.impulse_peakamp.String); if isempty(BasPeakAmp) || numel(BasPeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "peak amplitude" of impulse function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end MeanLatOnset = str2num(gui_erp_simulation.impulse_latency.String); if isempty(MeanLatOnset) || numel(MeanLatOnset)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "latency" of impulse function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end elseif gui_erp_simulation.square_op.Value ==1 @@ -1537,52 +1964,45 @@ function simulation_apply(~,~) BasPeakAmp = str2num(gui_erp_simulation.square_peakamp.String); if isempty(BasPeakAmp) || numel(BasPeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "peak amplitude" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end MeanLatOnset = str2num(gui_erp_simulation.square_onset.String); if isempty(MeanLatOnset) || numel(MeanLatOnset)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "onset" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end SDOffset = str2num(gui_erp_simulation.square_offset.String); if isempty(SDOffset) || numel(SDOffset)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "offset" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if SDOffset< MeanLatOnset msgboxText = ['Create Artificial ERP Waveform> Please "offset" should be larger than "onset" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end - end %%---------------------------Noise signal---------------------------------- if gui_erp_simulation.sin_op.Value==1 SinoiseAmp = str2num(gui_erp_simulation.sin_amp.String); if isempty(SinoiseAmp) || numel(SinoiseAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "amplitude" of sinusoidal noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end SinoiseFre = str2num(gui_erp_simulation.sin_fre.String); if isempty(SinoiseFre) || numel(SinoiseFre)~=1 || SinoiseFre<=0 msgboxText = ['Create Artificial ERP Waveform> Please define one positive numeric for "frequency" of sinusoidal noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end else @@ -1593,9 +2013,8 @@ function simulation_apply(~,~) WhiteAmp = str2num(gui_erp_simulation.white_amp.String); if isempty(WhiteAmp) || numel(WhiteAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "amplitude" of white noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end else @@ -1606,9 +2025,8 @@ function simulation_apply(~,~) PinkAmp = str2num(gui_erp_simulation.pink_amp.String); if isempty(PinkAmp) || numel(PinkAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "amplitude" of pink noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end else @@ -1616,59 +2034,83 @@ function simulation_apply(~,~) end NewnoiseFlag = gui_erp_simulation.newnoise_op.Value; - try - ALLERP = []; - [ERP, ERPCOM] = pop_ERP_simulation(ALLERP,BasFuncName,'EpochStart',EpochStart,'EpochStop',EpochStop,'Srate',Srate,'BasPeakAmp',BasPeakAmp,'MeanLatencyOnset',MeanLatOnset,'SDOffset',SDOffset,... - 'ExGauTau',ExGauTau,'SinoiseAmp',SinoiseAmp,'SinoiseFre',SinoiseFre,'WhiteAmp',WhiteAmp,'PinkAmp',PinkAmp,'NewnoiseFlag',NewnoiseFlag,'Saveas', 'off','History', 'gui'); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); - - Answer = f_ERP_save_single_file(strcat(ERP.erpname),ERP.filename,length(observe_ERPDAT.ALLERP)+1); - if isempty(Answer) - beep; - return; - end - - if ~isempty(Answer) - ERPName = Answer{1}; - if ~isempty(ERPName) - ERP.erpname = ERPName; - end - fileName_full = Answer{2}; - if isempty(fileName_full) - ERP.filename = ERP.erpname; - elseif ~isempty(fileName_full) - [pathstr, file_name, ext] = fileparts(fileName_full); - ext = '.erp'; - if strcmp(pathstr,'') - pathstr = cd; - end - ERP.filename = [file_name,ext]; - ERP.filepath = pathstr; - %%----------save the current sdata as-------------------- - [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); - [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + gui_erp_simulation.apply.BackgroundColor = [ 1 1 1]; + gui_erp_simulation.apply.ForegroundColor = [0 0 0]; + ERP_simulation_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [1 1 1]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_stimulation',0); + + gui_erp_simulation.Paras{1}=gui_erp_simulation.realerp_check.Value; + gui_erp_simulation.Paras{2} = str2num(gui_erp_simulation.erpsetedit.String); + gui_erp_simulation.Paras{3} = str2num(gui_erp_simulation.channeledit.String); + gui_erp_simulation.Paras{4} = str2num(gui_erp_simulation.binedit.String); + gui_erp_simulation.Paras{5} = str2num(gui_erp_simulation.epoch_start.String); + gui_erp_simulation.Paras{6} = str2num(gui_erp_simulation.epoch_stop.String); + gui_erp_simulation.Paras{7} = gui_erp_simulation.srate.Value; + gui_erp_simulation.Paras{8} = str2num(gui_erp_simulation.srateedit.String); + gui_erp_simulation.Paras{9} = gui_erp_simulation.exgua_op.Value; + gui_erp_simulation.Paras{10} = str2num(gui_erp_simulation.exgua_peakamp.String); + gui_erp_simulation.Paras{11} = str2num(gui_erp_simulation.exgua_mean.String); + gui_erp_simulation.Paras{12} = str2num(gui_erp_simulation.exgua_sd.String); + gui_erp_simulation.Paras{13} = str2num(gui_erp_simulation.exgua_tau.String); + gui_erp_simulation.Paras{14} = gui_erp_simulation.impulse_op.Value; + gui_erp_simulation.Paras{15} = str2num(gui_erp_simulation.impulse_peakamp.String); + gui_erp_simulation.Paras{16} = str2num(gui_erp_simulation.impulse_latency.String); + gui_erp_simulation.Paras{17} =gui_erp_simulation.square_op.Value; + gui_erp_simulation.Paras{18} =str2num(gui_erp_simulation.square_peakamp.String); + gui_erp_simulation.Paras{19} =str2num(gui_erp_simulation.square_onset.String); + gui_erp_simulation.Paras{20} =str2num(gui_erp_simulation.square_offset.String); + gui_erp_simulation.Paras{21} = gui_erp_simulation.sin_op.Value; + gui_erp_simulation.Paras{22} = str2num(gui_erp_simulation.sin_amp.String); + gui_erp_simulation.Paras{23} = str2num(gui_erp_simulation.sin_fre.String); + gui_erp_simulation.Paras{24} = gui_erp_simulation.white_op.Value; + gui_erp_simulation.Paras{25} = str2num(gui_erp_simulation.white_amp.String); + gui_erp_simulation.Paras{26} = gui_erp_simulation.pink_op.Value; + gui_erp_simulation.Paras{27} = str2num(gui_erp_simulation.pink_amp.String); + ALLERP = []; + [ERP, ERPCOM] = pop_ERP_simulation(ALLERP,BasFuncName,'EpochStart',EpochStart,'EpochStop',EpochStop,'Srate',Srate,'BasPeakAmp',BasPeakAmp,'MeanLatencyOnset',MeanLatOnset,'SDOffset',SDOffset,... + 'ExGauTau',ExGauTau,'SinoiseAmp',SinoiseAmp,'SinoiseFre',SinoiseFre,'WhiteAmp',WhiteAmp,'PinkAmp',PinkAmp,'NewnoiseFlag',NewnoiseFlag,'Saveas', 'off','History', 'gui'); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + + Answer = f_ERP_save_single_file(strcat(ERP.erpname),ERP.filename,length(observe_ERPDAT.ALLERP)+1); + if isempty(Answer) + return; + end + if ~isempty(Answer) + ERPName = Answer{1}; + if ~isempty(ERPName) + ERP.erpname = ERPName; + end + fileName_full = Answer{2}; + if isempty(fileName_full) + ERP.filename = ERP.erpname; + elseif ~isempty(fileName_full) + [pathstr, file_name, ext] = fileparts(fileName_full); + ext = '.erp'; + if strcmp(pathstr,'') + pathstr = cd; end + ERP.filename = [file_name,ext]; + ERP.filepath = pathstr; + %%----------save the current sdata as-------------------- + [ERP, issave, ERPCOM] = pop_savemyerp(ERP, 'erpname', ERP.erpname, 'filename', ERP.filename, 'filepath',ERP.filepath); + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); end - assignin('base','ALLERPCOM',ALLERPCOM); - assignin('base','ERPCOM',ERPCOM); - if length(observe_ERPDAT.ALLERP)==1 && strcmpi(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') - observe_ERPDAT.ALLERP = ERP; - else - observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; - end - observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); - observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); - estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); - erpworkingmemory('ERP_simulation',1); - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - observe_ERPDAT.Process_messg =2; - catch - % estudioworkingmemory('selectederpstudio',Selected_ERP_afd); - observe_ERPDAT.Process_messg =3; - observe_ERPDAT.Count_currentERP = observe_ERPDAT.Count_currentERP+1; - return; end - observe_ERPDAT.Two_GUI = observe_ERPDAT.Two_GUI+1; + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + if isempty(observe_ERPDAT.ALLERP) + observe_ERPDAT.ALLERP = ERP; + else + observe_ERPDAT.ALLERP(length(observe_ERPDAT.ALLERP)+1) = ERP; + end + observe_ERPDAT.CURRENTERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + estudioworkingmemory('selectederpstudio',observe_ERPDAT.CURRENTERP); + estudioworkingmemory('ERP_simulation',1); + observe_ERPDAT.Count_currentERP = 1; + observe_ERPDAT.Process_messg =2; end @@ -1676,7 +2118,6 @@ function simulation_apply(~,~) %%-----------------Plot ERP for the simulation----------------------------- %%------------------------------------------------------------------------- function plot_erp_simulation(~,~) - MatchFlag = gui_erp_simulation.realerp_check.Value; ALLERP = observe_ERPDAT.ALLERP; ERP = []; @@ -1735,17 +2176,15 @@ function plot_erp_simulation(~,~) srate = str2num(gui_erp_simulation.srateedit.String); if isempty(srate) || numel(srate)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for sampling rate']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateedit.String = ''; return; end if srate<=0 msgboxText = ['Create Artificial ERP Waveform>Sampling rate must be a positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateedit.String = ''; return; end @@ -1753,17 +2192,15 @@ function plot_erp_simulation(~,~) Speriod = str2num(gui_erp_simulation.srateperiodedit.String); if isempty(Speriod) || numel(Speriod)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for sampling period']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateperiodedit.String = ''; return; end if Speriod<=0 msgboxText = ['Create Artificial ERP Waveform>Sampling period must be positive numeric']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); gui_erp_simulation.srateperiodedit.String = ''; return; end @@ -1771,31 +2208,27 @@ function plot_erp_simulation(~,~) end if isempty(EpochStart) || numel(EpochStart)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for epoch start']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if isempty(EpochStop) || numel(EpochStop)~=1 msgboxText = ['Create Artificial ERP Waveform>Please define one numeric for epoch stop']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if EpochStop<=EpochStart msgboxText = ['Create Artificial ERP Waveform> Start time of epoch must be smaller than stop time of epoch']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if 1000/srate>= (EpochStop-EpochStart) msgboxText = ['Create Artificial ERP Waveform> Please sampling period must be much smaller than ',32,num2str(EpochStop-EpochStart)]; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end @@ -1865,9 +2298,8 @@ function plot_erp_simulation(~,~) [x2,y2] = find(roundn(Times,-3)==roundn(EpochStop,-3)); if isempty(y1) || isempty(y2) msgboxText = 'Create Artificial ERP Waveform> The exact time periods you have specified cannot be exactly created with the specified sampling rate. We will round to the nearest possible time values when the ERPset is created.'; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); end Desiredsignal = zeros(1,numel(Times)); Desirednosizesin = zeros(1,numel(Times)); @@ -1880,35 +2312,31 @@ function plot_erp_simulation(~,~) PeakAmp = str2num(gui_erp_simulation.exgua_peakamp.String); if isempty(PeakAmp) || numel(PeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "peak amplitude" of ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end Meanamp = str2num(gui_erp_simulation.exgua_mean.String); if isempty(Meanamp) || numel(Meanamp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "Gaussian mean" of Ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end Tau = str2num(gui_erp_simulation.exgua_tau.String); if isempty(Tau) || numel(Tau)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "Tau" of Ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end SD = str2num(gui_erp_simulation.exgua_sd.String); if isempty(SD) || numel(SD)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "SD" of Ex-Gaussian function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end SD = SD/100; @@ -1939,17 +2367,15 @@ function plot_erp_simulation(~,~) PeakAmp = str2num(gui_erp_simulation.impulse_peakamp.String); if isempty(PeakAmp) || numel(PeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "peak amplitude" of impulse function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end Latency = str2num(gui_erp_simulation.impulse_latency.String); if isempty(Latency) || numel(Latency)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "latency" of impulse function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if Latency Please define one numeric for "peak amplitude" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end onsetLat = str2num(gui_erp_simulation.square_onset.String); if isempty(onsetLat) || numel(onsetLat)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "onset" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end offsetLat = str2num(gui_erp_simulation.square_offset.String); if isempty(offsetLat) || numel(offsetLat)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "offset" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end if offsetLat< onsetLat msgboxText = ['Create Artificial ERP Waveform> Please "offset" should be larger than "onset" of Boxcar function']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end [xxx, latsamp, latdiffms] = closest(Times, [onsetLat,offsetLat]); @@ -1998,7 +2420,7 @@ function plot_erp_simulation(~,~) end %%---------------------------Noise signal---------------------------------- - % SimulationSeed = erpworkingmemory('SimulationSeed'); + % SimulationSeed = estudioworkingmemory('SimulationSeed'); SimulationSeed= gui_erp_simulation.SimulationSeed ; try SimulationSeed_Type = SimulationSeed.Type; @@ -2008,7 +2430,7 @@ function plot_erp_simulation(~,~) SimulationSeed_seed = 1; end %phase for sin noise - % SimulationPhase = erpworkingmemory('SimulationPhase'); + % SimulationPhase = estudioworkingmemory('SimulationPhase'); SimulationPhase = gui_erp_simulation.SimulationPhase; if isempty(SimulationPhase) || ~isnumeric(SimulationPhase) SimulationPhase = 0; @@ -2019,24 +2441,20 @@ function plot_erp_simulation(~,~) if SimulationPhase<0 || SimulationPhase>1 SimulationPhase = 0; end - - if gui_erp_simulation.sin_op.Value==1 PeakAmp = str2num(gui_erp_simulation.sin_amp.String); if isempty(PeakAmp) || numel(PeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "amplitude" of sinusoidal noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end FreHz = str2num(gui_erp_simulation.sin_fre.String); if isempty(FreHz) || numel(FreHz)~=1 || FreHz<=0 msgboxText = ['Create Artificial ERP Waveform> Please define one positive numeric for "frequency" of sinusoidal noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end X = Times/1000; @@ -2047,9 +2465,8 @@ function plot_erp_simulation(~,~) PeakAmp = str2num(gui_erp_simulation.white_amp.String); if isempty(PeakAmp) || numel(PeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "amplitude" of white noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end try @@ -2058,7 +2475,6 @@ function plot_erp_simulation(~,~) rng(1,'twister'); end Desirednosizewhite = randn(1,numel(Times));%%white noise - Desirednosizewhite = PeakAmp*Desirednosizewhite./max(abs(Desirednosizewhite(:))); end @@ -2066,9 +2482,8 @@ function plot_erp_simulation(~,~) PeakAmp = str2num(gui_erp_simulation.pink_amp.String); if isempty(PeakAmp) || numel(PeakAmp)~=1 msgboxText = ['Create Artificial ERP Waveform> Please define one numeric for "amplitude" of pink noise']; - fprintf(2,['\n Warning: ',msgboxText,'.\n']); - erpworkingmemory('f_ERP_proces_messg',msgboxText); - observe_ERPDAT.Process_messg =4; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); return; end try @@ -2076,38 +2491,37 @@ function plot_erp_simulation(~,~) catch rng(1,'twister'); end - Desirednosizepink = f_pinknoise(numel(Times)); - Desirednosizepink = reshape(Desirednosizepink,1,numel(Desirednosizepink)); Desirednosizepink = PeakAmp*Desirednosizepink./max(abs(Desirednosizepink(:))); - end Sig = Desirednosizesin+Desiredsignal+Desirednosizepink+Desirednosizewhite; if ~isempty(ERP) && ~isempty(ChannelArray) && ~isempty(binArray) try - % hold(handles.axes1,'on'); RealData = squeeze(ERP.bindata(ChannelArray,:,binArray)); plot(gui_erp_simulation.plot_erp,Times,[Sig;RealData],'linewidth',1.5); - % legend(gui_erp_simulation.plot_erp,{'Simulated data',['Real data at',32,ERP.chanlocs(ChannelArray).labels]},'FontSize',FonsizeDefault); - % legend(gui_erp_simulation.plot_erp,'boxoff'); catch end else plot(gui_erp_simulation.plot_erp,Times,Sig,'k','linewidth',1.5); - % legend(gui_erp_simulation.plot_erp,{'Simulated data'},'FontSize',FonsizeDefault); - % legend(gui_erp_simulation.plot_erp,'boxoff'); end - gui_erp_simulation.plot_erp.FontSize =12; + % gui_erp_simulation.plot_erp.FontSize =12; xlim(gui_erp_simulation.plot_erp,[Times(1),Times(end)]); end %%-------enable the panel for real data------------------------------------ function Count_currentERPChanged(~,~) - if length(observe_ERPDAT.ALLERP)==1 && strcmpi(observe_ERPDAT.ALLERP(1).erpname,'No ERPset loaded') + if observe_ERPDAT.Count_currentERP~=19 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 gui_erp_simulation.realerp_check.Value =0; EnableFlag = 'off'; gui_erp_simulation.realerp_check.Enable = EnableFlag; @@ -2117,6 +2531,9 @@ function Count_currentERPChanged(~,~) gui_erp_simulation.channelpopup.Enable = EnableFlag; gui_erp_simulation.binedit.Enable = EnableFlag; gui_erp_simulation.binpopup.Enable = EnableFlag; + gui_erp_simulation.newnoise_op.Enable = EnableFlag; + gui_erp_simulation.simulation_cancel.Enable = EnableFlag; + gui_erp_simulation.apply.Enable = EnableFlag; else gui_erp_simulation.realerp_check.Enable = 'on'; if gui_erp_simulation.realerp_check.Value==1 @@ -2130,6 +2547,9 @@ function Count_currentERPChanged(~,~) gui_erp_simulation.channelpopup.Enable = EnableFlag; gui_erp_simulation.binedit.Enable = EnableFlag; gui_erp_simulation.binpopup.Enable = EnableFlag; + gui_erp_simulation.newnoise_op.Enable = 'on'; + gui_erp_simulation.simulation_cancel.Enable = 'on'; + gui_erp_simulation.apply.Enable = 'on'; if gui_erp_simulation.realerp_check.Value==1 EnableFlags = 'off'; else @@ -2153,9 +2573,121 @@ function Count_currentERPChanged(~,~) gui_erp_simulation.srateperiodedit.Enable = 'on'; end end + gui_erp_simulation.Paras{1}=gui_erp_simulation.realerp_check.Value; + gui_erp_simulation.Paras{2} = str2num(gui_erp_simulation.erpsetedit.String); + gui_erp_simulation.Paras{3} = str2num(gui_erp_simulation.channeledit.String); + gui_erp_simulation.Paras{4} = str2num(gui_erp_simulation.binedit.String); + gui_erp_simulation.Paras{5} = str2num(gui_erp_simulation.epoch_start.String); + gui_erp_simulation.Paras{6} = str2num(gui_erp_simulation.epoch_stop.String); + gui_erp_simulation.Paras{7} = gui_erp_simulation.srate.Value; + gui_erp_simulation.Paras{8} = str2num(gui_erp_simulation.srateedit.String); + gui_erp_simulation.Paras{9} = gui_erp_simulation.exgua_op.Value; + gui_erp_simulation.Paras{10} = str2num(gui_erp_simulation.exgua_peakamp.String); + gui_erp_simulation.Paras{11} = str2num(gui_erp_simulation.exgua_mean.String); + gui_erp_simulation.Paras{12} = str2num(gui_erp_simulation.exgua_sd.String); + gui_erp_simulation.Paras{13} = str2num(gui_erp_simulation.exgua_tau.String); + gui_erp_simulation.Paras{14} = gui_erp_simulation.impulse_op.Value; + gui_erp_simulation.Paras{15} = str2num(gui_erp_simulation.impulse_peakamp.String); + gui_erp_simulation.Paras{16} = str2num(gui_erp_simulation.impulse_latency.String); + gui_erp_simulation.Paras{17} =gui_erp_simulation.square_op.Value; + gui_erp_simulation.Paras{18} =str2num(gui_erp_simulation.square_peakamp.String); + gui_erp_simulation.Paras{19} =str2num(gui_erp_simulation.square_onset.String); + gui_erp_simulation.Paras{20} =str2num(gui_erp_simulation.square_offset.String); + gui_erp_simulation.Paras{21} = gui_erp_simulation.sin_op.Value; + gui_erp_simulation.Paras{22} = str2num(gui_erp_simulation.sin_amp.String); + gui_erp_simulation.Paras{23} = str2num(gui_erp_simulation.sin_fre.String); + gui_erp_simulation.Paras{24} = gui_erp_simulation.white_op.Value; + gui_erp_simulation.Paras{25} = str2num(gui_erp_simulation.white_amp.String); + gui_erp_simulation.Paras{26} = gui_erp_simulation.pink_op.Value; + gui_erp_simulation.Paras{27} = str2num(gui_erp_simulation.pink_amp.String); + plot_erp_simulation(); + end + observe_ERPDAT.Count_currentERP=20; + end +%%--------------press return to execute "Apply"---------------------------- + function erp_simuls_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_stimulation'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + simulation_apply(); + gui_erp_simulation.apply.BackgroundColor = [ 1 1 1]; + gui_erp_simulation.apply.ForegroundColor = [0 0 0]; + ERP_simulation_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [1 1 1]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_stimulation',0); + else + return; end - plot_erp_simulation(); end +%%--------------reset this panel with the default parameters--------------- + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=16 + return; + end + gui_erp_simulation.apply.BackgroundColor = [ 1 1 1]; + gui_erp_simulation.apply.ForegroundColor = [0 0 0]; + ERP_simulation_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_simulation.simulation_cancel.BackgroundColor = [1 1 1]; + gui_erp_simulation.simulation_cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_stimulation',0); + gui_erp_simulation.realerp_check.Value=0; + EnableFlag = 'off'; + gui_erp_simulation.erpsetedit.Enable = EnableFlag; + gui_erp_simulation.erpsetedit.String = ''; + gui_erp_simulation.erpsetpopup.Enable = EnableFlag; + gui_erp_simulation.channeledit.Enable = EnableFlag; + gui_erp_simulation.channeledit.String = ''; + gui_erp_simulation.channelpopup.Enable = EnableFlag; + gui_erp_simulation.binedit.Enable = EnableFlag; + gui_erp_simulation.binedit.String = ''; + gui_erp_simulation.binpopup.Enable = EnableFlag; + EnableFlagn = 'on'; + gui_erp_simulation.epoch_start.Enable = EnableFlagn; + gui_erp_simulation.epoch_start.String = '-200'; + gui_erp_simulation.epoch_stop.Enable = EnableFlagn; + gui_erp_simulation.epoch_stop.String = '799'; + gui_erp_simulation.srate.Enable = EnableFlagn; + gui_erp_simulation.srate.Value=1; + gui_erp_simulation.srateedit.Enable = EnableFlagn; + gui_erp_simulation.srateedit.String = '1000'; + gui_erp_simulation.srateperiod.Enable = EnableFlagn; + gui_erp_simulation.srateperiod.Value=0; + gui_erp_simulation.srateperiodedit.Enable = EnableFlagn; + gui_erp_simulation.srateperiodedit.String = '1'; + %%ex-Gaussian + gui_erp_simulation.exgua_op.Value =1; + gui_erp_simulation.exgua_peakamp.Enable = 'on'; + gui_erp_simulation.exgua_peakamp.String = '1'; + gui_erp_simulation.exgua_mean.Enable = 'on'; + gui_erp_simulation.exgua_mean.String = '100'; + gui_erp_simulation.exgua_sd.Enable = 'on'; + gui_erp_simulation.exgua_sd.String = '50'; + gui_erp_simulation.exgua_tau.Enable = 'on'; + gui_erp_simulation.exgua_tau.String = '0'; + gui_erp_simulation.impulse_op.Value = 0; + gui_erp_simulation.impulse_peakamp.Enable = 'off'; + gui_erp_simulation.impulse_latency.Enable = 'off'; + gui_erp_simulation.square_op.Value = 0; + gui_erp_simulation.square_onset.Enable = 'off'; + gui_erp_simulation.square_offset.Enable = 'off'; + gui_erp_simulation.square_peakamp.Enable = 'off'; + %%sin noise + gui_erp_simulation.sin_op.Value=0; + gui_erp_simulation.sin_amp.Enable = 'off'; + gui_erp_simulation.sin_fre.Enable = 'off'; + %%white noise + gui_erp_simulation.white_op.Value=0; + gui_erp_simulation.white_amp.Enable ='off'; + %%pink noise + gui_erp_simulation.pink_op.Value=0; + gui_erp_simulation.pink_amp.Enable = 'off'; + plot_erp_simulation(); + observe_ERPDAT.Reset_erp_paras_panel=17; + end end %Progem end: ERP simulation \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_spectral_GUI.m b/studio_functions/GUIs/ERP Tab/f_ERP_spectral_GUI.m index db63c73b..4d1745e6 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_spectral_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_spectral_GUI.m @@ -2,25 +2,22 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 & Nov. 2023 % ERPLAB Studio function varargout = f_ERP_spectral_GUI(varargin) -% global gui_erp_spectral; global observe_ERPDAT; -% addlistener(observe_ERPDAT,'ALLERP_change',@erpschange); -% addlistener(observe_ERPDAT,'ERP_change',@drawui_CB); -% addlistener(observe_ERPDAT,'CURRENTERP_change',@cerpchange); addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); -% erp_m_t_p = S_OUT.geterpvalues; -defaulpar = erpworkingmemory('f_ERP_spectral'); +defaulpar = estudioworkingmemory('f_ERP_spectral'); defaulpar{1} = 0;defaulpar{2} = [];defaulpar{3} = [];defaulpar{4} = [];defaulpar{5} = []; defaulpar{6} = [];defaulpar{7} = []; -erpworkingmemory('f_ERP_spectral',defaulpar); +estudioworkingmemory('f_ERP_spectral',defaulpar); %%---------------------------gui------------------------------------------- try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; @@ -45,7 +42,7 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end erp_spectral_gui(FonsizeDefault); @@ -57,13 +54,7 @@ function erp_spectral_gui(FonsizeDefault) catch ColorB_def = [0.95 0.95 0.95]; end - - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; - end - + Enable_label = 'off'; gui_erp_spectral.spectral = uiextras.VBox('Parent',ERP_filtering_box,'Spacing',1,'BackgroundColor',ColorB_def); @@ -75,47 +66,93 @@ function erp_spectral_gui(FonsizeDefault) set(gui_erp_spectral.dispaly_title,'HorizontalAlignment','left'); gui_erp_spectral.amplitude = uicontrol('Style', 'radiobutton','Parent', gui_erp_spectral.amplitude_option,'String','Amplitude',... 'callback',@spectral_amplitude,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.amplitude.KeyPressFcn= @erp_spectral_presskey; gui_erp_spectral.phase = uicontrol('Style', 'radiobutton','Parent', gui_erp_spectral.amplitude_option,... 'String','Phase','callback',@spectral_phase,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.phase.KeyPressFcn= @erp_spectral_presskey; set( gui_erp_spectral.amplitude_option, 'Sizes', [80 100 100]); %%%power and dB gui_erp_spectral.pow_db = uiextras.HBox('Parent', gui_erp_spectral.spectral,'Spacing',1,'BackgroundColor',ColorB_def); uiextras.Empty('Parent', gui_erp_spectral.pow_db); gui_erp_spectral.power = uicontrol('Style', 'radiobutton','Parent', gui_erp_spectral.pow_db ,... 'String','Power','callback',@spectral_power,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.power.KeyPressFcn= @erp_spectral_presskey; gui_erp_spectral.db = uicontrol('Style', 'radiobutton','Parent', gui_erp_spectral.pow_db ,... 'String','dB','callback',@spectral_db,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.db.KeyPressFcn= @erp_spectral_presskey; set( gui_erp_spectral.pow_db , 'Sizes', [80 100 100]); %%% + if gui_erp_spectral.phase.Value==1 + gui_erp_spectral.Paras{1}=2; + elseif gui_erp_spectral.power.Value==1 + gui_erp_spectral.Paras{1}=3; + elseif gui_erp_spectral.db.Value==1 + gui_erp_spectral.Paras{1}=4; + else + gui_erp_spectral.Paras{1}=1; + end gui_erp_spectral.hamwin_title_option = uiextras.HBox('Parent', gui_erp_spectral.spectral,'Spacing',1,'BackgroundColor',ColorB_def); gui_erp_spectral.hamwin_title = uicontrol('Style','text','Parent', gui_erp_spectral.hamwin_title_option,'String','Hamming window:','FontSize',FonsizeDefault); set( gui_erp_spectral.hamwin_title,'HorizontalAlignment','left','BackgroundColor',ColorB_def); gui_erp_spectral.hamwin_on = uicontrol('Style', 'radiobutton','Parent', gui_erp_spectral.hamwin_title_option,... 'String','On','callback',@spectral_hamwin_on,'Value',1,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.hamwin_on.KeyPressFcn= @erp_spectral_presskey; gui_erp_spectral.hamwin_off = uicontrol('Style', 'radiobutton','Parent', gui_erp_spectral.hamwin_title_option,... 'String','Off','callback',@spectral_hamwin_off,'Value',0,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.hamwin_off.KeyPressFcn= @erp_spectral_presskey; uiextras.Empty('Parent', gui_erp_spectral.hamwin_title_option,'BackgroundColor',ColorB_def); set( gui_erp_spectral.hamwin_title_option, 'Sizes', [120 60 60 40]); - - + gui_erp_spectral.Paras{2}=gui_erp_spectral.hamwin_on.Value; + + %%frequency range + gui_erp_spectral.frerange_title = uiextras.HBox('Parent',gui_erp_spectral.spectral,'Spacing',1,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent',gui_erp_spectral.frerange_title,... + 'String','Freq. range [min max]:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_spectral.frerange = uicontrol('Style','edit','Parent',gui_erp_spectral.frerange_title,... + 'String',' ','callback',@frerange,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_erp_spectral.frerange.KeyPressFcn= @erp_spectral_presskey; + gui_erp_spectral.Paras{3} = []; + set(gui_erp_spectral.frerange_title,'Sizes',[120 -1]); + + %% gui_erp_spectral.other_option = uiextras.HBox('Parent',gui_erp_spectral.spectral,'Spacing',1,'BackgroundColor',ColorB_def); + gui_erp_spectral.cancel = uicontrol('Style','pushbutton','Parent',gui_erp_spectral.other_option,... + 'String','Cancel','callback',@spectral_cancel,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); gui_erp_spectral.plot = uicontrol('Style','pushbutton','Parent',gui_erp_spectral.other_option,... - 'String','Plot','callback',@spectral_plot,'Enable',Enable_label,'FontSize',FonsizeDefault); + 'String','Plot','callback',@spectral_plot,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); gui_erp_spectral.save = uicontrol('Style','pushbutton','Parent',gui_erp_spectral.other_option,... - 'String','Save','callback',@spectral_save,'Enable',Enable_label,'FontSize',FonsizeDefault); - gui_erp_spectral.advanced = uicontrol('Parent',gui_erp_spectral.other_option,'Style','pushbutton',... - 'String','Advanced','callback',@spectral_advanced,'Enable',Enable_label,'FontSize',FonsizeDefault); - - set(gui_erp_spectral.spectral, 'Sizes', [20 20 20 30]); + 'String','Save','callback',@spectral_save,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + set(gui_erp_spectral.spectral, 'Sizes', [20 20 20 25 30]); + estudioworkingmemory('ERPTab_spectral',0); end -%%**************************************************************************************************************************************** -%%******************* Subfunctions *************************************************************************************************** -%%**************************************************************************************************************************************** +%%************************************************************************* +%%******************* Subfunctions ************************************ +%%************************************************************************* %%--------------------------------setting for amplitude------------------ function spectral_amplitude(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + + estudioworkingmemory('ERPTab_spectral',1); + gui_erp_spectral.amplitude.Value =1; gui_erp_spectral.phase.Value = 0; gui_erp_spectral.power.Value = 0; @@ -124,6 +161,25 @@ function spectral_amplitude(source,~) %%--------------------------Setting for phase----------------------------- function spectral_phase(source,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_spectral',1); + gui_erp_spectral.phase.Value = 1; gui_erp_spectral.amplitude.Value =0; gui_erp_spectral.power.Value = 0; @@ -132,6 +188,25 @@ function spectral_phase(source,~) %%--------------------Setting for power------------------------------------ function spectral_power(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_spectral',1); + gui_erp_spectral.phase.Value = 0; gui_erp_spectral.amplitude.Value =0; gui_erp_spectral.power.Value =1; @@ -140,6 +215,25 @@ function spectral_power(~,~) %%--------------------Setting for dB------------------------------------ function spectral_db(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_spectral',1); + gui_erp_spectral.phase.Value = 0; gui_erp_spectral.amplitude.Value =0; gui_erp_spectral.power.Value =0; @@ -149,720 +243,396 @@ function spectral_db(~,~) %%-------------------------Setting for hamming window:on------------------- function spectral_hamwin_on(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_spectral',1); + gui_erp_spectral.hamwin_on.Value = 1; gui_erp_spectral.hamwin_off.Value = 0; end %%-------------------------Setting for hamming window:off------------------- function spectral_hamwin_off(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_spectral',1); gui_erp_spectral.hamwin_on.Value = 0; gui_erp_spectral.hamwin_off.Value = 1; end +%%----------------------frequency range------------------------------------ + function frerange(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [ 0.5137 0.7569 0.9176]; + gui_erp_spectral.plot.ForegroundColor = [1 1 1]; + ERP_filtering_box.TitleColor= [ 0.5137 0.7569 0.9176];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.save.ForegroundColor = [1 1 1]; + + gui_erp_spectral.cancel.BackgroundColor = [0.5137 0.7569 0.9176]; + gui_erp_spectral.cancel.ForegroundColor = [1 1 1]; + estudioworkingmemory('ERPTab_spectral',1); + + FreqRange = str2num(gui_erp_spectral.frerange.String); + if isempty(FreqRange) || numel(FreqRange)~=2 || any(FreqRange(:)>floor(observe_ERPDAT.ERP.srate/2)) || any(FreqRange(:)<0) + FreqRange = [0 floor(observe_ERPDAT.ERP.srate/2)]; + gui_erp_spectral.frerange.String = num2str(FreqRange); + msgboxText = ['Spectral Analysis>Freq. range [min max]: it should have two values and between 0 and',32,num2str(floor(observe_ERPDAT.ERP.srate/2))]; + titlNamerro = 'Warning for ERP Tab'; + estudio_warning(msgboxText,titlNamerro); + end + end -%%--------------------------Setting for plot------------------------------- - function spectral_plot(~,~) - if gui_erp_spectral.hamwin_on.Value - iswindowed =1; - else - iswindowed = 0; +%%-----------------------------cancel-------------------------------------- + function spectral_cancel(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end - - Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_erpset); + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end - - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan =S_binchan.checked_ERPset_Index; - - - defaulpar1 = erpworkingmemory('f_ERP_spectral'); - BinArray = []; - ChanArray = []; - FreqRange = []; - - if checked_ERPset_Index_bin_chan(1) ==1 - BinArray = []; - elseif checked_ERPset_Index_bin_chan(2) ==2 - ChanArray = []; + gui_erp_spectral.plot.BackgroundColor = [1 1 1]; + gui_erp_spectral.plot.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [1 1 1]; + gui_erp_spectral.save.ForegroundColor = [0 0 0]; + + gui_erp_spectral.cancel.BackgroundColor = [1 1 1]; + gui_erp_spectral.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_spectral',0); + amplitude = gui_erp_spectral.Paras{1}; + if isempty(amplitude) || numel(amplitude)~=1 || (amplitude~=1 && amplitude~=2 && amplitude~=3 && amplitude~=4) + amplitude = 1; + gui_erp_spectral.Paras{1}=1; end - - try - - BinArray = S_binchan.bins{1}; - ChanArray = S_binchan.elecs_shown{1}; - catch - BinArray = []; - ChanArray = []; + if amplitude==2 + gui_erp_spectral.amplitude.Value = 0; + gui_erp_spectral.phase.Value=1; + gui_erp_spectral.power.Value=0; + gui_erp_spectral.db.Value=0; + elseif amplitude==3 + gui_erp_spectral.amplitude.Value = 0; + gui_erp_spectral.phase.Value=0; + gui_erp_spectral.power.Value=1; + gui_erp_spectral.db.Value=0; + elseif amplitude==4 + gui_erp_spectral.amplitude.Value = 0; + gui_erp_spectral.phase.Value=0; + gui_erp_spectral.power.Value=0; + gui_erp_spectral.db.Value=1; + else + gui_erp_spectral.amplitude.Value = 1; + gui_erp_spectral.phase.Value=0; + gui_erp_spectral.power.Value=0; + gui_erp_spectral.db.Value=0; end - %%Plot the spectrum for the selected ERPset - % try - for Numoferpset = 1:numel(Selected_erpset) - %%% - ERP_curret_s = observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)); - if strcmp(ERP_curret_s.datatype,'ERP') - ERP_FFT = f_getFFTfromERP(ERP_curret_s,iswindowed); - elseif strcmp(ERP_curret_s.datatype,'EFFT') - ERP_FFT = ERP_curret_s; - end - - ColumnNum = 1; - if isempty(BinArray) - BinArray = [1:ERP_curret_s.nbin]; - end - - if isempty(ChanArray) - ChanArray = [1:ERP_curret_s.nchan]; - end - - if max(BinArray(:))> ERP_FFT.nbin - BinArray = [1:ERP_FFT.nbin]; - end - - if max(ChanArray(:))> ERP_FFT.nchan - ChanArray = [1:ERP_FFT.nchan]; - end - RowNum = ceil(numel(ChanArray)/ColumnNum); - - if gui_erp_spectral.amplitude.Value - ERP_FFT.bindata = abs(ERP_FFT.bindata); - figure_name = ['Spectral analysis: Amplitude for ',32,ERP_FFT.erpname]; - elseif gui_erp_spectral.phase.Value - ERP_FFT.bindata = angle(ERP_FFT.bindata); - figure_name = ['Spectral analysis: Phase for ',32,ERP_FFT.erpname]; - elseif gui_erp_spectral.power.Value - ERP_FFT.bindata = abs(ERP_FFT.bindata).^2; - figure_name = ['Spectral analysis: Power for ',32,ERP_FFT.erpname]; - elseif gui_erp_spectral.db.Value - ERP_FFT.bindata = 20*log10(abs(ERP_FFT.bindata)); - figure_name = ['Spectral analysis: dB for ',32,ERP_FFT.erpname]; - end - - fig = figure('Name',figure_name); - set(fig,'outerposition',get(0,'screensize')); - - line_colors = erpworkingmemory('PWColor'); - if size(line_colors,1)~= ERP_FFT.nbin - if ERP_FFT.nbin> size(line_colors,1) - line_colors = get_colors(ERP_FFT.nbin); - else - line_colors = line_colors(1:ERP_FFT.nbin,:,:); - end - end - - if isempty(line_colors) - line_colors = get_colors(ERP_FFT.nbin); - end - FreqRange=[ERP_FFT.times(1), ERP_FFT.times(end)]; - FreqTick = default_time_ticks(ERP_FFT, FreqRange); - FreqTick = str2num(FreqTick{1}); - ERP_FFT.bindata = ERP_FFT.bindata(ChanArray,:,BinArray); - ERP_FFT.nbin = numel(BinArray); - ERP_FFT.nchan = numel(ChanArray); - ERP_FFT.chanlocs = ERP_FFT.chanlocs(ChanArray); - ERP_FFT.bindescr = ERP_FFT.bindescr(BinArray); - - pbox = f_getrow_columnautowaveplot(ChanArray); - try - RowNum = pbox(1); - ColumnNum = pbox(2); - catch - RowNum = numel(ChanArray); - ColumnNum = 1; - end - - count = 0; - for Numofcolumn = 1:ColumnNum - for Numofrow = 1: RowNum - count = count+1; - if ColumnNum*RowNum<5 - pause(1); - end - if count>ERP_FFT.nchan - break; - end - p_ax = subplot(RowNum,ColumnNum,count); - set(gca,'fontsize',14); - hold on; - temp = squeeze(ERP_FFT.bindata); - for Numofplot = 1:ERP_FFT.nbin - h_p(Numofplot) = plot(p_ax,ERP_FFT.times,squeeze(ERP_FFT.bindata(count,:,Numofplot)),'LineWidth',1,'Color',line_colors(Numofplot,:,:)); - end - axis(p_ax,[floor(ERP_FFT.times(1)),ceil(ERP_FFT.times(end)), 1.1*min(temp(:)) 1.1*max(temp(:))]); - xticks(p_ax,FreqTick); - if count == 1 - title(p_ax,[ERP_FFT.chanlocs(count).labels],'FontSize',14); %#ok<*NODEF> - legend(p_ax,ERP_FFT.bindescr,'FontSize',14); - legend(p_ax,'boxoff'); - else - title(p_ax,ERP_FFT.chanlocs(count).labels,'FontSize',14); - end - xlabel(p_ax,'Frequency/Hz','FontSize',14); - if gui_erp_spectral.phase.Value - ylabel(p_ax,'Angle/degree','FontSize',14); - elseif gui_erp_spectral.amplitude.Value - ylabel(p_ax,'Amplitude/\muV','FontSize',14); - elseif gui_erp_spectral.power.Value - ylabel(p_ax,'Power/\muV^2','FontSize',14); - elseif gui_erp_spectral.db.Value - ylabel(p_ax,'Decibels/dB','FontSize',14); - end - for NUmoflabel = 1:length(ERP_FFT.times) - X_label{NUmoflabel} = []; - end - set(gca,'TickDir','out'); - set(gca,'LineWidth',2); - end - end - - end%%end loop for ERPSET + hamwin_on = gui_erp_spectral.Paras{2}; + if isempty(hamwin_on) ||numel(hamwin_on)~=1 || (hamwin_on~=0 && hamwin_on~=1) + hamwin_on =1; + gui_erp_spectral.Paras{2}=1; + end + if gui_erp_spectral.phase.Value==1 + gui_erp_spectral.Paras{1}=2; + elseif gui_erp_spectral.power.Value==1 + gui_erp_spectral.Paras{1}=3; + elseif gui_erp_spectral.db.Value==1 + gui_erp_spectral.Paras{1}=4; + else + gui_erp_spectral.Paras{1}=1; + end + gui_erp_spectral.Paras{2}=gui_erp_spectral.hamwin_on.Value; + gui_erp_spectral.hamwin_on.Value=hamwin_on; + gui_erp_spectral.hamwin_off.Value=~hamwin_on; + try frerange = gui_erp_spectral.Paras{3} ;catch frerange = []; end; + if isempty(frerange) || numel(frerange)~=2 || any(frerange(:)>floor(observe_ERPDAT.ERP.srate/2)) + frerange = [0 floor(observe_ERPDAT.ERP.srate/2)]; + gui_erp_spectral.Paras{3} = [0 floor(observe_ERPDAT.ERP.srate/2)]; + end + gui_erp_spectral.frerange.String = num2str(frerange); end - -%%-----------------Setting for save option--------------------------------- - function spectral_save(~,~) - pathName = erpworkingmemory('ERP_save_folder'); - if isempty(pathName) - pathName = cd; +%%--------------------------Setting for plot------------------------------- + function spectral_plot(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel + end + gui_erp_spectral.plot.BackgroundColor = [1 1 1]; + gui_erp_spectral.plot.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [1 1 1]; + gui_erp_spectral.save.ForegroundColor = [0 0 0]; + + gui_erp_spectral.cancel.BackgroundColor = [1 1 1]; + gui_erp_spectral.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_spectral',0); if gui_erp_spectral.hamwin_on.Value iswindowed =1; else iswindowed = 0; end - Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_erpset); + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan =S_binchan.checked_ERPset_Index; - - - BinArray = []; - ChanArray = []; - FreqRange = []; - - if checked_ERPset_Index_bin_chan(1) ==1 - BinArray = []; - elseif checked_ERPset_Index_bin_chan(2) ==2 - ChanArray = []; + if gui_erp_spectral.phase.Value==1 + gui_erp_spectral.Paras{1}=2; + elseif gui_erp_spectral.power.Value==1 + gui_erp_spectral.Paras{1}=3; + elseif gui_erp_spectral.db.Value==1 + gui_erp_spectral.Paras{1}=4; + else + gui_erp_spectral.Paras{1}=1; end - - try - BinArray = S_binchan.bins{1}; - ChanArray = S_binchan.elecs_shown{1}; - catch - BinArray = []; - ChanArray = []; + Amptypev = gui_erp_spectral.Paras{1}; + if Amptypev==2 + Amptype = 'phase'; + elseif Amptypev==3 + Amptype = 'power'; + elseif Amptypev==4 + Amptype = 'db'; + else + Amptype = 'amp'; end - try - ALLERPCOM = evalin('base','ALLERPCOM'); - catch - ALLERPCOM = []; - assignin('base','ALLERPCOM',ALLERPCOM); + + freqrange = str2num(gui_erp_spectral.frerange.String); + if isempty(freqrange) || numel(freqrange)~=2 || any(freqrange(:)>floor(observe_ERPDAT.ERP.srate/2)) || any(freqrange(:)<0) + freqrange = [0 floor(observe_ERPDAT.ERP.srate/2)]; + gui_erp_spectral.frerange.String = num2str(freqrange); end - %%Plot the spectrum for the selected ERPset - %-----------Setting for import------------------------------------- - try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - catch - ColorB_def = [0.7020 0.77 0.85]; - end - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',ColorB_def); - [ind,tf] = listdlg('ListString',{'".mat"','".csv"'},'SelectionMode','single','PromptString','Please select a type to export to...','Name','Export Spectrum for Selected ERPset to','OKString','Ok'); - set(0,'DefaultUicontrolBackgroundColor',[1 1 1]); - if isempty(ind) - beep; - disp(['User selected cancel']); - return; + gui_erp_spectral.Paras{3} =freqrange; + + if iswindowed==1 + TaperWindow = 'on'; + else + TaperWindow = 'off'; end - for Numoferpset = 1:numel(Selected_erpset) + + ChanArray = estudioworkingmemory('ERP_ChanArray'); + BinArray = estudioworkingmemory('ERP_BinArray'); + + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = []; end + for Numoferpset = 1:numel(ERPArray) %%% - ERP_curret_s = observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)); - if strcmp(ERP_curret_s.datatype,'ERP') - ERP_FFT = f_getFFTfromERP(ERP_curret_s,iswindowed); - else - ERP_FFT = ERP_curret_s; - end - if isempty(BinArray) - BinArray = [1:ERP_curret_s.nbin]; + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferpset)); + if isempty(freqrange) || numel(freqrange)~=2 || any(freqrange(:)>floor(ERP.srate/2)) || any(freqrange(:)<0) + freqrange = [0 floor(ERP.srate/2)]; end - if isempty(ChanArray) - ChanArray = [1:ERP_curret_s.nchan]; + if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; end - - if max(BinArray(:))> ERP_FFT.nbin - BinArray = [1:ERP_FFT.nbin]; + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = 1:ERP.nbin; end - - if max(ChanArray(:))> ERP_FFT.nchan - ChanArray = [1:ERP_FFT.nchan]; - end - - if isempty(FreqRange) || FreqRange(2)>ERP_FFT.times(end) - FreqRange=[ERP_FFT.times(1), ERP_FFT.times(end)]; - end - [xxx, latsamp, latdiffms] = closest(ERP_FFT.times, FreqRange); - tmin = latsamp(1); - tmax = latsamp(2); - ERP_FFT.bindata = ERP_FFT.bindata(ChanArray,tmin:tmax,BinArray); - ERP_FFT.nbin = numel(BinArray); - ERP_FFT.nchan = numel(ChanArray); - ERP_FFT.chanlocs = ERP_FFT.chanlocs(ChanArray); - ERP_FFT.bindescr = ERP_FFT.bindescr(BinArray); - ERP_FFT.times = ERP_FFT.times(tmin:tmax); - - if strcmp(ERP_curret_s.datatype,'ERP') - if gui_erp_spectral.amplitude.Value - ERP_FFT.bindata = abs(ERP_FFT.bindata); - figure_name = [ERP_FFT.erpname,'_Spectrum_Amplitude']; - elseif gui_erp_spectral.phase.Value - ERP_FFT.bindata = angle(ERP_FFT.bindata); - figure_name = [ERP_FFT.erpname,'_Spectrum_Phase']; - elseif gui_erp_spectral.power.Value - ERP_FFT.bindata = abs(ERP_FFT.bindata).^2; - figure_name = [ERP_FFT.erpname,'_Spectrum_Power']; - elseif gui_erp_spectral.db.Value - ERP_FFT.bindata = 20*log10(abs(ERP_FFT.bindata)); - figure_name = [ERP_FFT.erpname,'_Spectrum_ dB']; - end + [~, ERPCOM] = pop_ERP_spectralanalysis(ERP, 'Amptype',Amptype,'TaperWindow',TaperWindow,... + 'freqrange',freqrange,'BinArray',BinArray,'ChanArray',ChanArray,'Plotwave','on','Saveas', 'off','History','gui'); + if Numoferpset == numel(ERPArray) + [observe_ERPDAT.ALLERP(ERPArray(Numoferpset)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); else - if gui_erp_spectral.amplitude.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_amplitude']; - elseif gui_erp_spectral.phase.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_phase']; - elseif gui_erp_spectral.power.Value - figure_name = strcat(ERP_FFT.erpname,'Spectrum_Power'); - - elseif gui_erp_spectral.db.Value - figure_name = strcat(ERP_FFT.erpname,'_Spectrum_dB'); - end + [observe_ERPDAT.ALLERP(ERPArray(Numoferpset)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - - if ind==1 - - [filenamei, pathname] = uiputfile({'*.mat';'*.*'},['Save',32,'"',ERP_FFT.erpname,'"', 32,'as'],fullfile(pathName,figure_name)); - if isequal(filenamei,0) - disp('User selected Cancel') - return - else - [pathx, filename, ext] = fileparts(filenamei); - ext = '.mat'; - filename = [filename ext]; - end - - if strcmpi(ext,'.mat') - [ERP_FFT, issave, ERPCOM] = pop_savemyerp(ERP_FFT, 'erpname', ERP_FFT.erpname, 'filename', filename, 'filepath',pathname); - [~, ALLERPCOM] = erphistory(ERP_FFT, ALLERPCOM, ERPCOM); - end - - %%save as '.csv' - elseif ind==2 - def = erpworkingmemory('f_export2csvGUI'); - if isempty(def) - def = {1, 1, 1, 3, ''}; - end - def{5} = fullfile(pathName,ERP_FFT.filename); - answer_export = f_export2csvGUI(ERP_FFT,def); - erpworkingmemory('f_export2csvGUI',answer_export); - if isempty(answer_export) - beep; - disp('User selected cancel!!!'); - return; - end - binArray = [1:ERP_FFT.nbin]; - decimal_num = answer_export{4}; - istime =answer_export{1} ; - electrodes=answer_export{2} ; - transpose=answer_export{3}; - filenamei = answer_export{5}; - [pathx, filename, ext] = fileparts(filenamei); - ext = '.csv'; - if isempty(pathx) - pathx =cd; - end - filename = [filename ext]; - mkdir([pathx,filesep]); - try - export2csv_spectranl_analysis(ERP_FFT,fullfile(pathx,filename), binArray,istime, electrodes,transpose, decimal_num); - catch - beep; - disp('Fail to save selected ERPset as ".csv"!!!'); - return; - end - end - - end + end%%end loop for ERPSET + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP=20; + gui_erp_spectral.Paras{2}=gui_erp_spectral.hamwin_on.Value; end -%%-------------------Setting for advance option--------------------------- - function spectral_advanced(~,~) - pathName_folder = erpworkingmemory('ERP_save_folder'); - if isempty(pathName_folder) - pathName_folder = cd; +%%-----------------Setting for save option--------------------------------- + function spectral_save(~,~) + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end + %%first checking if the changes on the other panels have been applied + [messgStr,eegpanelIndex] = f_check_erptab_panelchanges(); + if ~isempty(messgStr) && eegpanelIndex~=9 + observe_ERPDAT.Count_currentERP=eegpanelIndex+1;%%call the functions from the other panel end + gui_erp_spectral.plot.BackgroundColor = [1 1 1]; + gui_erp_spectral.plot.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [1 1 1]; + gui_erp_spectral.save.ForegroundColor = [0 0 0]; + + gui_erp_spectral.cancel.BackgroundColor = [1 1 1]; + gui_erp_spectral.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_spectral',0); + + estudioworkingmemory('f_ERP_proces_messg','Spectral Analysis - Save'); + observe_ERPDAT.Process_messg =1; + if gui_erp_spectral.hamwin_on.Value iswindowed =1; else iswindowed = 0; end - - try - def = erpworkingmemory('f_spectral_analysis_adavance'); - catch - def = {1,[], [], [1 16], 1, 1,1,0}; - end - if isempty(def) - def = {1,[], [], [1 16], 1, 1,1,0}; - - end - try - ALLERPCOM = evalin('base','ALLERPCOM'); - catch - ALLERPCOM = []; - assignin('base','ALLERPCOM',ALLERPCOM); - end - - Selected_erpset = estudioworkingmemory('selectederpstudio'); - if isempty(Selected_erpset) - Selected_erpset = observe_ERPDAT.CURRENTERP; - S_erpbinchan = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,Selected_erpset); - estudioworkingmemory('geterpbinchan',S_erpbinchan.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpbinchan.geterpplot); - estudioworkingmemory('selectederpstudio',Selected_erpset); + ERPArray = estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) + ERPArray = observe_ERPDAT.CURRENTERP; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = ERPArray; end - S_binchan = estudioworkingmemory('geterpbinchan'); - checked_ERPset_Index_bin_chan =S_binchan.checked_ERPset_Index; - - try - BinArray = S_binchan.bins{1}; - ChanArray = S_binchan.elecs_shown{1}; - catch - BinArray = []; - ChanArray = []; + if gui_erp_spectral.phase.Value==1 + gui_erp_spectral.Paras{1}=2; + elseif gui_erp_spectral.power.Value==1 + gui_erp_spectral.Paras{1}=3; + elseif gui_erp_spectral.db.Value==1 + gui_erp_spectral.Paras{1}=4; + else + gui_erp_spectral.Paras{1}=1; end - - def{2} = BinArray; - def{3} = ChanArray; - - ERP_d =f_getFFTfromERP(observe_ERPDAT.ERP,iswindowed); - - - defaulpar1 = f_spectral_analysis_advance(ERP_d,def); - if isempty(defaulpar1) - beep; - disp('User selected cancel!!!'); - return; + Amptypev = gui_erp_spectral.Paras{1}; + if Amptypev==2 + Amptype = 'phase'; + elseif Amptypev==3 + Amptype = 'power'; + elseif Amptypev==4 + Amptype = 'db'; + else + Amptype = 'amp'; end - erpworkingmemory('f_spectral_analysis_adavance',defaulpar1); - - BinArray = defaulpar1{2}; - ChanArray = defaulpar1{3}; - if checked_ERPset_Index_bin_chan(1)==1 - BinArray = []; + freqrange = str2num(gui_erp_spectral.frerange.String); + if isempty(freqrange) || numel(freqrange)~=2 || any(freqrange(:)>floor(observe_ERPDAT.ERP.srate/2)) || any(freqrange(:)<0) + freqrange = [0 floor(observe_ERPDAT.ERP.srate/2)]; + gui_erp_spectral.frerange.String = num2str(freqrange); end + gui_erp_spectral.Paras{3} =freqrange; - if checked_ERPset_Index_bin_chan(2) ==2 - ChanArray = []; + if iswindowed==1 + TaperWindow = 'on'; + else + TaperWindow = 'off'; end - FreqRange = defaulpar1{4}; - FreqTick = defaulpar1{5}; - RowNum = defaulpar1{6}; - ColumnNum = defaulpar1{7}; - Save_label = defaulpar1{8}; + ChanArray = estudioworkingmemory('ERP_ChanArray'); + BinArray = estudioworkingmemory('ERP_BinArray'); - if Save_label - try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - catch - ColorB_def = [0.7020 0.77 0.85]; - end - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',ColorB_def); - [ind,tf] = listdlg('ListString',{'".mat"','".csv"'},'SelectionMode','single','PromptString','Please select a type to export to...','Name','Export Spctrum for Selected ERPset to','OKString','Ok'); - set(0,'DefaultUicontrolBackgroundColor',[1 1 1]); - - if isempty(ind) - beep; - disp(['User selected cancel']); - return; - end - end - - %%Plot the spectrum for the selected ERPset - % Loop start for the selected ERPsets try - for Numoferpset = 1:numel(Selected_erpset) + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM = []; end + for Numoferpset = 1:numel(ERPArray) %%% - ERP_curret_s = observe_ERPDAT.ALLERP(Selected_erpset(Numoferpset)); - if strcmp(ERP_curret_s.datatype,'ERP') - ERP_FFT = f_getFFTfromERP(ERP_curret_s,iswindowed); - elseif strcmp(ERP_curret_s.datatype,'EFFT') - ERP_FFT = ERP_curret_s; - else - disp(['Please selected ERPsets']); - return; - end - if isempty(ColumnNum) - ColumnNum = 1; - end - - if isempty(ChanArray) - ChanArray = [1:ERP_curret_s.nchan]; - end - - if isempty(RowNum) - RowNum = ceil(numel(ChanArray)/ColumnNum); - end - if isempty(BinArray) - BinArray = [1:ERP_curret_s.nbin]; - end - - if max(BinArray(:))> ERP_FFT.nbin - BinArray = [1:ERP_FFT.nbin]; + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferpset)); + if isempty(freqrange) || numel(freqrange)~=2 || any(freqrange(:)>floor(ERP.srate/2)) || any(freqrange(:)<0) + freqrange = [0 floor(ERP.srate/2)]; end - if max(ChanArray(:))> ERP_FFT.nchan - ChanArray = [1:ERP_FFT.nchan]; + if isempty(ChanArray) || any(ChanArray(:)>ERP.nchan) || any(ChanArray(:)<1) + ChanArray = [1:ERP.nchan]; end - - if isempty(FreqRange) || FreqRange(2)>ERP_FFT.times(end) - FreqRange=[ERP_FFT.times(1), ERP_FFT.times(end)]; - FreqTick = default_time_ticks(ERP_FFT, FreqRange); - FreqTick = str2num(FreqTick{1}); - end - if isempty(FreqTick) - FreqTick = default_time_ticks(ERP_FFT, FreqRange); - FreqTick = str2num(FreqTick{1}); + if isempty(BinArray) || any(BinArray(:)>ERP.nbin) || any(BinArray(:)<1) + BinArray = 1:ERP.nbin; end - - [xxx, latsamp, latdiffms] = closest(ERP_FFT.times, FreqRange); - tmin = latsamp(1); - tmax = latsamp(2); - ERP_FFT.bindata = ERP_FFT.bindata(ChanArray,tmin:tmax,BinArray); - ERP_FFT.nbin = numel(BinArray); - ERP_FFT.nchan = numel(ChanArray); - ERP_FFT.chanlocs = ERP_FFT.chanlocs(ChanArray); - ERP_FFT.bindescr = ERP_FFT.bindescr(BinArray); - ERP_FFT.times = ERP_FFT.times(tmin:tmax); - ERP_FFT.xmin = ERP_FFT.times(1); - ERP_FFT.xmax = ERP_FFT.times(end); - ERP_FFT.pnts = numel(ERP_FFT.times); - if strcmp(ERP_curret_s.datatype,'ERP') - if gui_erp_spectral.amplitude.Value - ERP_FFT.bindata = abs(ERP_FFT.bindata); - figure_name = ['Spectral analysis: Amplitude for ',32,ERP_FFT.erpname]; - elseif gui_erp_spectral.phase.Value - ERP_FFT.bindata = angle(ERP_FFT.bindata); - figure_name = ['Spectral analysis: Phase for ',32,ERP_FFT.erpname]; - elseif gui_erp_spectral.power.Value - ERP_FFT.bindata = abs(ERP_FFT.bindata).^2; - figure_name = ['Spectral analysis: Power for ',32,ERP_FFT.erpname]; - elseif gui_erp_spectral.db.Value - ERP_FFT.bindata = 20*log10(abs(ERP_FFT.bindata)); - figure_name = ['Spectral analysis: dB for ',32,ERP_FFT.erpname]; - end + [~, ERPCOM] = pop_ERP_spectralanalysis(ERP, 'Amptype',Amptype,'TaperWindow',TaperWindow,... + 'freqrange',freqrange,'BinArray',BinArray,'ChanArray',ChanArray,'Plotwave','off',... + 'Saveas', 'csv','History','gui'); + if Numoferpset == numel(ERPArray) + [observe_ERPDAT.ALLERP(ERPArray(Numoferpset)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); else - if gui_erp_spectral.amplitude.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_amplitude']; - elseif gui_erp_spectral.phase.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_phase']; - elseif gui_erp_spectral.power.Value - figure_name = ['Spectral analysis: Power for ',32,ERP_FFT.erpname]; - - elseif gui_erp_spectral.db.Value - figure_name = ['Spectral analysis: dB for ',32,ERP_FFT.erpname]; - end + [observe_ERPDAT.ALLERP(ERPArray(Numoferpset)), ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); end - - if ~Save_label - fig = figure('Name',figure_name); - set(fig,'outerposition',get(0,'screensize')); - - line_colors = erpworkingmemory('PWColor'); - if size(line_colors,1)~= ERP_FFT.nbin - if ERP_FFT.nbin> size(line_colors,1) - line_colors = get_colors(ERP_FFT.nbin); - else - line_colors = line_colors(1:ERP_FFT.nbin,:,:); - end - end - - if isempty(line_colors) - line_colors = get_colors(ERP_FFT.nbin); - end - - count = 0; - for Numofcolumn = 1:ColumnNum - for Numofrow = 1: RowNum - count = count+1; - % waitbar(count/(ColumnNum*RowNum),Hw); - if ColumnNum*RowNum<5 - pause(1); - end - if count>ERP_FFT.nchan - break; - end - p_ax = subplot(RowNum,ColumnNum,count); - set(gca,'fontsize',14); - hold on; - temp = squeeze(ERP_FFT.bindata(:,:,:)); - for Numofplot = 1:ERP_FFT.nbin - h_p(Numofplot) = plot(p_ax,ERP_FFT.times,squeeze(ERP_FFT.bindata(count,:,Numofplot)),'LineWidth',1.5,'Color',line_colors(Numofplot,:,:)); - end - axis(p_ax,[floor(ERP_FFT.times(1)),ceil(ERP_FFT.times(end)), 1.1*min(temp(:)) 1.1*max(temp(:))]); - xticks(p_ax,FreqTick); - xlim([floor(ERP_FFT.times(1)),ceil(ERP_FFT.times(end))]); - if count == 1 - title(p_ax,[ERP_FFT.chanlocs(count).labels],'FontSize',14); - legend(p_ax,ERP_FFT.bindescr,'FontSize',14); - legend(p_ax,'boxoff'); - else - title(p_ax,ERP_FFT.chanlocs(count).labels,'FontSize',14); - end - xlabel(p_ax,'Frequency/Hz','FontSize',14); - if gui_erp_spectral.phase.Value - ylabel(p_ax,'Angle/degree','FontSize',14); - elseif gui_erp_spectral.amplitude.Value - ylabel(p_ax,'Amplitude/\muV','FontSize',14); - elseif gui_erp_spectral.power.Value - ylabel(p_ax,'Power/\muV^2','FontSize',14); - elseif gui_erp_spectral.db.Value - ylabel(p_ax,'Decibels/dB','FontSize',14); - end - for Numoflabel = 1:length(ERP_FFT.times) - X_label{Numoflabel} = []; - end - set(gca,'TickDir','out'); - set(gca,'LineWidth',2); - end - end - hold off; - clear h_p - end - %%Save the transformed data for the selected ERPsets as - if Save_label - if strcmp(ERP_FFT.datatype,'EFFT') - if gui_erp_spectral.amplitude.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_Amplitude']; - elseif gui_erp_spectral.phase.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_Phase']; - elseif gui_erp_spectral.power.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_Power']; - elseif gui_erp_spectral.db.Value - figure_name = [ERP_FFT.erpname,'_Spectrum_ dB']; - end - - end - - if ind==1 - [filenamei, pathname] = uiputfile({'*.mat';'*.*'},['Save',32,'"',ERP_FFT.erpname,'"', 32,'as'],fullfile(pathName_folder,figure_name)); - - if isequal(filenamei,0) - disp('User selected Cancel') - return - else - [pathx, filename, ext] = fileparts(filenamei); - if ~strcmpi(ext,'.mat') - ext = '.mat'; - end - filename = [filename ext]; - end - - if strcmpi(ext,'.mat') - [ERP_FFT, issave, ERPCOM] = pop_savemyerp(ERP_FFT, 'erpname', ERP_FFT.erpname, 'filename', filename, 'filepath',pathname); - [~, ALLERPCOM] = erphistory(ERP_FFT, ALLERPCOM, ERPCOM); - end - - %%save as '.csv' - elseif ind==2 - def = erpworkingmemory('f_export2csvGUI'); - if isempty(def) - def = {1, 1, 1, 3, ''}; - end - - def{5} = fullfile(pathName_folder,ERP_FFT.filename); - answer_export = f_export2csvGUI(ERP_FFT,def); - erpworkingmemory('f_export2csvGUI',answer_export); - if isempty(answer_export) - beep; - disp('User selected cancel!!!'); - return; - end - binArray = [1:ERP_FFT.nbin]; - decimal_num = answer_export{4}; - istime =answer_export{1} ; - electrodes=answer_export{2} ; - transpose=answer_export{3}; - filenamei = answer_export{5}; - [pathx, filename, ext] = fileparts(filenamei); - if ~strcmpi(ext,'.csv') - ext = '.csv'; - end - if isempty(pathx) - pathx =cd; - end - filename = [filename ext]; - mkdir([pathx,filesep]); - try - export2csv_spectranl_analysis(ERP_FFT,fullfile(pathx,filename), binArray,istime, electrodes,transpose, decimal_num); - catch - beep; - disp('Fail to save selected ERPset as ".csv"!!!'); - return; - end - end - end - end%%end loop for ERPSET + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP=20; + gui_erp_spectral.Paras{2}=gui_erp_spectral.hamwin_on.Value; end - %%-------------------Setting for the whole panel of fitering based on ALLERP and CURRENTERP-------------- function Count_currentERPChanged(~,~) - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - gui_erp_spectral.advanced.Enable = 'off'; - gui_erp_spectral.save.Enable = 'off'; - gui_erp_spectral.plot.Enable = 'off'; - gui_erp_spectral.phase.Enable = 'off'; - gui_erp_spectral.amplitude.Enable = 'off'; - gui_erp_spectral.hamwin_on.Enable = 'off'; - gui_erp_spectral.hamwin_off.Enable = 'off'; - gui_erp_spectral.power.Enable = 'off'; - gui_erp_spectral.db.Enable = 'off'; + if observe_ERPDAT.Count_currentERP~=18 + return; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') || ViewerFlag==1 + Enable_label = 'off'; else - gui_erp_spectral.advanced.Enable = 'on'; - gui_erp_spectral.save.Enable = 'on'; - gui_erp_spectral.plot.Enable = 'on'; - gui_erp_spectral.phase.Enable = 'on'; - gui_erp_spectral.amplitude.Enable = 'on'; - gui_erp_spectral.power.Enable = 'on'; - gui_erp_spectral.db.Enable = 'on'; - gui_erp_spectral.hamwin_on.Enable = 'on'; - gui_erp_spectral.hamwin_off.Enable = 'on'; + Enable_label = 'on'; end + + gui_erp_spectral.save.Enable = Enable_label; + gui_erp_spectral.plot.Enable = Enable_label; + gui_erp_spectral.phase.Enable = Enable_label; + gui_erp_spectral.amplitude.Enable =Enable_label; + gui_erp_spectral.power.Enable = Enable_label; + gui_erp_spectral.db.Enable = Enable_label; + gui_erp_spectral.hamwin_on.Enable =Enable_label; + gui_erp_spectral.hamwin_off.Enable = Enable_label; + gui_erp_spectral.cancel.Enable = Enable_label; + gui_erp_spectral.frerange.Enable = Enable_label; + if ~isempty(observe_ERPDAT.ERP) && ~isempty(observe_ERPDAT.ALLERP) && ~strcmp(observe_ERPDAT.ERP.datatype,'EFFT') + frerange = str2num(gui_erp_spectral.frerange.String); + if isempty(frerange) || any(frerange(:)>floor(observe_ERPDAT.ERP.srate/2)) || any(frerange(:)<0) + gui_erp_spectral.frerange.String = num2str([0 floor(observe_ERPDAT.ERP.srate/2)]); + gui_erp_spectral.Paras{3} = [0 floor(observe_ERPDAT.ERP.srate/2)]; + end + end + + observe_ERPDAT.Count_currentERP=19; end %%----Get the color for lines-------------------------------------- @@ -888,5 +658,64 @@ function Count_currentERPChanged(~,~) end end + +%%--------------press return to execute "Apply"---------------------------- + function erp_spectral_presskey(~,eventdata) + keypress = eventdata.Key; + ChangeFlag = estudioworkingmemory('ERPTab_spectral'); + if ChangeFlag~=1 + return; + end + if strcmp (keypress, 'return') || strcmp (keypress , 'enter') + spectral_plot(); + gui_erp_spectral.plot.BackgroundColor = [1 1 1]; + gui_erp_spectral.plot.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [1 1 1]; + gui_erp_spectral.save.ForegroundColor = [0 0 0]; + + gui_erp_spectral.cancel.BackgroundColor = [1 1 1]; + gui_erp_spectral.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_spectral',0); + else + return; + end + end + + function Reset_erp_panel_change(~,~) + if observe_ERPDAT.Reset_erp_paras_panel~=15 + return; + end + gui_erp_spectral.plot.BackgroundColor = [1 1 1]; + gui_erp_spectral.plot.ForegroundColor = [0 0 0]; + ERP_filtering_box.TitleColor= [0.05,0.25,0.50];%% the default is [0.0500 0.2500 0.5000] + gui_erp_spectral.save.BackgroundColor = [1 1 1]; + gui_erp_spectral.save.ForegroundColor = [0 0 0]; + gui_erp_spectral.cancel.BackgroundColor = [1 1 1]; + gui_erp_spectral.cancel.ForegroundColor = [0 0 0]; + estudioworkingmemory('ERPTab_spectral',0); + gui_erp_spectral.hamwin_on.Value = 1; + gui_erp_spectral.hamwin_off.Value = 0; + gui_erp_spectral.phase.Value = 0; + gui_erp_spectral.amplitude.Value =1; + gui_erp_spectral.power.Value =0; + gui_erp_spectral.db.Value =0; + if ~isempty(observe_ERPDAT.ERP) + gui_erp_spectral.frerange.String = num2str([0 floor(observe_ERPDAT.ERP.srate/2)]); + end + + if gui_erp_spectral.phase.Value==1 + gui_erp_spectral.Paras{1}=2; + elseif gui_erp_spectral.power.Value==1 + gui_erp_spectral.Paras{1}=3; + elseif gui_erp_spectral.db.Value==1 + gui_erp_spectral.Paras{1}=4; + else + gui_erp_spectral.Paras{1}=1; + end + gui_erp_spectral.Paras{2}=gui_erp_spectral.hamwin_on.Value; + gui_erp_spectral.Paras{3} = [0 floor(observe_ERPDAT.ERP.srate/2)]; + observe_ERPDAT.Reset_erp_paras_panel=16; + end end -%Progem end: ERP Measurement tool \ No newline at end of file +%Progem end: \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_ERP_suffix_gui.m b/studio_functions/GUIs/ERP Tab/f_ERP_suffix_gui.m index a013df32..dafb666f 100755 --- a/studio_functions/GUIs/ERP Tab/f_ERP_suffix_gui.m +++ b/studio_functions/GUIs/ERP Tab/f_ERP_suffix_gui.m @@ -65,11 +65,11 @@ function f_ERP_suffix_gui_OpeningFcn(hObject, eventdata, handles, varargin) set(handles.menuerp.Children, 'Enable','off'); end -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - Add Suffix GUI']) -set(handles.edit_erpname, 'String', '_processed'); +set(handles.edit_erpname, 'String', erpname); set(handles.current_erp_label,'String', ['Enter suffix, which will be added onto the name of each selected ERPset'],... 'FontWeight','Bold', 'FontSize', 16); @@ -144,15 +144,8 @@ function pushbutton_Cancel_Callback(hObject, eventdata, handles) function pushbutton4_okay_Callback(hObject, eventdata, handles) erpname = strtrim(get(handles.edit_erpname, 'String')); -if isempty(erpname) - msgboxText = 'You must enter a suffix at least!'; - title = 'EStudio: f_ERP_suffix_gui empty suffix.'; - errorfound(msgboxText, title); - return -end - -handles.output = {erpname}; +handles.output = erpname; % Update handles structure guidata(hObject, handles); diff --git a/studio_functions/GUIs/ERP Tab/f_appenderpGUI.fig b/studio_functions/GUIs/ERP Tab/f_appenderpGUI.fig old mode 100644 new mode 100755 index 9bd183d9..4a4495d6 Binary files a/studio_functions/GUIs/ERP Tab/f_appenderpGUI.fig and b/studio_functions/GUIs/ERP Tab/f_appenderpGUI.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_appenderpGUI.m b/studio_functions/GUIs/ERP Tab/f_appenderpGUI.m old mode 100644 new mode 100755 index f33a5af0..9d47c6ff --- a/studio_functions/GUIs/ERP Tab/f_appenderpGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_appenderpGUI.m @@ -82,8 +82,9 @@ function f_appenderpGUI_OpeningFcn(hObject, eventdata, handles, varargin) % set GUI handles = setbuttonsgui(hObject, eventdata, handles); -erplab_studio_default_values; -version = erplabstudiover; + +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - APPEND ERPs GUI']) handles = painterplabstudio(handles); @@ -1155,3 +1156,10 @@ function radiobutton_ERPsetcustom_Callback(hObject, eventdata, handles) set(hObject,'Value',1); set(handles.radiobutton_erpset,'Value',0); end + + +% --- Executes during object deletion, before destroying properties. +% function pushbutton_help_DeleteFcn(hObject, eventdata, handles) +% hObject handle to pushbutton_help (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) diff --git a/studio_functions/GUIs/ERP Tab/f_basicfilterGUI2.m b/studio_functions/GUIs/ERP Tab/f_basicfilterGUI2.m index 479eaec8..fceeb77d 100755 --- a/studio_functions/GUIs/ERP Tab/f_basicfilterGUI2.m +++ b/studio_functions/GUIs/ERP Tab/f_basicfilterGUI2.m @@ -156,8 +156,6 @@ function f_basicfilterGUI2_OpeningFcn(hObject, eventdata, handles, varargin) - - % Update handles structure guidata(hObject, handles); @@ -2663,9 +2661,9 @@ function setall(hObject, eventdata, handles, ERPLAB, def) % % Name & version % -erplab_studio_default_values; -version = erplabstudiover; -set(handles.gui_chassis,'Name', ['EStudio V.', version ' - ERP Filtering > Advanced' ]) +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ', version ' - ERP Filtering > Advanced' ]) highpasscutoff = locutoff; lowpasscutoff = hicutoff; maxsliders = handles.maxsliders; diff --git a/studio_functions/GUIs/ERP Tab/f_chanoperGUI.m b/studio_functions/GUIs/ERP Tab/f_chanoperGUI.m index 20cec6c7..e92c186a 100755 --- a/studio_functions/GUIs/ERP Tab/f_chanoperGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_chanoperGUI.m @@ -76,7 +76,8 @@ function f_chanoperGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Name & version % -version = geterplabstudioversion; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - Channel Operation GUI for ' typedata]) % formulas = erpworkingmemory(formtype); diff --git a/studio_functions/GUIs/ERP Tab/f_check_erptab_panelchanges.m b/studio_functions/GUIs/ERP Tab/f_check_erptab_panelchanges.m new file mode 100644 index 00000000..84efba07 --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_check_erptab_panelchanges.m @@ -0,0 +1,135 @@ +function [messgStr,erpanelIndex]= f_check_erptab_panelchanges() + +messgStr = ''; +erpanelIndex = 0; + + + +MyViewer_chanbin = estudioworkingmemory('ERPTab_chanbin'); +if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 + messgStr = char( 'Changes on "Bin and Channel Selection" have not been applied'); + erpanelIndex =1; + return; +end + + +MyViewer_chanbin = estudioworkingmemory('ERPTab_plotset'); +if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 + messgStr = char( 'Changes on "Plot Setting" have not been applied'); + erpanelIndex =2; + return; +end + + + +%%topos +% MyViewer_chanbin = estudioworkingmemory('ERPTab_topos'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Plot Scalp Maps" have not been applied'); +% erpanelIndex =3; +% return; +% end +% +% %%baseline correction & detrend +% MyViewer_chanbin = estudioworkingmemory('ERPTab_baseline_detrend'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Baseline Correction & Linear Detrend" have not been applied'); +% erpanelIndex =4; +% return; +% end +% +% +% +% %%filter +% MyViewer_chanbin = estudioworkingmemory('ERPTab_filter'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Filtering" have not been applied'); +% erpanelIndex =5; +% return; +% end +% +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_chanop'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "ERP Channel Operations" have not been applied'); +% erpanelIndex =6; +% return; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_binop'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "ERP Bin Operations" have not been applied'); +% erpanelIndex =7; +% return; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_csd'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Convert Voltage to CSD" have not been applied'); +% erpanelIndex =8; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_spectral'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Spectral Analysis" have not been applied'); +% erpanelIndex =9; +% return; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_mesuretool'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "ERP Measurement Tool" have not been applied'); +% erpanelIndex =10; +% return; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_gravg'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Average across ERPsets" have not been applied'); +% erpanelIndex =11; +% return; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_append'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Append ERPsets" have not been applied'); +% erpanelIndex =12; +% return; +% end +% +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_stimulation'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Create Artificial ERP Waveform" have not been applied'); +% erpanelIndex =13; +% return; +% end +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_resample'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Resample ERPsets" have not been applied'); +% erpanelIndex =14; +% return; +% end +% +% +% +% MyViewer_chanbin = estudioworkingmemory('ERPTab_editchan'); +% if ~isempty(MyViewer_chanbin) && MyViewer_chanbin==1 +% messgStr = char( 'Changes on "Edit Channel Info" have not been applied'); +% erpanelIndex =15; +% return; +% end + + + +return; diff --git a/studio_functions/GUIs/ERP Tab/f_erp2ascGUI.m b/studio_functions/GUIs/ERP Tab/f_erp2ascGUI.m index 9c0d08d9..7aa47e63 100755 --- a/studio_functions/GUIs/ERP Tab/f_erp2ascGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_erp2ascGUI.m @@ -73,9 +73,9 @@ function f_erp2ascGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Name & version % -erplab_studio_default_values; -version = erplabstudiover; -set(handles.gui_chassis,'Name', strcat('EStudio',version,' - Save "',ERP.erpname, '" as ERPSS')) +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', strcat('Estudio ',version,' - Save "',ERP.erpname, '" as ERPSS')) [pathx, erpfilename, ext] = fileparts(ERP.filename); ERPFileName = char(strcat(erpfilename,'.txt')); diff --git a/studio_functions/GUIs/ERP Tab/f_erp_dataquality_SME_GUI.m b/studio_functions/GUIs/ERP Tab/f_erp_dataquality_SME_GUI.m index d755cf36..b776926a 100755 --- a/studio_functions/GUIs/ERP Tab/f_erp_dataquality_SME_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_erp_dataquality_SME_GUI.m @@ -3,7 +3,7 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 +%Feb. 2022 && Nov. 2023 @@ -13,41 +13,6 @@ global observe_ERPDAT; addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - -if nargin < 1 - beep; - help f_erp_dataquality_SME_GUI; - return; -end - - -try - ERP = evalin('base','ERP'); -catch - beep; - disp('f_erp_dataquality_SME_GUI: No ERP was found in workspace'); - return; -end - -if isempty(ERP) - msgboxText = 'No ERPset was found!'; - title_msg = 'ERPLAB: f_erp_dataquality_SME_GUI() error:'; - errorfound(msgboxText, title_msg); - return -end -if ~isfield(ERP, 'bindata') - msgboxText = 'f_erp_dataquality_SME_GUI cannot handle an empty ERP dataset'; - title = 'ERPLAB: f_erp_dataquality_SME_GUI() error:'; - errorfound(msgboxText, title); - return -end -if isempty(ERP.bindata) - msgboxText = 'f_erp_dataquality_SME_GUI cannot handle an empty ERP dataset'; - title = 'ERPLAB: f_erp_dataquality_SME_GUI() error:'; - errorfound(msgboxText, title); - return -end - try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch @@ -56,11 +21,11 @@ if nargin == 0 fig = figure(); % Parent figure - Erp_information = uiextras.BoxPanel('Parent', fig, 'Title', 'Data Quality (aSME)', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + Erp_information = uiextras.BoxPanel('Parent', fig, 'Title', 'View Data Quality Metrics', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Data Quality (aSME)', 'Padding', 5,'BackgroundColor',ColorB_def); + Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'View Data Quality Metrics', 'Padding', 5,'BackgroundColor',ColorB_def); else - Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'Data Quality (aSME)', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'View Data Quality Metrics', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); end varargout{1} = Erp_information; @@ -71,106 +36,79 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_information(FonsizeDefault); - - function drawui_erp_information(FonsizeDefault) - try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch ColorB_def = [0.95 0.95 0.95]; end - SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end + Enable_label = 'off'; - S_binchan = estudioworkingmemory('geterpbinchan'); - SelectedERP_current_index = S_binchan.Select_index; + gui_erp_DQSME.DataSelBox = uiextras.VBox('Parent', Erp_information, 'Spacing',1,'BackgroundColor',ColorB_def); + %%ERP setname and file name + gui_erp_DQSME.setfilename_title = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', gui_erp_DQSME.setfilename_title,'String','Current ERP setname & file name',... + 'FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorB_def); - if ~isempty(SelectedERP)&& SelectedERP_current_index> numel(SelectedERP) - SelectedERP(1) = observe_ERPDAT.CURRENTERP; - SelectedERP_current_index = 1; - end - if strcmp(observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index)).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; + gui_erp_DQSME.setfilename_title2 = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; end + gui_erp_DQSME.table_setfilenames = uitable( ... + 'Parent' , gui_erp_DQSME.setfilename_title2,... + 'Data' , dsnames, ... + 'ColumnWidth' , {500}, ... + 'ColumnName' , {''}, ... + 'RowName' , {'ERP name','File name'},... + 'ColumnEditable',[false]); - ERP_SME_summary = f_dq_summary(observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index))); - - gui_erp_DQSME.DataSelBox = uiextras.VBox('Parent', Erp_information, 'Spacing',1,'BackgroundColor',ColorB_def); %%----------------------------Setting midian SME--------------------- gui_erp_DQSME.Median_sme = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_DQSME.Median_sme_title = uicontrol('Style','text','Parent', gui_erp_DQSME.Median_sme,'String','Median:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_DQSME.Median_sme_title = uicontrol('Style','text','Parent', gui_erp_DQSME.Median_sme,'String','Median aSME:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); set(gui_erp_DQSME.Median_sme_title,'HorizontalAlignment','left'); - Median_tw =ERP_SME_summary{3,1}; - Median_name = strcat(num2str(roundn(ERP_SME_summary{1,1},-2)),', chan.',num2str(ERP_SME_summary{2,1}),',',32,num2str(Median_tw(1)),'-',num2str(Median_tw(2)),'ms, bin:',32,num2str(ERP_SME_summary{4,1})); - gui_erp_DQSME.Median_sme_name = uicontrol('Style','text','Parent', gui_erp_DQSME.Median_sme,'String',Median_name,'FontSize',FonsizeDefault); + + gui_erp_DQSME.Median_sme_name = uicontrol('Style','text','Parent', gui_erp_DQSME.Median_sme,'String','','FontSize',FonsizeDefault); set(gui_erp_DQSME.Median_sme_name,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_DQSME.Median_sme,'Sizes',[60 400]); + set(gui_erp_DQSME.Median_sme,'Sizes',[100 400]); %%----------------------------Setting min. SME--------------------- gui_erp_DQSME.min_sme = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_DQSME.min_sme_title = uicontrol('Style','text','Parent', gui_erp_DQSME.min_sme,'String','Min:','FontSize',FonsizeDefault); + gui_erp_DQSME.min_sme_title = uicontrol('Style','text','Parent', gui_erp_DQSME.min_sme,'String','Min aSME:','FontSize',FonsizeDefault); set(gui_erp_DQSME.min_sme_title,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - Min_tw =ERP_SME_summary{3,2}; - Min_name = strcat(num2str(roundn(ERP_SME_summary{1,2},-2)),', chan.',num2str(ERP_SME_summary{2,2}),',',32,num2str(Min_tw(1)),'-',num2str(Min_tw(2)),'ms, bin:',32,num2str(ERP_SME_summary{4,2})); - gui_erp_DQSME.min_sme_name = uicontrol('Style','text','Parent', gui_erp_DQSME.min_sme,'String',Min_name,'FontSize',FonsizeDefault); + + gui_erp_DQSME.min_sme_name = uicontrol('Style','text','Parent', gui_erp_DQSME.min_sme,'String','','FontSize',FonsizeDefault); set(gui_erp_DQSME.min_sme_name,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_DQSME.min_sme,'Sizes',[40 400]); + set(gui_erp_DQSME.min_sme,'Sizes',[80 400]); %%----------------------------Setting max. SME--------------------- gui_erp_DQSME.max_sme = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_DQSME.max_sme_title = uicontrol('Style','text','Parent', gui_erp_DQSME.max_sme,'String','Max:','FontSize',FonsizeDefault); + gui_erp_DQSME.max_sme_title = uicontrol('Style','text','Parent', gui_erp_DQSME.max_sme,'String','Max aSME:','FontSize',FonsizeDefault); set(gui_erp_DQSME.max_sme_title,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - Max_tw =ERP_SME_summary{3,3}; - Max_name = strcat(num2str(roundn(ERP_SME_summary{1,3},-2)),', chan.',num2str(ERP_SME_summary{2,3}),',',32,num2str(Max_tw(1)),'-',num2str(Max_tw(2)),'ms, bin:',32,num2str(ERP_SME_summary{4,3})); - gui_erp_DQSME.max_sme_name = uicontrol('Style','text','Parent', gui_erp_DQSME.max_sme,'String',Max_name,'FontSize',FonsizeDefault); + + gui_erp_DQSME.max_sme_name = uicontrol('Style','text','Parent', gui_erp_DQSME.max_sme,'String','','FontSize',FonsizeDefault); set(gui_erp_DQSME.max_sme_name,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_DQSME.max_sme,'Sizes',[40 400]); + set(gui_erp_DQSME.max_sme,'Sizes',[80 400]); gui_erp_DQSME.DQSME_option = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'BackgroundColor',ColorB_def); gui_erp_DQSME.DQSME_option_table = uicontrol('Style','pushbutton','Parent', gui_erp_DQSME.DQSME_option,'String','Show in a table',... - 'callback',@DQSME_table,'Enable',Enable_label,'FontSize',FonsizeDefault); + 'callback',@DQSME_table,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); gui_erp_DQSME.DQSME_option_file = uicontrol('Style','pushbutton','Parent', gui_erp_DQSME.DQSME_option,'String','Save to file',... - 'callback',@DQSME_file,'Enable',Enable_label,'FontSize',FonsizeDefault); + 'callback',@DQSME_file,'Enable',Enable_label,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); set(gui_erp_DQSME.DQSME_option,'Sizes',[120 120]); - try - ERP_data_quality = observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index)).dataquality.data; - catch - ERP_data_quality =[]; - end - if isempty(ERP_data_quality) - set(gui_erp_DQSME.DQSME_option_table,'Enable','off'); - set(gui_erp_DQSME.DQSME_option_file,'Enable','off'); - end - gui_erp_DQSME.DQSME_option1 = uiextras.HBox('Parent',gui_erp_DQSME.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_DQSME.DQSME_option_measure = uicontrol('Style','pushbutton','Parent', gui_erp_DQSME.DQSME_option1,'String','Show measures on Command Window',... - 'callback',@DQSME_measures,'Enable',Enable_label,'FontSize',FonsizeDefault); - uiextras.Empty('Parent', gui_erp_DQSME.DQSME_option1); - set(gui_erp_DQSME.DQSME_option1,'Sizes',[240 10]); - set(gui_erp_DQSME.DataSelBox,'Sizes',[20 20 20 30 30]); + + set(gui_erp_DQSME.DQSME_option_table,'Enable','off'); + set(gui_erp_DQSME.DQSME_option_file,'Enable','off'); + set(gui_erp_DQSME.DataSelBox,'Sizes',[20 70 20 20 20 30]); end @@ -178,131 +116,132 @@ function drawui_erp_information(FonsizeDefault) %-----------------------------Subfunction---------------------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %%--------Settting will be modified if the selected was changed------------ function Count_currentERPChanged(~,~) - SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - S_binchan = estudioworkingmemory('geterpbinchan'); - SelectedERP_current_index = S_binchan.Select_index; - if ~isempty(SelectedERP)&& SelectedERP_current_index> numel(SelectedERP) - SelectedERP(1) = observe_ERPDAT.CURRENTERP; - SelectedERP_current_index = 1; + if observe_ERPDAT.Count_currentERP~=16 + return; end - - if strcmp(observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index)).erpname,'No ERPset loaded') - Enable_label = 'off'; + if isempty(observe_ERPDAT.ERP) || isempty(observe_ERPDAT.ALLERP) || strcmp(observe_ERPDAT.ERP.datatype,'EFFT') + Enableflag = 'off'; + gui_erp_DQSME.Median_sme_name.String =''; + gui_erp_DQSME.min_sme_name.String =''; + gui_erp_DQSME.max_sme_name.String=''; + gui_erp_DQSME.DQSME_option_table.Enable = Enableflag; + gui_erp_DQSME.DQSME_option_file.Enable = Enableflag; + + observe_ERPDAT.Count_currentERP=17; + return; else - Enable_label = 'on'; + Enableflag = 'on'; + end + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if ViewerFlag==1 + Enableflag = 'off'; + end + try + ERP_SME_summary = f_dq_summary(observe_ERPDAT.ERP); + catch + ERP_SME_summary = cell(3,3); end - - ERP_SME_summary = f_dq_summary(observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index))); Median_tw =ERP_SME_summary{3,1}; - Median_name = strcat(num2str(roundn(ERP_SME_summary{1,1},-2)),', chan.',num2str(ERP_SME_summary{2,1}),',',32,num2str(Median_tw(1)),'-',num2str(Median_tw(2)),'ms, bin',32,num2str(ERP_SME_summary{4,1})); + try + Median_name = strcat(num2str(roundn(ERP_SME_summary{1,1},-2)),', chan',32,num2str(ERP_SME_summary{2,1}),',',32,num2str(Median_tw(1)),'-',num2str(Median_tw(2)),'ms, bin',32,num2str(ERP_SME_summary{4,1})); + catch + Median_name = ''; + end gui_erp_DQSME.Median_sme_name.String = Median_name; Min_tw =ERP_SME_summary{3,2}; - Min_name = strcat(num2str(roundn(ERP_SME_summary{1,2},-2)),', chan.',num2str(ERP_SME_summary{2,2}),',',32,num2str(Min_tw(1)),'-',num2str(Min_tw(2)),'ms, bin',32,num2str(ERP_SME_summary{4,2})); + try + Min_name = strcat(num2str(roundn(ERP_SME_summary{1,2},-2)),', chan',32,num2str(ERP_SME_summary{2,2}),',',32,num2str(Min_tw(1)),'-',num2str(Min_tw(2)),'ms, bin',32,num2str(ERP_SME_summary{4,2})); + catch + Min_name = ''; + end gui_erp_DQSME.min_sme_name.String = Min_name; Max_tw =ERP_SME_summary{3,3}; - Max_name = strcat(num2str(roundn(ERP_SME_summary{1,3},-2)),', chan.',num2str(ERP_SME_summary{2,3}),',',32,num2str(Max_tw(1)),'-',num2str(Max_tw(2)),'ms, bin',32,num2str(ERP_SME_summary{4,3})); + try + Max_name = strcat(num2str(roundn(ERP_SME_summary{1,3},-2)),', chan',32,num2str(ERP_SME_summary{2,3}),',',32,num2str(Max_tw(1)),'-',num2str(Max_tw(2)),'ms, bin',32,num2str(ERP_SME_summary{4,3})); + catch + Max_name = ''; + end gui_erp_DQSME.max_sme_name.String=Max_name; - gui_erp_DQSME.DQSME_option_measure.Enable = Enable_label; + try% check if the data for SMEs exsists or not data_quality = observe_ERPDAT.ERP.dataquality.data; if isempty(data_quality) - Enable_label = 'off'; + Enableflag = 'off'; end catch - Enable_label = 'off'; - beep; - disp('There no SME exist in current ERPset'); + Enableflag = 'off'; end - gui_erp_DQSME.DQSME_option_table.Enable = Enable_label; - gui_erp_DQSME.DQSME_option_file.Enable = Enable_label; + gui_erp_DQSME.DQSME_option_table.Enable = Enableflag; + gui_erp_DQSME.DQSME_option_file.Enable = Enableflag; + try + filesetname{1,1} = observe_ERPDAT.ERP.erpname; + filesetname{2,1} = observe_ERPDAT.ERP.filename; + catch + filesetname{1,1} = ''; + filesetname{2,1} = ''; + end + gui_erp_DQSME.table_setfilenames.Data= filesetname; + + observe_ERPDAT.Count_currentERP=17; end - - %%---------------------Save SME to a table--------------------------------- function DQSME_table(~,~) - + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; + end SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + if isempty(SelectedERP) || any(SelectedERP> length(observe_ERPDAT.ALLERP)) + SelectedERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = SelectedERP; + estudioworkingmemory('selectederpstudio',SelectedERP); end - - S_binchan = estudioworkingmemory('geterpbinchan'); - SelectedERP_current_index = S_binchan.Select_index; - - if ~isempty(SelectedERP)&& SelectedERP_current_index> numel(SelectedERP) - SelectedERP_current_index = 1; + estudioworkingmemory('f_ERP_proces_messg','View Data Quality Metrics > Show in a table'); + observe_ERPDAT.Process_messg =1; + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM=[]; end + DQ_Table_GUI(observe_ERPDAT.ALLERP(SelectedERP(1)),observe_ERPDAT.ALLERP(SelectedERP),1,1); + for Numoferp = 1:numel(SelectedERP) + ERPCOM = [' DQ_Table_GUI(ERP,ALLERP,',num2str(Numoferp),',1);']; + if Numoferp==1 + fprintf(['\n',ERPCOM,'\n']); + end + [ERP, ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(SelectedERP(Numoferp)), ALLERPCOM, ERPCOM,2); + observe_ERPDAT.ALLERP(SelectedERP(Numoferp)) = ERP; end - DQ_Table_GUI(observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index)),observe_ERPDAT.ALLERP,SelectedERP(SelectedERP_current_index),1); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP = 20; + observe_ERPDAT.Process_messg =2; end - - %-----------------Save the SME to a file----------------------------------- function DQSME_file(~,~) - - SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); - end - - S_binchan = estudioworkingmemory('geterpbinchan'); - SelectedERP_current_index = S_binchan.Select_index; - - - if ~isempty(SelectedERP)&& SelectedERP_current_index> numel(SelectedERP) - SelectedERP_current_index = 1; + if isempty(observe_ERPDAT.ERP) + observe_ERPDAT.Count_currentERP=1; + return; end - - %-----------Setting for import------------------------------------- - try - [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; - catch - ColorB_def = [0.7020 0.77 0.85]; + SelectedERP= estudioworkingmemory('selectederpstudio'); + if isempty(SelectedERP) || any(SelectedERP> length(observe_ERPDAT.ALLERP)) + SelectedERP = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + observe_ERPDAT.CURRENTERP = SelectedERP; + estudioworkingmemory('selectederpstudio',SelectedERP); end - - oldcolor = get(0,'DefaultUicontrolBackgroundColor'); - set(0,'DefaultUicontrolBackgroundColor',ColorB_def); - + estudioworkingmemory('f_ERP_proces_messg','View Data Quality Metrics > Save to file'); + observe_ERPDAT.Process_messg =1; + try ALLERPCOM = evalin('base','ALLERPCOM'); catch ALLERPCOM=[]; end + countr= 0; for Numoferp = 1:numel(SelectedERP) ERP =observe_ERPDAT.ALLERP(SelectedERP(Numoferp)); try @@ -314,29 +253,29 @@ function DQSME_file(~,~) button = questdlg(sprintf(question, msgboxText), title,'OK','OK'); else save_data_quality(observe_ERPDAT.ALLERP(SelectedERP(Numoferp))); + ERPCOM = ['save_data_quality(ERP);']; + [ERP, ALLERPCOM] = erphistory(observe_ERPDAT.ALLERP(SelectedERP(Numoferp)), ALLERPCOM, ERPCOM,2); + observe_ERPDAT.ALLERP(SelectedERP(Numoferp)) = ERP; + countr=1; + if Numoferp==1 + fprintf(['\n',ERPCOM,'\n']); + end end catch msgboxText = ['No information for data quality is found!']; question = [ 'No information for data quality is found!']; - title = 'ERPLAB Studio: "Save to file" on "Data quality (aSME)".'; + title = 'ERPLAB Studio: "Save to file" on "View Data Quality Metrics".'; button = questdlg(sprintf(question, msgboxText), title,'OK','OK'); end - end set(0,'DefaultUicontrolBackgroundColor',[1 1 1]); - end - - - -%-------------------Show which Data Quality measures are in each loaded ERPSET--------------------------- - function DQSME_measures(~,~) - if isempty(observe_ERPDAT.ALLERP) - beep; - disp('f_erp_dataquality_SME_GUI: No ERP was found!!!'); - return; + if countr==1 + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + observe_ERPDAT.Count_currentERP = 20; end - erpset_summary(observe_ERPDAT.ALLERP); - + observe_ERPDAT.Process_messg =2; end end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_erp_informtion_GUI.m b/studio_functions/GUIs/ERP Tab/f_erp_informtion_GUI.m index 03a9f2ae..64377377 100755 --- a/studio_functions/GUIs/ERP Tab/f_erp_informtion_GUI.m +++ b/studio_functions/GUIs/ERP Tab/f_erp_informtion_GUI.m @@ -3,53 +3,14 @@ %Center for Mind and Brain %University of California, Davis %Davis, CA, USA -%Feb. 2022 - +%Feb. 2022 && Nov. 2023 function varargout = f_erp_informtion_GUI(varargin) - global observe_ERPDAT; addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); - -if nargin < 1 - beep; - help f_erp_informtion_GUI; - return; -end - - -try - ERP = evalin('base','ERP'); -catch - beep; - disp('f_erp_informtion_GUI: No ERP was found in workspace'); - return; - -end - -if isempty(ERP) - msgboxText = 'No ERPset was found!'; - title_msg = 'EStudio: f_erp_informtion_GUI() error:'; - errorfound(msgboxText, title_msg); - return -end -if ~isfield(ERP, 'bindata') - msgboxText = 'f_erp_informtion_GUI cannot handle an empty ERP dataset'; - title = 'EStudio: f_erp_informtion_GUI() error:'; - errorfound(msgboxText, title); - return -end -if isempty(ERP.bindata) - msgboxText = 'f_erp_informtion_GUI cannot handle an empty ERP dataset'; - title = 'EStudio: f_erp_informtion_GUI() error:'; - errorfound(msgboxText, title); - return -end - - try [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; catch @@ -57,11 +18,11 @@ end if nargin == 0 fig = figure(); % Parent figure - Erp_information = uiextras.BoxPanel('Parent', fig, 'Title', 'ERP Information', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel + Erp_information = uiextras.BoxPanel('Parent', fig, 'Title', 'ERP & Bin Information', 'Padding', 5,'BackgroundColor',ColorB_def); % Create boxpanel elseif nargin == 1 - Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Information', 'Padding', 5,'BackgroundColor',ColorB_def); + Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP & Bin Information', 'Padding', 5,'BackgroundColor',ColorB_def); else - Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP Information', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); + Erp_information = uiextras.BoxPanel('Parent', varargin{1}, 'Title', 'ERP & Bin Information', 'Padding', 5, 'FontSize', varargin{2},'BackgroundColor',ColorB_def); end varargout{1} = Erp_information; @@ -72,7 +33,7 @@ FonsizeDefault = []; end if isempty(FonsizeDefault) - FonsizeDefault = f_get_default_fontsize(); + FonsizeDefault = f_get_default_fontsize(); end drawui_erp_information(FonsizeDefault); @@ -85,79 +46,97 @@ function drawui_erp_information(FonsizeDefault) end gui_erp_information.DataSelBox = uiextras.VBox('Parent', Erp_information, 'Spacing',1,'BackgroundColor',ColorB_def); - %%----------------------------Setting sampling rate--------------------- - gui_erp_information.samplingrate = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_information.samplingrate_title = uicontrol('Style','text','Parent', gui_erp_information.samplingrate,'String','Sampling:','FontSize',FonsizeDefault); - if ERP.srate> 0 - ERP_time_resolution = strcat(32,num2str(roundn(1000/ERP.srate,-2)),32,'ms (resolution);',32,num2str(ERP.srate),32,'Hz','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - else - ERP_time_resolution = strcat(32,num2str(0),32,'ms (time resolution);',32,num2str(ERP.srate),32,'Hz (rate)','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + %%ERP setname and file name + gui_erp_information.setfilename_title = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); + uicontrol('Style','text','Parent', gui_erp_information.setfilename_title,'String','Current ERP setname & file name',... + 'FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorB_def); + + + gui_erp_information.setfilename_title2 = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = ''; + dsnames{ii,2} = ''; end - set(gui_erp_information.samplingrate_title,'HorizontalAlignment','left','BackgroundColor',ColorB_def); + gui_erp_information.table_setfilenames = uitable( ... + 'Parent' , gui_erp_information.setfilename_title2,... + 'Data' , dsnames, ... + 'ColumnWidth' , {500}, ... + 'ColumnName' , {''}, ... + 'RowName' , {'ERP name','File name'},... + 'ColumnEditable',[false]); - gui_erp_information.samplingrate_resolution = uicontrol('Style','text','Parent', gui_erp_information.samplingrate,'String',ERP_time_resolution,'FontSize',FonsizeDefault); + %%----------------------------Setting sampling rate--------------------- + gui_erp_information.samplingrate_title = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); + ERP_time_resolution = strcat('Sampling: '); + gui_erp_information.samplingrate_resolution = uicontrol('Style','text','Parent', gui_erp_information.samplingrate_title,'String',ERP_time_resolution,'FontSize',FonsizeDefault); set(gui_erp_information.samplingrate_resolution,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_information.samplingrate ,'Sizes',[70 430]); %%----------------------------Setting epoch--------------------- gui_erp_information.epoch = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_information.epoch_title = uicontrol('Style','text','Parent', gui_erp_information.epoch,'String','Epoch:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - set(gui_erp_information.epoch_title,'HorizontalAlignment','left'); - gui_erp_information.epoch_name = uicontrol('Style','text','Parent', gui_erp_information.epoch,'String',[32,num2str(roundn(ERP.times(1),-2)),32,'to',32,num2str(roundn(ERP.times(end),-2)),32,'ms (',num2str(numel(ERP.times)),32,'pts)'],'FontSize',FonsizeDefault); + gui_erp_information.epoch_name = uicontrol('Style','text','Parent', gui_erp_information.epoch,'String',['Epoch:'],'FontSize',FonsizeDefault); set(gui_erp_information.epoch_name,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_information.epoch ,'Sizes',[50 450]); + + %%----------------------------channel locations--------------------- + gui_erp_information.chanlocs_title = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); + gui_erp_information.chanlocs = uicontrol('Style','text','Parent', gui_erp_information.chanlocs_title,'String','Channel locations:',... + 'FontSize',FonsizeDefault,'HorizontalAlignment','left','BackgroundColor',ColorB_def); %%----------------------------Number of Channels--------------------- gui_erp_information.chan_num = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_information.numofchan_title = uicontrol('Style','text','Parent', gui_erp_information.chan_num,'String','Number of channels:','FontSize',FonsizeDefault); - set(gui_erp_information.numofchan_title,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - gui_erp_information.numofchan = uicontrol('Style','text','Parent', gui_erp_information.chan_num,'String',[32,num2str(ERP.nchan)],'FontSize',FonsizeDefault); + gui_erp_information.numofchan = uicontrol('Style','text','Parent', gui_erp_information.chan_num,'String','Number of channels:','FontSize',FonsizeDefault); set(gui_erp_information.numofchan,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_information.chan_num ,'Sizes',[125 375]); - % set(gui_erp_information.filename_gui,'Sizes',[100 -1]); - %%----------------------------Number of bins--------------------- gui_erp_information.bin_num = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_information.bin_num_title = uicontrol('Style','text','Parent', gui_erp_information.bin_num,'String','Number of bins:','FontSize',FonsizeDefault); - set(gui_erp_information.bin_num_title,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - gui_erp_information.numofbin = uicontrol('Style','text','Parent', gui_erp_information.bin_num,'String',[num2str(ERP.nbin)],'FontSize',FonsizeDefault); - % set(gui_erp_information.filename_gui,'Sizes',[100 -1]); + gui_erp_information.numofbin = uicontrol('Style','text','Parent', gui_erp_information.bin_num,'String','Number of bins:','FontSize',FonsizeDefault); set(gui_erp_information.numofbin,'HorizontalAlignment','left','BackgroundColor',ColorB_def); - set(gui_erp_information.bin_num ,'Sizes',[110 390]); %%----------------------------Total accepted--------------------- - N_trials = ERP.ntrials; - N_trial_total = sum(N_trials.accepted(:))+sum(N_trials.rejected(:))+sum(N_trials.invalid(:)); - N_trial_rejected = sum(N_trials.rejected(:)); - + N_trials = 0; + N_trial_total = 0; + N_trial_rejected = 0; if N_trial_total ==0 - Total_rejected_trials = strcat('0'); + Total_rejected_trials = strcat('0%'); else - Total_rejected_trials = strcat(num2str(roundn(N_trial_rejected/N_trial_total,-3)*100),'%'); + Total_rejected_trials = strcat('0%'); end - gui_erp_information.total_rejected = uiextras.HBox('Parent',gui_erp_information.DataSelBox); - gui_erp_information.total_rejected_title = uicontrol('Style','text','Parent', gui_erp_information.total_rejected,'String','Total rejected trials:','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); - set(gui_erp_information.total_rejected_title,'HorizontalAlignment','left'); - - gui_erp_information.total_rejected_percentage = uicontrol('Style','text','Parent', gui_erp_information.total_rejected,'String',Total_rejected_trials,'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + gui_erp_information.total_rejected_percentage = uicontrol('Style','text','Parent', gui_erp_information.total_rejected,'String',['Total rejected trials:',32,Total_rejected_trials],'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); set(gui_erp_information.total_rejected_percentage,'HorizontalAlignment','left'); - set(gui_erp_information.total_rejected,'Sizes',[125 375]); - %%------------totla rejected---------- + + %%----------------------totla rejected----------------------------- gui_erp_information.total_rejected_show = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); - gui_erp_information.total_rejected_option = uicontrol('Style','pushbutton','Parent', gui_erp_information.total_rejected_show,'String','Artifact rejection details',... - 'callback',@total_reject_ops,'FontSize',FonsizeDefault); + gui_erp_information.total_rejected_option2 = uicontrol('Style','pushbutton','Parent', gui_erp_information.total_rejected_show,'String','Bin Info Table',... + 'callback',@total_reject_ops,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_erp_information.total_rejected_option2.Enable = 'off'; + gui_erp_information.total_rejected_option = uicontrol('Style','pushbutton','Parent', gui_erp_information.total_rejected_show,'String','Classic artifact summary',... + 'callback',@total_reject_clasc,'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + gui_erp_information.total_rejected_option.Enable = 'off'; - if strcmp(observe_ERPDAT.ERP.erpname,'No ERPset loaded') - gui_erp_information.total_rejected_option.Enable = 'off'; - end - uiextras.Empty('Parent', gui_erp_information.total_rejected_show); - set(gui_erp_information.total_rejected_show,'Sizes',[150 250]); - set(gui_erp_information.DataSelBox,'Sizes',[20 20 20 20 20 30]) + %%---------------------Table--------------------------------------- + gui_erp_information.bin_latency_title = uiextras.HBox('Parent', gui_erp_information.DataSelBox,'BackgroundColor',ColorB_def); + gui_erp_information.trialinfor= uicontrol('Style', 'text','Parent', gui_erp_information.bin_latency_title,... + 'String','Trial information','FontWeight','bold','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + + gui_erp_information.table_title = uiextras.HBox('Parent',gui_erp_information.DataSelBox,'Spacing',1,'BackgroundColor',ColorB_def); + for ii = 1:100 + dsnames{ii,1} = []; + dsnames{ii,2} = []; + dsnames{ii,3} = []; + dsnames{ii,4} = []; + dsnames{ii,5} = []; + end + gui_erp_information.table_event = uitable( ... + 'Parent' , gui_erp_information.table_title,... + 'Data' , dsnames, ... + 'ColumnWidth' , {30,40,60,60,50}, ... + 'ColumnName' , {'Bin','Total','Accepted','Rejected','invalid'}, ... + 'RowName' , [],... + 'ColumnEditable',[false, false, false, false, false]); + set(gui_erp_information.DataSelBox,'Sizes',[20 70 20 20 20 20 20 20 30 20 100]) end @@ -165,177 +144,171 @@ function drawui_erp_information(FonsizeDefault) %-----------------------------Subfunction---------------------------------- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %%--------Settting will be modified if the selected was changed------------ function Count_currentERPChanged(~,~) -% try -% ERPloadIndex = estudioworkingmemory('ERPloadIndex'); -% catch -% ERPloadIndex =0; -% end -% if ERPloadIndex==1 -% ALLERPIN = evalin('base','ALLERP'); -% CURRENTERPIN = evalin('base','CURRENTERP'); -% observe_ERPDAT.ALLERP = ALLERPIN; -% observe_ERPDAT.CURRENTERP =CURRENTERPIN; -% try -% observe_ERPDAT.ERP = ALLERPIN(CURRENTERPIN); -% catch -% observe_ERPDAT.ERP = ALLERPIN(end); -% observe_ERPDAT.CURRENTERP =length(ALLERPIN); -% end -% end + if observe_ERPDAT.Count_currentERP~=7 + return; + end + ERP = observe_ERPDAT.ERP; + if ~isempty(ERP) + ERP_time_resolution = strcat('Sampling:',32,num2str(ERP.srate),32,'Hz',32,'(',num2str(roundn(1000/ERP.srate,-2)),32,'ms/sample)'); + else + ERP_time_resolution = strcat('Sampling: '); + end + gui_erp_information.samplingrate_resolution.String = [ERP_time_resolution]; + try + gui_erp_information.epoch_name.String=strcat('Epoch:',32,num2str(roundn(ERP.times(1),-2)),32,'to',32,num2str(roundn(ERP.times(end),-2)),32,... + 'ms (',num2str(numel(ERP.times)),32,'pnts)'); + catch + gui_erp_information.epoch_name.String=['Epoch:']; + end - SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; + %%channel locations? + try + count = 0; + if ~isempty(ERP.chanlocs) + for Numofchan = 1:ERP.nchan + if ~isempty(ERP.chanlocs(Numofchan).X) + count =1; + end + end + end + if count==1 + gui_erp_information.chanlocs.String = 'Channel locations: set'; + else + gui_erp_information.chanlocs.String = 'Channel locations: not set'; end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); + catch + gui_erp_information.chanlocs.String = 'Channel locations: not set'; end - S_binchan = estudioworkingmemory('geterpbinchan'); - SelectedERP_current_index = S_binchan.Select_index; - if ~isempty(SelectedERP)&& SelectedERP_current_index> numel(SelectedERP) - SelectedERP(1) = observe_ERPDAT.CURRENTERP; - SelectedERP_current_index = 1; + try + gui_erp_information.numofchan.String=['Number of channels:',32,num2str(ERP.nchan)]; + catch + gui_erp_information.numofchan.String=['Number of channels:',32,]; end - - if strcmp(observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index)).erpname,'No ERPset loaded') - Enable_label = 'off'; - else - Enable_label = 'on'; + try + gui_erp_information.numofbin.String=['Number of bins:',32,num2str(ERP.nbin)]; + catch + gui_erp_information.numofbin.String=['Number of bins:',32,num2str(0)]; end - - ERP_current_index = observe_ERPDAT.ALLERP(SelectedERP(SelectedERP_current_index)); - if numel(SelectedERP)==1 - if ERP_current_index.srate> 0 - ERP_time_resolution = strcat(32,num2str(roundn(1000/ERP_current_index.srate,-2)),32,'ms(resolution);',32,num2str(ERP_current_index.srate),32,'Hz'); - else - ERP_time_resolution = strcat(32,num2str(0),32,'ms(time resolution);',32,num2str(ERP_current_index.srate),32,'Hz (rate)'); - end - gui_erp_information.samplingrate_resolution.String = ERP_time_resolution; - try - gui_erp_information.epoch_name.String=char(strcat(num2str(roundn(ERP_current_index.times(1),-2)),32,'to',32,num2str(roundn(ERP_current_index.times(end),-2)),32,... - 'ms(',num2str(numel(ERP_current_index.times)),32,'pts)')); - catch - gui_erp_information.epoch_name.String=char(strcat('0 to 0ms(0 pts)')); - end - - gui_erp_information.numofchan.String=num2str(ERP_current_index.nchan); - gui_erp_information.numofbin.String=num2str(ERP_current_index.nbin); - N_trials = ERP_current_index.ntrials; + for ii = 1:100 + dsnamesdef{ii,1} = []; + dsnamesdef{ii,2} = []; + dsnamesdef{ii,3} = []; + dsnamesdef{ii,4} = []; + dsnamesdef{ii,5} = []; + end + if ~isempty(ERP) + gui_erp_information.trialinfor.String = ['Trial information for ERP:',32,num2str(observe_ERPDAT.CURRENTERP)]; + N_trials = ERP.ntrials; N_trial_total = sum(N_trials.accepted(:))+sum(N_trials.rejected(:))+sum(N_trials.invalid(:)); N_trial_rejected = sum(N_trials.rejected(:)); if N_trial_total ==0 - Total_rejected_trials = strcat('0'); + Total_rejected_trials = strcat('Total rejected trials: 0 (0)'); else - Total_rejected_trials = strcat(num2str(roundn(N_trial_rejected/N_trial_total,-3)*100),'%'); + Total_rejected_trials = strcat('Total rejected trials:',32,[num2str(N_trial_rejected),32,'(',num2str(roundn(N_trial_rejected/N_trial_total,-3)*100),'%)']); end - gui_erp_information.total_rejected_percentage.Enable = Enable_label; gui_erp_information.total_rejected_percentage.String = Total_rejected_trials; - gui_erp_information.total_rejected_option.Enable = Enable_label; - end - - if numel(SelectedERP)>1 - Check_Selected_erpset = [0 0 0 0 0 0 0]; - if numel(SelectedERP)>1 - - Check_Selected_erpset = S_binchan.checked_ERPset_Index; - - end - %%bin - if Check_Selected_erpset(1) ==1 - gui_erp_information.numofbin.String = 'Varied across ERPsets'; - else - try - BinNum = observe_ERPDAT.ERP.nbin; - catch - BinNum = 0; - end - gui_erp_information.numofbin.String = num2str(BinNum); - end - - %%chan - if Check_Selected_erpset(2) ==2 - gui_erp_information.numofchan.String = 'Varied across ERPsets'; - else - try - chanNum = observe_ERPDAT.ERP.nchan; - catch - chanNum = 0; - end - gui_erp_information.numofchan.String = num2str(chanNum); - end - %%Total rejected artifacts - gui_erp_information.total_rejected_percentage.String = 'Varied across ERPsets'; - - %%sampling rate - if Check_Selected_erpset(7) ==7 - gui_erp_information.samplingrate_resolution.String = 'Varied across ERPsets'; - else - try - if observe_ERPDAT.ERP.srate - ERP_time_resolution = strcat(32,num2str(roundn(1000/ERP_current_index.srate,-2)),32,'ms(resolution);',32,num2str(ERP_current_index.srate),32,'Hz'); - end - catch - ERP_time_resolution = strcat(32,num2str(0),32,'ms(time resolution);',32,num2str(ERP_current_index.srate),32,'Hz (rate)'); - end - gui_erp_information.samplingrate_resolution.String = ERP_time_resolution; - end + Enable_label = 'on'; - if any(Check_Selected_erpset(4:6)) - gui_erp_information.epoch_name.String=char(strcat('Varied across ERPsets')); - else - try - gui_erp_information.epoch_name.String=char(strcat(num2str(roundn(ERP_current_index.times(1),-2)),32,'to',32,num2str(roundn(ERP_current_index.times(end),-2)),32,... - 'ms(',num2str(numel(ERP_current_index.times)),32,'pts)')); - catch - gui_erp_information.epoch_name.String=char(strcat('0 to 0ms(0 pts)')); + try + for ii = 1:numel(ERP.ntrials.accepted) + dsnames{ii,1} = ii; + dsnames{ii,2} = ERP.ntrials.accepted(ii)+ ERP.ntrials.rejected(ii)+ERP.ntrials.invalid(ii); + dsnames{ii,3} = ERP.ntrials.accepted(ii); + dsnames{ii,4} = ERP.ntrials.rejected(ii); + dsnames{ii,5} = ERP.ntrials.invalid(ii); end + catch + dsnames = dsnamesdef; end - - + else + gui_erp_information.total_rejected_percentage.String = 'Total rejected trials: 0'; + Enable_label = 'off'; + dsnames = dsnamesdef; + gui_erp_information.trialinfor.String = ['Trial information']; end - - + gui_erp_information.table_event.Data = dsnames; + ViewerFlag=estudioworkingmemory('ViewerFlag'); + if isempty(ViewerFlag) || (ViewerFlag~=0 && ViewerFlag~=1) + ViewerFlag=0;estudioworkingmemory('ViewerFlag',0); + end + if ViewerFlag==1 + Enable_label = 'off'; + end + gui_erp_information.total_rejected_percentage.Enable = Enable_label; + gui_erp_information.total_rejected_option.Enable = Enable_label; + gui_erp_information.total_rejected_option2.Enable = Enable_label; + try + filesetname{1,1} = ERP.erpname; + filesetname{2,1} = ERP.filename; + catch + filesetname{1,1} = ''; + filesetname{2,1} = ''; + end + gui_erp_information.table_setfilenames.Data= filesetname; + observe_ERPDAT.Count_currentERP=8; end +%%-------------------------------artifact summary-------------------------- + function total_reject_ops(~,~) + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; + end + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = ERPArray; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + estudioworkingmemory('selectederpstudio',ERPArray); + end + ERPCOM = pop_erp_ar_summary(observe_ERPDAT.ALLERP,ERPArray); + fprintf( ['\n',repmat('-',1,100) '\n']); + fprintf(['*ERP & Bin Information>Bin Info table*',32,32,32,32,datestr(datetime('now')),'\n']); + fprintf( [ERPCOM]); + fprintf( ['\n',repmat('-',1,100) '\n']); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + [observe_ERPDAT.ERP, ALLERPCOM] = erphistory(observe_ERPDAT.ERP, ALLERPCOM, ERPCOM,2); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.Count_currentERP = 20; + end -%%----------------Rejection option---------------------------------------- - function total_reject_ops(~,~) - - SelectedERP= estudioworkingmemory('selectederpstudio'); - if isempty(SelectedERP) - SelectedERP = observe_ERPDAT.CURRENTERP; - - if isempty(SelectedERP) - msgboxText = 'No ERPset was selected!!!'; - title = 'EStudio: ERPsets'; - errorfound(msgboxText, title); - return; - end - S_erpplot = f_ERPplot_Parameter(observe_ERPDAT.ALLERP,SelectedERP); - estudioworkingmemory('geterpbinchan',S_erpplot.geterpbinchan); - estudioworkingmemory('geterpplot',S_erpplot.geterpplot); +%%----------------Rejection option classic--------------------------------- + function total_reject_clasc(~,~) + if isempty(observe_ERPDAT.ALLERP) || isempty(observe_ERPDAT.ERP) + return; + end + ERPArray= estudioworkingmemory('selectederpstudio'); + if isempty(ERPArray) || any(ERPArray>length(observe_ERPDAT.ALLERP)) + ERPArray = length(observe_ERPDAT.ALLERP); + observe_ERPDAT.CURRENTERP = ERPArray; + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(end); + estudioworkingmemory('selectederpstudio',ERPArray); end - try - for Numoferp = 1:numel(SelectedERP) - ERP = observe_ERPDAT.ALLERP(SelectedERP(Numoferp)); - [ERP, acce, rej, histoflags, erpcom] = pop_summary_AR_erp_detection(ERP); + try ALLERPCOM = evalin('base','ALLERPCOM');catch ALLERPCOM = []; end + for Numoferp = 1:numel(ERPArray) + ERP = observe_ERPDAT.ALLERP(ERPArray(Numoferp)); + [ERP, acce, rej, histoflags, ERPCOM] = pop_summary_AR_erp_detection(ERP); + if isempty(ERPCOM) + return; + end + if Numoferp ==numel(ERPArray) + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,2); + else + [ERP, ALLERPCOM] = erphistory(ERP, ALLERPCOM, ERPCOM,1); + end + observe_ERPDAT.ALLERP(ERPArray(Numoferp)) = ERP; end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + assignin('base','ALLERPCOM',ALLERPCOM); + assignin('base','ERPCOM',ERPCOM); + observe_ERPDAT.Count_currentERP = 20; catch return; end diff --git a/studio_functions/GUIs/ERP Tab/f_erp_save_history.m b/studio_functions/GUIs/ERP Tab/f_erp_save_history.m new file mode 100644 index 00000000..fe64278a --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_erp_save_history.m @@ -0,0 +1,19 @@ + +function erpcom = f_erp_save_history(erpname,fname,pname) + +% fname = [fname ext]; +erpcom = sprintf('%s = pop_savemyerp(%s', 'ERP','ERP'); +if ~isempty(erpname) + erpcom = sprintf('%s, ''erpname'', ''%s''', erpcom, erpname); +end +if ~isempty(fname) + erpcom = sprintf('%s, ''filename'', ''%s''', erpcom, fname); +end +if ~isempty(pname) + erpcom = sprintf('%s, ''filepath'', ''%s''', erpcom, pname); +% if warnop==1 +% erpcom = sprintf('%s, ''Warning'', ''on''', erpcom); +% end +end + erpcom = sprintf('%s);', erpcom); +end \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_erp_viewerGUI.fig b/studio_functions/GUIs/ERP Tab/f_erp_viewerGUI.fig new file mode 100644 index 00000000..f7d13170 Binary files /dev/null and b/studio_functions/GUIs/ERP Tab/f_erp_viewerGUI.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_erp_viewerGUI.m b/studio_functions/GUIs/ERP Tab/f_erp_viewerGUI.m new file mode 100644 index 00000000..e79d4bc2 --- /dev/null +++ b/studio_functions/GUIs/ERP Tab/f_erp_viewerGUI.m @@ -0,0 +1,2959 @@ +function varargout = f_erp_viewerGUI(varargin) +% F_ERP_VIEWERGUI MATLAB code for f_erp_viewerGUI.fig +% F_ERP_VIEWERGUI, by itself, creates a new F_ERP_VIEWERGUI or raises the existing +% singleton*. +% +% H = F_ERP_VIEWERGUI returns the handle to a new F_ERP_VIEWERGUI or the handle to +% the existing singleton*. +% +% F_ERP_VIEWERGUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in F_ERP_VIEWERGUI.M with the given input arguments. +% +% F_ERP_VIEWERGUI('Property','Value',...) creates a new F_ERP_VIEWERGUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before f_erp_viewerGUI_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to f_erp_viewerGUI_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 2009-2020 The MathWorks, Inc. + +% Edit the above text to modify the response to help f_erp_viewerGUI + +% Last Modified by GUIDE v2.5 09-Apr-2024 14:56:17 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @f_erp_viewerGUI_OpeningFcn, ... + 'gui_OutputFcn', @f_erp_viewerGUI_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 f_erp_viewerGUI is made visible. +function f_erp_viewerGUI_OpeningFcn(hObject, eventdata, handles, varargin) + +try + ALLERP = varargin{1}; + CurrentERP = varargin{2}; + BinArray = varargin{3}; + ChanArray = varargin{4}; +catch + ALLERP = []; + CurrentERP = []; + BinArray = []; + ChanArray = []; +end + +handles.ALLERP=ALLERP; +handles.CurrentERP=CurrentERP; +handles.BinArray=BinArray; +handles.ChanArray = ChanArray; +handles.ERP =[]; + +handles.output = []; +if ~isempty(ALLERP) + if isempty(CurrentERP) || any(CurrentERP>length(ALLERP)) || numel(CurrentERP)~=1 + CurrentERP=length(ALLERP); + handles.CurrentERP=CurrentERP; + end + OutputViewerparerp = f_preparms_mtviewer_erptab(ALLERP(CurrentERP),0); + handles.timeStart =OutputViewerparerp{3}; + handles.timEnd =OutputViewerparerp{4}; + handles.xtickstep=OutputViewerparerp{5}; + bindata = []; + for Numoferp = 1:numel(CurrentERP) + ERP = ALLERP(CurrentERP); + bindata(:,:,:,Numoferp) = ERP.bindata(ChanArray,:,BinArray); + end + y_scale_def = [floor(1.1*min(bindata(:))),ceil(1.1*max(bindata(:)))]; + + handles.Yscale = y_scale_def; + handles.Min_vspacing = OutputViewerparerp{7}; + handles.Fillscreen = OutputViewerparerp{8}; + handles.positive_up = OutputViewerparerp{10}; + handles.moption= OutputViewerparerp{12}; + handles.latency= OutputViewerparerp{13}; + handles.blc = OutputViewerparerp{14}; + handles.intfactor = OutputViewerparerp{15}; + handles.Resolution =OutputViewerparerp{16}; + handles.Matlab_ver = OutputViewerparerp{22}; + handles.GridposArray = OutputViewerparerp{24}; + ChanArray11 = ChanArray(1); + ChanArray11 = vect2colon(ChanArray11,'Sort', 'off'); + ChanArray11 = erase(ChanArray11,{'[',']'}); + handles.edit_chans.String = ChanArray11; + BinArray1 = BinArray(1); + BinArray1 = vect2colon(BinArray1,'Sort', 'off'); + BinArray1 = erase(BinArray1,{'[',']'}); + handles.edit_bin.String = BinArray1; + CurrentERP = CurrentERP(1); + ERPArray1 = vect2colon(CurrentERP,'Sort', 'off'); + ERPArray1 = erase(ERPArray1,{'[',']'}); + handles.edit5_erpset.String = ERPArray1; + handles.CurrentERP=CurrentERP; +end + +%%for bins +handles.radiobutton_parbin.Value=1; +handles.checkbox1_bin.Value=0; +handles.edit_bin.Enable = 'on'; +handles.pushbutton_binsmall.Enable = 'on'; +handles.pushbutton_binlarge.Enable = 'on'; +handles.pushbutton_browse_bin.Enable = 'on'; + +%%for chans +handles.radiobutton_chanpor.Value=1; +handles.checkbox_chan.Value=0; +handles.edit_chans.Enable = 'on'; +handles.pushbutton8_chansmall.Enable = 'on'; +handles.pushbutton_chanlarge.Enable = 'on'; +handles.pushbutton_chanborwse.Enable = 'on'; +handles.radiobutton_chanoverlay.Value=0; +handles.radiobutton_chan_separate.Value=1; +handles.radiobutton_chanoverlay.Enable = 'off'; +handles.radiobutton_chan_separate.Enable = 'off'; +%%erpsets +handles.radiobutton_erppor.Value=1; +handles.checkbox_erp.Value=0; +handles.edit5_erpset.Enable = 'on'; +handles.pushbutton_erpsetsmall.Enable = 'on'; +handles.pushbutton_erpsetlarge.Enable = 'on'; +handles.pushbutton_erpset_browse.Enable = 'on'; +if ~isempty(ALLERP) + checkindex = checkerpsets(ALLERP); + if ~isempty(checkindex) + handles.checkbox_erp.Enable='off'; + handles.text_warningmessage.String = [checkindex,', and you therfore donot allow to select all for ERPsets']; + end +end +handles.ALLERP = ALLERP; +ALLERP = handles.ALLERP; + +handles.positive_up=1; +handles.radiobutton7.Value=1; +handles.radiobutton7.BackgroundColor = [0.7020 0.7647 0.8392]; +handles.radiobutton6.Value=0; + + +erplab_default_values; +version = erplabver; +set(handles.figure1,'Name', ['EStudio ' version ' - Viewer for Measurement GUI']) +handles.figure1.Color = [0.7020 0.7647 0.8392]; + +handles = painterplabstudio(handles); +% +% % +% % Set font size +% % +handles = setfonterplabestudio(handles); + +if isempty(ALLERP) + return; +end + + +handles= plot_wave_viewer(hObject,handles); + + +% Update handles structure +guidata(hObject, handles); + +% UIWAIT makes f_erp_viewerGUI wait for user response (see UIRESUME) +uiwait(handles.figure1); + + +% --- Outputs from this function are returned to the command line. +function varargout = f_erp_viewerGUI_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 edit1_time_range_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +timeRange = str2num(handles.edit1_time_range.String); +if isempty(timeRange) || numel(timeRange)~=2 + handles.edit1_time_range.String = num2str([handles.timeStart,handles.timEnd]); + handles.text_warningmessage.String = ['Time range must have two values']; + return; +end +if timeRange(1)>=ERP.times(end) + handles.edit1_time_range.String = num2str([handles.timeStart,handles.timEnd]); + handles.text_warningmessage.String = ['Left edge of Time range must be smaller than',32,num2str(ERP.times(end))]; + return; +end +if timeRange(2)<=ERP.times(1) + handles.edit1_time_range.String = num2str([handles.timeStart,handles.timEnd]); + handles.text_warningmessage.String = ['Right edge of Time range must be lager than',32,num2str(ERP.times(1))]; + return; +end +if timeRange(1) > timeRange(2) + handles.edit1_time_range.String = num2str([handles.timeStart,handles.timEnd]); + handles.text_warningmessage.String = ['Right edge of Time range must be lager than the left one']; + return; +end +handles.timeStart= timeRange(1); +handles.timEnd = timeRange(2); +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes during object creation, after setting all properties. +function edit1_time_range_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function edit2_yrange_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +yScale = str2num(handles.edit2_yrange.String); +if isempty(yScale) || numel(yScale)~=2 + handles.text_warningmessage.String = ['Inputs for Y range are invalid']; + handles.edit2_yrange.String = num2str(handles.Yscale); + return; +end +handles.Yscale = yScale; +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes during object creation, after setting all properties. +function edit2_yrange_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in pushbutton_polarity_up. +function pushbutton_polarity_up_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end + +handles.positive_up=1; +handles.pushbutton_polarity_up.Value=1; +handles.radiobutton6.Value=0; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + + +%----previous bin +function pushbutton_binsmall_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end + +BinArray_edit = str2num(handles.edit_bin.String); +if numel(BinArray_edit)~=1 + handles.text_warningmessage.String = ['Please enter a single value for bin first before using "<".']; + return; +end +BinArray = handles.BinArray; +BinArray =reshape(BinArray,1,numel(BinArray)); +[~,binpos] = find(BinArray ==BinArray_edit); +if isempty(binpos) + BinArray_edit = BinArray(1); + binpos = 1; +end + +binpos = binpos-1; +if binpos<1 + binpos = 1; +end +% handles.BinArray = BinArraynew; +if numel(BinArray_edit)~=1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +else + if binpos==1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'on'; + elseif binpos == numel(BinArray) + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'off'; + else + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'on'; + end +end +binpos = vect2colon(BinArray(binpos),'Sort', 'off'); +binpos = erase(binpos,{'[',']'}); +handles.edit_bin.String = binpos; + +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + +% -- next bin +function pushbutton_binlarge_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end + +BinArray_edit = str2num(handles.edit_bin.String); +if numel(BinArray_edit)~=1 + handles.text_warningmessage.String = ['Please enter a single value for bin first before using ">".']; + return; +end + +BinArray = handles.BinArray; +BinArray =reshape(BinArray,1,numel(BinArray)); +[~,binpos] = find(BinArray ==BinArray_edit); +if isempty(binpos) + BinArray_edit = BinArray(1); + binpos = 1; +end + + +binpos = binpos+1; +if binpos> numel(BinArray) + binpos = numel(BinArray); +end + + +if numel(binpos)~=1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +else + if binpos==1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'on'; + elseif binpos == numel(BinArray) + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'off'; + else + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'on'; + end +end +BinArraynew = BinArray(binpos); +BinArraynew = vect2colon(BinArraynew,'Sort', 'off'); +BinArraynew = erase(BinArraynew,{'[',']'}); +handles.edit_bin.String = BinArraynew; +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +function edit_bin_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end + +BinArray = str2num(handles.edit_bin.String); +if isempty(BinArray) || any(BinArray<=0) || any(BinArray>ERP.nbin) + BinArray1 = vect2colon(handles.BinArray,'Sort', 'off'); + BinArray1 = erase(BinArray1,{'[',']'}); + handles.edit_bin.String =BinArray1; + handles.text_warningmessage.String = ['Input(s) for bin must be between 1 and ',32,num2str(ERP.nbin)]; + return; +end +handles.BinArray = BinArray; +if numel(BinArray)~=1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +else + if BinArray==1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'on'; + elseif BinArray == ERP.nbin + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'off'; + else + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'on'; + end +end +if numel(BinArray)~=ERP.nbin + handles.checkbox1_bin.Value=0; +else + handles.checkbox1_bin.Value=1; +end +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + +% --- Executes during object creation, after setting all properties. +function edit_bin_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in checkbox1_bin. +function checkbox1_bin_Callback(hObject, eventdata, handles) + +handles.checkbox1_bin.Value=1; +handles.radiobutton_parbin.Value=0; +handles.pushbutton_binsmall.Enable = 'off'; +handles.pushbutton_binlarge.Enable = 'off'; +handles.edit_bin.Enable = 'on'; +handles.pushbutton_browse_bin.Enable = 'off'; +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +BinArray = vect2colon(handles.BinArray,'Sort', 'off'); +BinArray = erase(BinArray,{'[',']'}); +handles.edit_bin.String = BinArray; + +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- previous channel +function pushbutton8_chansmall_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +ChanArray_edit = str2num(handles.edit_chans.String); +if numel(ChanArray_edit)~=1 + handles.text_warningmessage.String = ['Please enter a single value for channel first before using "<".']; + return; +end + +ChanArray = handles.ChanArray; +ChanArray =reshape(ChanArray,1,numel(ChanArray)); +[~,chanpos] = find(ChanArray ==ChanArray_edit); +if isempty(chanpos) + ChanArray_edit = ChanArray(1); + chanpos = 1; +end + + +chanpos = chanpos-1; +if chanpos<1 + chanpos=1; +end + +if numel(chanpos)~=1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +else + if chanpos==1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'on'; + elseif chanpos==numel(ChanArray) + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'off'; + else + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'on'; + end +end + +ChanArray11 = vect2colon(ChanArray(chanpos),'Sort', 'off'); +ChanArray11 = erase(ChanArray11,{'[',']'}); +handles.edit_chans.String = ChanArray11; +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- next channel +function pushbutton_chanlarge_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +ChanArray_edit = str2num(handles.edit_chans.String); +if numel(ChanArray_edit)~=1 + handles.text_warningmessage.String = ['Please enter a single value for channel first before using ">".']; + return; +end + +ChanArray = handles.ChanArray; +ChanArray =reshape(ChanArray,1,numel(ChanArray)); +[~,chanpos] = find(ChanArray ==ChanArray_edit); +if isempty(chanpos) + ChanArray_edit = ChanArray(1); + chanpos = 1; +end +chanpos = chanpos+1; +if chanpos>numel(ChanArray) + chanpos = numel(ChanArray); +end + +if numel(chanpos)~=1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +else + if chanpos==1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'on'; + elseif chanpos==numel(ChanArray) + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'off'; + else + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'on'; + end +end + +ChanArray11 = vect2colon(ChanArray(chanpos),'Sort', 'off'); +ChanArray11 = erase(ChanArray11,{'[',']'}); +handles.edit_chans.String = ChanArray11; +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + + +function edit_chans_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +ChanArray = str2num(handles.edit_chans.String); +if isempty(ChanArray) || any(ChanArray<=0) || any(ChanArray>ERP.nchan) + handles.text_warningmessage.String = ['Inputs for channels must be between 1 and',32,num2str(ERP.nchan)]; + + ChanArray11 = vect2colon(handles.ChanArray,'Sort', 'off'); + ChanArray11 = erase(ChanArray11,{'[',']'}); + handles.edit_chans.String = ChanArray11; + return; +end +handles.ChanArray = ChanArray; +ChanArray11 = vect2colon(ChanArray,'Sort', 'off'); +ChanArray11 = erase(ChanArray11,{'[',']'}); +handles.edit_chans.String = ChanArray11; +if numel(ChanArray)~=1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +else + if ChanArray==1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'on'; + elseif ChanArray ==ERP.nchan + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'off'; + else + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'on'; + end +end +if numel(ChanArray)~=ERP.nchan + handles.checkbox_chan.Value=0; +else + handles.checkbox_chan.Value=1; +end +guidata(hObject, handles); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes during object creation, after setting all properties. +function edit_chans_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in checkbox_chan. +function checkbox_chan_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +handles.radiobutton_chanpor.Value=0; +handles.checkbox_chan.Value=1; +handles.pushbutton8_chansmall.Enable = 'off'; +handles.pushbutton_chanlarge.Enable = 'off'; +handles.pushbutton_chanborwse.Enable = 'off'; +handles.edit_chans.Enable = 'on'; +handles.radiobutton_chanoverlay.Enable = 'on'; +handles.radiobutton_chan_separate.Enable = 'on'; +if isempty(ALLERP) || isempty(ERP) + return; +end + +ChanArray11 = vect2colon(handles.ChanArray,'Sort', 'off'); +ChanArray11 = erase(ChanArray11,{'[',']'}); +handles.edit_chans.String = ChanArray11; +% handles.ChanArray = 1:ERP.nchan; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- previous ERPset +function pushbutton_erpsetsmall_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +ERPArray = str2num(handles.edit5_erpset.String); +if numel(ERPArray)~=1 + handles.text_warningmessage.String = ['Please enter a single value for ERPsets first before using "<".']; + return; +end +ERPArray_new = ERPArray-1; +if ERPArray_new<1 + ERPArray_new=1; +end + +if ERPArray_new==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; +elseif ERPArray_new==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; +end +handles.CurrentERP = ERPArray_new; +handles.edit5_erpset.String = num2str(ERPArray_new); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + +% --- Next erpset +function pushbutton_erpsetlarge_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +ERPArray = str2num(handles.edit5_erpset.String); +if numel(ERPArray)~=1 + handles.text_warningmessage.String = ['Please enter a single value for ERPsets first before using "<".']; + return; +end +ERPArray_new = ERPArray+1; +if ERPArray_new > length(ALLERP) + ERPArray_new=length(ALLERP); +end +if ERPArray_new==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; +elseif ERPArray_new==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; +end +handles.edit5_erpset.String = num2str(ERPArray_new); +handles.CurrentERP = ERPArray_new; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + + +function edit5_erpset_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end +ERPArray = str2num(handles.edit5_erpset.String); +if isempty(ERPArray) || any(ERPArray(:)>length(ALLERP)) || any(ERPArray(:)<1) + handles.text_warningmessage.String = ['Index of ERPset must be single value and not more than',32,num2str(length(ALLERP))]; + handles.edit5_erpset.String = num2str(handles.CurrentERP); + return; +end +handles.CurrentERP = ERPArray; +if numel(ERPArray)==1 + if ERPArray==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + elseif ERPArray==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; + else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + end +else + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +end + +checkindex = checkerpsets(ALLERP(ERPArray)); +if ~isempty(checkindex) + handles.text_warningmessage.String = [checkindex,'. You cannot display multiple ERPsets simultaneously']; + ERPArray = ERPArray(1); + handles.CurrentERP = ERPArray; + handles.edit5_erpset.String = str2num(ERPArray); + if ERPArray==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + elseif ERPArray==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; + else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + end + +end + +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + +% --- Executes during object creation, after setting all properties. +function edit5_erpset_CreateFcn(hObject, eventdata, handles) +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in checkbox_erp. +function checkbox_erp_Callback(hObject, eventdata, handles) +handles.checkbox_erp.Value=1; +handles.radiobutton_erppor.Value=0; +handles.edit5_erpset.Enable = 'off'; +handles.pushbutton_erpsetsmall.Enable = 'off'; +handles.pushbutton_erpsetlarge.Enable = 'off'; +handles.pushbutton_erpset_browse.Enable = 'off'; + +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end +ERPArray = str2num(handles.edit5_erpset.String); +if isempty(ERPArray) || any(ERPArray(:)>length(ALLERP)) + ERPArray=1; + handles.edit5_erpset.String = '1'; +end +checkindex = checkerpsets(ALLERP); + +if ~isempty(checkindex) + handles.text_warningmessage.String = [checkindex,'. You cannot display multiple ERPsets simultaneously']; + handles.checkbox_erp.Value=0; + handles.radiobutton_erppor.Value=1; + handles.edit5_erpset.Enable = 'on'; + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + handles.pushbutton_erpset_browse.Enable = 'on'; + if isempty(ERPArray) + ERPArray=1; + else + ERPArray = ERPArray(1); + end + handles.edit5_erpset.String = num2str(ERPArray); + handles.CurrentERP = ERPArray; + if ERPArray==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + elseif ERPArray==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; + else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + end + return; +end + +ERPArray = [1:length(ALLERP)]; +handles.edit5_erpset.String = num2str(ERPArray); +ERPArray = vect2colon(ERPArray,'Sort', 'off'); +ERPArray = erase(ERPArray,{'[',']'}); +handles.edit5_erpset.String = ERPArray; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +function checkindex = checkerpsets(ALLERP) +if isempty(ALLERP) + return; +end +checkindex = ''; + +for Numoferp = 1:length(ALLERP) + Numchan(Numoferp) = ALLERP(Numoferp).nchan; + Numbin(Numoferp) = ALLERP(Numoferp).nbin; + Numpnts(Numoferp) = ALLERP(Numoferp).pnts; + Numsrate(Numoferp) = ALLERP(Numoferp).srate; + Numxmin(Numoferp) = ALLERP(Numoferp).xmin; + Numxmax(Numoferp) = ALLERP(Numoferp).xmax; +end +if numel(unique(Numchan))~=1 + checkindex = 'Number of channels varies across ERPsets'; + return; +end + +if numel(unique(Numbin))~=1 + checkindex = 'Number of bins varies across ERPsets'; + return; +end + +if numel(unique(Numpnts))~=1 + checkindex = 'Number of sample points varies across ERPsets'; + return; +end + +if numel(unique(Numsrate))~=1 + checkindex = 'Sampling rate varies across ERPsets'; + return; +end + +if numel(unique(Numxmin))~=1 + checkindex = 'Minimal value of the epoch varies across ERPsets'; + return; +end + +if numel(unique(Numxmax))~=1 + checkindex = 'Maximal value of the epoch varies across ERPsets'; + return; +end + + + +% --- Executes on button press in pushbutton_matlabfig. +function pushbutton_matlabfig_Callback(hObject, eventdata, handles) + +f_plot_wave_viewer_popup(hObject,handles); + + +% --- Executes on button press in pushbutton_exit. +function pushbutton_exit_Callback(hObject, eventdata, handles) +% handles.output = []; +% Update handles structure +guidata(hObject, handles); +uiresume(handles.figure1); +delete(handles.figure1); + + + +% ----------------------------------------------------------------------- +function figure1_CloseRequestFcn(hObject, eventdata, handles) + +if isequal(get(handles.figure1, 'waitstatus'), 'waiting') + %The GUI is still in UIWAIT, us UIRESUME + handles.output = ''; + %Update handles structure + guidata(hObject, handles); + uiresume(handles.figure1); +else + % The GUI is no longer waiting, just close it + delete(handles.figure1); +end + + + +function handles = plot_wave_viewer(hObject,handles) +try ALLERP = handles.ALLERP;catch ALLERP = []; end + +if isempty(ALLERP) + return; +end +handles.ALLERP=ALLERP; +%%current erp +ERPArray=str2num(handles.edit5_erpset.String); +if isempty(ERPArray) || any(ERPArray(:)> length(ALLERP)) || any(ERPArray(:)<1) + ERPArray = 1; + handles.CurrentERP = ERPArray; +end +checkindex = checkerpsets(ALLERP(ERPArray)); +if ~isempty(checkindex) + handles.text_warningmessage.String = [checkindex,'. You cannot display multiple ERPsets simultaneously']; + handles.checkbox_erp.Value=0; + handles.radiobutton_erppor.Value=1; + ERPArray = ERPArray(1); +end + +handles.edit5_erpset.String = num2str(ERPArray); +if numel(ERPArray)==1 + if ERPArray==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + elseif ERPArray==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; + else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + end +else + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +end +if numel(ERPArray)== numel(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +end +ERP = ALLERP(ERPArray(1)); +if numel(ERPArray)==1 + handles.text_erpname.String = ERP.erpname; +else + handles.text_erpname.String = 'Multiple ERPsets were slected'; +end + +%%channels +ChanArray_new = str2num(handles.edit_chans.String); +nbchan = ERP.nchan; +handles.ERP = ERP; +ChanArray = handles.ChanArray; +ChanArray =reshape(ChanArray,1,numel(ChanArray)); +if isempty(ChanArray_new) || any(ChanArray_new>nbchan) || any(ChanArray_new<=0) + ChanArray_new =ChanArray; + handles.ChanArray = ChanArray_new; +end + +if handles.radiobutton_chanpor.Value==1 + [~,chanpos] = find(ChanArray ==ChanArray_new); +else + chanpos=1; +end +if isempty(chanpos) + ChanArray_new = ChanArray(1); + handles.edit_chans.String = num2str( ChanArray(1)); + chanpos = 1; +end + +if numel(ChanArray_new)~=1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +else + if chanpos==1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'on'; + elseif chanpos==numel(ChanArray) + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'off'; + else + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'on'; + end +end +if numel(ChanArray_new) == numel(handles.ChanArray) + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +end + +ChanArray11 = vect2colon(ChanArray_new,'Sort', 'off'); +ChanArray11 = erase(ChanArray11,{'[',']'}); +handles.edit_chans.String = ChanArray11; + +chanOverlay = handles.radiobutton_chanoverlay.Value; + +%%bin +nbin = ERP.nbin; +BinArray_edit =str2num(handles.edit_bin.String); +if isempty(BinArray_edit) || any(BinArray_edit>nbin) || any(BinArray_edit<=0) + BinArray_edit = [1:nbin]; + handles.BinArray = BinArray; +end +BinArray = handles.BinArray; +BinArray =reshape(BinArray,1,numel(BinArray)); +if handles.radiobutton_erppor.Value==1 + [~,binpos] = find(BinArray==BinArray_edit); +else + BinArray = []; + binpos =1; +end +if isempty(binpos) + BinArray_edit = BinArray(1); + handles.edit_bin.String = num2str(BinArray_edit); + binpos = 1; +end + +if numel(BinArray_edit)~=1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +else + if binpos==1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'on'; + elseif binpos == numel(BinArray) + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'off'; + else + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'on'; + end +end + +if numel(BinArray_edit)== numel(handles.BinArray) + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +end +BinArray1 = vect2colon(BinArray_edit,'Sort', 'off'); +BinArray1 = erase(BinArray1,{'[',']'}); +handles.edit_bin.String = BinArray1; + +%%-----------------------create the panel---------------------------------- +FonsizeDefault = f_get_default_fontsize(); +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) + ColorB_def = [0.7020 0.77 0.85]; +end +handles.ViewContainer = handles.uipanel1_viewer; +handles.plotgrid = uiextras.VBox('Parent',handles.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); + +handles.plot_wav_legend = uiextras.HBox( 'Parent', handles.plotgrid,'BackgroundColor',[1 1 1]); +handles.ViewAxes_legend = uix.ScrollingPanel( 'Parent', handles.plot_wav_legend,'BackgroundColor',[1 1 1]); +handles.plot_wav = uiextras.HBox( 'Parent', handles.plotgrid,'BackgroundColor',[1 1 1]); +handles.ViewAxes = uix.ScrollingPanel( 'Parent', handles.plot_wav,'BackgroundColor',[1 1 1]); + + +handles.erptabwaveiwer = axes('Parent', handles.ViewAxes,'Color','none','Box','on','FontWeight','normal'); +hold(handles.erptabwaveiwer,'on'); +handles.erptabwaveiwer_legend = axes('Parent', handles.ViewAxes_legend,'Color','none','Box','off'); +hold(handles.erptabwaveiwer_legend,'on'); +set(handles.erptabwaveiwer_legend, 'XTick', [], 'YTick', []); +handles.ERP_M_T_Viewer = uiextras.HBox( 'Parent', handles.plotgrid,'BackgroundColor',ColorB_def); + +timeStart =handles.timeStart; +timEnd =handles.timEnd; +if isempty(timeStart)|| numel(timeStart)~=1 || timeStart>=ERP.times(end) + timeStart=ERP.times(1); + timEnd = ERP.times(end); + handles.timeStart=timeStart; + handles.timEnd=timEnd; +end +if isempty(timEnd)|| numel(timEnd)~=1 || timEnd<=ERP.times(1) + timeStart=ERP.times(1); + timEnd = ERP.times(end); + handles.timeStart=timeStart; + handles.timEnd=timEnd; +end +handles.edit1_time_range.String = num2str([timeStart,timEnd]); + +xtickstep=handles.xtickstep; +[~, chanLabels, ~, ~, ~] = readlocs(ERP.chanlocs); +Yscale = handles.Yscale; +bindata = []; +ChanArray = str2num(handles.edit_chans.String); +BinArray = str2num(handles.edit_bin.String); +for Numoferp = 1:numel(ERPArray) + ERP = ALLERP(ERPArray(Numoferp)); + bindata(:,:,:,Numoferp) = ERP.bindata(ChanArray,:,BinArray); +end +y_scale_def = [floor(1.1*min(bindata(:))),ceil(1.1*max(bindata(:)))]; +if isempty(Yscale) || numel(Yscale)~=2 + Yscale= y_scale_def; + handles.Yscale=Yscale; +end +handles.edit2_yrange.String = num2str(Yscale); + +Min_vspacing = handles.Min_vspacing; +positive_up = handles.positive_up; +moption= handles.moption; +latency= handles.latency; +Min_time = ERP.times(1); +Max_time = ERP.times(end); +blc = handles.blc; +intfactor = handles.intfactor; +Resolution =handles.Resolution; +BinchanOverlay = 0; +columNum=1; +if chanOverlay==0 + rowNums=numel(ChanArray); +else + rowNums=1; +end + +handles.GridposArray = zeros(rowNums,columNum); +for ii = 1:rowNums + handles.GridposArray(ii,1) = ChanArray(ii); +end +GridposArray = handles.GridposArray; + + + +%%----------------------measurement name----------------------------------- +measurearray = {'Instantaneous amplitude',... + 'Mean amplitude between two fixed latencies',... + 'Peak amplitude',... + 'Peak latency',... + 'Fractional Peak latency',... + 'Numerical integration/Area between two fixed latencies',... + 'Fractional Area latency'}; +meacodes = {'instabl', 'meanbl', 'peakampbl', 'peaklatbl', 'fpeaklat',... + 'areat', 'areap', 'arean','fareatlat',... + 'fareaplat','fninteglat','fareanlat', 'ninteg'}; + +[tfm, indxmeaX] = ismember_bc2({moption}, meacodes); + +if ismember_bc2(indxmeaX,[6 7 8 13])%'areat','areap', 'arean','ninteg', + meamenu = 6; % 'Numerical integration/Area between two fixed latencies',... + % elseif ismember_bc2(indxmeaX,[9 10 11 17])% + % meamenu = 7; % 'Numerical integration/Area between two (automatically detected) zero-crossing latencies'... +elseif ismember_bc2(indxmeaX,[9 10 11 12])%'fareatlat','fareaplat','fninteglat','fareanlat', + meamenu = 7; % 'Fractional Area latency' +elseif ismember_bc2(indxmeaX,1)%'instabl' + meamenu = 1; % 'Instantaneous amplitude',... +elseif ismember_bc2(indxmeaX,2)%'meanbl', + meamenu = 2; % 'mean amp +elseif ismember_bc2(indxmeaX,3)%'peakampbl', + meamenu = 3; % 'peak amp',... +elseif ismember_bc2(indxmeaX,4)%'peaklatbl' + meamenu = 4; % 'peak lat',... +elseif ismember_bc2(indxmeaX,5)%'fpeaklat' + meamenu = 5; % 'Fractional Peak latency',..',... +else + meamenu = 1; % 'Instantaneous amplitude',...%'instabl', +end +mls = sprintf('%s\n%s',measurearray{meamenu},['Measurement Window:',32,num2str(handles.latency)]); + +set(handles.text_measure_type, 'String', mls); +offset = f_plotaberpwave(ALLERP,ERPArray,ERP,ChanArray,BinArray,timeStart,timEnd,xtickstep,Yscale,columNum,... + positive_up,chanOverlay,rowNums,GridposArray,handles.erptabwaveiwer,handles.erptabwaveiwer_legend); +% set(handles.erptabwaveiwer,'BackgroundColor',[1 1 1]); +Res = handles.ViewContainer.Position; +handles.Res = Res; +splot_n = numel(ChanArray); + +pb_height = Min_vspacing*Res(4); %px + +ndata = BinArray; + + +pnts = ERP.pnts; +timeor = ERP.times; % original time vector +p1 = timeor(1); +p2 = timeor(end); +if intfactor~=1 + timex = linspace(p1,p2,round(pnts*intfactor)); +else + timex = timeor; +end +[xxx, latsamp, latdiffms] = closest(timex, [Min_time Max_time]); +tmin = latsamp(1); +tmax = latsamp(2); +if tmin < 1 + tmin = 1; +end +if tmax > numel(timex) + tmax = numel(timex); +end +Plot_erp_data_TRAN = []; +for Numofsub = 1:numel(ERPArray) + ERP1 = ALLERP(ERPArray(Numofsub)); + if intfactor~=1 + for Numoftwo = 1:size(ERP1.bindata,3) + for Numofone = 1:size(ERP1.bindata,1) + data = squeeze(ERP1.bindata(Numofone,:,Numoftwo)); + data = spline(timeor, data, timex); % re-sampled data + blv = blvalue2(data, timex, blc); + data = data - blv; + Plot_erp_data_TRAN(Numofone,:,Numoftwo) = data; + end + end + Bindata(:,:,:,Numofsub) = Plot_erp_data_TRAN; + else + Bindata(:,:,:,Numofsub) = ERP1.bindata; + end +end + +plot_erp_data = nan(splot_n,tmax-tmin+1,numel(ndata)); +for Numofsub = 1:numel(ERPArray) + for i = 1:splot_n + for i_bin = 1:numel(ndata) + plot_erp_data(i,:,i_bin,Numofsub) = Bindata(ChanArray(i),tmin:tmax,BinArray(i_bin),Numofsub)'*positive_up; % + end + end +end + +[Numchan,Numsamp,Numbin,Numerp] = size(plot_erp_data); +if chanOverlay==1 + % plot_erp_data = permute(plot_erp_data,[2 1 3 4]); + % plot_erp_data = reshape(plot_erp_data,1,Numsamp,Numchan*Numbin*Numerp); + plot_erp_data11 = []; + count = 0; + for Numoferp = 1:Numerp + for Numofchan = 1: Numchan + for Numofbin = 1:Numbin + count = count+1; + plot_erp_data11(1,:,count) = squeeze(plot_erp_data(Numofchan,:,Numofbin,Numoferp)); + end + end + end + plot_erp_data = plot_erp_data11; +else + % plot_erp_data = reshape(plot_erp_data,Numchan,Numsamp,Numbin*Numerp); + plot_erp_data11 = []; + count = 0; + for Numoferp = 1:Numerp + for Numofbin = 1:Numbin + count = count+1; + plot_erp_data11(:,:,count) = squeeze(plot_erp_data(:,:,Numofbin,Numoferp)); + end + end + plot_erp_data = plot_erp_data11; +end + +[~,~,Num_plot] = size(plot_erp_data); +line_colors = get_colors(Num_plot); + +% line_colors = repmat(line_colors,[splot_n 1]); %repeat the colors once for every plot +% return; +for i = 1:size(plot_erp_data,1) + plot_erp_data(i,:,:) = plot_erp_data(i,:,:) + ones(size(plot_erp_data(i,:,:)))*offset(i); +end +if chanOverlay==1 + offset = zeros(size(plot_erp_data,3),1); +end +% +%%%Mark the area/latency/amplitude of interest within the defined window. +ERP_mark_area_latency(handles.erptabwaveiwer,timex(tmin:tmax),moption,plot_erp_data,latency,... + line_colors,offset,positive_up,ERP,ChanArray,BinArray,Yscale,ALLERP,ERPArray,chanOverlay);%cwm = [0 0 0];% white: Background color for measurement window +set(handles.erptabwaveiwer,'color',[1 1 1]); +% %%%-------------------Display results obtained from "Measurement Tool" Panel--------------------------------- +offset1 = zeros(numel(ChanArray),1); +for Numofsub = 1:numel(ERPArray) + ERP1 = ALLERP(ERPArray(Numofsub)); + [~,~,~,Amp1,Lat1]= f_ERP_plot_wav(ERP1,offset1,ChanArray,BinArray); + Amp(:,:,Numofsub) = Amp1; + Lat(:,:,Numofsub) = Lat1; +end + +RowName = {}; +count = 0; +for Numofsub = 1:numel(ERPArray) + for Numofbin = 1:numel(BinArray) + count = count+1; + RowName{count} = strcat('Set:',32,num2str(ERPArray(Numofsub))); + end +end + +ColumnName{1} = '#Bin'; +for Numofsel_chan = 1:numel(ChanArray) + ColumnName{Numofsel_chan+1} = ['',num2str(ChanArray(Numofsel_chan)),'.',32,chanLabels{ChanArray(Numofsel_chan)}]; + +end +line_colors_ldg = get_colors(Num_plot); + +if ismember_bc2(moption, {'instabl','peaklatbl','fpeaklat','fareatlat','fninteglat','fareaplat','fareanlat','meanbl','peakampbl','areat','ninteg','areap','arean','ninteg','areazt','nintegz','areazp','areazn'}) + Data_display = Amp(BinArray,ChanArray,:); +else + Data_display = Lat(BinArray,ChanArray,:); +end +if ismember_bc2(moption,{'arean','areazn'}) + Data_display= -1.*Data_display; +end + +Data_display_tra = {}; +count = 0; +for Numofsub = 1:numel(ERPArray) + for Numofbin = 1:numel(BinArray) + count = count+1; + Data_display1(count,:) = Data_display(Numofbin,:,Numofsub); + Data_display_tra{count,1} = sprintf(['%.',num2str(0),'f'], BinArray(Numofbin)); + end +end + +for Numofone = 1:size(Data_display1,1) + for Numoftwo = 1:size(Data_display1,2) + if ~isnan(Data_display1(Numofone,Numoftwo)) + Data_display_tra{Numofone,Numoftwo+1} = sprintf(['%.',num2str(Resolution),'f'], Data_display1(Numofone,Numoftwo)); + else + Data_display_tra{Numofone,Numoftwo+1} = ['NaN']; + end + end +end + +handles.ERP_M_T_Viewer_table = uitable(handles.ERP_M_T_Viewer,'Data',Data_display_tra,'Units','Normalize'); +handles.ERP_M_T_Viewer_table.RowName = RowName; +handles.ERP_M_T_Viewer_table.ColumnName = ColumnName; + + +if numel(ChanArray)<12 + ColumnWidth = {}; + for Numofchan =1:numel(ChanArray)+1 + ColumnWidth{Numofchan} = handles.ERP_M_T_Viewer.Position(3)/(numel(ChanArray)+1); + end + handles.ERP_M_T_Viewer_table.ColumnWidth = ColumnWidth; +elseif numel(ChanArray) ==1 + handles.ERP_M_T_Viewer_table.ColumnWidth = {handles.ERP_M_T_Viewer.Position(3)}; +end + + +handles.plotgrid.Heights(1) = 70; % set the first element (pageinfo) to 30px high +handles.plotgrid.Heights(2) = -1; % set the second element (x axis) to 30px high +handles.plotgrid.Heights(3) = 100; +handles.plotgrid.Units = 'pixels'; + +if Num_plot*pb_height<(handles.plotgrid.Position(4)-handles.plotgrid.Heights(1)) + pb_height = (handles.plotgrid.Position(4)-handles.plotgrid.Heights(1)-handles.plotgrid.Heights(2))/Num_plot; +end +handles.ViewAxes.Heights = Num_plot*pb_height; +handles.ERP_M_T_Viewer_table.FontSize = FonsizeDefault; +handles.text_warningmessage.String =''; +guidata(hObject, handles); + + +function OffSetY = f_plotaberpwave(ALLERP,ERPArray,ERP,ChanArray,BinArray,timeStart,timEnd,xtickstep,qYScales,columNum,... + positive_up,chanOverlay,rowNums,GridposArray,waveview,legendview) +OffSetY = []; +FonsizeDefault = f_get_default_fontsize(); +%%matlab version +matlab_ver = version('-release'); +Matlab_ver = str2double(matlab_ver(1:4)); + +qtimeRange = [timeStart timEnd]; + +qPLOTORG = [1 2 3]; +[~, qplotArrayStr, ~, ~, ~] = readlocs(ERP.chanlocs(ChanArray)); +qLegendName= ERP.bindescr(BinArray); +for Numoferp = 1:numel(ERPArray) + ERP1 = ALLERP(ERPArray(Numoferp)); + [ERPdatadef1,legendNamedef,ERPerrordatadef,timeRangedef] = f_geterpdata(ERP1,1,qPLOTORG,1); + ERPdatadef(:,:,:,Numoferp) = ERPdatadef1; +end +bindata = ERPdatadef(ChanArray,:,BinArray,:); +[Numchan,Numsamp,Numbin,Numerp] = size(bindata); + +if chanOverlay==1 + plotArray=1; + bindata = permute(bindata,[2 1 3 4]); + bindata = reshape(bindata,1,Numsamp,Numchan*Numbin*Numerp); + qplotArrayStr{1,1} = 'No label'; +else + plotArray = ChanArray; + bindata = reshape(bindata,Numchan,Numsamp,Numbin*Numerp); + count = 0; + for Numofsub = 1:numel(ERPArray) + for Numofbin = 1:numel(BinArray) + count = count+1; + qLegendName1{count} = ['ERPset',32,num2str(Numofsub),':',qLegendName{Numofbin}]; + end + end + qLegendName = qLegendName1; +end + + +if isempty(timeRangedef) + timeRangedef = ERP.times; +end +fs= ERP.srate; +% qYScales = [-YtickInterval,YtickInterval]; +Ypert =20; +%%get y axis +y_scale_def = [1.1*min(bindata(:)),1.1*max(bindata(:))]; +if numel(qYScales)==2 && qYScales(1) qtimeRangedef(2) + break; + else + qXticks(numel(qXticks)+1) =xtickcheck; + end +end +if isempty(qXticks)|| stepX==xtickstep + qXticks = timeticksdef; +end +%%remove the margins of a plot +ax = waveview; +outerpos = ax.OuterPosition; +ti = ax.TightInset; +left = outerpos(1) + ti(1); +bottom = outerpos(2) + ti(2); +ax_width = outerpos(3) - ti(1) - ti(3); +ax_height = outerpos(4) - ti(2) - ti(4); +ax.Position = [left bottom ax_width ax_height]; + +%%check elements in qGridposArray +if chanOverlay==1 + GridposArray(1,1)=1; +else + plotArray = reshape(plotArray,1,[]); + for Numofrows = 1:size(GridposArray,1) + for Numofcolumns = 1:size(GridposArray,2) + SingleGridpos = GridposArray(Numofrows,Numofcolumns); + if SingleGridpos~=0 + ExistGridops = f_existvector(plotArray,SingleGridpos); + if ExistGridops==1 + GridposArray(Numofrows,Numofcolumns) =0; + else + [xpos,ypos]= find(plotArray==SingleGridpos); + GridposArray(Numofrows,Numofcolumns) =ypos; + end + end + end + end +end +fontnames = 'Helvetica'; + +hplot = []; +countPlot = 0; +for Numofrows = 1:rowNums + for Numofcolumns = 1:columNum + try + plotdatalabel = GridposArray(Numofrows,Numofcolumns); + catch + plotdatalabel = 0; + end + + try + labelcbe = qplotArrayStr{plotdatalabel}; + if isempty(labelcbe) + labelcbe = ''; + end + catch + labelcbe = 'no'; + end + if chanOverlay==1 + labelcbe = ''; + end + try + plotbindata = bindata(plotdatalabel,:,:,:); + catch + plotbindata = []; + end + + if plotdatalabel ~=0 && plotdatalabel<= numel(plotArray) && ~isempty(plotbindata) + countPlot =countPlot +1; + if qPolarityWave==1 + data4plot = squeeze(bindata(plotdatalabel,:,:,1)); + else + data4plot = squeeze(bindata(plotdatalabel,:,:,1))*(-1); + end + + data4plot = reshape(data4plot,numel(timeRangedef),NumOverlay); + for Numofoverlay = 1:NumOverlay + [Xtimerange, bindatatrs] = f_adjustbindtabasedtimedefd(squeeze(data4plot(:,Numofoverlay)), timeRangedef,qtimeRange,fs); + PosIndexsALL = [Numofrows,columNum]; + if isxaxislabel==2 + [~,XtimerangetrasfALL,~,~,~] = f_adjustdata_xyrange_xyticks_overlay(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexsALL,StepXP); + else + [~,XtimerangetrasfALL,~] = f_adjustdata_xyrange_xyticks(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexsALL,StepX,fs); + end + PosIndexs = [Numofrows,Numofcolumns]; + if isxaxislabel==2 + [bindatatrs,Xtimerangetrasf,qXtickstransf,TimeAdjustOut,XtimerangeadjustALL] = f_adjustdata_xyrange_xyticks_overlay(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexs,StepXP); + else + [bindatatrs,Xtimerangetrasf,qXtickstransf] = f_adjustdata_xyrange_xyticks(bindatatrs,Xtimerange,qXticks,OffSetY,columNum,PosIndexs,StepX,fs); + end + hplot(Numofoverlay) = plot(waveview,Xtimerangetrasf, bindatatrs,'LineWidth',1,... + 'Color', qLineColorspec(Numofoverlay,:)); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%----------------------Adjust y axis------------------------%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + props = get(waveview); + if qPolarityWave==1 + props.YTick = qYticks+OffSetY(Numofrows); + else + props.YTick = fliplr (-1*qYticks)+OffSetY(Numofrows); + end + props.YTickLabel = cell(numel(props.YTick),1); + + + for Numofytick = 1:numel(props.YTick) + props.YTickLabel(Numofytick) = {num2str(props.YTick(Numofytick))}; + end + + [x,y_0] = find(Xtimerange==0); + if isempty(y_0) + y_0 = 1; + end + myY_Crossing = Xtimerangetrasf(y_0); + tick_top = 0; + + if countPlot ==1 + ytick_bottom = -props.TickLength(1)*diff(props.XLim); + ytick_bottomratio = abs(ytick_bottom)/diff(props.XLim); + else + try + ytick_bottom = ytick_bottom; + ytick_bottomratio = ytick_bottomratio; + catch + ytick_bottom = -props.TickLength(1)*diff(props.XLim); + ytick_bottomratio = abs(ytick_bottom)/diff(props.XLim); + end + end + %%add yunits + if ~isempty(props.YTick) + ytick_y = repmat(props.YTick, 2, 1); + ytick_x = repmat([tick_top;ytick_bottom] +myY_Crossing, 1, length(props.YTick)); + line(waveview,ytick_x(:,:), ytick_y(:,:), 'color', 'k','LineWidth',1); + try + [~,y_below0] =find(qYticks<0); + if isempty(y_below0) && qYScales(1)<0 + line(waveview,ytick_x(:,:), ones(2,1)*(qYScales(1)+OffSetY(Numofrows)), 'color', 'k','LineWidth',1); + end + [~,y_over0] =find(qYticks>0); + if isempty(y_over0) && qYScales(2)>0 + line(waveview,ytick_x(:,:), ones(2,1)*(qYScales(2)+OffSetY(Numofrows)), 'color', 'k','LineWidth',1); + end + catch + end + end + + if ~isempty(qYScales) && numel(qYScales)==2 %qYScales(end))+OffSetY(1) + if qPolarityWave==1 + qYScalestras = qYScales; + else + qYScalestras = fliplr (-1*qYScales); + end + plot(waveview,ones(numel(qYScalestras),1)*myY_Crossing, qYScalestras+OffSetY(Numofrows),'k','LineWidth',1); + else + if ~isempty(y_scale_def) && numel(unique(y_scale_def))==2 + if qPolarityWave==0 + qYScalestras = y_scale_def; + else + qYScalestras = fliplr (-1*y_scale_def); + end + plot(waveview,ones(numel(qYScales),1)*myY_Crossing, qYScalestras+OffSetY(Numofrows),'k','LineWidth',1); + else + end + end + + qYtickdecimal=1; + nYTicks = length(props.YTick); + for iCount = 1:nYTicks + if qPolarityWave==1 + ytick_label= sprintf(['%.',num2str(qYtickdecimal),'f'],str2num(char(props.YTickLabel(iCount, :)))-OffSetY(Numofrows)); + else + qyticktras = fliplr(-1*qYticks); + ytick_label= sprintf(['%.',num2str(qYtickdecimal),'f'],-qyticktras(iCount)); + end + % end + if str2num(char(ytick_label)) ==0 || (str2num(char(ytick_label))<0.0001 && str2num(char(ytick_label))>0) || (str2num(char(ytick_label))>-0.0001 && str2num(char(ytick_label))<0) + ytick_label = ''; + end + text(waveview,myY_Crossing-2*abs(ytick_bottom),props.YTick(iCount), ... + ytick_label, ... + 'HorizontalAlignment', 'right', ... + 'VerticalAlignment', 'middle', ... + 'FontSize', FonsizeDefault, ... + 'FontAngle', props.FontAngle, ... + 'FontUnits', props.FontUnits,... + 'FontName', fontnames, ... + 'Color',[0 0 0]);% + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%----------------------Adjust x axis------------------------%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + props.XTick = qXtickstransf; + props.XTickLabel = cell(numel(qXticks),1); + for Numofytick = 1:numel(props.XTick) + props.XTickLabel(Numofytick) = {num2str(qXticks(Numofytick))}; + end + myX_Crossing = OffSetY(Numofrows); + if countPlot ==1 + xtick_bottom = -props.TickLength(2)*max(props.YLim); + if abs(xtick_bottom)/max(props.YLim) > ytick_bottomratio + xtick_bottom = -ytick_bottomratio*max(props.YLim); + end + else + try + xtick_bottom = xtick_bottom; + catch + xtick_bottom = -props.TickLength(2)*max(props.YLim); + if abs(xtick_bottom)/max(props.YLim) > ytick_bottomratio + xtick_bottom = -ytick_bottomratio*max(props.YLim); + end + end + end + if ~isempty(props.XTick) + xtick_x = repmat(props.XTick, 2, 1); + xtick_y = repmat([xtick_bottom; tick_top]*0.5 + myX_Crossing, 1, length(props.XTick)); + line(waveview,xtick_x, xtick_y, 'color', 'k','LineWidth',1); + end + [x_xtick,y_xtick] = find(props.XTick==0); + if ~isempty(y_xtick) + props.XTick(y_xtick) = 2*xtick_bottom; + end + plot(waveview,Xtimerangetrasf, myX_Crossing.*ones(numel(Xtimerangetrasf),1),'k','LineWidth',1); + nxTicks = length(props.XTick); + qXticklabel = 'on'; + for iCount = 1:nxTicks + xtick_label = (props.XTickLabel(iCount, :)); + if strcmpi(qXticklabel,'on') + if strcmpi(xtick_label,'0') + xtick_label = ''; + end + else + xtick_label = ''; + end + text(waveview,props.XTick(iCount), xtick_bottom*0.5 + myX_Crossing, ... + xtick_label, ... + 'HorizontalAlignment', 'Center', ... + 'VerticalAlignment', 'Top', ... + 'FontSize', FonsizeDefault, ... + 'FontAngle', props.FontAngle, ... + 'FontUnits', props.FontUnits,... + 'FontName', fontnames, ... + 'Color',[0 0 0]);%'FontName', qXlabelfont, ... + end + %%-----------------minor X--------------- + set(waveview,'xlim',[Xtimerange(1),Xtimerangetrasf(end)]); + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%------------------channel/bin/erpset label-----------------%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + ypercentage =100; + ypos_LABEL = (qYScalestras(end)-qYScalestras(1))*(ypercentage)/100+qYScalestras(1); + xpercentage = 0; + xpos_LABEL = (Xtimerangetrasf(end)-Xtimerangetrasf(1))*xpercentage/100 + Xtimerangetrasf(1); + labelcbe = strrep(char(labelcbe),'_','\_'); + try + labelcbe = regexp(labelcbe, '\;', 'split'); + catch + end + text(waveview,xpos_LABEL,ypos_LABEL+OffSetY(Numofrows), char(labelcbe),'FontName', fontnames,'HorizontalAlignment', 'center');%'FontWeight', 'bold', + else + end + try + if 2 length(ALLERP)) || any(ERPArray(:)<1) + ERPArray = 1; + handles.CurrentERP = ERPArray; +end +checkindex = checkerpsets(ALLERP(ERPArray)); +if ~isempty(checkindex) + handles.text_warningmessage.String = [checkindex,'. You cannot display multiple ERPsets simultaneously']; + handles.checkbox_erp.Value=0; + handles.radiobutton_erppor.Value=1; + ERPArray = ERPArray(1); +end + +handles.edit5_erpset.String = num2str(ERPArray); +if numel(ERPArray)==1 + if ERPArray==1 + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + elseif ERPArray==length(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'off'; + else + handles.pushbutton_erpsetsmall.Enable = 'on'; + handles.pushbutton_erpsetlarge.Enable = 'on'; + end +else + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +end +if numel(ERPArray)== numel(ALLERP) + handles.pushbutton_erpsetsmall.Enable = 'off'; + handles.pushbutton_erpsetlarge.Enable = 'off'; +end +ERP = ALLERP(ERPArray(1)); +if numel(ERPArray)==1 + handles.text_erpname.String = ERP.erpname; +else + handles.text_erpname.String = 'Multiple ERPsets were slected'; +end + +%%channels +ChanArray_new = str2num(handles.edit_chans.String); +nbchan = ERP.nchan; +handles.ERP = ERP; +ChanArray = handles.ChanArray; +ChanArray =reshape(ChanArray,1,numel(ChanArray)); +if isempty(ChanArray_new) || any(ChanArray_new>nbchan) || any(ChanArray_new<=0) + ChanArray_new =ChanArray; + handles.ChanArray = ChanArray_new; +end + + +[~,chanpos] = find(sort(ChanArray) ==sort(ChanArray_new)); +if isempty(chanpos) + ChanArray_new = ChanArray(1); + handles.edit_chans.String = num2str( ChanArray(1)); + chanpos = 1; +end + +if numel(ChanArray_new)~=1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +else + if chanpos==1 + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'on'; + elseif chanpos==numel(ChanArray) + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'off'; + else + handles.pushbutton8_chansmall.Enable = 'on'; + handles.pushbutton_chanlarge.Enable = 'on'; + end +end +if numel(ChanArray_new) == numel(ChanArray) + handles.pushbutton8_chansmall.Enable = 'off'; + handles.pushbutton_chanlarge.Enable = 'off'; +end +ChanArray = ChanArray_new; +ChanArray11 = vect2colon(ChanArray_new,'Sort', 'off'); +ChanArray11 = erase(ChanArray11,{'[',']'}); +handles.edit_chans.String = ChanArray11; + + +%%bin +nbin = ERP.nbin; +BinArray_edit =str2num(handles.edit_bin.String); +if isempty(BinArray_edit) || any(BinArray_edit>nbin) || any(BinArray_edit<=0) + BinArray_edit = [1:nbin]; + handles.BinArray = BinArray; +end +BinArray = handles.BinArray; +BinArray =reshape(BinArray,1,numel(BinArray)); +[~,binpos] = find(sort(BinArray) ==sort(BinArray_edit)); +if isempty(binpos) + BinArray_edit = BinArray(1); + handles.edit_bin.String = num2str(BinArray_edit); + binpos = 1; +end + +if numel(BinArray_edit)~=1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +else + if binpos==1 + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'on'; + elseif binpos == numel(BinArray) + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'off'; + else + handles.pushbutton_binsmall.Enable = 'on'; + handles.pushbutton_binlarge.Enable = 'on'; + end +end + +if numel(BinArray_edit)== numel(BinArray) + handles.pushbutton_binsmall.Enable = 'off'; + handles.pushbutton_binlarge.Enable = 'off'; +end +BinArray =BinArray_edit; +BinArray1 = vect2colon(BinArray_edit,'Sort', 'off'); +BinArray1 = erase(BinArray1,{'[',']'}); +handles.edit_bin.String = BinArray1; + +%%-----------------------create the panel---------------------------------- +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.7020 0.77 0.85]; +end +if isempty(ColorB_def) + ColorB_def = [0.7020 0.77 0.85]; +end + +Position = handles.erptabwaveiwer.OuterPosition; +chanOverlay = handles.radiobutton_chanoverlay.Value; + +if chanOverlay==0 + rowNums=numel(ChanArray); +else + rowNums=1; +end + + +FigureName= figure( 'Name',[ERP.erpname] , ... + 'NumberTitle', 'off','Color',[1 1 1]); +FigureName.Position(3:4) = Position(3:4); +FigureName.Position(1:2) = [0 0]; +erptabwaveiwer_legend = subplot(ceil(rowNums*5)+1, 1, 1,'align'); + +hbig = subplot(ceil(rowNums*5)+1,1,[2:ceil(rowNums*5)+1]); +hold(hbig,'on'); +set(erptabwaveiwer_legend, 'XTick', [], 'YTick', [],'Box','off', 'Color','none','xcolor','none','ycolor','none','box','off'); + + +timeStart =handles.timeStart; +timEnd =handles.timEnd; +if isempty(timeStart)|| numel(timeStart)~=1 || timeStart>=ERP.times(end) + timeStart=ERP.times(1); + timEnd = ERP.times(end); + handles.timeStart=timeStart; + handles.timEnd=timEnd; +end +if isempty(timEnd)|| numel(timEnd)~=1 || timEnd<=ERP.times(1) + timeStart=ERP.times(1); + timEnd = ERP.times(end); + handles.timeStart=timeStart; + handles.timEnd=timEnd; +end +handles.edit1_time_range.String = num2str([timeStart,timEnd]); + +xtickstep=handles.xtickstep; +[~, chanLabels, ~, ~, ~] = readlocs(ERP.chanlocs); +Yscale = handles.Yscale; +bindata = ERP.bindata(ChanArray,:,BinArray); +y_scale_def = [1.1*min(bindata(:)),1.1*max(bindata(:))]; +if isempty(Yscale) || numel(Yscale)~=2 + Yscale= y_scale_def; + handles.Yscale=Yscale; +end +handles.edit2_yrange.String = num2str(Yscale); + +Min_vspacing = handles.Min_vspacing; +Fillscreen = handles.Fillscreen; +positive_up = handles.positive_up; +moption= handles.moption; +latency= handles.latency; +Min_time = ERP.times(1); +Max_time = ERP.times(end); +blc = handles.blc; +intfactor = handles.intfactor; +Resolution =handles.Resolution; +BinchanOverlay = 0; +columNum=1; + +handles.GridposArray = zeros(rowNums,columNum); +for ii = 1:rowNums + handles.GridposArray(ii,1) = ChanArray(ii); +end +GridposArray = handles.GridposArray; + +%%----------------------measurement name----------------------------------- +offset = f_plotaberpwave(ALLERP,ERPArray,ERP,ChanArray,BinArray,timeStart,timEnd,xtickstep,Yscale,columNum,... + positive_up,chanOverlay,rowNums,GridposArray,hbig,erptabwaveiwer_legend); + +splot_n = numel(ChanArray); + +ndata = BinArray; +pnts = ERP.pnts; +timeor = ERP.times; % original time vector +p1 = timeor(1); +p2 = timeor(end); +if intfactor~=1 + timex = linspace(p1,p2,round(pnts*intfactor)); +else + timex = timeor; +end +[xxx, latsamp, latdiffms] = closest(timex, [Min_time Max_time]); +tmin = latsamp(1); +tmax = latsamp(2); +if tmin < 1 + tmin = 1; +end +if tmax > numel(timex) + tmax = numel(timex); +end +Plot_erp_data_TRAN = []; +for Numofsub = 1:numel(ERPArray) + ERP1 = ALLERP(ERPArray(Numofsub)); + if intfactor~=1 + for Numoftwo = 1:size(ERP1.bindata,3) + for Numofone = 1:size(ERP1.bindata,1) + data = squeeze(ERP1.bindata(Numofone,:,Numoftwo)); + data = spline(timeor, data, timex); % re-sampled data + blv = blvalue2(data, timex, blc); + data = data - blv; + Plot_erp_data_TRAN(Numofone,:,Numoftwo) = data; + end + end + Bindata(:,:,:,Numofsub) = Plot_erp_data_TRAN; + else + Bindata(:,:,:,Numofsub) = ERP1.bindata; + end +end + +plot_erp_data = nan(splot_n,tmax-tmin+1,numel(ndata)); +for Numofsub = 1:numel(ERPArray) + for i = 1:splot_n + for i_bin = 1:numel(ndata) + plot_erp_data(i,:,i_bin,Numofsub) = Bindata(ChanArray(i),tmin:tmax,BinArray(i_bin),Numofsub)'*positive_up; % + end + end +end + +[Numchan,Numsamp,Numbin,Numerp] = size(plot_erp_data); +if chanOverlay==1 + plot_erp_data11 = []; + count = 0; + for Numoferp = 1:Numerp + for Numofchan = 1: Numchan + for Numofbin = 1:Numbin + count = count+1; + plot_erp_data11(1,:,count) = squeeze(plot_erp_data(Numofchan,:,Numofbin,Numoferp)); + end + end + end + plot_erp_data = plot_erp_data11; +else + plot_erp_data11 = []; + count = 0; + for Numoferp = 1:Numerp + for Numofbin = 1:Numbin + count = count+1; + plot_erp_data11(:,:,count) = squeeze(plot_erp_data(:,:,Numofbin,Numoferp)); + end + end + plot_erp_data = plot_erp_data11; +end + +[~,~,Num_plot] = size(plot_erp_data); +line_colors = get_colors(Num_plot); + +if chanOverlay==1 + offset = zeros(size(plot_erp_data,3),1); +end + +for i = 1:size(plot_erp_data,1) + plot_erp_data(i,:,:) = plot_erp_data(i,:,:) + ones(size(plot_erp_data(i,:,:)))*offset(i); +end + +% +%%%Mark the area/latency/amplitude of interest within the defined window. +ERP_mark_area_latency(hbig,timex(tmin:tmax),moption,plot_erp_data,latency,line_colors,offset,... + positive_up,ERP,ChanArray,BinArray,Yscale,ALLERP,ERPArray,chanOverlay);%cwm = [0 0 0];% white: Background color for measurement window + + + +function colors = get_colors(ncolors) +% Each color gets 1 point divided into up to 2 of 3 groups (RGB). +degree_step = 6/ncolors; +angles = (0:ncolors-1)*degree_step; +colors = nan(numel(angles),3); +for i = 1:numel(angles) + if angles(i) < 1 + colors(i,:) = [1 (angles(i)-floor(angles(i))) 0]*0.75; + elseif angles(i) < 2 + colors(i,:) = [(1-(angles(i)-floor(angles(i)))) 1 0]*0.75; + elseif angles(i) < 3 + colors(i,:) = [0 1 (angles(i)-floor(angles(i)))]*0.75; + elseif angles(i) < 4 + colors(i,:) = [0 (1-(angles(i)-floor(angles(i)))) 1]*0.75; + elseif angles(i) < 5 + colors(i,:) = [(angles(i)-floor(angles(i))) 0 1]*0.75; + else + colors(i,:) = [1 0 (1-(angles(i)-floor(angles(i))))]*0.75; + end +end + + + + +function ERP_mark_area_latency(r_ax,timex,moption,plot_erp_data,latency,line_colors,offset,... + positive_up,ERP,ChanArray,BinArray,Yscale,ALLERP,ERPArray,chanOverlay) + +cwm_backgb=[0.7 0.7 0.7]; +cwm =[0 0 0]; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Plot area within the defined time-window%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%Set area within the defined time-window for 1.Fractional area latency, 2. Numerical integration/Area between two fixed latencies +mearea = { 'areat', 'areap', 'arean','areazt','areazp','areazn', 'ninteg','nintegz'}; +plot_erp_data = permute(plot_erp_data,[2 1 3]); +[~,Num_data,Num_plot] = size(plot_erp_data); + +if ismember_bc2(moption, mearea) || ismember_bc2(moption, {'fareatlat', 'fareaplat','fninteglat','fareanlat'}) + if numel(latency) ==2 + latx = latency; + [xxx, latsamp] = closest(timex, latx); + datax = plot_erp_data(latsamp(1):latsamp(2),:,:); + datax = permute(datax,[1 3 2]); + end + + Time_res = timex(2)-timex(1); + + if ismember_bc2(moption, {'areap', 'fareaplat'}) % positive area + + for Numofstione = 1:size(datax,3) + for Numofstitwo = 1:size(datax,2) + timexx = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); + data_check = dataxx-offset(Numofstione); + if positive_up==1 + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + elseif positive_up ==-1 + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + else + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + end + + if ~isempty(dataxx) && numel(dataxx)>=2 + %%Check isolated point + Check_outlier =[]; + count = 0; + + if (timexx(2)-timexx(1)>Time_res) + count= count +1; + Check_outlier(count) = 1; + end + if numel(dataxx)>=3 + for Numofsample = 2:length(timexx)-1 + if (timexx(Numofsample+1)-timexx(Numofsample)>Time_res) && (timexx(Numofsample)-timexx(Numofsample-1)< Time_res) + count = count+1; + Check_outlier(count) = Numofsample; + end + end + end + dataxx(Check_outlier) = []; + timexx(Check_outlier) = []; + + Check_isolated =[]; + count = 0; + for Numofsample = 1:length(timexx)-1 + if timexx(Numofsample+1)-timexx(Numofsample)>Time_res + count = count+1; + Check_isolated(count) = Numofsample; + end + end + if numel(Check_isolated) ==1 + inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; + inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + inBetweenRegionX2 = [timexx(Check_isolated(1)+1:end),fliplr(timexx(Check_isolated(1)+1:end))]; + inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(1)+1:end))))]; + fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + elseif numel(Check_isolated) >1 + for Numofrange = 1:numel(Check_isolated)-1 + inBetweenRegionX = [timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; + inBetweenRegionY = [squeeze(dataxx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; + inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + inBetweenRegionX2 = [timexx(Check_isolated(Numofrange+1)+1:end),fliplr(timexx(Check_isolated(Numofrange+1)+1:end))]; + inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange+1)+1:end))))]; + fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + else + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + end + + end + + end + + elseif ismember_bc2(moption, {'arean', 'fareanlat'}) % negative area + for Numofstione = 1:size(datax,3) + for Numofstitwo = 1:size(datax,2) + timexx = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); + data_check = dataxx-offset(Numofstione); + if positive_up==1 + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + elseif positive_up ==-1 + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + else + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + end + + %%Check isolated point + if ~isempty(dataxx) && numel(dataxx)>=2 + Check_outlier =[]; + count = 0; + + if (timexx(2)-timexx(1)>Time_res) + count= count +1; + Check_outlier(count) = 1; + end + if numel(dataxx)>=3 + for Numofsample = 2:length(timexx)-1 + if (timexx(Numofsample+1)-timexx(Numofsample)>Time_res) && (timexx(Numofsample)-timexx(Numofsample-1)< Time_res) + count = count+1; + Check_outlier(count) = Numofsample; + end + end + end + dataxx(Check_outlier) = []; + timexx(Check_outlier) = []; + + Check_isolated =[]; + count = 0; + for Numofsample = 1:length(timexx)-1 + if timexx(Numofsample+1)-timexx(Numofsample)>Time_res + count = count+1; + Check_isolated(count) = Numofsample; + end + end + if numel(Check_isolated) ==1 + inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; + inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + inBetweenRegionX2 = [timexx(Check_isolated(1)+1:end),fliplr(timexx(Check_isolated(1)+1:end))]; + inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(1)+1:end))))]; + fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + elseif numel(Check_isolated) >1 + for Numofrange = 1:numel(Check_isolated)-1 + inBetweenRegionX = [timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; + inBetweenRegionY = [squeeze(dataxx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + inBetweenRegionX1 = [timexx(1:Check_isolated(1)),fliplr(timexx(1:Check_isolated(1)))]; + inBetweenRegionY1 = [squeeze(dataxx(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexx(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + inBetweenRegionX2 = [timexx(Check_isolated(Numofrange+1)+1:end),fliplr(timexx(Check_isolated(Numofrange+1)+1:end))]; + inBetweenRegionY2 = [squeeze(dataxx(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexx(Check_isolated(Numofrange+1)+1:end))))]; + fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + else + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + end + end + end + + elseif ismember_bc2(moption, {'ninteg', 'fninteglat'}) % integration(area for negative substracted from area for positive) + for Numofstione = 1:size(datax,3) + for Numofstitwo = 1:size(datax,2) + timexxp = timex(latsamp(1):latsamp(2)); + dataxxp = squeeze(datax(:,Numofstitwo,Numofstione)); + timexxn = timex(latsamp(1):latsamp(2)); + dataxxn = squeeze(datax(:,Numofstitwo,Numofstione)); + data_check = dataxxn-offset(Numofstione); + if positive_up==1 + dataxxp(data_check<0) = []; + timexxp(data_check<0) = []; + dataxxn(data_check>0) = []; + timexxn(data_check>0) = []; + elseif positive_up ==-1 + dataxxp(data_check>0) = []; + timexxp(data_check>0) = []; + dataxxn(data_check<0) = []; + timexxn(data_check<0) = []; + else + dataxxp(data_check<0) = []; + timexxp(data_check<0) = []; + dataxxn(data_check>0) = []; + timexxn(data_check>0) = []; + end + + if ~isempty(dataxxp) && numel(dataxxp)>=2 + %%Check isolated point + Check_outlierp =[]; + count = 0; + + if (timexxp(2)-timexxp(1)>Time_res) + count= count +1; + Check_outlierp(count) = 1; + end + if numel(dataxxp)>=3 + for Numofsample = 2:length(timexxp)-1 + if (timexxp(Numofsample+1)-timexxp(Numofsample)>Time_res) && (timexxp(Numofsample)-timexxp(Numofsample-1)< Time_res) + count = count+1; + Check_outlierp(count) = Numofsample; + end + end + end + dataxxp(Check_outlierp) = []; + timexxp(Check_outlierp) = []; + + Check_isolated =[]; + count = 0; + for Numofsample = 1:length(timexxp)-1 + if timexxp(Numofsample+1)-timexxp(Numofsample)>Time_res + count = count+1; + Check_isolated(count) = Numofsample; + end + end + if numel(Check_isolated) ==1 + inBetweenRegionXp1 = [timexxp(1:Check_isolated(1)),fliplr(timexxp(1:Check_isolated(1)))]; + inBetweenRegionYp1 = [squeeze(dataxxp(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionXp1, inBetweenRegionYp1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + inBetweenRegionXp2 = [timexxp(Check_isolated(1)+1:end),fliplr(timexxp(Check_isolated(1)+1:end))]; + inBetweenRegionYp2 = [squeeze(dataxxp(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(Check_isolated(1)+1:end))))]; + fill(r_ax,inBetweenRegionXp2, inBetweenRegionYp2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + elseif numel(Check_isolated) >1 + for Numofrange = 1:numel(Check_isolated)-1 + inBetweenRegionX = [timexxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; + inBetweenRegionY = [squeeze(dataxxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + inBetweenRegionX1 = [timexxp(1:Check_isolated(1)),fliplr(timexxp(1:Check_isolated(1)))]; + inBetweenRegionY1 = [squeeze(dataxxp(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + inBetweenRegionX2 = [timexxp(Check_isolated(Numofrange+1)+1:end),fliplr(timexxp(Check_isolated(Numofrange+1)+1:end))]; + inBetweenRegionY2 = [squeeze(dataxxp(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxp(Check_isolated(Numofrange+1)+1:end))))]; + fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + else + inBetweenRegionX = [timexxp,fliplr(timexxp)]; + inBetweenRegionY = [squeeze(dataxxp)',fliplr(offset(Numofstione)*ones(1,numel(timexxp)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + end%Positive part end + + if ~isempty(dataxxn) && numel(dataxxn)>=2 + %%Check isolated point + Check_outliern =[]; + count = 0; + + if (timexxn(2)-timexxn(1)>Time_res) + count= count +1; + Check_outliern(count) = 1; + end + if numel(dataxxn)>=3 + for Numofsample = 2:length(timexxn)-1 + if (timexxn(Numofsample+1)-timexxn(Numofsample)>Time_res) && (timexxn(Numofsample)-timexxn(Numofsample-1)< Time_res) + count = count+1; + Check_outliern(count) = Numofsample; + end + end + end + dataxxn(Check_outliern) = []; + timexxn(Check_outliern) = []; + + Check_isolated =[]; + count = 0; + for Numofsample = 1:length(timexxn)-1 + if timexxn(Numofsample+1)-timexxn(Numofsample)>Time_res + count = count+1; + Check_isolated(count) = Numofsample; + end + end + if numel(Check_isolated) ==1 + inBetweenRegionXp1 = [timexxn(1:Check_isolated(1)),fliplr(timexxn(1:Check_isolated(1)))]; + inBetweenRegionYp1 = [squeeze(dataxxn(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionXp1, inBetweenRegionYp1,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + inBetweenRegionXp2 = [timexxn(Check_isolated(1)+1:end),fliplr(timexxn(Check_isolated(1)+1:end))]; + inBetweenRegionYp2 = [squeeze(dataxxn(Check_isolated(1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(Check_isolated(1)+1:end))))]; + fill(r_ax,inBetweenRegionXp2, inBetweenRegionYp2,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + elseif numel(Check_isolated) >1 + for Numofrange = 1:numel(Check_isolated)-1 + + inBetweenRegionX = [timexxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)),fliplr(timexxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))]; + inBetweenRegionY = [squeeze(dataxxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(Check_isolated(Numofrange)+1:Check_isolated(Numofrange+1)))))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + end + inBetweenRegionX1 = [timexxn(1:Check_isolated(1)),fliplr(timexxn(1:Check_isolated(1)))]; + inBetweenRegionY1 = [squeeze(dataxxn(1:Check_isolated(1)))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(1:Check_isolated(1)))))]; + fill(r_ax,inBetweenRegionX1, inBetweenRegionY1,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + + inBetweenRegionX2 = [timexxn(Check_isolated(Numofrange+1)+1:end),fliplr(timexxn(Check_isolated(Numofrange+1)+1:end))]; + inBetweenRegionY2 = [squeeze(dataxxn(Check_isolated(Numofrange+1)+1:end))',fliplr(offset(Numofstione)*ones(1,numel(timexxn(Check_isolated(Numofrange+1)+1:end))))]; + fill(r_ax,inBetweenRegionX2, inBetweenRegionY2,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + else + inBetweenRegionX = [timexxn,fliplr(timexxn)]; + inBetweenRegionY = [squeeze(dataxxn)',fliplr(offset(Numofstione)*ones(1,numel(timexxn)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:).*0.3,'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + end%%Negative part end + end + end + + elseif ismember_bc2(moption, {'areat', 'fareatlat'})% negative values become positive + for Numofstione = 1:size(datax,3) + for Numofstitwo = 1:size(datax,2) + timexx = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(datax(:,Numofstitwo,Numofstione)); + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx)',fliplr(offset(Numofstione)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(Numofstitwo,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(Numofstitwo,:,:)); + end + end + + elseif ismember_bc2(moption, {'areazt','areazp','areazn', 'nintegz'}) + if chanOverlay==1 + offset = zeros(numel(ChanArray),1); + end + countcolor=0; + for Numoferp = 1:numel(ERPArray) + ERP1 = ALLERP(ERPArray(Numoferp)); + bindata = ERP1.bindata(ChanArray,:,BinArray); + [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(ERP1,offset,ChanArray,BinArray); + + if strcmp(moption,'areazt')%% all area were included + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + latx = Lat{Numofbin,Numofchan}; + [xxx, latsamp] = closest(timex, latx); + + timexx = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx),fliplr(offset(Numofchan)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(countcolor,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + end + end + + elseif strcmp(moption,'areazp')%% Only positive area was included + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + + latx = Lat{Numofbin,Numofchan}; + [xxx, latsamp] = closest(timex, latx); + datax = plot_erp_data(latsamp(1):latsamp(2),:,:); + timexx = timex(latsamp(1):latsamp(2)); + timexx_unsl = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + data_check_unsl = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + data_check = dataxx -offset(Numofchan); + if positive_up==1 + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + data_check_unsl(data_check>0) =[]; + timexx_unsl(data_check>0) = []; + elseif positive_up ==-1 + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + data_check_unsl(data_check<0) =[]; + timexx_unsl(data_check<0) = []; + else + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + data_check_unsl(data_check>0) =[]; + timexx_unsl(data_check>0) = []; + end + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx),fliplr(offset(Numofchan)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(countcolor,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + inBetweenRegionX_unsl = [timexx_unsl,fliplr(timexx_unsl)]; + inBetweenRegionY_unsl = [squeeze(data_check_unsl),fliplr(offset(Numofchan)*ones(1,numel(timexx_unsl)))]; + fill(r_ax,inBetweenRegionX_unsl, inBetweenRegionY_unsl,[1 1 1],'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + end + end + + elseif strcmp(moption,'areazn')%% Only positive area was included + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + + latx = Lat{Numofbin,Numofchan}; + [xxx, latsamp] = closest(timex, latx); + timexx = timex(latsamp(1):latsamp(2)); + timexx_unsl = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + data_check_unsl = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + data_check = dataxx -offset(Numofchan); + if positive_up==1 + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + data_check_unsl(data_check<0) =[]; + timexx_unsl(data_check<0) = []; + elseif positive_up ==-1 + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + data_check_unsl(data_check>0) =[]; + timexx_unsl(data_check>0) = []; + else + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + data_check_unsl(data_check<0) =[]; + timexx_unsl(data_check<0) = []; + end + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx),fliplr(offset(Numofchan)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(countcolor,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + inBetweenRegionX_unsl = [timexx_unsl,fliplr(timexx_unsl)]; + inBetweenRegionY_unsl = [squeeze(data_check_unsl),fliplr(offset(Numofchan)*ones(1,numel(timexx_unsl)))]; + fill(r_ax,inBetweenRegionX_unsl, inBetweenRegionY_unsl,[1 1 1],'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + end + end + + elseif strcmp(moption,'nintegz')%% Only positive area was included + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + + latx = Lat{Numofbin,Numofchan}; + [xxx, latsamp] = closest(timex, latx); + timexx = timex(latsamp(1):latsamp(2)); + timexx_unsl = timex(latsamp(1):latsamp(2)); + dataxx = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + data_check_unsl = squeeze(bindata(Numofchan,latsamp(1):latsamp(2),Numofbin))+offset(Numofchan); + data_check = dataxx -offset(Numofchan); + if positive_up==1 + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + data_check_unsl(data_check>0) =[]; + timexx_unsl(data_check>0) = []; + elseif positive_up ==-1 + dataxx(data_check>0) = []; + timexx(data_check>0) = []; + data_check_unsl(data_check<0) =[]; + timexx_unsl(data_check<0) = []; + else + dataxx(data_check<0) = []; + timexx(data_check<0) = []; + data_check_unsl(data_check>0) =[]; + timexx_unsl(data_check>0) = []; + end + inBetweenRegionX = [timexx,fliplr(timexx)]; + inBetweenRegionY = [squeeze(dataxx),fliplr(offset(Numofchan)*ones(1,numel(timexx)))]; + fill(r_ax,inBetweenRegionX, inBetweenRegionY,line_colors(countcolor,:,:),'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + inBetweenRegionX_unsl = [timexx_unsl,fliplr(timexx_unsl)];% + inBetweenRegionY_unsl = [squeeze(data_check_unsl),fliplr(offset(Numofchan)*ones(1,numel(timexx_unsl)))]; + fill(r_ax,inBetweenRegionX_unsl, inBetweenRegionY_unsl,line_colors(countcolor,:,:)*0.5,'FaceAlpha',0.3,'EdgeColor',line_colors(countcolor,:,:)); + end + end + end + end%%loop for erpsets + + end +end + +% return; + +if length(latency)==1 + if ismember_bc2(moption, {'areazt','areazp','areazn', 'nintegz'})%% Four options for Numerical integration/Area between two (automatically detected)zero-crossing latencies + xline(r_ax,latency, 'Color', cwm,'LineWidth' ,1); + else + xline(r_ax,latency, 'Color', cwm,'LineWidth' ,1); + end + if ismember_bc2(moption, 'instabl') + count111 = 0; + for Numoferp = 1:numel( ERPArray) + ERP1 = ALLERP(ERPArray(Numoferp)); + if chanOverlay==1 + offset = zeros(numel(ChanArray),1); + end + [new_erp_data, Amp_out,Lat]= f_ERP_plot_wav(ERP1,offset,ChanArray,BinArray); + for Numofstitwo = 1:size(Amp_out,1) + count111 = count111+1; + for Numofstione = 1:size(Amp_out,2) + plot(r_ax,latency,squeeze(Amp_out(Numofstitwo,Numofstione)),'Color',line_colors(count111,:,:),'LineWidth' ,1); + end + end + end + end +elseif length(latency)==2 + countcolor = 0; + line_colors1 = []; + if chanOverlay==1 + offset = zeros(numel(ChanArray),1); + end + + Max_values = 1.1*max([max(plot_erp_data(:)),Yscale(2)]); + Min_values = 1.1*min([min((plot_erp_data(:))),Yscale(1)]); + plot_area_up = area(r_ax,[latency latency(2) latency(1)],[Min_values,Max_values Min_values,Max_values]); + plot_area_low = area(r_ax,[latency latency(2) latency(1)],[0,Min_values 0,Min_values]); + set(plot_area_up,'FaceAlpha',0.2, 'EdgeAlpha', 0.1, 'EdgeColor', cwm,'FaceColor',cwm_backgb); + set(plot_area_low,'FaceAlpha',0.2, 'EdgeAlpha', 0.1, 'EdgeColor', cwm,'FaceColor',cwm_backgb); + + for Numoferp = 1:numel(ERPArray) + ERP1 = ALLERP(ERPArray(Numoferp)); + bindata = ERP1.bindata(ChanArray,:,BinArray); + [~, Amp_out,Lat]= f_ERP_plot_wav(ERP1,offset,ChanArray,BinArray); + % Amp_out = Amp_out*positive_up; + if ismember_bc2(moption, {'peakampbl'})%Local Peak amplitude + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + Amp_all = squeeze(bindata(Numofchan,:,Numofbin))*positive_up +offset(Numofchan); + [xxx, latsamp, latdiffms] = closest(timex, Lat{Numofbin,Numofchan}); + if ~isnan(Lat{Numofbin,Numofchan}) + line(r_ax, [Lat{Numofbin,Numofchan} Lat{Numofbin,Numofchan}],[offset(Numofchan),Amp_all(latsamp)],'Color',line_colors(countcolor,:,:),'LineWidth',1,'LineStyle','-.'); + end + end + end + elseif ismember_bc2(moption, { 'fareatlat', 'fareaplat','fninteglat','fareanlat'})%fractional area latency + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + Amp_all = squeeze(bindata(Numofchan,:,Numofbin))*positive_up +offset(Numofchan); + if ~isnan(Amp_out(Numofbin,Numofchan)) + [xxx, latsamp, latdiffms] = closest(timex, Amp_out(Numofbin,Numofchan)); + line(r_ax, [Amp_out(Numofbin,Numofchan) Amp_out(Numofbin,Numofchan)],sort([offset(Numofchan),Amp_all(latsamp)]),'Color',line_colors(countcolor,:,:),'LineWidth',1,'LineStyle','-.'); + end + end + end + + elseif ismember_bc2(moption, {'peaklatbl','fpeaklat'}) % fractional peak latency && Local peak latency + for Numofbin = 1:numel(BinArray) + if chanOverlay==0 + countcolor = countcolor+1; + end + for Numofchan = 1:numel(ChanArray) + if chanOverlay==1 + countcolor = countcolor+1; + end + Amp_all = squeeze(bindata(Numofchan,:,Numofbin))*positive_up +offset(Numofchan); + if ~isnan(Amp_out(Numofbin,Numofchan)) + if ismember_bc2(moption, {'fpeaklat'}) + [xxx, latsamp, latdiffms] = closest(timex,Lat{Numofbin,Numofchan}); + line(r_ax, [Lat{Numofbin,Numofchan} Lat{Numofbin,Numofchan}],sort([offset(Numofchan),Amp_all(latsamp)]),'Color',line_colors(countcolor,:,:),'LineWidth',1,'LineStyle','-.'); + elseif ismember_bc2(moption, {'peaklatbl'}) + [xxx, latsamp, latdiffms] = closest(timex,Amp_out(Numofbin,Numofchan)); + line(r_ax, [Amp_out(Numofbin,Numofchan) Amp_out(Numofbin,Numofchan)],sort([offset(Numofchan),Amp_all(latsamp)]),'Color',line_colors(countcolor,:,:),'LineWidth',1,'LineStyle','-.'); + end + + end + end + end + + end + end + +end + + +% --- Executes when figure1 is resized. +function figure1_SizeChangedFcn(hObject, eventdata, handles) +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes on button press in radiobutton_parbin. +function radiobutton_parbin_Callback(hObject, eventdata, handles) +handles.checkbox1_bin.Value=0; +handles.radiobutton_parbin.Value=1; +handles.pushbutton_binsmall.Enable = 'on'; +handles.pushbutton_binlarge.Enable = 'on'; +handles.edit_bin.Enable = 'on'; +handles.pushbutton_browse_bin.Enable = 'on'; + +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end + +BinArray = str2num(handles.edit_bin.String); +if isempty(BinArray) || any(BinArray>ERP.nbin) + BinArray = handles.BinArray; +end + +handles.pushbutton_binsmall.Enable = 'on'; +handles.pushbutton_binlarge.Enable = 'on'; +handles.edit_bin.String = num2str(BinArray(1)); + +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + + +% --- Executes on button press in pushbutton_browse_bin. +function pushbutton_browse_bin_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +BinArray = handles.BinArray; +BinArray =reshape(BinArray,1,numel(BinArray)); + + +BinArray_edit = str2num(handles.edit_bin.String); +if isempty(BinArray_edit) || any(BinArray_edit>numel(BinArray)) + BinArray_edit = BinArray(1); +end + +for Numofbin = 1:numel(BinArray) + listname{Numofbin} = [num2str(BinArray(Numofbin)),'.',ERP.bindescr{BinArray(Numofbin)}]; +end + +BinArray = handles.BinArray; +BinArray =reshape(BinArray,1,numel(BinArray)); +[~,binpos] = find(BinArray ==BinArray_edit); +if isempty(binpos) + BinArray_edit = BinArray(1); + binpos = 1; + handles.edit_bin.String = num2str(BinArray_edit); +end + +indxlistb =binpos; +titlename = 'Select one bin:'; +bin_select = browsechanbinGUI(listname, indxlistb, titlename); +if isempty(bin_select) + return; +end + +handles.edit_bin.String = num2str(BinArray(bin_select(1))); +handles.pushbutton_binsmall.Enable = 'on'; +handles.pushbutton_binlarge.Enable = 'on'; + + +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes on button press in radiobutton_chanpor. +function radiobutton_chanpor_Callback(hObject, eventdata, handles) + +handles.radiobutton_chanpor.Value=1; +handles.checkbox_chan.Value=0; +handles.pushbutton8_chansmall.Enable = 'on'; +handles.pushbutton_chanlarge.Enable = 'on'; +handles.pushbutton_chanborwse.Enable = 'on'; +handles.edit_chans.Enable = 'on'; + + +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +chan_select = str2num(handles.edit_chans.String); +if isempty(chan_select) || any(chan_select>ERP.nchan) + chan_select = handles.ChanArray(1); +end + +handles.edit_chans.String = num2str(chan_select(1)); +handles.radiobutton_chanoverlay.Value = 0; +handles.radiobutton_chan_separate.Value = 1; +handles.radiobutton_chanoverlay.Enable = 'off'; +handles.radiobutton_chan_separate.Enable = 'off'; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes on button press in pushbutton_chanborwse. +function pushbutton_chanborwse_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +try + ERP = ALLERP(handles.CurrentERP); +catch + ERP=[]; +end +if isempty(ALLERP) || isempty(ERP) + return; +end +ChanArray = handles.ChanArray; +ChanArray =reshape(ChanArray,1,numel(ChanArray)); +chanArray_edit = str2num(handles.edit_chans.String); +if isempty(chanArray_edit) || any(chanArray_edit>numel(ChanArray)) + chanArray_edit = ChanArray(1); +end + +for Numofchan = 1:numel(ChanArray) + listname{Numofchan} = [num2str(ChanArray(Numofchan)),'.',ERP.chanlocs(ChanArray(Numofchan)).labels]; +end + + +[~,chanpos] = find(ChanArray ==chanArray_edit); +if isempty(chanpos) + chanArray_edit = ChanArray(1); + chanpos = 1; + handles.edit_chans.String = num2str(ChanArray(1)); +end + +indxlistb =chanpos; + +titlename = 'Select one chan:'; +chan_select = browsechanbinGUI(listname, indxlistb, titlename); +if isempty(chan_select) + return; +end + +handles.edit_chans.String = num2str(ChanArray(chan_select(1))); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + + + + +% --- Executes on button press in radiobutton_chanoverlay. +function radiobutton_chanoverlay_Callback(hObject, eventdata, handles) +handles.radiobutton_chanoverlay.Value = 1; +handles.radiobutton_chan_separate.Value = 0; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + +% --- Executes on button press in radiobutton_chan_separate. +function radiobutton_chan_separate_Callback(hObject, eventdata, handles) +handles.radiobutton_chanoverlay.Value = 0; +handles.radiobutton_chan_separate.Value = 1; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + +% --- Executes on button press in pushbutton_erpset_browse. +function pushbutton_erpset_browse_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end +ERPArray = str2num(handles.edit5_erpset.String); +if isempty(ERPArray) || any(ERPArray(:)>length(ALLERP)) + ERPArray = length(ALLERP); +end +for Numoferp = 1:length(ALLERP) + listname{Numoferp} = ['ERPset:',32,num2str(Numoferp)]; +end + +indxlistb =ERPArray; +titlename = 'Select one erpset:'; +erpset_select = browsechanbinGUI(listname, indxlistb, titlename); +if isempty(erpset_select) + return; +end + +ERPArray = erpset_select(1); +handles.edit5_erpset.String = num2str(ERPArray); +handles.CurrentERP = ERPArray; + +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes on button press in radiobutton_erppor. +function radiobutton_erppor_Callback(hObject, eventdata, handles) +handles.checkbox_erp.Value=0; +handles.radiobutton_erppor.Value=1; +handles.checkbox_erp.Enable = 'on'; +handles.edit5_erpset.Enable = 'on'; +handles.pushbutton_erpsetsmall.Enable = 'on'; +handles.pushbutton_erpsetlarge.Enable = 'on'; +handles.pushbutton_erpset_browse.Enable = 'on'; +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end + +ERPArray = str2num(handles.edit5_erpset.String); +if isempty(ERPArray) || any(ERPArray(:)>length(ALLERP)) + ERPArray=1; +end + +handles.edit5_erpset.String = num2str(ERPArray(1)); +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +function pushbutton_polarity_up_DeleteFcn(hObject, eventdata, handles) + +% --- Executes on button press in radiobutton6. +function radiobutton6_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end + +handles.positive_up=-1; +handles.radiobutton7.Value=0; +handles.radiobutton6.Value=1; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); + + +% --- Executes on button press in radiobutton7. +function radiobutton7_Callback(hObject, eventdata, handles) +ALLERP = handles.ALLERP; +if isempty(ALLERP) + return; +end + +handles.positive_up=1; +handles.radiobutton7.Value=1; +handles.radiobutton6.Value=0; +handles= plot_wave_viewer(hObject,handles); +guidata(hObject, handles); diff --git a/studio_functions/GUIs/ERP Tab/f_export2csvGUI.fig b/studio_functions/GUIs/ERP Tab/f_export2csvGUI.fig index 47afcceb..7515da5a 100755 Binary files a/studio_functions/GUIs/ERP Tab/f_export2csvGUI.fig and b/studio_functions/GUIs/ERP Tab/f_export2csvGUI.fig differ diff --git a/studio_functions/GUIs/ERP Tab/f_export2csvGUI.m b/studio_functions/GUIs/ERP Tab/f_export2csvGUI.m index 48438e6d..e0beebf3 100755 --- a/studio_functions/GUIs/ERP Tab/f_export2csvGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_export2csvGUI.m @@ -1,9 +1,9 @@ % -% Author: Javier Lopez-Calderon & Steven Luck & Guanghui ZHANG +% Author: Javier Lopez-Calderon & Steven Luck & Guanghui Zhang % Center for Mind and Brain % University of California, Davis, % Davis, CA -% 2009 & 2022 +% 2009 & 2022 & 2023 %b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b % @@ -83,8 +83,9 @@ function f_export2csvGUI_OpeningFcn(hObject, eventdata, handles, varargin) prec = def{4}; filename = def{5}; -% version = geterplabversion; -set(handles.gui_chassis,'Name', ['EStudio ' '2022.1' ' - Export spectrum for selected ERPset as ".csv"']) +erplab_default_values; +version = erplabver; +set(handles.gui_chassis,'Name', ['EStudio ' version ' - Export spectrum for selected ERPset as ".csv"']) [pathx, erpfilename, ext] = fileparts(filename); ERPFileName = char(strcat(erpfilename,'.csv')); @@ -271,7 +272,6 @@ function pushbutton_browse_Callback(hObject, eventdata, handles) [fname, pathname, filterindex] = uiputfile({'*.csv';'*.*'},'Save Output file as', prename); if isequal(fname,0) - disp('User selected Cancel') return else @@ -311,42 +311,4 @@ function gui_chassis_CloseRequestFcn(hObject, eventdata, handles) function uipanel1_SizeChangedFcn(hObject, eventdata, handles) % hObject handle to uipanel1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB -% handles structure with handles and user data (see GUIDATA) - - - -% function edit_custom_bin_Callback(hObject, eventdata, handles) -% -% -% -% % --- Executes during object creation, after setting all properties. -% function edit_custom_bin_CreateFcn(hObject, eventdata, handles) -% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) -% set(hObject,'BackgroundColor','white'); -% end - - -% % --- Executes on button press in pushbutton_browse_bin. -% function pushbutton_browse_bin_Callback(hObject, eventdata, handles) -% % hObject handle to pushbutton_browse_bin (see GCBO) -% % eventdata reserved - to be defined in a future version of MATLAB -% % handles structure with handles and user data (see GUIDATA) -% -% -% -% function edit_custom_chan_Callback(hObject, eventdata, handles) -% -% -% -% % --- Executes during object creation, after setting all properties. -% function edit_custom_chan_CreateFcn(hObject, eventdata, handles) -% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) -% set(hObject,'BackgroundColor','white'); -% end -% -% -% % --- Executes on button press in pushbutton_browse_chan. -% function pushbutton_browse_chan_Callback(hObject, eventdata, handles) -% % hObject handle to pushbutton_browse_chan (see GCBO) -% % eventdata reserved - to be defined in a future version of MATLAB -% % handles structure with handles and user data (see GUIDATA) +% handles structure with handles and user data (see GUIDATA) \ No newline at end of file diff --git a/studio_functions/GUIs/ERP Tab/f_export2textGUI.m b/studio_functions/GUIs/ERP Tab/f_export2textGUI.m index 9b87e99e..91eaceff 100755 --- a/studio_functions/GUIs/ERP Tab/f_export2textGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_export2textGUI.m @@ -92,9 +92,9 @@ function f_export2textGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Name & version % -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ', version, ' - Export ERP GUI']) [pathx, erpfilename, ext] = fileparts(filename); diff --git a/studio_functions/GUIs/ERP Tab/f_rerefassistantGUI.m b/studio_functions/GUIs/ERP Tab/f_rerefassistantGUI.m index ea236564..80f65858 100755 --- a/studio_functions/GUIs/ERP Tab/f_rerefassistantGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_rerefassistantGUI.m @@ -87,8 +87,8 @@ function f_rerefassistantGUI_OpeningFcn(hObject, eventdata, handles, varargin) % % Name & version % -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - Rereference GUI']) % diff --git a/studio_functions/GUIs/ERP Tab/f_scalplotadvanceGUI.m b/studio_functions/GUIs/ERP Tab/f_scalplotadvanceGUI.m index ce7a4c5f..67d9ca18 100755 --- a/studio_functions/GUIs/ERP Tab/f_scalplotadvanceGUI.m +++ b/studio_functions/GUIs/ERP Tab/f_scalplotadvanceGUI.m @@ -71,8 +71,8 @@ function f_scalplotadvanceGUI_OpeningFcn(hObject, eventdata, handles, varargin) handles.is2Dmap = is2Dmap; % Name & version % -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - SCALP MAPPING ADVANCED GUI']) diff --git a/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.fig b/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.fig index cde446d6..498dca05 100755 Binary files a/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.fig and b/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.fig differ diff --git a/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.m b/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.m index 894b172c..5948c18a 100755 --- a/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.m +++ b/studio_functions/GUIs/ERP Tab/geterpvaluesparasGUI2.m @@ -63,7 +63,7 @@ function geterpvaluesparasGUI2_OpeningFcn(hObject, eventdata, handles, varargin) def = varargin{1}; handles.def = def; catch - def = {'fpeaklat', 3, 0, 1, 3, 0, 0.5, 0, 0, 1, 1, 1}; + def = {'fpeaklat', 3, 1, 3, 0, 0.5, 0, 0, 1, 1, 1}; handles.def = def; end @@ -124,17 +124,7 @@ function geterpvaluesparasGUI2_OpeningFcn(hObject, eventdata, handles, varargin) % viewerbutton % -% Set Measurement menu -% -% set(handles.listbox_erpnames, 'Value',1) -% set(handles.popupmenu_measurement, 'Backgroundcolor',[1 1 0.8]) -% set(handles.popupmenu_pol_amp, 'Backgroundcolor',[1 1 0.8]) -% set(handles.popupmenu_samp_amp, 'Backgroundcolor',[1 1 0.8]) -% set(handles.popupmenu_locpeakreplacement, 'Backgroundcolor',[1 1 0.8]) -% set(handles.popupmenu_fracreplacement, 'Backgroundcolor',[1 1 0.8]) -% set(handles.popupmenu_precision, 'Backgroundcolor',[1 1 0.8]) -%set(handles.text_fraca,'String', {''}); -%set(handles.text_fa3,'String',{''}); + drawnow % UIWAIT makes geterpvaluesparasGUI2 wait for user response (see UIRESUME) @@ -237,7 +227,7 @@ function pushbutton_run_Callback(hObject, eventdata, handles) % Send to workspace % -send2ws = get(handles.checkbox_send2ws, 'Value'); % 0:no; 1:yes +send2ws =0;% get(handles.checkbox_send2ws, 'Value'); % 0:no; 1:yes owfp = handles.owfp; % over write file permission appendfile = 0; @@ -274,95 +264,25 @@ function pushbutton_run_Callback(hObject, eventdata, handles) % return % end moption = 'instabl'; - fprintf('\nInstantaneous amplitude measurement in progress...\n'); + case 2 % meanbl - % if nlate~=2 - % if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % msgboxText = 'You must define two frequencies'; - % else - % msgboxText = 'You must define two latencies'; - % end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end + moption = 'meanbl'; - fprintf('\nMean amplitude measurement in progress...\n'); + case 3 % peakampbl - % if nlate~=2 - % if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % msgboxText = 'You must define two frequencies'; - % else - % msgboxText = 'You must define two latencies'; - % end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end + moption = 'peakampbl'; polpeak = 2-get(handles.popupmenu_pol_amp,'Value'); sampeak = get(handles.popupmenu_samp_amp,'Value') - 1; locpeakrep = 2-get(handles.popupmenu_locpeakreplacement,'Value'); - - % cc1 = late(1)-sample2time(TimeOp, sampeak, srate) < xmin*kktime; - % ccdiff = abs((late(1)-sample2time(TimeOp, sampeak, srate)) - xmin*kktime); - % cc2 = time2sample(TimeOp, ccdiff, srate)>2; - % cc3 = late(2)+sample2time(TimeOp, sampeak, srate)>xmax*kktime; - % ccdiff = abs((late(2)+sample2time(TimeOp, sampeak, srate)) - xmax*kktime); - % cc4 = time2sample(TimeOp, ccdiff, srate)>2; - - % if (cc1 && cc2) || (cc3 && cc4) - % msgboxText = msgboxText4peak; - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText,sampeak, sampeak, sampeak, xmin*kktime, xmax*kktime, xmin*kktime+sample2time(TimeOp, sampeak,srate), xmax*kktime-sample2time(TimeOp, sampeak,srate)), title); - % return - % end - fprintf('\nLocal peak measurement in progress...\n'); case 4 % peaklatbl - % if nlate~=2 - % if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % msgboxText = 'You must define two frequencies'; - % else - % msgboxText = 'You must define two latencies'; - % end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end + moption = 'peaklatbl'; polpeak = 2-get(handles.popupmenu_pol_amp,'Value'); sampeak = get(handles.popupmenu_samp_amp,'Value') - 1; locpeakrep = 2-get(handles.popupmenu_locpeakreplacement,'Value'); - - % cc1 = late(1)-sample2time(TimeOp, sampeak, srate) < xmin*kktime; - % ccdiff = abs((late(1)-sample2time(TimeOp, sampeak, srate)) - xmin*kktime); - % cc2 = time2sample(TimeOp, ccdiff, srate)>2; - % cc3 = late(2)+sample2time(TimeOp, sampeak, srate)>xmax*kktime; - % ccdiff = abs((late(2)+sample2time(TimeOp, sampeak, srate)) - xmax*kktime); - % cc4 = time2sample(TimeOp, ccdiff, srate)>2; - - % if (cc1 && cc2) || (cc3 && cc4) - % msgboxText = msgboxText4peak; - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText,sampeak, sampeak, sampeak, xmin*kktime, xmax*kktime, xmin*kktime+sample2time(TimeOp, sampeak,srate), xmax*kktime-sample2time(TimeOp, sampeak,srate)), kktime); - % return - % end - if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - fprintf('\nLocal peak frequency measurement in progress...\n'); - else - fprintf('\nLocal peak latency measurement in progress...\n'); - end case 5 % fpeaklat - % if nlate~=2 - % if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % msgboxText = 'You must define two frequencies'; - % else - % msgboxText = 'You must define two latencies'; - % end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end + set(handles.text_fraca,'String', 'Fractional Peak') moption = 'fpeaklat'; frac = (get(handles.popupmenu_fraca,'Value') - 1)/100; % 0 to 1 @@ -370,49 +290,17 @@ function pushbutton_run_Callback(hObject, eventdata, handles) sampeak = get(handles.popupmenu_samp_amp,'Value') - 1; locpeakrep = 2-get(handles.popupmenu_locpeakreplacement,'Value'); fracmearep = 2-get(handles.popupmenu_fracreplacement,'Value'); - - % cc1 = late(1)-sample2time(TimeOp, sampeak, srate) < xmin*kktime; - % ccdiff = abs((late(1)-sample2time(TimeOp, sampeak, srate)) - xmin*kktime); - % cc2 = time2sample(TimeOp, ccdiff, srate)>2; - % cc3 = late(2)+sample2time(TimeOp, sampeak, srate)>xmax*kktime; - % ccdiff = abs((late(2)+sample2time(TimeOp, sampeak, srate)) - xmax*kktime); - % cc4 = time2sample(TimeOp, ccdiff, srate)>2; - - % if (cc1 && cc2) || (cc3 && cc4) - % msgboxText = msgboxText4peak; - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText,sampeak, sampeak, sampeak, xmin*kktime, xmax*kktime, xmin*kktime+sample2time(TimeOp, sampeak,srate), xmax*kktime-sample2time(TimeOp, sampeak,srate)), title); - % return - % end - if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - fprintf('\nFractional Peak Frequency measurement in progress...\n'); - else - fprintf('\nFractional Peak Latency measurement in progress...\n'); - end case 6 % inte/area value (fixed latencies) - % if nlate~=2 - % if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % msgboxText = 'You must define two frequencies'; - % else - % msgboxText = 'You must define two latencies'; - % end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end + switch areatype case 1 moption = 'areat'; - fprintf('\nTotal area measurement in progress...\n'); case 2 moption = 'ninteg'; - fprintf('\nNumerical integration in progress...\n'); case 3 moption = 'areap'; - fprintf('\nPositive area measurement in progress...\n'); case 4 moption = 'arean'; - fprintf('\nNegative area measurement in progress...\n'); end case 7 % inte/area value (auto latencies) @@ -422,64 +310,31 @@ function pushbutton_run_Callback(hObject, eventdata, handles) errorfound(sprintf(msgboxText), title); return end - % if nlate~=1 - % %if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % % msgboxText = 'You must define only one frequency'; - % %else - % msgboxText = 'You must define only one latency'; - % %end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end + switch areatype case 1 moption = 'areazt'; - fprintf('\nTotal area measurement in progress...\n'); case 2 moption = 'nintegz'; - fprintf('\nNumerical integration (automatic limits) in progress...\n'); case 3 moption = 'areazp'; - fprintf('\nPositive area measurement (automatic limits) in progress...\n'); case 4 moption = 'areazn'; - fprintf('\nNegative area measurement (automatic limits) in progress...\n'); end case 8 % fractional inte/area latency - % if nlate~=2 - % if strcmpi(datatype, 'TFFT') || strcmpi(datatype, 'EFFT') % Hz - % msgboxText = 'You must define two frequencies'; - % else - % msgboxText = 'You must define two latencies'; - % end - % title = 'ERPLAB: measurement window'; - % errorfound(sprintf(msgboxText), title); - % return - % end set(handles.text_fraca,'String', 'Fractional Area') frac = (get(handles.popupmenu_fraca,'Value') - 1)/100; % 0 to 1 - if strcmpi(datatype, 'ERP') - meawordx = 'Latency'; - else - meawordx = 'Frequency'; - end switch areatype case 1 moption = 'fareatlat'; - fprintf('\nFractional Total Area %s measurement in progress...\n', meawordx); case 2 moption = 'fninteglat'; - fprintf('\nFractional Total Area %s measurement in progress...\n', meawordx); case 3 moption = 'fareaplat'; - fprintf('\nFractional Positive Area %s measurement in progress...\n', meawordx); - case 4 moption = 'fareanlat'; - fprintf('\nFractional Negative Area %s measurement in progress...\n', meawordx); otherwise error('wrong area type.') end @@ -490,8 +345,8 @@ function pushbutton_run_Callback(hObject, eventdata, handles) dig = get(handles.popupmenu_precision, 'Value'); -binlabop = get(handles.checkbox_binlabel,'Value'); % bin label option for table -inclate = get(handles.checkbox_include_used_latencies, 'Value'); +binlabop =0; %get(handles.checkbox_binlabel,'Value'); % bin label option for table +inclate = 0;%get(handles.checkbox_include_used_latencies, 'Value'); intfactor = get(handles.popupmenu_interpofactor, 'Value'); peakonset = get(handles.popupmenu_rise, 'Value'); % axs - get onset from menu value @@ -818,14 +673,14 @@ function setall(hObject, eventdata, handles) if ~isempty(def) op = def{1}; % option: type of measurement ---> instabl, meanbl, peakampbl, peaklatbl, area, areaz, or errorbl. dig = def{2}; %Resolution - binlabop = def{3}; % 0: bin# as bin label for table, 1 bin label + % binlabop = def{3}; % 0: bin# as bin label for table, 1 bin label polpeak = def{4}; % local peak polarity sampeak = def{5}; % number of samples (one-side) for local peak detection criteria locpeakrep = def{6}; % 1 abs peak , 0 Nan frac = def{7}; fracmearep = def{8}; % def{19}; NaN - send2ws = def{9}; % 1 send to ws, 0 dont do - inclate = def{10}; + send2ws = 0;%def{9}; % 1 send to ws, 0 dont do + inclate = 0;%def{10}; intfactor = def{11}; if isempty(sampeak) sampeak = 3; @@ -836,14 +691,14 @@ function setall(hObject, eventdata, handles) %%def = {'fareaplat', 3, 0, 1, 3, 0, 0.5, NaN, 0, 0, 1, 1}; op = 'meanbl'; % option: type of measurement ---> instabl, meanbl, peakampbl, peaklatbl, area, areaz, or errorbl. dig = 3; %Resolution - binlabop = 0; % 0: bin# as bin label for table, 1 bin label + % binlabop = 0; % 0: bin# as bin label for table, 1 bin label polpeak = 1; % local peak polarity sampeak = 3; % number of samples (one-side) for local peak detection criteria locpeakrep = 0; % 1 abs peak , 0 Nan frac = 0.5; fracmearep = 0; % def{19}; NaN send2ws = 0; % 1 send to ws, 0 dont do - inclate = 1; + inclate = 0; intfactor = 1; end if isempty(frac) @@ -887,10 +742,10 @@ function setall(hObject, eventdata, handles) % % 1 = one measurement per line; 0 = one erpset per line % -set(handles.checkbox_include_used_latencies, 'Value', inclate); +% set(handles.checkbox_include_used_latencies, 'Value', inclate); -set(handles.checkbox_send2ws, 'Value', send2ws); -set(handles.checkbox_binlabel, 'Value', binlabop); %0: use bin number as binlabel; 1:use bin descr as binlabel +% set(handles.checkbox_send2ws, 'Value', send2ws); +% set(handles.checkbox_binlabel, 'Value', binlabop); %0: use bin number as binlabel; 1:use bin descr as binlabel % interpolation set(handles.popupmenu_interpofactor, 'Value', intfactor); @@ -962,13 +817,7 @@ function setall(hObject, eventdata, handles) set(handles.popupmenu_locpeakreplacement,'value',2-locpeakrep); set(handles.popupmenu_fracreplacement,'value',2-fracmearep); set(handles.popupmenu_areatype,'Enable','off'); - % set(handles.popupmenu_fracreplacement, 'String', {'"not a number" (NaN)','show error message'}); - if strcmpi(fracmearep,'NaN') - set(handles.popupmenu_fracreplacement, 'Value', 1); - else - set(handles.popupmenu_fracreplacement, 'Value', 2); - end case 7 % area and integral with auto limits menupeakoff(hObject, eventdata, handles); menufareaoff(hObject, eventdata, handles); @@ -993,12 +842,8 @@ function setall(hObject, eventdata, handles) set(handles.text_fraca,'String', 'Fractional Area') set(handles.popupmenu_areatype,'Enable','on') set(handles.popupmenu_areatype,'Value',areatype) - set(handles.popupmenu_fracreplacement, 'String', {'show error message','"not a number" (NaN)'}); - if strcmpi(fracmearep,'NaN') - set(handles.popupmenu_fracreplacement, 'Value', 2); - else - set(handles.popupmenu_fracreplacement, 'Value', 1); - end + set(handles.popupmenu_fracreplacement, 'String', {'"not a number" (NaN)','show error message'}); + otherwise menupeakoff(hObject, eventdata, handles) @@ -1006,7 +851,7 @@ function setall(hObject, eventdata, handles) end set(handles.popupmenu_precision, 'Value', dig) -set(handles.checkbox_send2ws, 'Value', send2ws); +% set(handles.checkbox_send2ws, 'Value', send2ws); srate = handles.srate; try @@ -1022,8 +867,8 @@ function setall(hObject, eventdata, handles) % meamenu = get(handles.popupmenu_measurement, 'String'); currentm = get(handles.popupmenu_measurement, 'Value'); -erplab_studio_default_values; -version = erplabstudiover; +erplab_default_values; +version = erplabver; set(handles.gui_chassis,'Name', ['EStudio ' version ' - ERP Measurement Tool > Type > Option']) handles.frac = frac; @@ -1034,9 +879,6 @@ function setall(hObject, eventdata, handles) %-------------------------------------------------------------------------- function gui_chassis_CreateFcn(hObject, eventdata, handles) -%-------------------------------------------------------------------------- -function checkbox_send2ws_Callback(hObject, eventdata, handles) - %-------------------------------------------------------------------------- @@ -1178,35 +1020,3 @@ function text_fraca_CreateFcn(hObject, eventdata, handles) % hObject handle to text_fa1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called - - -% --- Executes during object creation, after setting all properties. -function checkbox_include_used_latencies_CreateFcn(hObject, eventdata, handles) -% hObject handle to checkbox_include_used_latencies (see GCBO) -% eventdata reserved - to be defined in a future version of MATLAB -% handles empty - handles not created until after all CreateFcns called - - -% --- Executes during object deletion, before destroying properties. -function checkbox_include_used_latencies_DeleteFcn(hObject, eventdata, handles) -% hObject handle to checkbox_include_used_latencies (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 checkbox_include_used_latencies. -function checkbox_include_used_latencies_Callback(hObject, eventdata, handles) -% hObject handle to checkbox_include_used_latencies (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 checkbox_include_used_latencies - - -% --- Executes on button press in checkbox_binlabel. -function checkbox_binlabel_Callback(hObject, eventdata, handles) -% hObject handle to checkbox_binlabel (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 checkbox_binlabel diff --git a/studio_functions/GUIs/ERP_Tab_rename_gui.mlapp b/studio_functions/GUIs/ERP_Tab_rename_gui.mlapp new file mode 100644 index 00000000..c7391430 Binary files /dev/null and b/studio_functions/GUIs/ERP_Tab_rename_gui.mlapp differ diff --git a/studio_functions/GUIs/ERP_evenlist_gui.mlapp b/studio_functions/GUIs/ERP_evenlist_gui.mlapp new file mode 100644 index 00000000..0e11fcf0 Binary files /dev/null and b/studio_functions/GUIs/ERP_evenlist_gui.mlapp differ diff --git a/studio_functions/GUIs/ERP_spectral_analysis_GUI.mlapp b/studio_functions/GUIs/ERP_spectral_analysis_GUI.mlapp new file mode 100644 index 00000000..c4858697 Binary files /dev/null and b/studio_functions/GUIs/ERP_spectral_analysis_GUI.mlapp differ diff --git a/studio_functions/GUIs/EStudio_plot_set_waves.mlapp b/studio_functions/GUIs/EStudio_plot_set_waves.mlapp new file mode 100644 index 00000000..43f62a5b Binary files /dev/null and b/studio_functions/GUIs/EStudio_plot_set_waves.mlapp differ diff --git a/studio_functions/GUIs/EStudio_pos_gui.mlapp b/studio_functions/GUIs/EStudio_pos_gui.mlapp new file mode 100644 index 00000000..3693e789 Binary files /dev/null and b/studio_functions/GUIs/EStudio_pos_gui.mlapp differ diff --git a/studio_functions/GUIs/dq_trial_rejection.mlapp b/studio_functions/GUIs/dq_trial_rejection.mlapp new file mode 100644 index 00000000..c2eb2097 Binary files /dev/null and b/studio_functions/GUIs/dq_trial_rejection.mlapp differ diff --git a/studio_functions/GUIs/estudio_classic_ar_summary_gui.mlapp b/studio_functions/GUIs/estudio_classic_ar_summary_gui.mlapp new file mode 100644 index 00000000..400664ad Binary files /dev/null and b/studio_functions/GUIs/estudio_classic_ar_summary_gui.mlapp differ diff --git a/studio_functions/GUIs/estudio_epoch2contn_gui.mlapp b/studio_functions/GUIs/estudio_epoch2contn_gui.mlapp new file mode 100644 index 00000000..177c69b9 Binary files /dev/null and b/studio_functions/GUIs/estudio_epoch2contn_gui.mlapp differ diff --git a/studio_functions/GUIs/estudio_reset_paras.mlapp b/studio_functions/GUIs/estudio_reset_paras.mlapp new file mode 100644 index 00000000..b8b5f61f Binary files /dev/null and b/studio_functions/GUIs/estudio_reset_paras.mlapp differ diff --git a/studio_functions/GUIs/estudio_warning.m b/studio_functions/GUIs/estudio_warning.m new file mode 100644 index 00000000..9cb4419f --- /dev/null +++ b/studio_functions/GUIs/estudio_warning.m @@ -0,0 +1,42 @@ + + + + +function estudio_warning(Messagestr,titleName) + +if nargin<1 + help estudio_warning + return +end +if nargin<2 + titleName = ''; +end + +if isempty(Messagestr) + help estudio_warning + return +end + +FonsizeDefault = f_get_default_fontsize(); +try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef;%%Get background color +catch + ColorB_def = [0.95 0.95 0.95]; +end +if isempty(ColorB_def) + ColorB_def = [0.95 0.95 0.95]; +end + +mh = msgbox(Messagestr, ['Estudio:',32,titleName]); %create msgbox +mh.Resize = 'on'; +th = findall(mh, 'Type', 'Text'); %get handle to text within msgbox +th.FontSize = FonsizeDefault; +set(mh,'color',ColorB_def); +deltaWidth = sum(th.Extent([1,3]))-mh.Position(3) + th.Extent(1); +deltaHeight = sum(th.Extent([2,4]))-mh.Position(4) + 10; +mh.Position([3,4]) = mh.Position([3,4]) + [deltaWidth, deltaHeight]; + + +delete(findobj(mh,'string','OK')); +delete(findobj(mh,'style','frame')); +end \ No newline at end of file diff --git a/studio_functions/GUIs/f_creaeventlist_excel.m b/studio_functions/GUIs/f_creaeventlist_excel.m new file mode 100644 index 00000000..39e8796b --- /dev/null +++ b/studio_functions/GUIs/f_creaeventlist_excel.m @@ -0,0 +1,307 @@ +% PURPOSE: Creates a .xls version of the ERPLAB's EVENTLIST structure +% +% FORMAT: +% +% [EEG EVENTLIST] = f_creaeventlist_excel(EEG, EVENTLIST, lfname, wf) +% +% Inputs: +% +% EEG - input dataset +% EVENTLIST - ERPLAB's EVENTLIST structure +% lfname - full filename of EventList file to save (*.txt) +% wf - write the file. 1 yes; 0 no +% +% Output +% +% EEG - updated dataset +% EVENTLIST - ERPLAB's EVENTLIST structure +% +% Author: Guanghui & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + +%b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b +% +% ERPLAB Toolbox +% Copyright © 2007 The Regents of the University of California +% Created by Javier Lopez-Calderon and Steven Luck +% Center for Mind and Brain, University of California, Davis, +% javlopez@ucdavis.edu, sjluck@ucdavis.edu +% +% This program 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. +% +% This program 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 this program. If not, see . + +function [EEG, EVENTLIST] = f_creaeventlist_excel(EEG, EVENTLIST, lfname, wf) +if nargin < 1 + help f_creaeventlist_excel + return +end +if nargin==1 + wf =0; + evefilepath = ''; + evefilename = ''; + + if isfield(EEG, 'EVENTLIST') + if isfield(EEG.EVENTLIST, 'eventinfo') + if isempty(EEG.EVENTLIST.eventinfo) + EVENTLIST = creaeventinfo(EEG); + else + EVENTLIST = EEG.EVENTLIST; + end + else + EVENTLIST = creaeventinfo(EEG); + end + if ~isfield(EEG.EVENTLIST, 'bdf') + EVENTLIST.bdf = []; + end + else + EVENTLIST = creaeventinfo(EEG); + EVENTLIST.bdf = []; + end +elseif nargin==2 + wf = 1; + p = which('eegplugin_erplab'); + path_temp = p(1:findstr(p,'eegplugin_erplab.m')-1); + evefilepath = fullfile(path_temp, 'erplab_Box'); + if exist(evefilepath, 'dir')~=7 + mkdir(evefilepath); % Thanks to Johanna Kreither. Jan 31, 2013 + end + evefilename = ['eventlist_backup_' num2str((datenum(datestr(now))*1e10))]; +else + if nargin>4 + error('ERPLAB says: error at f_creaeventlist_excel(). Too many arguments!!!!\n') + end + if nargin<4 + wf=1; + end + + [evefilepath, evefilename, ext] = fileparts(lfname); + + if (~strcmp(ext,'.xls') || ~strcmp(ext,'.xlsx')) && ~strcmp(evefilename,'') && ~strcmp(evefilename,'no') && ~strcmp(evefilename,'none') + ext = '.xls'; + end + if ~strcmp(evefilename,'') + evefilename = [evefilename ext]; + else + wf=0; + end + if strcmpi(evefilepath,'') + evefilepath = cd; + end + if isempty(EVENTLIST) + EVENTLIST = creaeventinfo(EEG); + + end + if ~isfield(EVENTLIST, 'bdf') + EVENTLIST.bdf = []; + end + if isfield(EEG, 'EVENTLIST') + EEG.EVENTLIST = []; % Warning! + end +end + +fprintf('Creating a EventList structure...\n'); +fin = length(EVENTLIST.eventinfo); % total events in dataset +% item = zeros(1,fin); +fprintf('Total Events (eventcodes + pauses) = %g \n', fin); + +if ~isfield(EVENTLIST, 'setname') + if isfield(EEG, 'setname') + EVENTLIST.setname = EEG.setname; + else + EVENTLIST.setname = 'none_specified'; + end +end +if ~isfield(EVENTLIST, 'report') + EVENTLIST.report = ''; +end +if ~isfield(EVENTLIST, 'bdfname') + EVENTLIST.bdfname = ''; +end +if ~isfield(EVENTLIST, 'nbin') + EVENTLIST.nbin = []; +end +if ~isfield(EVENTLIST, 'version') + EVENTLIST.version = geterplabversion; +end +if ~isfield(EVENTLIST, 'account') + EVENTLIST.account = ''; +end +if ~isfield(EVENTLIST, 'username') + EVENTLIST.username = ''; +end +if ~isfield(EVENTLIST, 'trialsperbin') + EVENTLIST.trialsperbin = []; +end + +EVENTLIST.elname = fullfile(evefilepath, evefilename); + +if isfield(EVENTLIST, 'bdf') + if isempty(EVENTLIST.bdf) + EVENTLIST.bdf.expression = []; + EVENTLIST.bdf.description = []; + EVENTLIST.bdf.prehome = []; + EVENTLIST.bdf.athome = []; + EVENTLIST.bdf.posthome = []; + EVENTLIST.bdf.namebin = []; + EVENTLIST.bdf.rtname = []; + EVENTLIST.bdf.rtindex = []; + EVENTLIST.bdf.rt = []; + end +else + EVENTLIST.bdf.expression = []; + EVENTLIST.bdf.description = []; + EVENTLIST.bdf.prehome = []; + EVENTLIST.bdf.athome = []; + EVENTLIST.bdf.posthome = []; + EVENTLIST.bdf.namebin = []; + EVENTLIST.bdf.rtname = []; + EVENTLIST.bdf.rtindex = []; + EVENTLIST.bdf.rt = []; + EVENTLIST.trialsperbin = []; +end + +EVENTLIST.eldate = datestr(now); +[EVENTLIST, serror] = sorteventliststruct(EVENTLIST); % organizes EVENTLIST +eegnbchan = 0; +if wf ==1 + fprintf('Creating an EventList .xsl file...\n'); + + % + % Header + % + if isfield(EEG, 'setname') + if strcmp(EEG.setname,'') + eegsetname = 'none_specified'; + else + eegsetname = EEG.setname; + end + else + eegsetname = 'none_specified'; + end + if isfield(EEG, 'epoch') + if isempty(EEG.epoch) + dataform = 'continuous'; + else + dataform = 'epoched'; + end + else + dataform = 'none_specified'; + end + if isfield(EEG, 'filename') + if strcmp(EEG.filename,'') + eegfilename = 'none_specified'; + else + eegfilename = EEG.filename; + end + else + eegfilename = 'none_specified'; + end + if isfield(EEG, 'filepath') + if strcmp(EEG.filepath,'') + eegfilepath = 'none_specified'; + else + eegfilepath = EEG.filepath; + end + else + eegfilepath = 'none_specified'; + end + if isfield(EEG, 'nbchan') + eegnbchan = EEG.nbchan; + %else + % eegnbchan = 0; + end + if isfield(EEG, 'pnts') + eegpnts = EEG.pnts; + else + eegpnts = 0; + end + if isfield(EEG, 'srate') + eegsrate = EEG.srate; + else + eegsrate = 0; + end + flinkname = fullfile(evefilepath, evefilename); + columName2 = {'item','bepoch','ecode','label','onset','diff','dura','b_flags','a_flags','enable','bin'}; + sheet_label_T = table(columName2); + writetable(sheet_label_T,flinkname,'Range','A1','WriteVariableNames',false,"AutoFitWidth",false); + + % + % Prepares diffe field + % + xtime = single([EVENTLIST.eventinfo.time]); + diffe = [0 diff(xtime)]*1000; % sec to msec + data = cell(fin,11); + for k=1:fin + sitem = num2str(k); + if isfield(EVENTLIST.eventinfo, 'bepoch') + sbepoch = num2str(EVENTLIST.eventinfo(k).bepoch); + else + sbepoch = '0'; + end + + scode = num2str(EVENTLIST.eventinfo(k).code); + sclab = num2str(EVENTLIST.eventinfo(k).codelabel); + stime = sprintf('%.4f', EVENTLIST.eventinfo(k).time); + sdiff = sprintf('%.2f', diffe(k)); + sdura = sprintf('%.1f', EVENTLIST.eventinfo(k).dura); + sflag = dec2bin(EVENTLIST.eventinfo(k).flag,16); + senbl = num2str(EVENTLIST.eventinfo(k).enable); + sbini = num2str(EVENTLIST.eventinfo(k).bini); + + if strcmp(sbini,'-1') + sbini = ''; + end + + sitem = [sitem blanks(6-length(sitem))]; + sbepoch = [sbepoch blanks(6-length(sbepoch))]; + scode = [blanks(7-length(scode)) scode]; + sclab = [blanks(16-length(sclab)) sclab]; + stime = [blanks(12-length(stime)) stime]; + sdiff = [blanks(10-length(sdiff)) sdiff]; + sdura = [blanks(7-length(sdura)) sdura]; + sflaga = [blanks(4) sflag(9:16)]; + sflagb = [blanks(4) sflag(1:8)]; + senbl = [blanks(4-length(senbl)) senbl]; + sbini = [blanks(7-length(sbini)) sbini]; + data{k,1}=sitem; + data{k,2}=sbepoch; + data{k,3}=scode; + data{k,4}=sclab; + data{k,5}=stime; + data{k,6}=sdiff; + data{k,7}=sdura; + data{k,8}=sflagb; + data{k,9}=sflaga; + data{k,10}=senbl; + data{k,11}=sbini; + end + xls_d = table(data); + writetable(xls_d,flinkname,'Range','A2','WriteVariableNames',false,"AutoFitWidth",false); % write data + + + + disp(['A new EventList file was created at ' flinkname '']) +end +if isfield(EEG, 'chanlocs') + if ~isfield(EEG.chanlocs,'labels') + for e=1:eegnbchan + EEG.chanlocs(e).labels = ['Ch' num2str(e)]; + end + disp('Your dataset did not have channel labels.') + disp('f_creaeventlist_excel() added basic labels to your channels.') + end +end + diff --git a/studio_functions/GUIs/f_readeventlist_excel.m b/studio_functions/GUIs/f_readeventlist_excel.m new file mode 100644 index 00000000..6fd16f11 --- /dev/null +++ b/studio_functions/GUIs/f_readeventlist_excel.m @@ -0,0 +1,168 @@ +% PURPOSE: reads an EVENTLIST from a .xls file +% +% FORMAT: +% +% [EEG EVENTLIST] = f_readeventlist_excel(EEG, elfilename ); +% +% +% *** This function is part of ERPLAB Toolbox *** +% Author: Guanghui Zhang & Steven Luck +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2024 + +%b8d3721ed219e65100184c6b95db209bb8d3721ed219e65100184c6b95db209b +% +% ERPLAB Toolbox +% Copyright © 2007 The Regents of the University of California +% Created by Javier Lopez-Calderon and Steven Luck +% Center for Mind and Brain, University of California, Davis, +% javlopez@ucdavis.edu, sjluck@ucdavis.edu +% +% This program 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. +% +% This program 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 this program. If not, see . + +function [EEG EVENTLIST] = f_readeventlist_excel(EEG, elfilename ) + +fprintf('reading EVENTLIST...\n'); + +if nargin<1 + help f_readeventlist_excel + return +elseif nargin>2 + error('ERPLAB says: error at f_readeventlist_excel(). To many INPUTs!!!\n'); +end + +EVENTLIST = []; +fid_bl = fopen( elfilename ); + +% +% Reads Header +% +EVENTLIST.bdf = []; +isbin = 1; +detect = 0; +nada = 0; +j = 1; + +% while isbin +% p0 = ftell(fid_bl); +% tdatas = textscan(fid_bl, '%[^\n]',1); +% [lmatch ltoken] = regexpi(char(tdatas{1}), 'bin\s*(\d+),\s*#\s*(\d+),\s*(.+)','match', 'tokens'); +% firstitem = regexpi(char(tdatas{1}), '^1', 'match'); +% +% if ~isempty(ltoken) +% EVENTLIST.trialsperbin(j) = str2num(char(ltoken{1}{2})); % first check. Counter of captured eventcodes per bin +% EVENTLIST.bdf(1,j).expresion = {}; +% EVENTLIST.bdf(j).description = strtrim(char(ltoken{1}{3})); +% EVENTLIST.bdf(j).prehome = {}; +% EVENTLIST.bdf(j).athome = {}; +% EVENTLIST.bdf(j).posthome = {}; +% EVENTLIST.bdf(j).namebin = ['BIN ' num2str(j)]; +% j = j+1; +% detect = 1; +% position = ftell(fid_bl); +% elseif isempty(ltoken) && detect +% isbin=0; +% else +% if isempty(firstitem) +% nada = nada + 1; +% if nada>100 +% fprintf('\nWARNING: readbinlist() did not find any bin summary.\n'); +% fprintf('Now, reading event''s information...\n\n'); +% position = p0; +% isbin=0; +% end +% else +% position = p0; +% isbin=0; +% end +% end +% end + +% EVENTLIST.info.flink = elfilename; +try + EVENTLIST.trialsperbin =EEG.EVENTLIST.trialsperbin; +catch + EVENTLIST.trialsperbin = []; +end +% first check. Counter of captured eventcodes per bin +try + EVENTLIST.bdf = EEG.EVENTLIST.bdf; +catch + EVENTLIST.bdf =[]; +end + + +% fseek(fid_bl, position, 'bof'); +xbin = []; +currentline= readtable(elfilename); +currentline = table2cell(currentline); + +for k = 1:size(currentline,1) + EVENTLIST.eventinfo(k).item = str2num(char(currentline{k,1})); + EVENTLIST.eventinfo(k).bepoch = str2num(char(currentline{k,2})); + EVENTLIST.eventinfo(k).code = str2num(char(currentline{k,3})); + EVENTLIST.eventinfo(k).codelabel= char(currentline{k,4}); + EVENTLIST.eventinfo(k).time = single(str2num(char(currentline{k,5}))); + EVENTLIST.eventinfo(k).spoint = 0; + EVENTLIST.eventinfo(k).dura = single(str2num(char(currentline{k,7}))); % thanks to Ahren Fitzroy + EVENTLIST.eventinfo(k).flag = bin2dec([char(currentline{k,8}) char(currentline{k,9})]); + EVENTLIST.eventinfo(k).enable = str2num(char(currentline{k,10})); + EVENTLIST.eventinfo(k).bini = str2num(char(currentline{k,11})); + + if isempty(EVENTLIST.eventinfo(k).bini) + EVENTLIST.eventinfo(k).binlabel = '""'; + EVENTLIST.eventinfo(k).bini = -1; % 8/19/2009 + else + auxname = num2str(EVENTLIST.eventinfo(k).bini); + bname = regexprep(auxname, '\s+', ',', 'ignorecase'); % inserts a comma instead blank space + binName = ['B' bname '(' num2str(EVENTLIST.eventinfo(k).code) ')']; %B#(Code) + EVENTLIST.eventinfo(k).binlabel = binName; + + xbin = [xbin EVENTLIST.eventinfo(k).bini]; + end + % k = k+1; + +end + + +if isfield(EEG,'srate') + srate = EEG.srate; + % EVENTLIST.info.srate = srate; +else + Ts = mode(diff([EVENTLIST.eventinfo.time])); + srate = 1/Ts; +end + +neve = length(EVENTLIST.eventinfo); +spo = num2cell([EVENTLIST.eventinfo.time]*srate+1); +[EVENTLIST.eventinfo(1:neve).spoint] = spo{:}; +ubin = 1:max(unique_bc2(xbin)); %2/14/2010 +lbin = length(ubin); +binaux = [EVENTLIST.eventinfo.bini]; % pending: see multiple bins case... +binhunter = sort(binaux(binaux>0)); %8/19/2009 +EVENTLIST.nbin = lbin; + +if lbin>=1 + for q=1:lbin + EVENTLIST.trialsperbin(q) = nnz(ismember_bc2(binhunter,q)); % 2/14/2010 + end +else + EVENTLIST.trialsperbin = 0; + fprintf('\nWARNING: f_readeventlist_excel() did not found bin assigned.\n'); + fprintf('You will need to use Create EventList or Binlister as a further step.\n\n'); +end + +[EEG EVENTLIST] = creaeventlist(EEG, EVENTLIST,'', 0); diff --git a/studio_functions/erplab_running_version.erpm b/studio_functions/erplab_running_version.erpm index 7d4a9a5c..9d608d8e 100644 Binary files a/studio_functions/erplab_running_version.erpm and b/studio_functions/erplab_running_version.erpm differ diff --git a/studio_functions/erplab_running_version.m b/studio_functions/erplab_running_version.m old mode 100644 new mode 100755 diff --git a/studio_functions/erplab_studio_default_values.m b/studio_functions/erplab_studio_default_values.m index 9c796e1e..23c84cc9 100755 --- a/studio_functions/erplab_studio_default_values.m +++ b/studio_functions/erplab_studio_default_values.m @@ -1,4 +1,4 @@ -erplabstudiover = '1.00'; % current erplab studio version +erplabstudiover = '10.00'; % current erplab studio version erplabstudiorel = '26-April-2022'; % DOB erplabstudiodeveloper = 'Simmons&Zhang'; % erplabstudiolabel = 1;%0: using ERPLAB; 1:using ERPLAB Studio diff --git a/studio_functions/estudio.m b/studio_functions/estudio.m new file mode 100755 index 00000000..ffe0f8a9 --- /dev/null +++ b/studio_functions/estudio.m @@ -0,0 +1,791 @@ +% New GUI Layout -ERPLAB Studio +% +% Author: Guanghui Zhang & Steve J. Luck & Andrew Stewart +% Center for Mind and Brain +% University of California, Davis, +% Davis, CA +% 2022-2024 + +% ERPLAB Studio Toolbox +% + +% +% This program 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. +% +% This program 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 this program. If not, see . + +% Reqs: +% - data loaded in valid ERPset and EEGset +% - GUI Layout Toolbox +% - ERPLAB +% - EEGLAB + +% +% Demo to explore an ERP Viewer using the new GUI Layout Toolbox +% Now with more in nested functions + + +function [] = estudio() + +tic;% +disp('Estudio is launching. Please be patient...'); + +erplabver1 = geterplabeversion; + +EStudioversion = erplabver1; +SignalProcessingToolboxCheck; +%%--------------------check memory file------------------------------------ + +disp('Initializing Parameters...'); + +if exist('memoryerpstudio.erpm','file')==2 + iserpmem = 1; % file for memory exists +else + iserpmem = 0; % does not exist file for memory +end +if iserpmem==0 + p1 = which('o_ERPDAT'); + p1 = p1(1:findstr(p1,'o_ERPDAT.m')-1); + save(fullfile(p1,'memoryerpstudio.erpm'),'EStudioversion') +end + +%%close EEGLAB +try + W_MAIN = findobj('tag', 'EEGLAB'); + close(W_MAIN); + clearvars ALLCOM; + LASTCOM = []; + global ALLCOM; + ALLCOM =[]; + % eegh('estudio;'); + evalin('base', 'eeg_global;'); + eeg_global; +catch +end +%%running estudio +p_location = which('o_ERPDAT'); +p_location = p_location(1:findstr(p_location,'o_ERPDAT.m')-1); +tooltype = 'estudio'; +save(fullfile(p_location,'erplab_running_version.erpm'),'tooltype'); + + +try + clearvars observe_EEGDAT; + clearvars observe_ERPDAT; + clearvars viewer_ERPDAT; +catch +end + +% global CURRENTERP; +global observe_EEGDAT; +global observe_ERPDAT; +global viewer_ERPDAT; +global EStudio_gui_erp_totl; +global gui_erp_waviewer; +viewer_ERPDAT = v_ERPDAT; + +%%Try to close existing GUI +% global EStudio_gui_erp_totl_Window +try + close(EStudio_gui_erp_totl.Window); +catch +end +%%try to close existing Viewer +try + close(gui_erp_waviewer.Window);%%close previous GUI if exists +catch +end +% Sanity checks +try + test = uix.HBoxFlex(); +catch + beep; + disp('The GUI Layout Toolbox might not be installed. Quitting') + return +end + +%%---------------ADD FOLDER TO PATH------------------- +estudiopath = which('estudio','-all'); +if length(estudiopath)>1 + fprintf('\nEStudio WARNING: More than one EStudio folder was found.\n\n'); +end +estudiopath = estudiopath{1}; +estudiopath= estudiopath(1:findstr(estudiopath,'estudio.m')-1); +% add all ERPLAB subfolders +addpath(genpath(estudiopath)); + +%%functions +myaddpath( estudiopath, 'EStudio_EEG_Tab.m', [ 'Functions' filesep 'EStudio',filesep,'EEG Tab']); +myaddpath( estudiopath, 'EStudio_ERP_Tab.m', [ 'Functions' filesep 'EStudio',filesep,'ERP Tab']); +myaddpath( estudiopath, 'ERPLAB_ERP_Viewer.m', [ 'Functions' filesep 'EStudio',filesep,'ERP Tab',filesep,'ERP wave viewer']); +%%GUIs +myaddpath( estudiopath, 'f_EEG_avg_erp_GUI.m', [ 'GUIs' filesep 'EEG Tab']); +myaddpath( estudiopath, 'f_ERP_append_GUI.m', [ 'GUIs' filesep 'ERP Tab']); + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%-------------------------------EEG-------------------------------------%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +observe_EEGDAT = o_EEGDATA; +observe_ERPDAT = o_ERPDAT; +EEG = []; +ALLEEG = []; +CURRENTSET = 0; +assignin('base','EEG',EEG); +assignin('base','ALLEEG', ALLEEG); +assignin('base','CURRENTSET', CURRENTSET); + + +observe_EEGDAT.ALLEEG = ALLEEG; +observe_EEGDAT.CURRENTSET = CURRENTSET; +observe_EEGDAT.EEG = EEG; +observe_EEGDAT.count_current_eeg = 0; +observe_EEGDAT.eeg_panel_message = 0; +observe_EEGDAT.eeg_two_panels = 0; +observe_EEGDAT.Reset_eeg_paras_panel = 0; + +addlistener(observe_EEGDAT,'alleeg_change',@alleeg_change); +addlistener(observe_EEGDAT,'eeg_change',@eeg_change); +addlistener(observe_EEGDAT,'count_current_eeg_change',@count_current_eeg_change); +addlistener(observe_EEGDAT,'eeg_two_panels_change',@eeg_two_panels_change); +addlistener(observe_EEGDAT,'eeg_panel_change_message',@eeg_panel_change_message); +addlistener(observe_EEGDAT,'Reset_eeg_panel_change',@Reset_eeg_panel_change); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%---------------------For ERP-------------------------------------------%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +ERP = []; % Start ERP Structure on workspace +ALLERP = []; %Start ALLERP Structure on workspace +ALLERPCOM = []; +CURRENTERP = 0; +assignin('base','ERP',ERP); +assignin('base','ALLERP', ALLERP); +assignin('base','CURRENTERP', CURRENTERP); +assignin('base','ALLERP',ALLERP); +assignin('base','ALLERPCOM',ALLERPCOM); + +observe_ERPDAT.ALLERP = ALLERP; +observe_ERPDAT.CURRENTERP = CURRENTERP; +observe_ERPDAT.ERP = ERP; +observe_ERPDAT.Count_ERP = 0; +observe_ERPDAT.Count_currentERP = 1; +observe_ERPDAT.Process_messg = 0;%0 is the default means there is no message for processing procedure; +observe_ERPDAT.erp_between_panels = 0; +observe_ERPDAT.Reset_erp_paras_panel = 0; + +addlistener(observe_ERPDAT,'cerpchange',@indexERP); +addlistener(observe_ERPDAT,'drawui_CB',@onErpChanged); +addlistener(observe_ERPDAT,'erpschange',@allErpChanged); +addlistener(observe_ERPDAT,'Count_ERP_change',@CountErpChanged); +addlistener(observe_ERPDAT,'Count_currentERP_change',@Count_currentERPChanged); +addlistener(observe_ERPDAT,'Messg_change',@Process_messg_change_main); +addlistener(observe_ERPDAT,'erp_between_panels_change',@erp_between_panels_change); +addlistener(observe_ERPDAT,'Reset_erp_panel_change',@Reset_erp_panel_change); + +estudioworkingmemory('f_EEG_proces_messg_pre',{'',0}); +estudioworkingmemory('ViewerFlag',0); +estudioworkingmemory('Change2epocheeg',0);%%Indicate whether we need to force "Epoched EEG" to be selected in EEGsets panel after epoched EEG. +estudioworkingmemory('eegicinspectFlag',0);%%Update the current EEG after Inspect/label ICs. +estudioworkingmemory('ERPTab_zoomSpace',0);%%zoom in/out for erp tab +EStudio_gui_erp_totl = struct(); +EStudio_gui_erp_totl = createInterface(); +EStudio_gui_erp_totl.EEG_transf = 0;%%reveaal if transfter continous EEG to epoched EEG or from epoched to continous EEG +EStudio_gui_erp_totl.EEG_autoplot = 1; %%Automatic plotting for eegsets +EStudio_gui_erp_totl.ERP_autoplot = 1; %%Automatic plotting for erpsets +estudioworkingmemory('EEGUpdate',0);%%For ICA function---inspect/label ICs OR Classify IC by IClbale + + +f_redrawERP(); +f_redrawEEG_Wave_Viewer(); +timeElapsed = toc; +fprintf([32,'It took',32,num2str(timeElapsed),'s to launch estudio.\n\n']); + + function EStudio_gui_erp_totl = createInterface() + disp('Launching Main Window...'); + try + version = geterplabeversion; + erplabstudiover = num2str(version); + catch + erplabstudiover = '??'; + end + currvers = ['ERPLAB Studio ' erplabstudiover]; + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.7020 0.77 0.85]; + end + EStudio_gui_erp_totl = struct(); + % First, let's start the window + EStudio_gui_erp_totl.Window = figure( 'Name', currvers, ... + 'NumberTitle', 'off', ... + 'MenuBar', 'none', ... + 'Toolbar', 'none', ... + 'HandleVisibility', 'on',... + 'tag', 'EStudio',... + 'DockControls','off');%%donot allow to dock + % set the window size + %%screen size + ScreenPos = []; + new_pos= estudioworkingmemory('EStudioScreenPos'); + if isempty(new_pos) || numel(new_pos)~=2 + new_pos = [75,75]; + estudioworkingmemory('EStudioScreenPos',new_pos); + end + try + ScreenPos = get( groot, 'Screensize' ); + catch + ScreenPos = get( 0, 'Screensize' ); + end + if ~isempty(new_pos(2)) && new_pos(2) >100 + POS4 = (new_pos(2)-1)/100; + new_pos =[0,0-1.1*ScreenPos(4)*POS4,ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100]; + else + new_pos =[0,0,ScreenPos(3)*new_pos(1)/100,ScreenPos(4)*new_pos(2)/100]; + end + try + set(EStudio_gui_erp_totl.Window, 'Position', new_pos); + catch + set(EStudio_gui_erp_totl.Window, 'Position', [0 0 0.75*ScreenPos(3) 0.75*ScreenPos(4)]); + estudioworkingmemory('EStudioScreenPos',[75 75]); + end + EStudio_gui_erp_totl.Window.Resize = 0; + EStudio_gui_erp_totl.ScreenPos = ScreenPos; + % + File menu + EStudio_gui_erp_totl.FileMenu = uimenu( EStudio_gui_erp_totl.Window, 'Label', 'File'); + uimenu( EStudio_gui_erp_totl.FileMenu, 'Label', 'Exit', 'Callback', @onExit); + + %%-----------Setting------------------------------------------------ + EStudio_gui_erp_totl.Setting = uimenu( EStudio_gui_erp_totl.Window, 'Label', 'Settings'); + + %%ERPStudio Memory + EStudio_gui_erp_totl.set_ERP_memory = uimenu( EStudio_gui_erp_totl.Setting, 'Label', 'Memory Settings','separator','off'); + uimenu( EStudio_gui_erp_totl.set_ERP_memory, 'Label', 'Reset Working Memory', 'Callback', @resetmemory,'separator','off'); + uimenu( EStudio_gui_erp_totl.set_ERP_memory, 'Label', 'Save a copy of the current working memory as...', 'Callback', 'estudioworking_mem_save_load(1)','separator','off'); + comLoadWM = ['clear vmemoryestudio; vmemoryestudio = estudioworking_mem_save_load(2); assignin(''base'',''vmemoryestudio'',vmemoryestudio);']; + uimenu( EStudio_gui_erp_totl.set_ERP_memory,'Label','Load a previous working memory file','CallBack',comLoadWM,'separator','off'); + + + EStudio_gui_erp_totl.set_windowsize = uimenu( EStudio_gui_erp_totl.Setting, 'Label','Window Size','separator','off','CallBack',@window_size); + EStudio_gui_erp_totl.set_reset = uimenu( EStudio_gui_erp_totl.Setting, 'Label','Reset','separator','off','CallBack',@rest_estudio); + %%Help + EStudio_gui_erp_totl.help_title = uimenu( EStudio_gui_erp_totl.Window, 'Label', 'Help'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'About ERPLAB Studio','separator','off','CallBack',@about_estudio); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'ERPLAB Studio Tutorial','separator','on','CallBack','web(''https://github.com/ucdavis/erplab/wiki/ERPLAB-Studio-Tutorial'', ''-browser'');'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'ERPLAB Studio Manual','separator','off','CallBack','web(''https://github.com/ucdavis/erplab/wiki/ERPLAB-Studio-Manual'', ''-browser'');'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'ERPLAB Scripting','separator','off','CallBack','web(''https://github.com/ucdavis/erplab/wiki/Scripting-Guide'', ''-browser'');'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'Frequent asked questions','separator','off','CallBack','web(''https://github.com/ucdavis/erplab/wiki/Troubleshooting-and-Frequently-Asked-Questions'', ''-browser'');'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'Send question/feedback to the ERPLAB Studio email list','separator','on','CallBack','web(''mailto:erplab@ucdavis.edu?subject=feedback'');'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'ERPLAB email list (may need to register)','separator','off','CallBack','web(''https://github.com/ucdavis/erplab/wiki/ERPLAB-email-list'', ''-browser'');'); + uimenu( EStudio_gui_erp_totl.help_title , 'Label', 'Download latest version','separator','off','CallBack','web(''https://github.com/ucdavis/erplab/releases'', ''-browser'');'); + + + %% Create tabs + FonsizeDefault = f_get_default_fontsize();figbgdColor = [1 1 1]; + EStudio_gui_erp_totl.context_tabs = uiextras.TabPanel('Parent', EStudio_gui_erp_totl.Window, 'Padding', 5,'BackgroundColor',ColorB_def,'FontSize',FonsizeDefault+1); + EStudio_gui_erp_totl.tabEEG = uix.HBoxFlex( 'Parent', EStudio_gui_erp_totl.context_tabs, 'Spacing', 10,'BackgroundColor',ColorB_def );%%EEG Tab + EStudio_gui_erp_totl.tabERP = uix.HBoxFlex( 'Parent', EStudio_gui_erp_totl.context_tabs, 'Spacing', 10,'BackgroundColor',ColorB_def);%%ERP Tab + % EStudio_gui_erp_totl.tabmvpa = uix.HBoxFlex( 'Parent', EStudio_gui_erp_totl.context_tabs, 'Spacing', 10,'BackgroundColor',ColorB_def);%%MVPA Tab + EStudio_gui_erp_totl.context_tabs.TabNames = {'EEG','ERP'};%, 'MVPA' + EStudio_gui_erp_totl.context_tabs.SelectedChild = 1; + EStudio_gui_erp_totl.context_tabs.SelectionChangedFcn = @SelectedTab; + EStudio_gui_erp_totl.context_tabs.HighlightColor = [0 0 0]; + EStudio_gui_erp_totl.context_tabs.FontWeight = 'bold'; + EStudio_gui_erp_totl.context_tabs.TabSize = (new_pos(3)-20)/2; + EStudio_gui_erp_totl.context_tabs.BackgroundColor = ColorB_def; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%------------EEG tab for continous EEG and epoched EEG------------ + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + EStudio_gui_erp_totl = EStudio_EEG_Tab(EStudio_gui_erp_totl,ColorB_def); + EStudio_gui_erp_totl.eegplotgrid = uix.VBox('Parent',EStudio_gui_erp_totl.eegViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.eegpageinfo_box = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.eegplotgrid,'BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.eegpageinfo_text = uicontrol('Parent',EStudio_gui_erp_totl.eegpageinfo_box,'Style','text','String','','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.eegpageinfo_minus = uicontrol('Parent',EStudio_gui_erp_totl.eegpageinfo_box,'Style', 'pushbutton', 'String', 'Prev.','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStudio_gui_erp_totl.eegpageinfo_edit = uicontrol('Parent',EStudio_gui_erp_totl.eegpageinfo_box,'Style', 'edit', 'String', '','FontSize',FonsizeDefault+2,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eegpageinfo_plus = uicontrol('Parent',EStudio_gui_erp_totl.eegpageinfo_box,'Style', 'pushbutton', 'String', 'Next','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1]); + EStudio_gui_erp_totl.eeg_plot_title = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.eegplotgrid,'BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.eegViewAxes = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.eeg_plot_title,'BackgroundColor',figbgdColor); + EStudio_gui_erp_totl.eegxaxis_panel1 = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.eegplotgrid,'BackgroundColor',ColorB_def); + uiextras.Empty('Parent', EStudio_gui_erp_totl.eegxaxis_panel1,'BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.eeg_plot_button_title = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.eegplotgrid,'BackgroundColor',ColorB_def);%%%Message + uiextras.Empty('Parent', EStudio_gui_erp_totl.eeg_plot_button_title); + EStudio_gui_erp_totl.eeg_zoom_in_large = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','|<',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eeg_zoom_in_fivesmall = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','-5X',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eeg_zoom_in_small = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','-X',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eeg_zoom_edit = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','edit','String','',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eeg_zoom_out_small = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','+X',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eeg_zoom_out_fivelarge = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','+5X',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.eeg_zoom_out_large = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','>|',... + 'FontSize',FonsizeDefault+1,'BackgroundColor',[1 1 1],'Enable','off'); + uiextras.Empty('Parent', EStudio_gui_erp_totl.eeg_plot_button_title); + EStudio_gui_erp_totl.popmemu_eeg = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','popupmenu','String','Window Size',... + 'FontSize',FonsizeDefault,'Enable','on','BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.eeg_reset = uicontrol('Parent',EStudio_gui_erp_totl.eeg_plot_button_title,'Style','pushbutton','String','Reset',... + 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + uiextras.Empty('Parent', EStudio_gui_erp_totl.eeg_plot_button_title); + set(EStudio_gui_erp_totl.eeg_plot_button_title, 'Sizes', [10 40 40 40 40 40 40 40 -1 150 50 5]); + + EStudio_gui_erp_totl.eegxaxis_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.eegplotgrid,'BackgroundColor',ColorB_def);%%%Message + EStudio_gui_erp_totl.eegProcess_messg = uicontrol('Parent',EStudio_gui_erp_totl.eegxaxis_panel,'Style','text','String','','FontSize',FonsizeDefault,'BackgroundColor',ColorB_def); + Startimes = 0; + pageNum=1; + pagecurrentNum=1; + PageStr = 'No EEG was loaded'; + EStudio_gui_erp_totl.eegpageinfo_str = ['Page',32,num2str(pagecurrentNum),'/',num2str(pageNum),':',PageStr]; + EStudio_gui_erp_totl.eegpageinfo_text.String=EStudio_gui_erp_totl.eegpageinfo_str; + EStudio_gui_erp_totl.eegpageinfo_edit.String=num2str(pagecurrentNum); + Enable_minus = 'off'; + Enable_plus = 'off'; + Enable_plus_BackgroundColor = [1 1 1]; + Enable_minus_BackgroundColor = [0 0 0]; + EStudio_gui_erp_totl.eegpageinfo_minus.Enable = Enable_minus; + EStudio_gui_erp_totl.eegpageinfo_plus.Enable = Enable_plus; + EStudio_gui_erp_totl.eegpageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; + EStudio_gui_erp_totl.eegpageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; + set(EStudio_gui_erp_totl.eegpageinfo_box, 'Sizes', [-1 70 50 70] ); + EStudio_gui_erp_totl.eeg_zoom_edit.String=num2str(Startimes); + + EStudio_gui_erp_totl.myeegviewer = axes('Parent', EStudio_gui_erp_totl.eegViewAxes,'Color','none','Box','off',... + 'FontWeight','normal', 'XTick', [], 'YTick', [], 'Color','none','xcolor','none','ycolor','none'); + EStudio_gui_erp_totl.eegplotgrid.Heights(1) = 30; % set the first element (pageinfo) to 30px high + EStudio_gui_erp_totl.eegplotgrid.Heights(3) = 5; + EStudio_gui_erp_totl.eegplotgrid.Heights(4) = 30; % set the second element (x axis) to 30px high + EStudio_gui_erp_totl.eegplotgrid.Heights(5) = 30; % set the second element (x axis) to 30px high + Pos = EStudio_gui_erp_totl.myeegviewer.Position; + EStudio_gui_erp_totl.myeegviewer.Position = [Pos(1)*0.5,Pos(2)*0.5,Pos(3)*1.15,Pos(4)*1.05];%%x,y,width,height + estudioworkingmemory('egfigsize',[EStudio_gui_erp_totl.myeegviewer.Position(3),EStudio_gui_erp_totl.myeegviewer.Position(4)]); + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%---------------set the layouts for ERP Tab----------------------- + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + EStudio_gui_erp_totl = EStudio_ERP_Tab(EStudio_gui_erp_totl,ColorB_def); + pageNum=1; + pagecurrentNum=1; + PageStr = 'No ERPset was loaded'; + estudioworkingmemory('selectederpstudio',1); + EStudio_gui_erp_totl.plotgrid = uix.VBox('Parent',EStudio_gui_erp_totl.ViewContainer,'Padding',0,'Spacing',0,'BackgroundColor',ColorB_def); + pageinfo_box = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def); + %%legends + ViewAxes_legend_title = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',[1 1 1]); + EStudio_gui_erp_totl.ViewAxes_legend = uix.ScrollingPanel( 'Parent', ViewAxes_legend_title,'BackgroundColor',[1 1 1]); + %%waves + EStudio_gui_erp_totl.plot_wav_legend = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',[1 1 1]); + EStudio_gui_erp_totl.ViewAxes = uix.ScrollingPanel( 'Parent', EStudio_gui_erp_totl.plot_wav_legend,'BackgroundColor',[1 1 1]); + + EStudio_gui_erp_totl.blank = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message + uiextras.Empty('Parent', EStudio_gui_erp_totl.blank,'BackgroundColor',ColorB_def); % 1A + + %%Setting title + pageinfo_str = ['Page',32,num2str(pagecurrentNum),'/',num2str(pageNum),':',32,PageStr]; + EStudio_gui_erp_totl.pageinfo_text = uicontrol('Parent',pageinfo_box,'Style','text','String',pageinfo_str,'FontSize',FonsizeDefault); + EStudio_gui_erp_totl.pageinfo_minus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', 'Prev.','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.pageinfo_edit = uicontrol('Parent',pageinfo_box,'Style', 'edit', 'String', num2str(pagecurrentNum),'FontSize',FonsizeDefault+2,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.pageinfo_plus = uicontrol('Parent',pageinfo_box,'Style', 'pushbutton', 'String', 'Next','FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + Enable_plus_BackgroundColor = [1 1 1]; + Enable_minus_BackgroundColor = [0 0 0]; + EStudio_gui_erp_totl.pageinfo_plus.ForegroundColor = Enable_plus_BackgroundColor; + EStudio_gui_erp_totl.pageinfo_minus.ForegroundColor = Enable_minus_BackgroundColor; + set(pageinfo_box, 'Sizes', [-1 70 50 70] ); + set(pageinfo_box,'BackgroundColor',ColorB_def); + set(EStudio_gui_erp_totl.pageinfo_text,'BackgroundColor',ColorB_def); + + commandfig_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message + uiextras.Empty('Parent', commandfig_panel); % 1A + EStudio_gui_erp_totl.erp_reset = uicontrol('Parent',commandfig_panel,'Style','pushbutton','String','Reset',... + 'FontSize',FonsizeDefault,'BackgroundColor',[1 1 1],'Enable','off'); + EStudio_gui_erp_totl.erp_popmenu = uicontrol('Parent',commandfig_panel,'Style','pushbutton','String','Reset',... + 'FontSize',FonsizeDefault,'BackgroundColor',ColorB_def,'Enable','on'); + uiextras.Empty('Parent', commandfig_panel); % 1A + set(commandfig_panel, 'Sizes', [-1 150 50 5]); + %%message + xaxis_panel = uiextras.HBox( 'Parent', EStudio_gui_erp_totl.plotgrid,'BackgroundColor',ColorB_def);%%%Message + EStudio_gui_erp_totl.Process_messg = uicontrol('Parent',xaxis_panel,'Style','text','String','','FontSize',FonsizeDefault,'FontWeight','bold','BackgroundColor',ColorB_def); + EStudio_gui_erp_totl.advanced_viewer.Enable = 'off'; + EStudio_gui_erp_totl.plotgrid.Heights(1) = 30; + EStudio_gui_erp_totl.plotgrid.Heights(2) = 70;% set the first element (pageinfo) to 30px high + + EStudio_gui_erp_totl.plotgrid.Heights(4) = 5; + EStudio_gui_erp_totl.plotgrid.Heights(5) = 30; + EStudio_gui_erp_totl.plotgrid.Heights(6) = 30; + end % createInterface + + +%%%---------------------window size---------------------------------------- + function window_size(~,~) + try + ScreenPos= EStudio_gui_erp_totl.ScreenPos; + catch + ScreenPos = get( 0, 'Screensize' ); + end + try + New_pos = EStudio_gui_erp_totl.Window.Position; + catch + return; + end + try + New_posin = estudioworkingmemory('EStudioScreenPos'); + catch + New_posin = [75,75]; + end + if isempty(New_posin) ||numel(New_posin)~=2 + New_posin = [75,75]; + end + New_posin(2) = abs(New_posin(2)); + + app = feval('EStudio_pos_gui',New_posin); + waitfor(app,'Finishbutton',1); + try + New_pos1 = app.output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + try New_pos1(2) = abs(New_pos1(2));catch; end; + + if isempty(New_pos1) || numel(New_pos1)~=2 + estudioworkingmemory('f_EEG_proces_messg',['The defined Window Size for EStudio is invalid and it must be two numbers']); + observe_EEGDAT.eeg_panel_message =4; + return; + end + estudioworkingmemory('EStudioScreenPos',New_pos1); + try + POS4 = (New_pos1(2)-New_posin(2))/100; + new_pos =[New_pos(1),New_pos(2)-ScreenPos(4)*POS4,ScreenPos(3)*New_pos1(1)/100,ScreenPos(4)*New_pos1(2)/100]; + if new_pos(2) < -abs(new_pos(4))%%if + + end + set(EStudio_gui_erp_totl.Window, 'Position', new_pos); + catch + estudioworkingmemory('f_EEG_proces_messg',['The defined Window Size for EStudio is invalid and it must be two numbers']); + observe_EEGDAT.eeg_panel_message =4; + set(EStudio_gui_erp_totl.Window, 'Position', [0 0 0.75*ScreenPos(3) 0.75*ScreenPos(4)]); + estudioworkingmemory('EStudioScreenPos',[75 75]); + end + f_redrawEEG_Wave_Viewer(); + f_redrawERP(); + EStudio_gui_erp_totl.context_tabs.TabSize = (new_pos(3)-20)/2; + end + + + + function rest_estudio(~,~) + %%first check if the changed parameters have been applied in any panels + [messgStr,eegpanelIndex] = f_check_eegtab_panelchanges(); + if ~isempty(messgStr) + observe_EEGDAT.eeg_two_panels = observe_EEGDAT.eeg_two_panels+1; + end + + estudioworkingmemory('EEGUpdate',0); + observe_EEGDAT.count_current_eeg =1; + if EStudio_gui_erp_totl.context_tabs.SelectedChild==1 + estudioworkingmemory('f_EEG_proces_messg','Reset parameters for ALL panels'); + observe_EEGDAT.eeg_panel_message=1; + app = feval('estudio_reset_paras',[1 0 0 0]); + elseif EStudio_gui_erp_totl.context_tabs.SelectedChild==2 + MessageViewer= char(strcat('Reset parameters for ALL panels ')); + estudioworkingmemory('f_ERP_proces_messg',MessageViewer); + observe_ERPDAT.Process_messg =2; + app = feval('estudio_reset_paras',[0 0 1 0]); + end + + waitfor(app,'Finishbutton',1); + try + reset_paras = app.Output; %NO you don't want to output EEG with edited channel locations, you want to output the parameters to run decoding + app.delete; %delete app from view + pause(0.1); %wait for app to leave + catch + return; + end + if isempty(reset_paras) + return; + end + observe_EEGDAT.eeg_panel_message=1; + if reset_paras(2)==1 + EStudio_gui_erp_totl.clear_alleeg = 1; + else + EStudio_gui_erp_totl.clear_alleeg = 0; + end + if reset_paras(1)==1 + observe_EEGDAT.Reset_eeg_paras_panel=1; + if EStudio_gui_erp_totl.clear_alleeg == 0 + f_redrawEEG_Wave_Viewer(); + else + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + estudioworkingmemory('EEGArray',1); + observe_EEGDAT.count_current_eeg =1; + end + else + if EStudio_gui_erp_totl.clear_alleeg == 1 + observe_EEGDAT.ALLEEG = []; + observe_EEGDAT.EEG = []; + observe_EEGDAT.CURRENTSET = 0; + estudioworkingmemory('EEGArray',1); + observe_EEGDAT.count_current_eeg =1; + end + end + if EStudio_gui_erp_totl.context_tabs.SelectedChild==1 + observe_EEGDAT.eeg_panel_message=2; + elseif EStudio_gui_erp_totl.context_tabs.SelectedChild==2 + observe_ERPDAT.Process_messg =2; + end + %%---------------- -------------erp tab------------------------------------ + if reset_paras(4)==1 + EStudio_gui_erp_totl.clear_allerp = 1; + else + EStudio_gui_erp_totl.clear_allerp = 0; + end + + if reset_paras(3)==1 + observe_ERPDAT.Reset_erp_paras_panel = 1; + if EStudio_gui_erp_totl.clear_allerp == 0 + f_redrawERP(); + else + observe_ERPDAT.ALLERP = []; + observe_ERPDAT.ERP = []; + observe_ERPDAT.CURRENTERP = 1; + estudioworkingmemory('selectederpstudio',1); + observe_ERPDAT.Count_currentERP = 1; + end + else + if EStudio_gui_erp_totl.clear_allerp == 1 + observe_ERPDAT.ALLERP = []; + observe_ERPDAT.ERP = []; + observe_ERPDAT.CURRENTERP = 1; + estudioworkingmemory('selectederpstudio',1); + observe_ERPDAT.Count_currentERP = 1; + end + end + + end + + + function about_estudio(~,~) + abouterplabGUI; + end + + + + + + + +%%---------------------------------allEEG------------------------------------- + function alleeg_change(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + assignin('base','ALLEEG',observe_EEGDAT.ALLEEG); + end + +%%---------------------------------EEG------------------------------------- + function eeg_change(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + assignin('base','EEG',observe_EEGDAT.EEG); + end + + function count_current_eeg_change(~,~) + if isempty(observe_EEGDAT.EEG) + return; + end + assignin('base','CURRENTSET',observe_EEGDAT.CURRENTSET); + return; + end + +%------------------------------------ERP----------------------------------- + function onErpChanged( ~, ~ ) + assignin('base','ERP',observe_ERPDAT.ERP); + end + + function indexERP( ~, ~ ) + assignin('base','CURRENTERP',observe_ERPDAT.CURRENTERP); + if ~strcmp(observe_ERPDAT.CURRENTERP,CURRENTERP) + CURRENTERP = observe_ERPDAT.CURRENTERP; + end + observe_ERPDAT.ERP = observe_ERPDAT.ALLERP(observe_ERPDAT.CURRENTERP); + end + + function allErpChanged(~,~) + assignin('base','ALLERP',observe_ERPDAT.ALLERP); + end + + function Count_currentERPChanged(~,~) + return; + end + + +%%------------------------Message panel------------------------------------ + function eeg_panel_change_message(~,~) + return; + end + + + +% %%%Display the processing procedure for some panels (e.g., Filter)------------------------ + function Process_messg_change_main(~,~) + if observe_ERPDAT.Process_messg==0 + return; + end + try + [version reldate,ColorB_def,ColorF_def,errorColorF_def] = geterplabstudiodef; + catch + ColorB_def = [0.95 0.95 0.95]; + end + FonsizeDefault = f_get_default_fontsize(); + Processed_Method=estudioworkingmemory('f_ERP_proces_messg'); + EStudio_gui_erp_totl.Process_messg.BackgroundColor = [0.95 0.95 0.95]; + EStudio_gui_erp_totl.Process_messg.FontSize = FonsizeDefault; + if observe_ERPDAT.Process_messg ==1 + EStudio_gui_erp_totl.Process_messg.String = strcat('1- ',Processed_Method,': Running....'); + EStudio_gui_erp_totl.Process_messg.ForegroundColor = [0 0 0]; + elseif observe_ERPDAT.Process_messg==2 + EStudio_gui_erp_totl.Process_messg.String = strcat('2- ',Processed_Method,': Complete'); + EStudio_gui_erp_totl.Process_messg.ForegroundColor = [0 0.5 0]; + elseif observe_ERPDAT.Process_messg ==3 + EStudio_gui_erp_totl.Process_messg.String = strcat('2- ',Processed_Method,': Error'); + EStudio_gui_erp_totl.Process_messg.ForegroundColor = [1 0 0]; + elseif observe_ERPDAT.Process_messg ==4 + EStudio_gui_erp_totl.Process_messg.String = strcat('Warning: ',32,Processed_Method); + EStudio_gui_erp_totl.Process_messg.ForegroundColor = [1 0.65 0]; + else + + end + if observe_ERPDAT.Process_messg ~=4 + pause(0.1); + EStudio_gui_erp_totl.Process_messg.String = ''; + EStudio_gui_erp_totl.Process_messg.BackgroundColor = ColorB_def;%[0.95 0.95 0.95]; + end + end + +%%--------------------Function to close the toolbox------------------------ + function onExit(~,~) + BackERPLABcolor = [1 0.9 0.3]; % yellow + question = ['Are you sure to quit EStudio?']; + title = 'Exit'; + oldcolor = get(0,'DefaultUicontrolBackgroundColor'); + set(0,'DefaultUicontrolBackgroundColor',BackERPLABcolor) + button = questdlg(sprintf(question), title,'Cancel','No', 'Yes','Yes'); + set(0,'DefaultUicontrolBackgroundColor',oldcolor); + if strcmpi(button,'Yes') + try + close(EStudio_gui_erp_totl.Window); + catch + return; + end + warning('on'); + else + return; + end + end + + +%%-------------------reset memory file------------------------------------- + function resetmemory(~,~) + runindex = etudioamnesia(1); + if runindex==1 + observe_EEGDAT.Reset_eeg_paras_panel=1; + observe_ERPDAT.Count_currentERP = 1; + f_redrawERP(); + f_redrawEEG_Wave_Viewer(); + end + end +%%%%%%%%%%%%%%%%%%%%%%% +end % end of the function + + +%%------------------------------------------------------------------------- +%%-------------------------------borrow from eeglab------------------------ +%%------------------------------------------------------------------------- +% find a function path and add path if not present +% ------------------------------------------------ +function myaddpath(estudiopath, functionname, pathtoadd) + +tmpp = mywhich(functionname); +tmpnewpath = [ estudiopath pathtoadd ]; +if ~isempty(tmpp) + tmpp = tmpp(1:end-length(functionname)); + if length(tmpp) > length(tmpnewpath), tmpp = tmpp(1:end-1); end % remove trailing filesep + if length(tmpp) > length(tmpnewpath), tmpp = tmpp(1:end-1); end % remove trailing filesep + %disp([ tmpp ' || ' tmpnewpath '(' num2str(~strcmpi(tmpnewpath, tmpp)) ')' ]); + if ~strcmpi(tmpnewpath, tmpp) + warning('off', 'MATLAB:dispatcher:nameConflict'); + addpath(tmpnewpath); + warning('on', 'MATLAB:dispatcher:nameConflict'); + end +else + %disp([ 'Adding new path ' tmpnewpath ]); + addpathifnotinlist(tmpnewpath); +end + +end + + +function res = mywhich(varargin) +try + res = which(varargin{:}); +catch + fprintf('Warning: permission error accessing %s\n', varargin{1}); +end +end + + + +function addpathifnotinlist(newpath) + +comp = computer; +if strcmpi(comp(1:2), 'PC') + newpathtest = [ newpath ';' ]; +else + newpathtest = [ newpath ':' ]; +end +p = path; +ind = strfind(p, newpathtest); +if isempty(ind) + if exist(newpath) == 7 + addpath(newpath); + end +end + +end + + +%%--------------------plot the wave if select new Tab---------------------- +function SelectedTab(~,~) +global EStudio_gui_erp_totl; + +if EStudio_gui_erp_totl.context_tabs.Selection==2%% ERP Tab + f_redrawERP(); +elseif EStudio_gui_erp_totl.context_tabs.Selection==3%% ERP Tab + +else%%EEG Tab + f_redrawEEG_Wave_Viewer(); +end +end + + +%%---------------------ERPLAB VERSION-------------------------------------- +function erplabver1 = geterplabeversion +erplab_default_values; +erplabver1 = str2num(erplabver); +estudioworkingmemory('erplabver', erplabver); +end diff --git a/studio_functions/memoryerpstudio.erpm b/studio_functions/memoryerpstudio.erpm index 55d6b607..d9b108e5 100644 Binary files a/studio_functions/memoryerpstudio.erpm and b/studio_functions/memoryerpstudio.erpm differ diff --git a/studio_functions/o_EEGDATA.m b/studio_functions/o_EEGDATA.m old mode 100644 new mode 100755 diff --git a/studio_functions/o_ERPDAT.m b/studio_functions/o_ERPDAT.m index ea07e70a..ad2de6f6 100755 --- a/studio_functions/o_ERPDAT.m +++ b/studio_functions/o_ERPDAT.m @@ -8,7 +8,8 @@ ERP_bin Count_currentERP Process_messg - Two_GUI + erp_between_panels + Reset_erp_paras_panel end @@ -21,57 +22,119 @@ ERP_bin_change Count_currentERP_change Messg_change - Two_GUI_change + erp_between_panels_change + Reset_erp_panel_change end methods function set.ALLERP(obj,value) - obj.ALLERP = value; - notify(obj,'erpschange'); + try + warning('off'); + obj.ALLERP = value; + notify(obj,'erpschange'); + catch + end + warning('on'); end + function set.ERP(obj,value) - obj.ERP = value; - notify(obj,'drawui_CB'); + try + warning('off'); + obj.ERP = value; + notify(obj,'drawui_CB'); + catch + end + warning('on'); end + %%Modified CurrentERP function set.CURRENTERP(obj,value) - obj.CURRENTERP = value; - notify(obj,'cerpchange'); + try + warning('off'); + obj.CURRENTERP = value; + notify(obj,'cerpchange'); + catch + end + warning('on'); end + %%ERP Plotting panel function set.Count_ERP(obj,value) - obj.Count_ERP = value; - notify(obj,'Count_ERP_change'); + try + warning('off'); + obj.Count_ERP = value; + notify(obj,'Count_ERP_change'); + catch + end + warning('on'); end + %Modified channels of the selected ERP function set.ERP_chan(obj,value) - obj.ERP_chan = value; - notify(obj,'ERP_chan_change'); + try + warning('off'); + obj.ERP_chan = value; + notify(obj,'ERP_chan_change'); + catch + end + warning('on'); end + %Modified bins of the selected ERP function set.ERP_bin(obj,value) - obj.ERP_bin = value; - notify(obj,'ERP_bin_change'); + try + warning('off'); + obj.ERP_bin = value; + notify(obj,'ERP_bin_change'); + catch + end + warning('on'); end + %Modified bins of the selected ERP function set.Count_currentERP(obj,value) - obj.Count_currentERP = value; - notify(obj,'Count_currentERP_change'); + try + warning('off'); + obj.Count_currentERP = value; + notify(obj,'Count_currentERP_change'); + catch + end + warning('on'); end - %Modified bins of the selected ERP function set.Process_messg(obj,value) - obj.Process_messg = value; - notify(obj,'Messg_change'); + try + warning('off'); + obj.Process_messg = value; + notify(obj,'Messg_change'); + catch + end + warning('on'); + end + + %%two panels + function set.erp_between_panels(obj_erp,values_erp) + try + warning('off', 'all'); + obj_erp.erp_between_panels = values_erp; + notify(obj_erp,'erp_between_panels_change'); + catch + warning('on'); + end end - %capture the change from main EStudio - function set.Two_GUI(obj,value) - obj.Two_GUI = value; - notify(obj,'Two_GUI_change'); + %%two panels + function set.Reset_erp_paras_panel(obj_erp,values_erp) + try + warning('off'); + obj_erp.Reset_erp_paras_panel = values_erp; + notify(obj_erp,'Reset_erp_panel_change'); + catch + warning('on'); + end end