📄 preprocess.m
字号:
%%% arg's first "word" is 4 letters long and it can be:%%%%%% 'key '%%% 'down'%%% 'drag'%%% 'up 'if strcmp(arg,'key ') %string is 'key' + 1 space!!! if ~LOG key=get(gcf,'CurrentCharacter'); else key=arg2 end if ~strcmp(key,'<') & ~strcmp(key,'>') return; end data=get(gcf,'UserData'); sel=data.selected_vects; if length(sel) == 1 if strcmp(key,'<') & sel ~= 1 data.selected_vects=sel-1; set(gcf,'UserData',data); elseif strcmp(key,'>') & sel ~= length(data.sData.data(:,1)) data.selected_vects = sel + 1; set(gcf,'UserData',data); end else if strcmp(key,'<') & sel(1) ~= 1 data.selected_vects=cat(2,sel(1)-1,sel); set(gcf,'UserData',data); elseif strcmp(key,'>') & sel(length(sel)) ~= length(sel) data.selected_vects=cat(2,sel,sel(length(sel))+1); set(gcf,'UserData',data); end end cplot_mimema; pro_tools('plot_hist'); pro_tools('c_stat'); vects=zeros(1,length(data.sData.data(:,1))); vects(data.selected_vects)=1; draw_vectors(vects,data.vector_h); if ~LOG data=get(gcf,'UserData'); data.LOG{length(data.LOG)+1}=... sprintf('preprocess(''vector_bdf'',''key %s'');',key); %string is 'key'+2spaces+%s set(gcf,'UserData',data); end return;endswitch arg case 'down' set(gcf,'WindowButtonUpFcn','preprocess(''vector_bdf'',''up '')'); set(gcf,'WindowButtonMotionFcn','preprocess(''vector_bdf'',''drag'')'); switch get(gcf,'SelectionType') case 'normal' data.lims1=round(getfield(get(gca,'CurrentPoint'),{1,1})); data.lims2=[]; case 'alt' tmp=round(getfield(get(gca,'CurrentPoint'),{1,1})); if isempty(get(gca,'UserData')) data.lims1=tmp; data.lims2=[]; else data.lims1=cat(2,getfield(get(gca,'UserData'),'lims1'),tmp); data.lims2=getfield(get(gca,'UserData'),'lims2'); end end coords=get(gca,'CurrentPoint'); h=line([coords(1),coords(1)],get(gca,'YLim'),'EraseMode','xor'); set(h,'Color','red'); h2=line([coords(1),coords(1)],get(gca,'YLim'),'EraseMode','xor'); set(h2,'Color','red'); data.h=h; data.h2=h2; set(gca,'UserData',data); case 'drag' coords=get(gca,'CurrentPoint'); lim=get(gca,'XLim'); h2=getfield(get(gca,'UserData'),'h2'); if lim(1) >= coords(1) set(h2,'XData',[lim(1) lim(1)]); elseif lim(2) <= coords(2) set(h2,'XData',[lim(2) lim(2)]); else set(h2,'XData',[coords(1) coords(1)]); end case 'up ' % string is 'up' + 2 spaces!!! set(gcf,'WindowButtonUpFcn',''); set(gcf,'WindowButtonMotionFcn',''); if ~LOG data=get(gca,'UserData'); delete(data.h); delete(data.h2); tmp=round(getfield(get(gca,'CurrentPoint'),{1,1})); data.lims2=cat(2,data.lims2,tmp); tmp_data=sort(cat(1,data.lims1,data.lims2)); high=getfield(get(gca,'XLim'),{2})-1; vectors=zeros(1,high); tmp_data(find(tmp_data<1))=1; tmp_data(find(tmp_data>high))=high; for i=1:getfield(size(tmp_data),{2}) vectors(tmp_data(1,i):tmp_data(2,i))=1; end selected_vects=find(vectors); else pre_h=findobj(get(0,'Children'),'Tag','Preprocess'); len=size(getfield(getfield(get(pre_h,'UserData'),'sData'),'data')); vectors=zeros(1,len(1)); i=1; while i <= length(arg2) & (isspace(arg2(i)) | ~isletter(arg2(i))) i=i+1; end arg3=arg2(i:length(arg2)); selected_vects=str2num(arg2(1:i-1)); if ~isempty(arg3) & ~all(isspace(arg3)) selected_vects=unique(cat(2,selected_vects,... getfield(get(pre_h,'UserData'),'selected_vects'))); end vectors(selected_vects)=1; set(pre_h,'CurrentAxes',getfield(get(pre_h,'UserData'),'vector_h')); set(0,'CurrentFigure',pre_h); end draw_vectors(vectors,gca); sData=getfield(get(gcf,'UserData'),'sData'); h=getfield(get(gcf,'UserData'),'vect_mean_h'); vect_means(sData,h,selected_vects); if ~LOG set(gca,'UserData',data); end data=get(gcf,'UserData'); data.undo.sData=data.sData; data.undo.selected=data.selected_vects; data.selected_vects=selected_vects; if ~LOG data.LOG{length(data.LOG)+1}='% Vector selection by using the mouse...'; tmp=sprintf('preprocess(''vector_bdf'',''up %s'');',... num2str(data.selected_vects)); if length(tmp) > 500 tmp=textwrap({tmp},500); data.LOG{length(data.LOG)+1}=cat(2,tmp{1},''');'); for i=2:length(tmp)-1 data.LOG{length(data.LOG)+1}=... cat(2,sprintf('preprocess(''vector_bdf'',''up %s',... tmp{i}),'add'');'); end data.LOG{length(data.LOG)+1}=... cat(2,sprintf('preprocess(''vector_bdf'',''up %s',... tmp{length(tmp)}(1:length(tmp{length(tmp)})-3)),' add'');'); else data.LOG{length(data.LOG)+1}=tmp; end end set(gcf,'UserData',data); cplot_mimema; sel_comp;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function sel_button(varargin) %SEL_BUTTON A Callback function. It performs the operations needed% when vector components are selected.%% See also SEL_COMP%if nargin == 1 LOG=1; pre_h=findobj(get(0,'Children'),'Tag','Preprocess'); string=getfield(get(pre_h,'UserData'),'comp_names_h'); string=getfield(get(string,'String'),{str2num(varargin{1})}); set(0,'CurrentFigure',pre_h);else LOG=0; val=get(getfield(get(gcf,'UserData'),'comp_names_h'),'Value');endsel_button_h=getfield(get(gcf,'UserData'),'sel_button_h');sel_comps_h=getfield(get(gcf,'UserData'),'sel_comps_h');comp_names_h=getfield(get(gcf,'UserData'),'comp_names_h');if ~LOG string=getfield(get(comp_names_h,'String'),{get(comp_names_h,'Value')});endtmp_string=get(sel_comps_h,'String');if iscell(tmp_string) for i=1:length(string) if ~any(strcmp(string{i},tmp_string)) tmp_string=cat(1,tmp_string,string(i)); end end string=tmp_string;endset(sel_comps_h,'String',string);set(comp_names_h,'Value',[]);sel_comp;if ~LOG data=get(gcf,'UserData'); data.LOG{length(data.LOG)+1}='% Select components'; data.LOG{length(data.LOG)+1}=sprintf('preprocess(''sel_button'',''%s'');',... num2str(val)); set(gcf,'UserData',data);end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function clear_button(varargin)%CLEAR_BUTTON Function callback evaluated when a 'Clear'-button is% pressed. It removes texts from the 'selected components' % -window and the 'selected component data' -window and% clears the 'histogram' -axis.%%if nargin==1 LOG=1; pre_h=findobj(get(0,'Children'),'Tag','Preprocess'); set(0,'CurrentFigure',pre_h);else LOG=0;endsel_comp_h=getfield(get(gcf,'UserData'),'sel_comp_h');sel_cdata_h=getfield(get(gcf,'UserData'),'sel_cdata_h');sel_cplot_h=getfield(get(gcf,'UserData'),'sel_cplot_h');sel_chist_h=getfield(get(gcf,'UserData'),'sel_chist_h');vector_h=getfield(get(gcf,'UserData'),'vector_h');set(sel_comp_h,'Value',1);set(sel_cdata_h,'String',' ');subplot(sel_chist_h);hold off;cla;selected=getfield(get(gcf,'UserData'),'selected_vects');dims=size(getfield(getfield(get(gcf,'UserData'),'sData'),'data'));vectors=zeros(1,dims(1));vectors(selected)=1;subplot(vector_h);draw_vectors(vectors,vector_h);if ~LOG data=get(gcf,'UserData'); data.LOG{length(data.LOG)+1}='% Remove components from the selected list.'; data.LOG{length(data.LOG)+1}='preprocess(''clear_button'',''foo'');'; set(gcf,'UserData',data);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function sel_comp(varargin)%SEL_COMP performs the operations needed when vector components are% chosen. It writes maxima, minima, mean and standard deviation% of the chosen component to a text box window and draws a% histogram of the chosen component of selected vectors' %%pre_h=findobj(get(0,'Children'),'Tag','Preprocess');set(0,'CurrentFigure',pre_h);sel_comp_h=getfield(get(pre_h,'UserData'),'sel_comp_h');if nargin == 1 set(sel_comp_h,'Value',str2num(varargin{1}));elseif ~isempty(gcbo) no=get(sel_comp_h,'Value'); data=get(gcf,'UserData'); data.LOG{length(data.LOG)+1}='% Select one component'; data.LOG{length(data.LOG)+1}=cat(2,'preprocess(''sel_comp'',''',... num2str(no),''');'); set(gcf,'UserData',data);endpro_tools('c_stat');pro_tools('plot_hist');data=get(gcf,'UserData');sData=data.sData; vector_h=data.vector_h;len=length(sData.data(:,1));vects=zeros(1,len);vects(data.selected_vects)=1;draw_vectors(vects,vector_h);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function cplot_mimemaglobal no_of_scsData=getfield(get(gcf,'UserData'),'sData');sel_cplot_h=getfield(get(gcf,'UserData'),'sel_cplot_h');selected=getfield(get(gcf,'UserData'),'selected_vects');set(sel_cplot_h,'YLim',[0 length(sData.data(1,:))+1]);subplot(sel_cplot_h);hold off;cla;hold on;for i=1:length(sData.data(1,:)) Max=max(sData.data(:,i)); Min=min(sData.data(:,i)); tmp=sData.data(selected,i); selMax=max(tmp); selMin=min(tmp); Mean=abs(mean(tmp(find(~isnan(tmp))))); Median=abs(median(tmp(find(~isnan(tmp))))); if Max ~= Min & ~all(isnan(sData.data(:,i))) if rem(i,no_of_sc) % no_of_sc is defined in the beginning of this file... line([abs(selMin-Min)/(Max-Min) (selMax-Min)/(Max-Min)],... [i i],'Color','black'); plot(abs(Mean-Min)/(Max-Min),i,'oblack'); plot(abs(Median-Min)/(Max-Min),i,'xblack'); else line([abs(selMin-Min)/(Max-Min) (selMax-Min)/(Max-Min)],... [i i],'Color','black','LineWidth',2); plot(abs(Mean-Min)/(Max-Min),i,'oblack','LineWidth',2); plot(abs(Median-Min)/(Max-Min),i,'xblack','LineWidth',2); end else if rem(i,no_of_sc) % N is defined in the beginning of this file. plot(mean(get(gca,'XLim')),i,'oblack'); plot(mean(get(gca,'XLim')),i,'xblack'); else plot(mean(get(gca,'XLim')),i,'oblack','LineWidth',2); plot(mean(get(gca,'XLim')),i,'xblack','LineWidth',2); end endend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function bool=set_sD_stats%SET_SD_STATS Writes the data set names to popup menu.%%bool=1;data=get(gcf,'UserData');for i=1:length(data.sD_set) % if ~isvalid_var_name({data.sD_set(i).name}) % close_preprocess; % bool=0; % return; % end string{i}=cat(2,sprintf('#%d: ',i),data.sD_set(i).name);endset(data.sD_set_h,'String',string);data.sData=data.sD_set(get(data.sD_set_h,'Value'));data.sData.MODIFIED=0;data.sData.INDEX=1;set(gcf,'UserData',data);write_sD_stats;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function write_sD_stats%WRITE_SD_STATS writes data's name, length and dimension to text box.%%pre_h=findobj(get(0,'Children'),'Tag','Preprocess');sD_name_h=getfield(get(pre_h,'UserData'),'sD_name_h');sData=getfield(get(pre_h,'UserData'),'sData');dims=size(sData.data);string{1}=cat(2,'Name: ',sData.name);string{2}=cat(2,'Length: ',sprintf('%d',dims(1)));string{3}=cat(2,'Dim: ',sprintf('%d',dims(2)));set(sD_name_h,'String',string);set(sD_name_h,'HorizontalAlignment','left');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function sel_sD(varargin)%SEL_SD sets new data to UserData's 'sData'.% %if nargin==1 LOG=1; index=str2num(varargin{1}); pre_h=findobj(get(0,'Children'),'Tag','Preprocess'); set(0,'CurrentFigure',pre_h);else LOG=0;endsD_set_h=getfield(get(gcf,'UserData'),'sD_set_h');comp_names_h=getfield(get(gcf,'UserData'),'comp_names_h');vector_h=getfield(get(gcf,'UserData'),'vector_h');vect_mean_h=getfield(get(gcf,'UserData'),'vect_mean_h');if ~LOG index=get(sD_set_h,'Value');enddata=get(gcf,'UserData');data.undo = [];INDEX=data.sData.INDEX;data.sData=rmfield(data.sData,'MODIFIED'); data.sData=rmfield(data.sData,'INDEX');tmp=data.sD_set(index);tmp.MODIFIED=0;tmp.INDEX=index;data.sD_set(INDEX)=data.sData;data.sData=tmp;len=getfield(size(tmp.data),{1});data.selected_vects=find(ones(1,len));if ~LOG data.LOG{length(data.LOG)+1}='% Select a new data set.'; data.LOG{length(data.LOG)+1}=sprintf('preprocess(''sel_sD'',''%s'');',... num2str(index));endset(gcf,'UserData',data);write_sD_stats;set_compnames(tmp,comp_names_h);draw_vectors(ones(1,len),vector_h);vect_means(tmp,vect_mean_h,data.selected_vects);clear_button;sel_comp;cplot_mimema;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function indices=get_indicespre_h=findobj(get(0,'Children'),'Tag','Preprocess');comp_names_h=getfield(get(pre_h,'UserData'),'comp_names_h');indices = get(comp_names_h,'Value');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function sD_management(varargin)if nargin ~= 1 pre_h=findobj(get(0,'Children'),'Tag','Preprocess'); preh_udata=get(pre_h,'UserData'); preh_udata.LOG{length(preh_udata.LOG)+1}=... '% Starting the ''Data Set Management'' -window...'; preh_udata.LOG{length(preh_udata.LOG)+1}=... 'preprocess(''sD_management'',''foo'');';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -