123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- function [ts_rl] = runlength(ts, ts_sh, plot_flag, time_axis, color_vec, y_offset, alphafill, alphaline)
- if nargin<8
- if nargin<7
- if nargin <6
- if nargin<5
- if nargin<4
- if nargin<3
- plot_flag=0;
- end
- if isvector(ts)
- time_axis=1:length(ts);
- else
- error('input1 needs to be vector');
- end
- end
- color_vec=[0 0 0];
- end
- y_offset=nan;
- end
- alphafill=.2;
- end
- alphaline=1;
- end
- % ts [Ntimepoints x 1] contains time series data
- % ts_sh [Ntps x Nshuffles] contains shuffled data
- if isrow(ts)
- ts=ts';
- end
- if ismatrix(ts_sh) && any(size(ts_sh)==length(ts))
- if size(ts_sh,2)==length(ts)
- ts_sh=ts_sh';
- end
- else
- error('input2 is not correct in size');
- end
- ts_p95=prctile(ts_sh,95,2);
- ts_ccs=countconsecutiveones(ts_sh>ts_p95);
- ts_ccs_p95=prctile(rmnans(ts_ccs(:)),95);
- if isnan(ts_ccs_p95); ts_ccs_p95=0; end
- [~,~,~,ts_rlen]=countconsecutiveones((ts>ts_p95),0,ts_ccs_p95);
- ts_rl=zeros(1,length(ts)); ts_rl(ts_rlen==0)=nan;
- if (plot_flag)
- plotmsem(time_axis,ts,color_vec); hold on;
- plotperc(time_axis,ts_sh,[5 95],color_vec,alphafill);
- gyl=get(gca,'YLim');
- if isnan(y_offset); y_offset=min(gyl)+0.01.*diff(gyl); end
- plot(time_axis,y_offset+ts_rl,'color',[color_vec alphaline],'linewidth',5); hold on;
- ylim(gyl);
- end
|