How to find a unexpected high value and make them to be mean of 2 neighboring values?

1 次查看(过去 30 天)
Hello
I have a matrix with 4 columns. As the data are experimental, sometimes there are sudden jumps. Then, I want to code it in a way that column 4th to be checked by matlab and those jumps (in this example: 400) to be discovered and changes to a mean of neighboring values (or if it is first or last number of the column, changes to near value). At the end, this matrix to be saved as csv file. (Since data are experimental, there is no rule to find this kind of error values in 4th column. I can say, it is at least 3 times bigger than neighing values)
I tried following code that considers whole “column mean” and also other one called as “rmoutliers” but they make mistake in removing data and make a mess. I will be grateful if someone can propose a way for this.
A = [2 3 4 2; 5 3 7 3; 8 9 0 6; 5 6 1 400]
as = length (A (:, 4))
M = mean (A (:, 4))
for i = 1: as
Max = max (A (:, 4))
if Max> 3 * M
A (A == Max) = 0
else end
end
fname = sprintf ( 'new.csv' );
csvwrite (fname, A); % Write to CSV file
  3 个评论
Masoud Taleb
Masoud Taleb 2020-5-12
How to discover those big elements in column when we do not know how many of them are present? This is the main question.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by