📄 getoutagelength.m
字号:
function [bleng, nbursts] = getOutageLength(x, minvalue)% bleng = getOutageLength(x, minvalue)%% This function gets a series of values, x, and compares it with a% lower threshold, minvalue. If several consecutive points are% below the threshold, that is considered an "outage burst". The% function returns a vector with the burst length, i.e. the length% of the vector is equal with the number of burst lengths in the% series and the i-th position is the length of the i-th burst.%% [bleng, nb] = getOutageLength(X, minvalue)% gets several series, each one being a column in x. In this case% bleng is a vector with all the burst lengths in X. nb is a vector% with as many elements as columns in X; nb(i) how many bursts are% there in X(:,i). Thus bleng(1:nb(1)) are the lengths of the% bursts in the first series.%% Created 2006.03.09 by Bogdan Timus% $Id: getOutageLength.m,v 1.1 2006/03/10 17:48:08 bogdant Exp $% find out how many series are there and how long. N is the number% of series, M is the length of each series.[M, N] = size(x);% mark the seconds in outage. Put an extra row of zeros, to be sure% that all the outage burst end.inoutage = [x < minvalue; logical(zeros(1,N))];% mark the moments when the outage burst endsisend = inoutage(1:M,:) &~inoutage(2:M+1,:);% count how many bursts are there for each observationnbursts = sum(isend)';% count the burst lengths. Use the following tricks. Accumulate the% number of observations in outage. At the end of each burst% (marked by isend) the accumulated value shows how many points% have been in outage up to then, i.e. the sum of burst length up% to the end of that particular burst.tmp = cumsum(inoutage(1:M,:));tmp(~isend) = 0;[dummy, realis, cumleng] = find(tmp);% cumleng contains the partial sum of burst length, concatenated% for all the series. Thus cumleng(1) is the length of the first% burst in the first series, cumleng(i) is the sum of all the burst% lengths up to the i-th, provided that the i-th burst is still in% the first series. Use diff to get the individual burst lengths% from the sum of lengths.bleng = [cumleng(1);diff(cumleng)];% Since the series have been concatenated, diff will give a wrong% value for the first burst in the series, if it is not in the% first series. nbursts could have been used here too, to find% which burst is the first in the series.indstart = bleng<0;bleng(indstart) = cumleng(indstart);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -