Can I write a script that keeps rows that are within 5% and 10 cells above and below a specific cell?
조회 수: 1 (최근 30일)
이전 댓글 표시
The idea is to have a script that takes stable data eleminating the peaks and valleys.
I want to have that cell compared with the 10 before and after itself and if all this 21 values are within 5% then I can keep that data. That script should also be able to check all the rows of an excel spreadsheet.
Any suggestions and ideas are much appreciated! I am a newby trying to do advanced stuff :)
댓글 수: 0
채택된 답변
Rik
2019년 8월 21일
If you have a cell array you should convert it to a numeric type (e.g. a double).
You can find outliers by using the movmean function:
k=21;
outlier=abs((data./movmean(data, k))-1)>=0.05;
Now you have a logical array with the outliers. Do you want to remove them or replace them?
댓글 수: 8
Rik
2019년 8월 23일
편집: Rik
2019년 8월 23일
So for each value within the window x/x_window must be between 0.95 and 1.05? If that is the case you could use something like the code below.
%your data and setting
data=[55;56;54;55;55;55;59;54;55;52;55;56;56;57;50;60;71;75;115;60;50;40;...
23;20;25;30;40;50;55;56;55;44;55;55;55;55;56;54;57;54;54;56;58;54;...
58;56;55;55;55;54;55;55;56;55;55;55;55;55;55;54;54;56;54;54;54;56;...
55;54;58;58;57;58;56;54;55;55;55;55;55;56;55;55;55;54;55;55;55;56;...
55;55;55;54;55;55;55;56;55;55;55;54;55;55;55;56;55;55;55;54;55;55;...
55;55;57;55;55;55;57;55;55;55;56;56;57;56;57;56;58;57;56;55;56;56;...
56;57;57;57;100;90;15;20;4;5;56;47;58;57;21;44;33;66;88;77;44;55;...
66;23;55;54;56;57;58;98;54;2;42;52;5;44;44;56;87;45;15;35;8;55;65;...
45;78;77;66;55;44;54;56;54;58;59;54;56;54;56;54;56;54;54;56;54;56;54];
k=21;
%%
%example data and setting
data=[100 100 100 106 100 98 100];
k=3;
%%
clc
L=false(size(data));
for n=( -(k-1)/2 ):( (k-1)/2 )
if n==0,continue,end
current=circshift(data,n);%shift the vector one position over
ratio=data./current;
p_diff=abs(ratio-1)*100;
L=L | p_diff>5;%store all positions where the ratio is off
end
data(L)=[]
With the example data it is easy to see that a lot of values are getting removed if you do it like this. The reason is that an invalid value 'taints' the surrounding values. In this case the 106 value causes the 100 on either to be removed as well.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!