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

조회 수: 5 (최근 30일)
Bradley
Bradley 2024년 12월 4일
댓글: Torsten 2024년 12월 4일
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.

답변 (1개)

Torsten
Torsten 2024년 12월 4일
이동: Torsten 2024년 12월 4일
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
Walter Roberson
Walter Roberson 2024년 12월 4일
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>

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by