How to check for outliers in only 1 column in a matrix

5 visualizaciones (últimos 30 días)
Bradley
Bradley el 4 de Dic. de 2024
Comentada: Torsten el 4 de Dic. de 2024
I have a huge dataset with 30 columns of data, columns 6 and 7 are latitude and longitude respectivly. I am trying to find and remove ouliers from just these two columns. There are definitly outliers in other columns of data but thats fine, I want to find oultiers from columns 6 and 7 and remove the row they belong to. The code ive been using until now is:
M = readmatrix(F);
[M1, ~, ~] = rmoutliers(M,1);
When the matrix is created (M) and outliers are removed it removes the first few thousand columns. Likely because one of the other columns have outliers, those outliers dont matter to me and I want them included. When I plot lat and long with no outliers removed I can see there are probably 30 or so outliers related to position, they either have the sign flipped or are 0. I tried to specify the column using:
[M1, ~, ~] = rmoutliers(M(:,6),1);
but got an error:
Index in position 2 exceeds array bounds. Index must not exceed 1.
Error in USV/bpf_btn (line 238)
Roll1 = M1(:,2);
^^^^^^^
meaning the second column of data is no longer being read. How do I specify the column I want to check for outliers and remove that row? Thank you again for your time.

Respuestas (1)

Torsten
Torsten el 4 de Dic. de 2024
Movida: Torsten el 4 de Dic. de 2024
A= [1 5 20;-2 16 3;4 3 -1067];
[~,idx] = rmoutliers(A(:,2))
idx = 3x1 logical array
0 1 0
[~,jdx] = rmoutliers(A(:,3))
jdx = 3x1 logical array
0 0 1
A = A(~idx&~jdx,:)
A = 1×3
1 5 20
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
  2 comentarios
Walter Roberson
Walter Roberson el 4 de Dic. de 2024
A= [1 5 20;-2 16 3;4 3 -1067];
[~,kdx] = rmoutliers(A(:,2:3))
kdx = 3x1 logical array
0 1 1
A(~kdx,:)
ans = 1×3
1 5 20
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by