フィルターのクリア

How can I plot outliers and original data together?

4 ビュー (過去 30 日間)
Seyed Navid Shoaiby
Seyed Navid Shoaiby 2022 年 10 月 15 日
コメント済み: Cris LaPierre 2022 年 10 月 15 日
I set a threshold for my outliers, a then find them by "any" command. Now I want to plot the original data and the outliers together. How can I do that?
Temp = data(:,2); % Separating the feature vector
Temp_z_score = (Temp - mean(Temp)) / std(Temp); % Calculation of the z-score (z-score = the number of standard deviations a point is below or over the mean)
threshold = abs(Temp_z_score)>1.8;
U = any(threshold,2);

回答 (1 件)

Cris LaPierre
Cris LaPierre 2022 年 10 月 15 日
編集済み: Cris LaPierre 2022 年 10 月 15 日
Wouldn't plotting the original data already contain the outliers? I assume you want to plot each group with a different linespec.
Since threshold is a logical array, use logical indexing when you plot. See the bottom of this page for an explanation.
Temp = rand(100,1);
Temp_z_score = (Temp - mean(Temp)) / std(Temp);
threshold = abs(Temp_z_score)>1.8;
plot(Temp(~threshold),'bo','DisplayName','Data')
hold on
plot(Temp(threshold),'r*','DisplayName','Outlier')
hold off
legend
  2 件のコメント
Seyed Navid Shoaiby
Seyed Navid Shoaiby 2022 年 10 月 15 日
移動済み: Cris LaPierre 2022 年 10 月 15 日
This plotting does not show the outliers in correct order. I want to plot the original data, and then mark the outliers in their correct order. The resulting graph is this. I want the red points in line with other data points. Any suggestions?
Cris LaPierre
Cris LaPierre 2022 年 10 月 15 日
You need to specify an x value then. You have not indicated there is one in your OP. If you don't have one, then x is the element number.
Temp = rand(100,1);
X=1:length(Temp);
Temp_z_score = (Temp - mean(Temp)) / std(Temp);
threshold = abs(Temp_z_score)>1.8;
plot(X(~threshold),Temp(~threshold),'bo','DisplayName','Data')
hold on
plot(X(threshold),Temp(threshold),'r*','DisplayName','Outlier')
hold off
legend

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by