0001 function gui_svar_cdf(command_str,eim_fname,sortvar_name,bins,jitter)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 if nargin==0,
0048 help gui_svar_cdf
0049 error('Function gui_svar_cdf requires at least one argment.');
0050 end
0051
0052 if nargin<5,
0053 jitter=0;
0054 end
0055
0056 if ~strcmpi(command_str,'initialize')
0057 h_fig = gcf;
0058 if ~strcmp(get(h_fig,'tag'),'gui_svar_cdf')
0059
0060
0061 h_figs = get(0,'children');
0062 h_fig = findobj(h_figs,'flat',...
0063 'tag','gui_svar_cdf');
0064 if isempty(h_fig)
0065
0066
0067
0068 if nargin<4 || nargin>5,
0069 help gui_svar_cdf
0070 error('You need to provide gui_svar_cdf four or five arguments when the GUI window is not already created.');
0071 else
0072 gui_svar_cdf('initialize',eim_fname,sortvar_name,bins,jitter);
0073 gui_svar_cdf(command_str,eim_fname,sortvar_name,bins,jitter);
0074 return;
0075 end
0076 end
0077 end
0078 tmp=get(h_fig,'userdata');
0079 end
0080
0081 if strcmpi(command_str,'initialize'),
0082 if nargin<4 || nargin>5,
0083 help gui_svar_cdf
0084 error('You need to provide gui_svar_cdf four or five arguments when the GUI window is not already created.');
0085 else
0086
0087 load(eim_fname,'-MAT');
0088
0089
0090 n_ep=length(ep_info);
0091 srt_val=zeros(1,n_ep)*NaN;
0092
0093 if strcmpi(sortvar_name,'rtmsec'),
0094 sortby_rt=1;
0095 else
0096 sortby_rt=0;
0097 end
0098
0099
0100 bins=str2num(bins);
0101
0102
0103 for a=1:n_ep,
0104
0105 if ~isempty(bins),
0106 got_it=0;
0107 if sortby_rt,
0108
0109
0110 rt_ids=zeros(1,length(bins));
0111 rt_ids_ct=0;
0112 for d=bins,
0113 rt_id=find(rtbins{a}==d);
0114 if ~isempty(rt_id),
0115 rt_ids_ct=rt_ids_ct+1;
0116 rt_ids(rt_ids_ct)=rt_id;
0117 end
0118 end
0119 if rt_ids_ct>0,
0120 uni_rt=unique(rtmsec{a}(rt_ids(1:rt_ids_ct)));
0121 if length(uni_rt)>1,
0122 error(sprintf(['Different bins have different RTs for epoch %d.\n' ...
0123 'You must specify bins that have the same RTs.'],a));
0124 else
0125 srt_val(a)=uni_rt;
0126 got_it=1;
0127 end
0128 end
0129 else
0130 for b=bins,
0131 for c=1:length(ep_info(a).eventtype),
0132 if strcmpi(ep_info(a).eventtype{c},['bin' int2str(b)]),
0133 cmnd=['srt_val(a)=ep_info(a).event' sortvar_name ';'];
0134 eval(cmnd);
0135 got_it=1;
0136 break;
0137 end
0138 end
0139 if got_it,
0140 break;
0141 end
0142 end
0143 end
0144 if ~got_it,
0145 srt_val(a)=NaN;
0146 end
0147
0148
0149 else
0150 if sortby_rt,
0151 uni_rt=unique(rtmsec{a});
0152 if length(uni_rt)>1,
0153 error(sprintf(['Different bins have different RTs for epoch %d.\n' ...
0154 'You must specify bins that have the same RTs.'],a));
0155 else
0156 srt_val(a)=uni_rt;
0157 end
0158 else
0159 cmnd=['srt_val(a)=ep_info(a).event' sortvar_name ';'];
0160 eval(cmnd);
0161 end
0162 end
0163 end
0164
0165
0166 sortvar_name=[sortvar_name ' '];
0167
0168 use_id=find(~isnan(srt_val));
0169 srt_val=srt_val(use_id);
0170 uni=unique(srt_val);
0171 n_uni=length(uni);
0172 cumu=zeros(1,n_uni);
0173 for a=1:n_uni,
0174 cumu(a)=mean(srt_val<=uni(a));
0175 end
0176 col=[1 1 1]*.7;
0177 if jitter,
0178 pos=get(gcf,'position');
0179 h_fig = figure('name','Sort Var Cumulative Distribution GUI','tag','gui_erpimage');
0180 set(h_fig,'color',col,'position',[pos(1:2)*1.1 pos(3:4)]);
0181 else
0182 h_fig = figure('name','Sort Var Cumulative Distribution GUI','tag','gui_erpimage');
0183 set(h_fig,'color',col);
0184 end
0185
0186 set(gcf,'tag','gui_svar_cdf');
0187
0188 h_panel=uipanel(h_fig,...
0189 'Units','normalized', ...
0190 'Position',[ .1 .3 .85 .65],...
0191 'shadowcolor','k', ...
0192 'bordertype','line', ...
0193 'borderwidth',1, ...
0194 'highlightcolor',col, ...
0195 'foregroundcolor',col, ...
0196 'backgroundcolor',col);
0197
0198
0199 tmp.h_ax=axes('position',[.1 .3 .85 .65],'box','on');
0200 set(tmp.h_ax,'color',col,'fontname','helvetica');
0201
0202
0203 tmp.h_frame_1 = uicontrol(h_fig,...
0204 'Units','normalized', ...
0205 'Position',[ 0 0 1 0.2 ],...
0206 'backgroundcolor',col, ...
0207 'Style','frame');
0208
0209 plot(uni,cumu,'.-'); hold on;
0210 v=axis;
0211 plot([v(1) uni(1)],[0 cumu(1)],'.-');
0212 lq=prctile(srt_val,25);
0213 uq=prctile(srt_val,75);
0214 tmp.mn=lq;
0215 tmp.mx=uq;
0216 tmp.h_shade=ShadePlotForEmphasis([lq uq],'r',.5);
0217 set(gca,'xgrid','on','ygrid','on');
0218 hy=ylabel('Proportion of Observations<=x Value ');
0219 set(hy,'fontsize',12,'fontweight','bold');
0220 hx=xlabel(sortvar_name);
0221 set(hx,'fontsize',12,'fontweight','bold');
0222
0223
0224 uicontrol(h_fig,...
0225 'Units','normalized', ...
0226 'Position',[ 0.055 0.11 0.16 0.07 ],...
0227 'String','Min x-Value:',...
0228 'fontsize',12, ...
0229 'tooltipstring',sprintf('Minimum value of %s to consider.',sortvar_name), ...
0230 'Style','text');
0231 tmp.h_mn = uicontrol(h_fig,...
0232 'CallBack','[dmy h_fig]=gcbo; tmp=get(h_fig,''userdata''); gui_svar_cdf(''new_lim'');',...
0233 'Units','normalized', ...
0234 'Position',[ 0.215 0.125 0.14 0.07 ],...
0235 'String',num2str(lq),...
0236 'fontsize',12, ...
0237 'tooltipstring',sprintf('Minimum value of %s to consider.',sortvar_name), ...
0238 'backgroundcolor','w', ...
0239 'Style','edit');
0240
0241
0242
0243 uicontrol(h_fig,...
0244 'Units','normalized', ...
0245 'Position',[ 0.405 0.11 0.16 0.07 ],...
0246 'String','Max x-Value:',...
0247 'fontsize',12, ...
0248 'tooltipstring',sprintf('Maximum value of %s to consider.',sortvar_name), ...
0249 'Style','text');
0250 tmp.h_mx = uicontrol(h_fig,...
0251 'CallBack','[dmy h_fig]=gcbo; tmp=get(h_fig,''userdata''); gui_svar_cdf(''new_lim'');',...
0252 'Units','normalized', ...
0253 'Position',[ 0.565 0.125 0.14 0.07 ],...
0254 'String',num2str(uq),...
0255 'fontsize',12, ...
0256 'tooltipstring',sprintf('Maximum value of %s to consider.',sortvar_name), ...
0257 'backgroundcolor','w', ...
0258 'Style','edit');
0259
0260
0261
0262 tmp.h_ntrials = uicontrol(h_fig,...
0263 'Units','normalized', ...
0264 'Position',[ 0.05 0.05 0.7 0.07 ],...
0265 'String',sprintf('Number of trials between x-min and x-max (inclusive): %d',sum( (srt_val>=lq).*(srt_val<=uq) )),...
0266 'fontsize',12, ...
0267 'Style','text');
0268
0269
0270 tmp.h_prop = uicontrol(h_fig,...
0271 'Units','normalized', ...
0272 'Position',[ 0.017 0.002 0.8 0.07 ],...
0273 'String',sprintf('Proportion of trials between x-min and x-max (inclusive): %.2f',mean( (srt_val>=lq).*(srt_val<=uq) )),...
0274 'fontsize',12, ...
0275 'horizontalalignment','center', ...
0276 'Style','text');
0277
0278
0279
0280
0281 uicontrol(h_fig,...
0282 'CallBack','close(gcf);',...
0283 'Units','normalized', ...
0284 'Position',[ 0.8 0.02 0.17 0.16 ],...
0285 'String','Close',...
0286 'fontsize',14, ...
0287 'Tag','cancel', ...
0288 'ToolTipString','Close GUI', ...
0289 'Style','pushbutton');
0290
0291
0292
0293 tmp.srt_val=srt_val;
0294 tmp.bins=bins;
0295 tmp.eim_fname=eim_fname;
0296 tmp.sortvar_name=sortvar_name;
0297 set(gcf,'userdata',tmp);
0298 end
0299 elseif strcmpi(command_str,'new_lim')
0300 mx=str2double(get(tmp.h_mx,'string'));
0301 mn=str2double(get(tmp.h_mn,'string'));
0302 if mn>mx,
0303 errordlg('x-min value needs to be less or equal to than x-max value. Resetting max and min to previous values.');
0304 set(tmp.h_mx,'string',num2str(tmp.mx));
0305 set(tmp.h_mn,'string',num2str(tmp.mn));
0306 else
0307 tmp.mn=mn;
0308 tmp.mx=mx;
0309 set(tmp.h_shade,'xdata',[mn mn mx mx]');
0310 nt_str=sprintf('Number of trials between x-min and x-max (inclusive): %d',sum( (tmp.srt_val>=mn).*(tmp.srt_val<=mx) ));
0311 set(tmp.h_ntrials,'string',nt_str);
0312 prop_str=sprintf('Proportion of trials between x-min and x-max (inclusive): %.2f',mean( (tmp.srt_val>=mn).*(tmp.srt_val<=mx) ));
0313 set(tmp.h_prop,'string',prop_str);
0314 set(gcf,'userdata',tmp);
0315 end
0316 else
0317 help gui_svar_cdf
0318 error('gui_svar_cdf does not recognize the command "%s".',command_str);
0319 end