Pergunta

In Matlab I have a large matrix A. The first column of the matrix contains a time in seconds. The second to 13th column contain results from a calculation. For each column (except the first) I calculated the whisker by:

quantile(A,[.75])-1.5*(quantile(A,[.75])-quantile(A,[.25]))

Now I would like to now how many outliers (= values below whisker) there are in each column, and when they occur. This will give me the ability to calculate how much the outliers are spread over time.

I prefer to create a loop which gives me 12 martices containing two columns. The second column should contain the values of the outliers (= values of cells below whisker) without any zero's in between, and the first column should contain the time at which a outlier occurs (chronologically).

How can I create this?

regards,

Vincent

Foi útil?

Solução

let,

A =

    0.6260    0.7690    0.1209    0.5523    0.0495
    0.6609    0.5814    0.8627    0.6299    0.4896
    0.7298    0.9283    0.4843    0.0320    0.1925
    0.8908    0.5801    0.8449    0.6147    0.1231
    0.9823    0.0170    0.2094    0.3624    0.2055

for second column:

B = quantile(A(:,2),[.75])-1.5*(quantile(A(:,2),[.75])-quantile(A(:,2),[.25]))

Then,

index = find(A(:,2) < B)

value_outliner = A(index,2)
outliner_time = A(index,1)

Outras dicas

No need to loop: use matrix operations and logical indexing instead.

Assuming you have a matrix A and outlier threshold thr is a 1x12 vector with the threshold for each column:

vals = A(:,2:13);
outliers = bsxfun(@lt, vals, thr); #% @lt is 'less than' function handle
#% outliers is a Nx12 logical matrix with true(1) where the value < threshold
#% and false(0) otherwise.

To get the time when these outliers occurred (for a given column, let's say column 2 of the data portion of the original matrix):

t = A(outliers(:,2), 1);
#%    ^____________ logical index of rows where outliers occurred in that column 

You can also easily get the number of outliers in each column (or row) by summing:

num_outliers = sum(outliers,1); 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top