0001
0002
0003
0004
0005
0006
0007
0008
0009 clear testChange negIdx dn startEndIdx gotTo inc longOnesIdx
0010
0011 testIdx=88;
0012
0013 dtJump=plotOPTS.change_type;
0014 lengthThreshold=12;
0015 changeThreshold=-0.5;
0016
0017
0018 testData=(squeeze(phChange(testIdx,1,:)));
0019 testTime=plotOPTS.Time_record(1:end-dtJump-1);
0020
0021
0022
0023
0024 testChange=diff(testData);
0025
0026 allIdx=1:length(testData);
0027 negIdx=testChange<0;
0028 dn=diff(negIdx);
0029
0030
0031 dnIdxStart=allIdx(dn==1)+1;
0032 dnIdxEnd=allIdx(dn==-1);
0033
0034
0035 if (numel(dnIdxStart)==1 || numel(dnIdxEnd)==1)
0036 if dnIdxStart==dnIdxEnd
0037 warning('Single spike in time series, so carry on.')
0038 continue
0039 end
0040 end
0041
0042 if sum(dnIdxStart)==0 || sum(dnIdxEnd)==0
0043
0044 continue
0045 end
0046
0047
0048
0049 if length(dnIdxEnd)>length(dnIdxStart)
0050 timeIndices=(dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold;
0051 elseif length(dnIdxEnd)<length(dnIdxStart)
0052 timeIndices=(dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold;
0053 elseif length(dnIdxEnd)==length(dnIdxStart)
0054 if dnIdxStart(1)==1
0055 timeIndices=(dnIdxEnd(1:end-1)-dnIdxStart(2:end))>=lengthThreshold;
0056 elseif dnIdxEnd(1)==1
0057 timeIndices=(dnIdxEnd(2:end)-dnIdxStart(1:end-1))>=lengthThreshold;
0058 else
0059 timeIndices=(dnIdxEnd-dnIdxStart)>=lengthThreshold;
0060 end
0061 else
0062 return
0063 end
0064
0065 if sum(timeIndices~=0)
0066 longOnesIdx(:,1)=dnIdxStart(timeIndices);
0067 longOnesIdx(:,2)=dnIdxEnd(timeIndices);
0068 else
0069 return
0070 end
0071
0072
0073
0074
0075
0076 checkInc=1;
0077 totalVolume=0;
0078 for jj=1:size(longOnesIdx,2)
0079 averageChange=mean(testData(longOnesIdx(jj,1):longOnesIdx(jj,2)));
0080 if averageChange<changeThreshold
0081 totalVolume=totalVolume+cellVolume(longOnesIdx(jj,1):longOnesIdx(jj,2));
0082 checkInc=checkInc+1;
0083 end
0084 end
0085
0086 close all
0087
0088 figure(2)
0089 plot(testTime,testChange)
0090 hold on
0091 plot(testTime(testChange<0),testChange(testChange<0),'r.')
0092
0093 for i=1:size(longOnesIdx,1)
0094 plot(testTime(longOnesIdx(i,:)),zeros(1,length(longOnesIdx(i,:))),'g-x')
0095 text(mean(testTime(longOnesIdx(i,:))),0.01,num2str((testTime(longOnesIdx(i,2))-testTime(longOnesIdx(i,1)))*24))
0096 end
0097
0098
0099
0100 close all
0101
0102 clear testChange negIdx dn startEndIdx gotTo inc longOnesIdx
0103
0104 testIdx=124;
0105
0106 dtJump=plotOPTS.change_type;
0107 lengthThreshold=4;
0108 changeThreshold=-1.5;
0109
0110
0111 testData=(squeeze(phChange(testIdx,1,:)));
0112 testTime=plotOPTS.Time_record(1:end-dtJump-1);
0113
0114
0115
0116
0117 testChange=diff(testData);
0118
0119 allIdx=1:length(testData);
0120 negIdx=testChange<0;
0121 dn=diff(negIdx);
0122
0123
0124 dnIdxStart=allIdx(dn==1)+1;
0125 dnIdxEnd=allIdx(dn==-1);
0126
0127
0128 if (numel(dnIdxStart)==1 || numel(dnIdxEnd)==1)
0129 if dnIdxStart==dnIdxEnd
0130 warning('Single spike in time series, so carry on.')
0131 end
0132 end
0133
0134 if sum(dnIdxStart)==0 || sum(dnIdxEnd)==0
0135
0136 warning('No appropriate values here, so carry on.')
0137 end
0138
0139 if dnIdxEnd(1)<dnIdxStart(1)
0140
0141 dnIdxEnd=dnIdxEnd(2:end);
0142 dnIdxStart=dnIdxStart(1:end-1);
0143 end
0144
0145
0146
0147
0148 if size(dnIdxEnd,2)>size(dnIdxStart,2)
0149 longOnesIdx(:,1)=dnIdxStart((dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold);
0150 longOnesIdx(:,2)=dnIdxEnd((dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold);
0151 elseif size(dnIdxEnd,2)<size(dnIdxStart,2)
0152 longOnesIdx(:,1)=dnIdxStart((dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold);
0153 longOnesIdx(:,2)=dnIdxEnd((dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold);
0154 else
0155 if dnIdxStart(1)==1
0156 longOnesIdx(:,1)=dnIdxStart((dnIdxEnd(1:end-1)-dnIdxStart(2:end))>=lengthThreshold);
0157 longOnesIdx(:,2)=dnIdxEnd((dnIdxEnd(1:end-1)-dnIdxStart(2:end))>=lengthThreshold);
0158 elseif dnIdxEnd(1)==1
0159 longOnesIdx(:,1)=dnIdxStart((dnIdxEnd(2:end)-dnIdxStart(1:end-1))>=lengthThreshold);
0160 longOnesIdx(:,2)=dnIdxEnd((dnIdxEnd(2:end)-dnIdxStart(1:end-1))>=lengthThreshold);
0161 else
0162 longOnesIdx(:,1)=dnIdxStart((dnIdxEnd-dnIdxStart)>=lengthThreshold);
0163 longOnesIdx(:,2)=dnIdxEnd((dnIdxEnd-dnIdxStart)>=lengthThreshold);
0164 end
0165 end
0166
0167 close all
0168
0169 plot(testTime,testChange)
0170 hold on
0171 plot(testTime(testChange<0),testChange(testChange<0),'r.')
0172
0173 for i=1:size(longOnesIdx,1)
0174 plot(testTime(longOnesIdx(i,:)),zeros(1,length(longOnesIdx(i,:))),'g-x')
0175 text(mean(testTime(longOnesIdx(i,:))),0.01,num2str((testTime(longOnesIdx(i,2))-testTime(longOnesIdx(i,1)))*24))
0176 end
0177
0178
0179
0180
0181 clear testChange negIdx dn startEndIdx gotTo inc allInc longOnesIdx
0182
0183 dtJump=plotOPTS.change_type;
0184 lengthThreshold=7;
0185 changeThreshold=-0.1;
0186
0187 testData=squeeze(phChange(:,1,:));
0188 testTime=plotOPTS.Time_record(1:end-dtJump-1);
0189
0190 inc=1;
0191
0192
0193
0194 for i=1:size(testData,1);
0195 disp(i)
0196 testChange=diff(testData(i,:),1,2);
0197 allIdx=1:length(testChange);
0198 negIdx=testChange<0;
0199 dn=diff(negIdx,1,2);
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 idxStart_dn=allIdx(dn==1)+1;
0221
0222
0223 dnIdxStart=idxStart_dn;
0224 idxEnd_dn=allIdx(dn==-1);
0225
0226
0227 dnIdxEnd=idxEnd_dn;
0228
0229
0230
0231
0232 if (numel(dnIdxStart)==1 || numel(dnIdxEnd)==1)
0233 if dnIdxStart==dnIdxEnd
0234 warning('Single spike in time series, so carry on.')
0235 continue
0236 end
0237 end
0238
0239 if sum(dnIdxStart)==0 || sum(dnIdxEnd)==0
0240
0241 warning('No appropriate values here, so carry on.')
0242 continue
0243 end
0244
0245 if dnIdxEnd(1)<dnIdxStart(1)
0246
0247 dnIdxEnd=dnIdxEnd(2:end);
0248 dnIdxStart=dnIdxStart(1:end-1);
0249 end
0250
0251
0252
0253 if size(dnIdxEnd,2)>size(dnIdxStart,2)
0254
0255 try
0256 timeRange(:,1)=dnIdxStart((dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold);
0257 timeRange(:,2)=dnIdxEnd((dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold);
0258 catch
0259 continue
0260 end
0261 elseif size(dnIdxEnd,2)<size(dnIdxStart,2)
0262 try
0263 timeRange(:,1)=dnIdxStart((dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold);
0264 timeRange(:,2)=dnIdxEnd((dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold);
0265 catch
0266 continue
0267 end
0268 else
0269 try
0270 timeRange(:,1)=dnIdxStart((dnIdxEnd-dnIdxStart)>=lengthThreshold);
0271 timeRange(:,2)=dnIdxEnd((dnIdxEnd-dnIdxStart)>=lengthThreshold);
0272 catch
0273 continue
0274 end
0275 end
0276
0277
0278 timeRange=timeRange(testChange(timeRange(:,1))<changeThreshold & testChange(timeRange(:,2))<changeThreshold,:);
0279
0280
0281 if numel(timeRange)>=2
0282 longOnesIdx{inc}=timeRange;
0283 allInc(inc)=i;
0284 inc=inc+1;
0285 end
0286 end
0287
0288
0289
0290 clear testChange negIdx dn startEndIdx gotTo inc allInc longOnesIdx timeRange
0291
0292 dtJump=plotOPTS.change_type;
0293 lengthThreshold=2;
0294 changeThreshold=-1;
0295
0296 testData=squeeze(phChange(:,1,:));
0297 testTime=plotOPTS.Time_record(1:end-dtJump-1);
0298
0299 inc=1;
0300
0301
0302
0303 for i=222
0304 disp(i)
0305
0306 testData=squeeze(phChange(i,1,:))*10000000000;
0307 testTime=plotOPTS.Time_record(1:end-dtJump-1);
0308
0309
0310
0311
0312 testChange=diff(testData);
0313
0314 allIdx=1:length(testData);
0315 negIdx=testChange<0;
0316 dn=diff(negIdx);
0317
0318
0319 dnIdxStart=allIdx(dn==1)+1;
0320 dnIdxEnd=allIdx(dn==-1);
0321
0322
0323 if (numel(dnIdxStart)==1 || numel(dnIdxEnd)==1)
0324 if dnIdxStart==dnIdxEnd
0325 warning('Single spike in time series, so carry on.')
0326 continue
0327 end
0328 end
0329
0330 if sum(dnIdxStart)==0 || sum(dnIdxEnd)==0
0331
0332 warning('No appropriate values here, so carry on.')
0333 continue
0334 end
0335
0336 if dnIdxEnd(1)<dnIdxStart(1)
0337
0338 dnIdxEnd=dnIdxEnd(2:end);
0339 dnIdxStart=dnIdxStart(1:end-1);
0340 end
0341
0342
0343
0344 clear timeRange
0345 if size(dnIdxEnd,2)>size(dnIdxStart,2)
0346
0347 try
0348 timeRange(:,1)=dnIdxStart((dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold);
0349 timeRange(:,2)=dnIdxEnd((dnIdxEnd(1:end-1)-dnIdxStart)>=lengthThreshold);
0350 catch
0351 continue
0352 end
0353 elseif size(dnIdxEnd,2)<size(dnIdxStart,2)
0354 try
0355 timeRange(:,1)=dnIdxStart((dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold);
0356 timeRange(:,2)=dnIdxEnd((dnIdxEnd-dnIdxStart(1:end-1))>=lengthThreshold);
0357 catch
0358 continue
0359 end
0360 else
0361 try
0362 timeRange(:,1)=dnIdxStart((dnIdxEnd-dnIdxStart)>=lengthThreshold);
0363 timeRange(:,2)=dnIdxEnd((dnIdxEnd-dnIdxStart)>=lengthThreshold);
0364 catch
0365 continue
0366 end
0367 end
0368
0369
0370 timeRange=timeRange(testChange(timeRange(:,1))<changeThreshold & testChange(timeRange(:,2))<changeThreshold,:);
0371
0372
0373
0374 if numel(timeRange)>=2
0375 longOnesIdx{inc}=timeRange;
0376 allInc(inc)=i;
0377 inc=inc+1;
0378 end
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416 end
0417
0418 close all
0419
0420 [tx,ty]=meshgrid(1:size(testChange,2),1:size(testChange,1));
0421
0422 pcolor(tx,ty,testChange); shading flat; axis tight
0423 colorbar
0424 caxis([-1 1])
0425 hold on
0426 plot(tx(allIdx(dn<0)),ty(allIdx(dn<0)),'r.')
0427 plot(tx(allIdx(dn>0)),ty(allIdx(dn>0)),'g.')
0428 for i=1:size(longOnesIdx,1)
0429 plot(tx(longOnesIdx(i,1)),ty(longOnesIdx(i,2)),'g-x')
0430 end
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469