There are three steps:
- Create an algorithm to define the outliers
- Identify the points that meet that definition
- Plot those points
Here is an example. You'll need to adapt to your case, for example, by doing this calculation inside of each for loop, and using your own definition of what constitutes an outlier.
Also, I would recommend against using red circles to identify outliers, since your plot is a red line.
N = 1000;
y = randn(N,1);
y_mean = mean(y);
y_std = std(y);
outlierIndex = find(abs(y - y_mean) > 2*y_std);
figure
hold on
plot(y,'.')
plot(outlierIndex,y(outlierIndex),'ro')
Best Answer