MATLAB Answers

0

How to pick five data points equally above and below ( five above and five below)

Asked by Mekala balaji on 14 Sep 2017
Latest activity Answered by Pal Szabo on 14 Sep 2017
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 Comments

Sign in to comment.

1 Answer

Answer by Pal Szabo on 14 Sep 2017
 Accepted Answer

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 Comments

Sign in to comment.