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

조회 수: 1 (최근 30일)
Mekala balaji 2017년 9월 14일
답변: Pal Szabo 2017년 9월 14일
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)

댓글을 달려면 로그인하십시오.

### 채택된 답변

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

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by