0001 function [bstats,wstats]=nt_plotxx(fname,bounds,chans,imageflag)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 nt_greetings;
0018
0019 assert(nargin>0, '!');
0020 if nargin<2; bounds=[]; end
0021 if nargin<3; chans=[]; end
0022 if nargin<4; imageflag=false; end
0023
0024 if ischar(fname)
0025 [FILEPATH,NAME,EXT]=fileparts(fname);
0026
0027 if isempty(FILEPATH)
0028 FILEPATH='./';
0029 fname=[FILEPATH,filesep,fname];
0030 end
0031
0032 disp(EXT)
0033 if ~strcmp(EXT,'.idxx')
0034 fname_data=fname;
0035 fname=[FILEPATH,filesep,'idxx',filesep,NAME,EXT,'.idxx'];
0036 end
0037
0038 if 2~=exist(fname)
0039 disp('No index file found. Create one.');
0040 if 2~=exist(fname_data)
0041 error('No data file either...');
0042 end
0043 disp('This may take a while...');
0044 tic;
0045 nt_idxx(fname);
0046 toc;
0047 end
0048 disp('read from file...'); tic;
0049 load(fname, '-mat', 'bstats', 'wstats');
0050 disp('done'); toc
0051 i=bstats;
0052 ii=wstats;
0053 elseif iscell(fname)
0054 i=fname{1};
0055 ii=fname{2};
0056 else
0057 error('!');
0058 end
0059
0060 if 2==exist('get_axes_width')
0061
0062 axes_width=get_axes_width(gca);
0063 else
0064 warning('get_axes_width() not found');
0065 disp('Download https://www.mathworks.com/matlabcentral/fileexchange/40790-plot-big');
0066 axes_width=500;
0067 end
0068
0069
0070 if isempty(chans); chans=1:i.nchans; end
0071 mn=nt_double2int(ii.min,{[],chans});
0072 mx=nt_double2int(ii.max,{[],chans});
0073 mnn=nt_double2int(ii.mean,{[],chans});
0074
0075
0076 mn=bsxfun(@minus,mn,mean(mnn));
0077 mx=bsxfun(@minus,mx,mean(mnn));
0078
0079 srr=i.sr/i.dsr;
0080
0081
0082 maxbound=(size(mn,1)-1)/srr;
0083 if ~maxbound;
0084 disp('warning: empty file');
0085 return
0086 end
0087 if isempty(bounds); bounds=[0,maxbound]; end
0088 start=1+max(0,min(size(mn,1)-1, round(bounds(1)*srr)));
0089 stop=1+max(0,min(size(mn,1)-1, round(bounds(2)*srr)));
0090 mn=mn(start:stop,:);
0091 mx=mx(start:stop,:);
0092
0093
0094 if size(mx,1)<axes_width
0095
0096
0097 end
0098 if imageflag
0099 dsr=round(size(mx,1)/(axes_width));
0100 mmx=dsmmx(cat(3,mn,mx),dsr);
0101 mn=mmx(:,:,1); mx=mmx(:,:,2);
0102 srr=srr/dsr;
0103
0104 imagesc((mx-mn)');
0105 else
0106 if size(mx,1)>axes_width*50
0107
0108 dsr=round(size(mx,1)/(axes_width*50));
0109 mmx=dsmmx(cat(3,mn,mx),dsr);
0110 mn=mmx(:,:,1); mx=mmx(:,:,2);
0111 srr=srr/dsr;
0112 end
0113
0114
0115 zz1=mn; zz1(1:2:end,:)=mx(1:2:end,:);
0116 zz2=mn; zz2(2:2:end,:)=mx(2:2:end,:);
0117 yy=[mn; flipud(mx); zz1; flipud(zz2)];
0118 xx=[(0:size(mn,1)-1)' ; (size(mn,1)-1:-1:0)'; (0:size(mn,1)-1)' ; (size(mn,1)-1:-1:0)'];
0119 if bounds(1)+max(xx/srr)<3600
0120 plot(bounds(1)+xx/srr , yy);
0121 xlabel('time (s)');
0122 xlim(bounds);
0123 else
0124 plot((bounds(1)+xx/srr)/3600 , yy);
0125 xlabel('time (h)');
0126 xlim(bounds/3600);
0127 end
0128 a=min(mn(:));
0129 b=max(mx(:));
0130 if b>a; ylim([a-(b-a)*0.1,b+(b-a)*0.1]); end
0131
0132 end
0133
0134 drawnow;
0135
0136 if 0
0137
0138 hold on;
0139 if size(mx,1)>axes_width
0140 dsr=round(size(mx,1)/(axes_width));
0141 mmx=dsmmx(cat(3,mn,mx),dsr);
0142 mn=mmx(:,:,1); mx=mmx(:,:,2);
0143 srr=srr/dsr;
0144 end
0145 npoints=size(mn,1);
0146 X=bounds(1)+(0:npoints-1)'/srr;
0147 h=fill([X;flipud(X)],[mn;flipud(mx)], 'k', 'LineStyle', 'none');
0148 colororder=get(gca,'colororder');
0149 for iPatch=1:numel(h);
0150 h(iPatch).FaceColor=colororder(1+rem(iPatch-1,7),:);
0151
0152 end
0153 hold off
0154 end
0155
0156
0157
0158
0159
0160
0161 userdata.i=i;
0162 userdata.ii=ii;
0163 userdata.bounds=bounds;
0164 set(gcf,'UserData',userdata);
0165
0166 end
0167
0168 function keyfunction(fig,eventDat)
0169 userdata=get(fig,'UserData');
0170 b=userdata.bounds;
0171 i=userdata.i;
0172 ii=userdata.ii;
0173 fname=i.fname;
0174 switch eventDat.Key
0175 case 'rightarrow'
0176 newbounds=[b(1)+(b(2)-b(1))*.5, b(1)+(b(2)-b(1))*1.5];
0177 disp(round([newbounds, diff(newbounds)]))
0178 nt_plotxx({i,ii},newbounds);
0179 case 'leftarrow'
0180 newbounds=[b(1)-(b(2)-b(1))*.5, b(1)+(b(2)-b(1))*.5];
0181 disp(round([newbounds, diff(newbounds)]))
0182 nt_plotxx({i,ii},newbounds);
0183 case 'uparrow'
0184 newbounds=[b(1)+(b(2)-b(1))*.25, b(1)+(b(2)-b(1))*.75];
0185 disp(round([newbounds, diff(newbounds)]))
0186 nt_plotxx({i,ii},newbounds);
0187 case 'downarrow'
0188 newbounds=[b(1)-(b(2)-b(1))*.5, b(1)+(b(2)-b(1))*1.5];
0189 disp(round([newbounds, diff(newbounds)]))
0190 nt_plotxx({i,ii},newbounds);
0191 otherwise
0192 end
0193 if nargout==0;
0194
0195 clear bstats wstats;
0196 end
0197 end
0198
0199
0200
0201 function y=dsmmx(mmx,dsr)
0202 assert(dsr<size(mmx,1), '!');
0203 assert(size(mmx,3)==2, '!');
0204 n=floor(size(mmx,1)/dsr);
0205 xtra=mmx(n*dsr+1:end,:,:);
0206 mmx=mmx(1:n*dsr,:,:);
0207 [nsamples,nchans,~]=size(mmx);
0208 mmx=permute(mmx,[3 1 2]);
0209 mmx=reshape(mmx, [dsr*2,nsamples/dsr, nchans]);
0210 mn=min(mmx);
0211 mx=max(mmx);
0212 y=cat(3,shiftdim(mn,1),shiftdim(mx,1));
0213
0214 end