0001 function handles = dsPlot(data,varargin)
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
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 data=dsCheckData(data, varargin{:});
0154
0155
0156
0157
0158 options=dsCheckOptions(varargin,{...
0159 'time_limits',[-inf inf],[],...
0160 'variable',[],[],...
0161 'max_num_overlaid',50,[],...
0162 'max_num_rows',20,[],...
0163 'plot_mode','trace',{'trace','image'},...
0164 'plot_type','waveform',{'waveform','rastergram','raster','power','rates'},...
0165 'xlim',[],[],...
0166 'ylim',[],[],...
0167 'figwidth',[1],[],...
0168 'figheight',[1],[],...
0169 'lock_gca',[false],[false, true],...
0170 'yscale','linear',{'linear','log','log10','log2'},...
0171 'visible','on',{'on','off'},...
0172 'auto_gen_test_data_flag',0,{0,1},...
0173 },false);
0174
0175
0176 if options.auto_gen_test_data_flag
0177 varargs = varargin;
0178 varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0179 varargs(end+1:end+2) = {'unit_test_flag',1};
0180 argin = [{data}, varargs];
0181 end
0182
0183
0184
0185
0186
0187 labels = data(1).labels;
0188 inds = arrayfun(@(s) ~isempty(s.(labels{1})),data);
0189 data = data(inds);
0190
0191
0192 fields=fieldnames(data);
0193 if any(strcmp(fields, 'varied'))
0194
0195 vary_labels = data(1).varied;
0196 no_vary_labels = length(vary_labels);
0197 vary_params = nan(length(data), no_vary_labels);
0198 vary_vectors = cell(no_vary_labels, 1);
0199 vary_lengths = nan(no_vary_labels, 1);
0200
0201
0202 for v = 1:no_vary_labels
0203 vary_params(:, v) = [data.(vary_labels{v})];
0204 vary_vectors{v} = unique(vary_params(:, v));
0205 vary_lengths(v) = length(vary_vectors{v});
0206 end
0207
0208 [effective_vary_indices, ~] = dsCheckCovary(vary_lengths, vary_params, varargin{:});
0209
0210 if prod(vary_lengths(effective_vary_indices)) == length(data)
0211
0212 dimensions_varied = sum(effective_vary_indices);
0213 vary_params = vary_params(:, effective_vary_indices);
0214 vary_vectors = vary_vectors(effective_vary_indices);
0215 vary_lengths = vary_lengths(effective_vary_indices);
0216
0217 else
0218
0219 warning('unable to determine which parameters are covaried. Data will be plotted as a lattice.')
0220
0221 dimensions_varied = 1;
0222
0223 end
0224
0225 if dimensions_varied > 2
0226 no_figures = prod(vary_lengths(3:end));
0227
0228 figure_params = nan(dimensions_varied - 2, 1);
0229
0230 vary_lengths_cp = cumprod(vary_lengths);
0231
0232 for f = 1:no_figures
0233 figure_params(1) = vary_vectors{3}(mod(f - 1, vary_lengths(3)) + 1);
0234
0235 for v = 4:dimensions_varied
0236 figure_params(v - 2) = vary_vectors{v}(ceil(f/vary_lengths_cp(v - 3)));
0237 end
0238
0239 figure_data_index = ones(size(vary_params, 1), 1);
0240 for v = 3:dimensions_varied
0241 figure_data_index = figure_data_index & vary_params(:, v) == figure_params(v - 2);
0242 end
0243
0244 vary_title = '';
0245
0246 for v = 1:(dimensions_varied - 2)
0247 vary_title = [vary_title, sprintf('%s = %f ', vary_labels{v + 2}, figure_params(v))];
0248 end
0249
0250 handles = dsPlot(data(figure_data_index), varargin{:});
0251 for h = 1:length(handles)
0252
0253 mtit(handles(h), vary_title, 'FontSize', 14, 'yoff', .2)
0254 end
0255
0256 end
0257 return
0258 end
0259 end
0260
0261 data=dsCheckData(data, varargin{:});
0262 handles=[];
0263
0264 lock_gca = options.lock_gca;
0265
0266
0267
0268
0269 var_fields=dsSelectVariables(data(1).labels,options.variable, varargin{:});
0270 tmp=regexp(var_fields,'_(.+)$','tokens','once');
0271 variables=unique([tmp{:}]);
0272
0273
0274 pop_names={data(1).model.specification.populations.name};
0275
0276 pop_indices=[];
0277 pop_var_indices={};
0278
0279 for i=1:length(pop_names)
0280
0281 var_inds=find(~cellfun(@isempty,regexp(var_fields,['^' pop_names{i}])));
0282 if any(var_inds)
0283 inds=cellfun(@(x)find(~cellfun(@isempty,regexp(var_fields(var_inds),['_' x '$'],'once'))),variables,'uni',0);
0284 varsel=~cellfun(@isempty,inds);
0285 fldind=unique([inds{:}]);
0286 pop_indices(end+1)=i;
0287 pop_var_indices{end+1}=nan(1,length(variables));
0288 pop_var_indices{end}(varsel)=var_inds(fldind);
0289 end
0290 end
0291 pop_names=pop_names(pop_indices);
0292
0293
0294 time=data(1).time;
0295 pop_sizes=[data(1).model.specification.populations(pop_indices).size];
0296 num_pops=length(pop_names);
0297 num_sims=length(data);
0298 num_vars=length(variables);
0299 num_labels=length(var_fields);
0300 num_times=length(time);
0301
0302 if isempty(options.time_limits)
0303 options.time_limits=[min(time) max(time)];
0304 end
0305
0306
0307 switch options.plot_type
0308 case 'waveform'
0309 xdata=time;
0310 xlab='time (ms)';
0311 case 'power'
0312 if any(cellfun(@isempty,regexp(var_fields,'.*_Power_SUA$')))
0313 data=dsCalcPower(data,varargin{:});
0314 end
0315 xdata=data(1).([var_fields{1} '_Power_SUA']).frequency;
0316 xlab='frequency (Hz)';
0317
0318 if isempty(options.xlim)
0319 options.xlim=[0 200];
0320 end
0321 case {'rastergram','raster'}
0322 if any(cellfun(@isempty,regexp(var_fields,'.*_spike_times$')))
0323 spike_fields=cellfun(@(x)[x '_spikes'],var_fields,'uni',0);
0324 idx=cellfun(@(x)isfield(data,x),spike_fields);
0325 if any(idx)
0326
0327 inds=find(idx);
0328 for s=1:length(data)
0329 for i=1:length(inds)
0330 spike_fld=[var_fields{inds(i)} '_spikes'];
0331 spike_time_fld=[var_fields{inds(i)} '_spike_times'];
0332 for j=1:size(data(s).(spike_fld),2)
0333 data(s).(spike_time_fld){j}=data(s).time((1==data(s).(spike_fld)(:,j)));
0334 end
0335 end
0336 end
0337
0338
0339
0340
0341
0342
0343 else
0344
0345 data=dsCalcFR(data,varargin{:});
0346 end
0347 end
0348 xdata=time;
0349 xlab='time (ms)';
0350 case 'rates'
0351 if any(cellfun(@isempty,regexp(var_fields,'.*_FR$')))
0352 data=dsCalcFR(data,varargin{:});
0353 end
0354 xdata=data.time_FR;
0355 xlab='time (ms, bins)';
0356 end
0357 if isempty(options.xlim)
0358 options.xlim=[min(xdata) max(xdata)];
0359 end
0360
0361 MRPF = options.max_num_rows;
0362 MTPP = options.max_num_overlaid;
0363
0364
0365 if num_sims==1 && num_pops==1 && num_vars==1 && ~lock_gca
0366 num_fig_sets=1; num_figs=ceil(pop_sizes/MRPF); num_rows=min(pop_sizes,MRPF);
0367 elseif num_sims==1 && num_pops==1 && num_vars==1 && lock_gca
0368 num_fig_sets=1; num_figs=1; num_rows=1;
0369 elseif num_sims==1 && num_pops==1 && num_vars>1
0370 num_fig_sets=1; num_figs=ceil(num_vars/MRPF); num_rows=min(num_vars,MRPF);
0371 elseif num_sims==1 && num_pops>1 && num_vars==1 && ~lock_gca
0372 num_fig_sets=1; num_figs=ceil(num_pops/MRPF); num_rows=min(num_pops,MRPF);
0373 elseif num_sims==1 && num_pops>1 && num_vars==1 && lock_gca
0374 num_fig_sets=1; num_figs=ceil(num_pops/MRPF); num_rows=1;
0375 elseif num_sims==1 && num_pops>1 && num_vars>1
0376 num_fig_sets=num_vars; num_figs=ceil(num_pops/MRPF); num_rows=min(num_pops,MRPF);
0377 elseif num_sims>1 && num_pops==1 && num_vars==1
0378 num_fig_sets=1; num_figs=ceil(num_sims/MRPF); num_rows=min(num_sims,MRPF);
0379 elseif num_sims>1 && num_pops==1 && num_vars>1
0380 num_fig_sets=num_vars; num_figs=ceil(num_sims/MRPF); num_rows=min(num_sims,MRPF);
0381 elseif num_sims>1 && num_pops>1 && num_vars==1
0382 num_fig_sets=1; num_figs=ceil(num_sims/MRPF); num_rows=min(num_sims,MRPF);
0383 elseif num_sims>1 && num_pops>1 && num_vars>1
0384 num_fig_sets=num_vars; num_figs=ceil(num_sims/MRPF); num_rows=min(num_sims,MRPF);
0385 else
0386 error('unrecognized dimensions');
0387 end
0388
0389
0390 if lock_gca && (num_sims>1 || num_vars>1)
0391 error('Option lock_gca cannot with more than one simulation or variable');
0392 end
0393
0394
0395 if num_sims>1 && isfield(data,'varied')
0396
0397 varied=data(1).varied;
0398 num_varied=length(varied);
0399 num_sims=length(data);
0400
0401 param_mat=zeros(num_sims,num_varied);
0402 param_cell=cell(1,num_varied);
0403
0404 for j=1:num_varied
0405 if isnumeric(data(1).(varied{j}))
0406 param_mat(:,j)=[data.(varied{j})];
0407 param_cell{j}=unique([data.(varied{j})]);
0408 else
0409
0410
0411 end
0412 end
0413 param_size=cellfun(@length,param_cell);
0414
0415 row_param_index=find(param_size==max(param_size),1,'first');
0416 row_param_name=varied{row_param_index};
0417 row_param_values=param_cell{row_param_index};
0418 num_rows=length(row_param_values);
0419
0420 num_figs=ceil(num_rows/MRPF);
0421
0422 indices={};
0423 for row=1:num_rows
0424 indices{row}=find(param_mat(:,row_param_index)==row_param_values(row));
0425 end
0426 num_per_row=cellfun(@length,indices);
0427 num_cols=max(num_per_row);
0428 sim_indices=nan(num_cols,num_rows);
0429
0430 for row=1:num_rows
0431 sim_indices(1:num_per_row(row),row)=indices{row};
0432 end
0433
0434
0435
0436
0437 else
0438 sim_indices=ones(1,num_rows);
0439 num_cols=1;
0440 end
0441
0442 max_legend_entries=10;
0443 for figset=1:num_fig_sets
0444 for fig=1:num_figs
0445 ylims=[nan nan];
0446
0447 if ~lock_gca
0448 handles(end+1)=figure('units','normalized','outerposition',[0 0 options.figwidth, options.figheight],'visible',options.visible);
0449
0450 haxes=tight_subplot(num_rows,num_cols,[.01 .03],[.05 .01],[.03 .01]);
0451 else
0452 handles = gcf;
0453 haxes = gca;
0454 end
0455
0456 axis_counter=0;
0457 AuxData=[];
0458 vlines=[];
0459 allspikes={};
0460 text_string='';
0461 legend_strings='';
0462 shared_ylims_flag=1;
0463
0464 for row=1:num_rows
0465 for col=1:num_cols
0466 dat=[];
0467 sim_index=sim_indices(col,row);
0468 axis_counter=axis_counter+1;
0469 if isnan(sim_index)
0470 continue;
0471 end
0472
0473
0474
0475
0476 if num_sims==1 && num_pops==1 && num_vars==1 && ~lock_gca
0477
0478
0479 var=var_fields{1};
0480 switch options.plot_type
0481 case 'waveform'
0482 dat=data(sim_index).(var)(:,row);
0483 case 'power'
0484 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0485 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0486 AuxDataName={'MUA Power'};
0487 var=[var '_Power_SUA'];
0488 dat=data(sim_index).(var).Pxx(:,row);
0489 legend_strings={'SUA','MUA'};
0490 case {'rastergram','raster'}
0491 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0492 allspikes{1}{1}=data(sim_index).([var '_spike_times']){row};
0493
0494 end
0495 if num_rows>1
0496 text_string{row,col}=sprintf('cell %g',row);
0497 end
0498
0499 elseif num_sims==1 && num_pops==1 && num_vars==1 && lock_gca
0500
0501 var=var_fields{1};
0502 switch options.plot_type
0503 case 'waveform'
0504 dat=data(sim_index).(var);
0505 case 'power'
0506 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0507 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0508 AuxDataName={'MUA Power'};
0509 var=[var '_Power_SUA'];
0510 dat=data(sim_index).(var).Pxx;
0511 case {'rastergram','raster'}
0512 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0513 allspikes{1}=data(sim_index).([var '_spike_times']);
0514 end
0515
0516 elseif num_sims==1 && num_pops==1 && num_vars>1
0517
0518
0519 var=var_fields{row};
0520 switch options.plot_type
0521 case 'waveform'
0522 dat=data(sim_index).(var);
0523 case 'power'
0524 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0525 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0526 AuxDataName={'MUA Power'};
0527 var=[var '_Power_SUA'];
0528 dat=data(sim_index).(var).Pxx;
0529 case {'rastergram','raster'}
0530 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0531 allspikes{1}=data(sim_index).([var '_spike_times']);
0532 end
0533 shared_ylims_flag=0;
0534
0535 elseif num_sims==1 && num_pops>1 && num_vars==1 && ~lock_gca
0536
0537
0538 var=var_fields{row};
0539 switch options.plot_type
0540 case 'waveform'
0541 dat=data(sim_index).(var);
0542 case 'power'
0543 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0544 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0545 AuxDataName={'MUA Power'};
0546 var=[var '_Power_SUA'];
0547 dat=data(sim_index).(var).Pxx;
0548 case {'rastergram','raster'}
0549 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0550 allspikes{1}=data(sim_index).([var '_spike_times']);
0551 end
0552
0553 elseif num_sims==1 && num_pops>1 && num_vars==1 && lock_gca
0554
0555
0556 switch options.plot_type
0557 case 'waveform'
0558
0559 dat=nan(num_times,num_pops);
0560 if ~strcmp(reportUI,'matlab') && exist('nanmean') ~= 2
0561 try
0562 pkg load statistics;
0563 catch
0564 error('nanmean function is needed, please install the statistics package from Octave Forge');
0565 end
0566 end
0567 for k=1:num_pops
0568 dat(:,k)=nanmean(data(sim_index).(var_fields{k}),2);
0569 end
0570 var=['<' variables{1} '>'];
0571 case 'power'
0572 dat=nan(length(xdata),num_pops);
0573 AuxData=nan(length(xdata),num_pops);
0574 AuxDataName={}; vlines=[];
0575 if ~strcmp(reportUI,'matlab') && exist('nanmean') ~= 2
0576 try
0577 pkg load statistics;
0578 catch
0579 error('nanmean function is needed, please install the statistics package from Octave Forge');
0580 end
0581 end
0582 for k=1:num_pops
0583 dat(:,k)=nanmean(data(sim_index).([var_fields{k} '_Power_SUA']).Pxx,2);
0584 AuxData(:,k)=data(sim_index).([var_fields{k} '_Power_MUA']).Pxx;
0585 AuxDataName{end+1}=strrep([var_fields{k} '_Power_MUA'],'_','\_');
0586 vlines(end+1)=data(sim_index).([var_fields{k} '_Power_MUA']).PeakFreq;
0587 end
0588 var=['<' variables{1} '_Power_SUA>'];
0589 case {'rastergram','raster'}
0590 set_name={};
0591 for k=1:num_pops
0592 tmp=regexp(var_fields{k},'^([a-zA-Z0-9]+)_','tokens','once');
0593 set_name{k}=tmp{1};
0594 allspikes{k}=data(sim_index).([var_fields{k} '_spike_times']);
0595 end
0596 var=['<' variables{1} '>'];
0597
0598 end
0599
0600 elseif num_sims==1 && num_pops>1 && num_vars>1
0601
0602
0603 if isnan(pop_var_indices{row}(figset))
0604 continue;
0605 end
0606 var=var_fields{pop_var_indices{row}(figset)};
0607 switch options.plot_type
0608 case 'waveform'
0609 dat=data(sim_index).(var);
0610 case 'power'
0611 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0612 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0613 AuxDataName={'MUA Power'};
0614 var=[var '_Power_SUA'];
0615 dat=data(sim_index).(var).Pxx;
0616 case {'rastergram','raster'}
0617 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0618 allspikes{1}=data(sim_index).([var '_spike_times']);
0619 end
0620
0621 elseif num_sims>1 && num_pops==1 && num_vars==1
0622
0623
0624 var=var_fields{1};
0625 switch options.plot_type
0626 case 'waveform'
0627 dat=data(sim_index).(var);
0628 case 'power'
0629 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0630 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0631 AuxDataName={'MUA Power'};
0632 var=[var '_Power_SUA'];
0633 dat=data(sim_index).(var).Pxx;
0634 case {'rastergram','raster'}
0635 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0636 allspikes{1}=data(sim_index).([var '_spike_times']);
0637 end
0638
0639 elseif num_sims>1 && num_pops==1 && num_vars>1
0640
0641
0642 if isnan(pop_var_indices{1}(figset))
0643 continue;
0644 end
0645 var=var_fields{pop_var_indices{1}(figset)};
0646 switch options.plot_type
0647 case 'waveform'
0648 dat=data(sim_index).(var);
0649 case 'power'
0650 AuxData=data(sim_index).([var '_Power_MUA']).Pxx;
0651 vlines=data(sim_index).([var '_Power_MUA']).PeakFreq;
0652 AuxDataName={'MUA Power'};
0653 var=[var '_Power_SUA'];
0654 dat=data(sim_index).(var).Pxx;
0655 case {'rastergram','raster'}
0656 set_name=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0657 allspikes{1}=data(sim_index).([var '_spike_times']);
0658 end
0659
0660 elseif num_sims>1 && num_pops>1 && num_vars==1
0661
0662
0663 switch options.plot_type
0664 case 'waveform'
0665
0666 dat=nan(num_times,num_pops);
0667 if ~strcmp(reportUI,'matlab') && exist('nanmean') ~= 2
0668 try
0669 pkg load statistics;
0670 catch
0671 error('nanmean function is needed, please install the statistics package from Octave Forge');
0672 end
0673 end
0674 for k=1:num_pops
0675 dat(:,k)=nanmean(data(sim_index).(var_fields{k}),2);
0676 end
0677 var=['<' variables{1} '>'];
0678 case 'power'
0679 dat=nan(length(xdata),num_pops);
0680 AuxData=nan(length(xdata),num_pops);
0681 AuxDataName={}; vlines=[];
0682 if ~strcmp(reportUI,'matlab') && exist('nanmean') ~= 2
0683 try
0684 pkg load statistics;
0685 catch
0686 error('nanmean function is needed, please install the statistics package from Octave Forge');
0687 end
0688 end
0689 for k=1:num_pops
0690 dat(:,k)=nanmean(data(sim_index).([var_fields{k} '_Power_SUA']).Pxx,2);
0691 AuxData(:,k)=data(sim_index).([var_fields{k} '_Power_MUA']).Pxx;
0692 AuxDataName{end+1}=strrep([var_fields{k} '_Power_MUA'],'_','\_');
0693 vlines(end+1)=data(sim_index).([var_fields{k} '_Power_MUA']).PeakFreq;
0694 end
0695 var=['<' variables{1} '_Power_SUA>'];
0696 case {'rastergram','raster'}
0697 set_name={};
0698 for k=1:num_pops
0699 tmp=regexp(var_fields{k},'^([a-zA-Z0-9]+)_','tokens','once');
0700 set_name{k}=tmp{1};
0701 allspikes{k}=data(sim_index).([var_fields{k} '_spike_times']);
0702 end
0703 var=['<' variables{1} '>'];
0704
0705 end
0706
0707 elseif num_sims>1 && num_pops>1 && num_vars>1
0708
0709
0710 switch options.plot_type
0711 case 'waveform'
0712
0713 dat=nan(num_times,num_pops);
0714 if ~strcmp(reportUI,'matlab') && exist('nanmean') ~= 2
0715 try
0716 pkg load statistics;
0717 catch
0718 error('nanmean function is needed, please install the statistics package from Octave Forge');
0719 end
0720 end
0721 for k=1:num_pops
0722 if isnan(pop_var_indices{k}(figset))
0723 continue;
0724 end
0725 var=var_fields{pop_var_indices{k}(figset)};
0726 dat(:,k)=nanmean(data(sim_index).(var),2);
0727 end
0728 var=['<' variables{figset} '>'];
0729 case 'power'
0730 dat=nan(length(xdata),num_pops);
0731 AuxData=nan(length(xdata),num_pops);
0732 AuxDataName={}; vlines=[];
0733 if ~strcmp(reportUI,'matlab') && exist('nanmean') ~= 2
0734 try
0735 pkg load statistics;
0736 catch
0737 error('nanmean function is needed, please install the statistics package from Octave Forge');
0738 end
0739 end
0740 for k=1:num_pops
0741 if isnan(pop_var_indices{k}(figset))
0742 continue;
0743 end
0744 var=var_fields{pop_var_indices{k}(figset)};
0745 dat(:,k)=nanmean(data(sim_index).([var '_Power_SUA']).Pxx,2);
0746 AuxData(:,k)=data(sim_index).([var '_Power_MUA']).Pxx;
0747 AuxDataName{end+1}=strrep([var '_Power_MUA'],'_','\_');
0748 vlines(end+1)=data(sim_index).([var '_Power_MUA']).PeakFreq;
0749 end
0750 var=['<' variables{figset} '_Power_SUA>'];
0751 case {'rastergram','raster'}
0752 set_name={};
0753 for k=1:num_pops
0754 if isnan(pop_var_indices{k}(figset))
0755 continue;
0756 end
0757 var=var_fields{pop_var_indices{k}(figset)};
0758 tmp=regexp(var,'^([a-zA-Z0-9]+)_','tokens','once');
0759 set_name{k}=tmp{1};
0760 allspikes{k}=data(sim_index).([var '_spike_times']);
0761 end
0762 var=['<' variables{figset} '>'];
0763 end
0764 end
0765
0766 if size(dat,2)>1
0767 legend_strings=cellfun(@(x)['cell ' num2str(x)],num2cell(1:min(size(dat,2),max_legend_entries)),'uni',0);
0768 end
0769
0770 if isfield(data,'varied')
0771 if num_sims>1
0772
0773 str=[row_param_name '=' num2str(row_param_values(row)) ': '];
0774 for k=1:num_varied
0775 fld=data(sim_index).varied{k};
0776 if ~strcmp(fld,row_param_name)
0777 val=data(sim_index).(fld);
0778 str=[str fld '=' num2str(val) ', '];
0779 end
0780 end
0781 if num_pops>1
0782 legend_strings=cellfun(@(x)[x ' (mean)'],pop_names,'uni',0);
0783 end
0784 else
0785 str='';
0786 for k=1:length(data.varied)
0787 fld=data(sim_index).varied{k};
0788 str=[str fld '=' num2str(data(sim_index).(fld)) ', '];
0789 end
0790 end
0791 text_string{row,col}=['(' strrep(str(1:end-2),'_','\_') ')'];
0792 end
0793 if ~isempty(AuxData) && length(legend_strings)<=max_legend_entries
0794 legend_strings=cat(2,legend_strings,AuxDataName);
0795 end
0796
0797
0798 set(gcf,'CurrentAxes',haxes(axis_counter));
0799 switch options.plot_type
0800 case {'waveform','power'}
0801
0802 if ~strcmp(options.yscale,'linear')
0803 dat=feval(options.yscale,dat);
0804
0805 end
0806 if length(options.xlim)==2
0807 sel=(xdata>=options.xlim(1)&xdata<=options.xlim(2));
0808 else
0809 sel=1:length(xdata);
0810 end
0811
0812 if strcmp(options.plot_mode,'trace')
0813
0814 dat=dat(:,1:min(size(dat,2),MTPP));
0815 plot(xdata(sel),dat(sel,:));
0816 set(gca,'ticklength',get(gca,'ticklength')/2)
0817 else
0818 imagesc(dat);
0819 end
0820 case {'rastergram','raster'}
0821
0822 ypos=0;
0823 yticks=[];
0824 yticklabels={};
0825 for p=1:length(allspikes)
0826 spikes=allspikes{p};
0827 for c=1:length(spikes)
0828 spks=spikes{c};
0829 for k=1:length(spks)
0830 spk=spks(k);
0831 line([spk spk],[c+ypos-.5 c+ypos+.5],'color','k'); hold on
0832 end
0833 end
0834
0835 yticks(end+1)=ypos+c/2+.5;
0836 yticklabels{end+1}=set_name{p};
0837
0838 if length(allspikes)>1
0839 pos=c+ypos+.5;
0840 line([min(time) max(time)],[pos pos],'color','k','linewidth',3);
0841 if p<length(allspikes)
0842
0843 ypos=ypos+c;
0844 end
0845 end
0846 end
0847
0848 dat=[.5 ypos+c+.5];
0849 shared_ylims_flag=0;
0850 legend_strings='';
0851
0852 set(gca,'ytick',yticks,'yticklabel',yticklabels);
0853
0854 plot([min(time) max(time)],[.5 .5],'w');
0855 nticks=length(get(gca,'xtick'));
0856 xticks=linspace(options.xlim(1),options.xlim(2),nticks);
0857 set(gca,'xtick',xticks,'xticklabel',xticks);
0858
0859 set(gca,'ticklength',get(gca,'ticklength')/2)
0860 end
0861
0862 if ~isempty(AuxData)
0863 hold on
0864 plot(xdata(sel),AuxData(sel,:),'-','linewidth',3);
0865 end
0866
0867 if row==num_rows
0868 xlabel(xlab);
0869 else
0870 set(haxes(axis_counter),'XTickLabel','');
0871
0872 end
0873 xlim(options.xlim);
0874 if ~strcmp(options.plot_type,'rastergram')
0875 ylabel(strrep(var,'_','\_'));
0876 end
0877 if ~isempty(options.ylim)
0878 ylims=options.ylim;
0879 elseif shared_ylims_flag
0880
0881 ylims(1)=min(ylims(1),min(dat(:)));
0882 ylims(2)=max(ylims(2),max(dat(:)));
0883 else
0884
0885 ylims=[min(dat(:)) max(dat(:))];
0886 if ylims(1)~=ylims(2)
0887 ylim(ylims);
0888 end
0889
0890 if ~isempty(text_string)
0891 xmin=min(xlim); xmax=max(xlim);
0892 ymin=min(dat(:)); ymax=max(dat(:));
0893 text_xpos=xmin+.05*(xmax-xmin);
0894 text_ypos=ymin+.9*(ymax-ymin);
0895 try
0896 if any(strcmp(options.plot_type, {'rastergram','raster'}))
0897 xlims = double(get(gca,'xlim'));
0898 ylims = double(get(gca,'ylim'));
0899 text(0.05*xlims(end),0.9*ylims(end),text_string{row,col});
0900 else
0901 text(text_xpos,text_ypos,text_string{row,col});
0902 end
0903 end
0904 end
0905 end
0906
0907 if ~isempty(vlines)
0908 for k=1:length(vlines)
0909 if ~isnan(vlines(k))
0910 line([vlines(k) vlines(k)],ylim,'color','k','linestyle','--');
0911 ymax=max(ylim);
0912 text(double(vlines(k) + 0.1*range(xlim)), 0.9*ymax, sprintf('MUA Sxx Peak F: %.f', vlines(k)))
0913 end
0914 end
0915 end
0916
0917 if ~isempty(legend_strings) && axis_counter==1
0918 legend(legend_strings);
0919 end
0920 end
0921 end
0922
0923 if shared_ylims_flag || ~isempty(options.ylim)
0924 if ylims(1)~=ylims(2)
0925 set(haxes,'ylim',ylims);
0926 end
0927 if ~isempty(text_string)
0928 axis_counter=0;
0929 for row=1:num_rows
0930 for col=1:num_cols
0931 if ~ischar(text_string{row,col})
0932 continue;
0933 end
0934 axis_counter=axis_counter+1;
0935
0936 set(gcf,'CurrentAxes',haxes(axis_counter));
0937 xmin=min(xlim); xmax=max(xlim);
0938 ymin=min(ylim); ymax=max(ylim);
0939 text_xpos=double(xmin+.05*(xmax-xmin));
0940 text_ypos=ymin+.9*(ymax-ymin);
0941 text(text_xpos,text_ypos,text_string{row,col});
0942 end
0943 end
0944 end
0945 end
0946
0947
0948 if numel(haxes) > 1
0949 linkaxes(haxes, 'x')
0950 end
0951
0952 end
0953 end
0954
0955
0956 if options.auto_gen_test_data_flag
0957 argout = {handles};
0958
0959 dsUnitSaveAutoGenTestDir(argin, argout);
0960 end
0961
0962
0963
0964
0965
0966
0967
0968
0969
0970
0971
0972
0973
0974
0975
0976
0977
0978
0979
0980
0981
0982
0983
0984
0985
0986
0987
0988
0989
0990
0991
0992
0993
0994
0995
0996
0997
0998
0999
1000
1001
1002