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

📄 wave_clus.m

📁 wave cluster for biomedical signal proce
💻 M
📖 第 1 页 / 共 3 页
字号:
        USER_DATA{3} = index/1000;        USER_DATA{4} = clu;        USER_DATA{5} = tree;        set(handles.wave_clus_figure,'userdata',USER_DATA)                    case 'MIT data'        [filename, pathname] = uigetfile('*.m','Select file');        set(handles.file_name,'string',['Loading:    ' pathname filename]);        cd(pathname);        file = filename(1:end-2);        eval(file);        sr = 1e6/c.t{1}.electrode1.waveforms(1).samplingInterval_us;    %in Hz.        handles.par = set_parameters_MIT(sr,filename,handles);          %Load parameters        set(handles.min_clus_edit,'string',num2str(handles.par.min_clus));        axes(handles.cont_data); cla        [spikes,index] = Clean_data_MIT(file,c,handles)                [inspk] = wave_features_wc(spikes,handles);                     %Extract spike features.        if handles.par.match == 'y';            naux = min(handles.par.max_spk,size(inspk,1));            inspk_aux = inspk(1:naux,:);        else            inspk_aux = inspk;        end                    %Interaction with SPC        set(handles.file_name,'string','Running SPC ...');        handles.par.fname_in = 'tmp_data';        fname_in = handles.par.fname_in;        save([fname_in],'inspk','-ascii');                          %Input file for SPC        handles.par.fname = [handles.par.fname '_wc'];              %Output filename of SPC        handles.par.fnamespc = handles.par.fname;                   %filename if "save clusters" button is pressed        handles.par.fnamesave = handles.par.fnamespc;        [clu,tree] = run_cluster(handles);        USER_DATA = get(handles.wave_clus_figure,'userdata');        USER_DATA{2} = spikes;        USER_DATA{3} = index;        USER_DATA{4} = clu;        USER_DATA{5} = tree;        USER_DATA{7} = inspk;        set(handles.wave_clus_figure,'userdata',USER_DATA)                case 'ASCII'            % ASCII matlab files        [filename, pathname] = uigetfile('*.mat','Select file');        set(handles.file_name,'string',['Loading:    ' pathname filename]);        cd(pathname);        handles.par = set_parameters_ascii(filename,handles);       %Load parameters        set(handles.min_clus_edit,'string',num2str(handles.par.min_clus));                index_all=[];        spikes_all=[];        for j=1:handles.par.segments                                %that's for cutting the data into pieces            % LOAD CONTINUOUS DATA            load(filename);            x=data(:)';            tsmin = (j-1)*floor(length(data)/handles.par.segments)+1;            tsmax = j*floor(length(data)/handles.par.segments);            x=data(tsmin:tsmax); clear data;             handles.flag = 1;                                      %flag for ploting only in the 1st loop                        % SPIKE DETECTION WITH AMPLITUDE THRESHOLDING            [spikes,thr,index]  = amp_detect_wc(x,handles);        %detection with amp. thresh.            index=index+tsmin-1;                        index_all = [index_all index];            spikes_all = [spikes_all; spikes];        end        index = index_all *1e3/handles.par.sr;                     %spike times in ms.        spikes = spikes_all;                USER_DATA = get(handles.wave_clus_figure,'userdata');        USER_DATA{2}=spikes;        USER_DATA{3}=index;        set(handles.wave_clus_figure,'userdata',USER_DATA);        [inspk] = wave_features_wc(spikes,handles);                %Extract spike features.        if handles.par.match == 'y';            naux = min(handles.par.max_spk,size(inspk,1));            inspk_aux = inspk(1:naux,:);        else            inspk_aux = inspk;        end                    %Interaction with SPC        set(handles.file_name,'string','Running SPC ...');        handles.par.fname_in = 'tmp_data';        fname_in = handles.par.fname_in;        save([fname_in],'inspk','-ascii');                         %Input file for SPC        handles.par.fnamesave = [handles.par.fname '_' ...                filename(1:end-4)];                                %filename if "save clusters" button is pressed        handles.par.fname = [handles.par.fname '_wc'];             %Output filename of SPC        handles.par.fnamespc = handles.par.fname;            [clu,tree] = run_cluster(handles);        USER_DATA = get(handles.wave_clus_figure,'userdata');        USER_DATA{4} = clu;        USER_DATA{5} = tree;        USER_DATA{7} = inspk;        set(handles.wave_clus_figure,'userdata',USER_DATA)                    case 'ASCII (pre-clustered)'                                   %ASCII matlab files        [filename, pathname] = uigetfile('*.mat','Select file');        set(handles.file_name,'string',['Loading:    ' pathname filename]);        cd(pathname);        handles.par = set_parameters_ascii(filename,handles);      %Load parameters        set(handles.min_clus_edit,'string',num2str(handles.par.min_clus));                %Load spikes and parameters        eval(['load times_' filename ';']);        index=cluster_class(:,2)';        %Load clustering results        fname = [handles.par.fname '_' filename(1:end-4)];         %filename for interaction with SPC        clu=load([fname '.dg_01.lab']);        tree=load([fname '.dg_01']);        handles.par.fnamespc = fname;        handles.par.fnamesave = fname;        USER_DATA = get(handles.wave_clus_figure,'userdata');        USER_DATA{2} = spikes;        USER_DATA{3} = index;        USER_DATA{4} = clu;        USER_DATA{5} = tree;        if exist('inspk');            USER_DATA{7} = inspk;        end        set(handles.wave_clus_figure,'userdata',USER_DATA)        %Load continuous data (for ploting)        load(filename);        x=data(:)';         x(60*handles.par.sr+1:end)=[];                                   %will plot just 60 sec.        [spikes,thr,index] = amp_detect_wc(x,handles);                   %Detection with amp. thresh.                   case 'ASCII spikes'        [filename, pathname] = uigetfile('*.mat','Select file');        set(handles.file_name,'string',['Loading:    ' pathname filename]);        cd(pathname);        handles.par = set_parameters_ascii_spikes(filename,handles);     %Load parameters        set(handles.min_clus_edit,'string',num2str(handles.par.min_clus));        axes(handles.cont_data); cla                %Load spikes        load(filename);                [inspk] = wave_features_wc(spikes,handles);                      %Extract spike features.        if handles.par.match == 'y';            naux = min(handles.par.max_spk,size(inspk,1));            inspk_aux = inspk(1:naux,:);        else            inspk_aux = inspk;        end                    %Interaction with SPC        set(handles.file_name,'string','Running SPC ...');        handles.par.fname_in = 'tmp_data';        fname_in = handles.par.fname_in;        save([fname_in],'inspk','-ascii');                      %Input file for SPC        handles.par.fname = [handles.par.fname '_wc'];          %Output filename of SPC        handles.par.fnamespc = handles.par.fname;        [clu,tree] = run_cluster(handles);        USER_DATA = get(handles.wave_clus_figure,'userdata');        USER_DATA{2} = spikes;        USER_DATA{3} = index(:)';        USER_DATA{4} = clu;        USER_DATA{5} = tree;        USER_DATA{7} = inspk;        set(handles.wave_clus_figure,'userdata',USER_DATA)                    case 'ASCII spikes (pre-clustered)'        [filename, pathname] = uigetfile('*.mat','Select file');        set(handles.file_name,'string',['Loading:    ' pathname filename]);        cd(pathname);        handles.par = set_parameters_ascii_spikes(filename,handles);     %Load parameters        set(handles.min_clus_edit,'string',num2str(handles.par.min_clus));        axes(handles.cont_data); cla        %Load spikes and parameters        eval(['load times_' filename ';']);        index=cluster_class(:,2)';        %Load clustering results        fname = [handles.par.fname '_' filename(1:end-4)];               %filename for interaction with SPC        clu=load([fname '.dg_01.lab']);        tree=load([fname '.dg_01']);        handles.par.fnamespc = fname;              USER_DATA = get(handles.wave_clus_figure,'userdata');        USER_DATA{2} = spikes;        USER_DATA{3} = index(:)';        USER_DATA{4} = clu;        USER_DATA{5} = tree;        set(handles.wave_clus_figure,'userdata',USER_DATA)        end    temp=find_temp(tree,handles);                                   %Selects temperature.temperature=handles.par.mintemp+temp*handles.par.tempstep;axes(handles.temperature_plot);switch handles.par.temp_plot    case 'lin'        plot([handles.par.mintemp handles.par.maxtemp-handles.par.tempstep], ...            [handles.par.min_clus handles.par.min_clus],'k:',...            handles.par.mintemp+(1:handles.par.num_temp)*handles.par.tempstep, ...            tree(1:handles.par.num_temp,5:size(tree,2)),[temperature temperature],[1 tree(1,5)],'k:')    case 'log'        semilogy([handles.par.mintemp handles.par.maxtemp-handles.par.tempstep], ...            [handles.par.min_clus handles.par.min_clus],'k:',...            handles.par.mintemp+(1:handles.par.num_temp)*handles.par.tempstep, ...            tree(1:handles.par.num_temp,5:size(tree,2)),[temperature temperature],[1 tree(1,5)],'k:')endxlim([0 handles.par.maxtemp])xlabel('Temperature');if handles.par.temp_plot == 'log'     set(get(gca,'ylabel'),'vertical','Cap');else    set(get(gca,'ylabel'),'vertical','Baseline');endylabel('Clusters size');set(handles.file_name,'string',[pathname filename]);if size(clu,2)-2 < size(spikes,1);    classes = clu(temp,3:end)+1;    classes = [classes(:)' zeros(1,size(spikes,1)-handles.par.max_spk)];else    classes = clu(temp,3:end)+1;endguidata(hObject, handles);USER_DATA = get(handles.wave_clus_figure,'userdata');USER_DATA{6} = classes(:)';USER_DATA{8} = temp;USER_DATA{9} = classes(:)';                                     %backup for non-forced classes.set(handles.wave_clus_figure,'userdata',USER_DATA);handles.setclus = 0;plot_spikes(handles);% --- Executes on button press in change_temperature_button.function change_temperature_button_Callback(hObject, eventdata, handles)axes(handles.temperature_plot)[temp aux]= ginput(1);                                          %gets the mouse inputtemp = round((temp-handles.par.mintemp)/handles.par.tempstep);if temp < 1; temp=1;end                                         %temp should be within the limitsif temp > handles.par.num_temp; temp=handles.par.num_temp; endmin_clus = round(aux);set(handles.min_clus_edit,'string',num2str(min_clus));USER_DATA = get(handles.wave_clus_figure,'userdata');par = USER_DATA{1};par.min_clus = min_clus;clu = USER_DATA{4};classes = clu(temp,3:end)+1;tree = USER_DATA{5};USER_DATA{1} = par;USER_DATA{6} = classes(:)';USER_DATA{8} = temp;USER_DATA{9} = classes(:)';                                     %backup for non-forced classes.set(handles.wave_clus_figure,'userdata',USER_DATA);temperature=handles.par.mintemp+temp*handles.par.tempstep;switch par.temp_plot    case 'lin'        plot([handles.par.mintemp handles.par.maxtemp-handles.par.tempstep],[par.min_clus par.min_clus],'k:',...            handles.par.mintemp+(1:handles.par.num_temp)*handles.par.tempstep, ...            tree(1:handles.par.num_temp,5:size(tree,2)),[temperature temperature],[1 tree(1,5)],'k:')    case 'log'         semilogy([handles.par.mintemp handles.par.maxtemp-handles.par.tempstep], ...            [par.min_clus par.min_clus],'k:',...            handles.par.mintemp+(1:handles.par.num_temp)*handles.par.tempstep, ...            tree(1:handles.par.num_temp,5:size(tree,2)),[temperature temperature],[1 tree(1,5)],'k:')endxlim([0 handles.par.maxtemp])xlabel('Temperature'); if par.temp_plot == 'log'     set(get(gca,'ylabel'),'vertical','Cap');else    set(get(gca,'ylabel'),'vertical','Baseline');endylabel('Clusters size');handles.setclus = 0;plot_spikes(handles);set(handles.force_button,'value',0);set(handles.force_button,'string','Force');set(handles.fix1_button,'value',0);set(handles.fix2_button,'value',0);set(handles.fix3_button,'value',0);for i=4:par.max_clus    eval(['par.fix' num2str(i) '=0;']);end    % --- Change min_clus_edit     function min_clus_edit_Callback(hObject, eventdata, handles)USER_DATA = get(handles.wave_clus_figure,'userdata');par = USER_DATA{1};par.min_clus = str2num(get(hObject, 'String'));clu = USER_DATA{4};temp = USER_DATA{8};classes = clu(temp,3:end)+1;tree = USER_DATA{5};USER_DATA{1} = par;USER_DATA{6} = classes(:)';USER_DATA{9} = classes(:)';                                     %backup for non-forced classes.set(handles.wave_clus_figure,'userdata',USER_DATA);temperature=handles.par.mintemp+temp*handles.par.tempstep;axes(handles.temperature_plot)switch par.temp_plot    case 'lin'        plot([handles.par.mintemp handles.par.maxtemp-handles.par.tempstep],[par.min_clus par.min_clus],'k:',...            handles.par.mintemp+(1:handles.par.num_temp)*handles.par.tempstep, ...            tree(1:handles.par.num_temp,5:size(tree,2)),[temperature temperature],[1 tree(1,5)],'k:')    case 'log'        semilogy([handles.par.mintemp handles.par.maxtemp-handles.par.tempstep], ...            [par.min_clus par.min_clus],'k:',...            handles.par.mintemp+(1:handles.par.num_temp)*handles.par.tempstep, ...            tree(1:handles.par.num_temp,5:size(tree,2)),[temperature temperature],[1 tree(1,5)],'k:')endxlim([0 handles.par.maxtemp])xlabel('Temperature'); if par.temp_plot == 'log'     set(get(gca,'ylabel'),'vertical','Cap');else    set(get(gca,'ylabel'),'vertical','Baseline');endylabel('Clusters size');handles.setclus = 0;plot_spikes(handles);set(handles.force_button,'value',0);set(handles.force_button,'string','Force');set(handles.fix1_button,'value',0);set(handles.fix2_button,'value',0);set(handles.fix3_button,'value',0);for i=4:par.max_clus    eval(['par.fix' num2str(i) '=0;']);end    % --- Executes on button press in save_clusters_button.function save_clusters_button_Callback(hObject, eventdata, handles)USER_DATA = get(handles.wave_clus_figure,'userdata');spikes = USER_DATA{2};par = USER_DATA{1};classes = USER_DATA{6};cont=0;% Classes should be consecutive numbersi=1;while i<=max(classes)    if isempty(classes(find(classes==i)))        for k=i+1:max(classes)            classes(find(classes==k))=k-1;        end    else        i=i+1;    endend%Saves clusterscurrentver = version;if currentver(1) == 7    verflag = [-v6];    %Makes output readable by version 6 else

⌨️ 快捷键说明

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