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

2 ビュー (過去 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>
Torsten
Torsten 2024 年 12 月 4 日
:-)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by