How to pick five data points equally above and below ( five above and five below)
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have below data:
1.2
3.5
4.7
4.9
5.9
6.3
7.9
8.0
10.0
10.5
11.8
Given point is 5.9
I want to select Five points above and Five points below 5.9. But here, there are only 4 points above 5.9, so in this case select 4 points above and 4 points below (that is minimum data count above and below equally because five data above and below not exist).
So, my desired out put is:
1.2
3.5
4.7
4.9
5.9
6.3
7.9
8.0
So, I need help:
1. If 5 data points not available, then select the next minimum data points (above & below equally). If suppose for example given data point is 10, then there are only two data points (10.5 &11.8) exist below 10 (although there are five data points available above 10) Therefore select two data point above and below (i.e.,data points above 10 are: 7.9 & 8, below are:10.5 & 11.8)
0 个评论
采纳的回答
Pal Szabo
2017-9-14
I believe this works:
data = [1.2;3.5;4.7;4.9;5.9;6.3;7.9;8.0;10.0;10.5;11.8]
givenpoint = 5.9
data_less_than_givenpoint=data(data<givenpoint)
data_greater_than_givenpoint=data(givenpoint<data)
indexofgivenpoint=find(data==givenpoint)
if (length(data_less_than_givenpoint)>5 && length(data_greater_than_givenpoint)>5)
desiredoutput=data((indexofgivenpoint-5):(indexofgivenpoint+5))
else
datapointsavailable = min([length(data_less_than_givenpoint) length(data_greater_than_givenpoint)])
desiredoutput=data((indexofgivenpoint-datapointsavailable): (indexofgivenpoint+datapointsavailable))
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!