How can I select n numbers from a large data that equals the given average?

조회 수: 1 (최근 30일)
For Example: I have a data of rand(1000) numbers. I want to pick the 10 numbers that satisfy the average 47. And provided, only one set of 10 numbers from the group will satisfy the average 47. How can I do this? Is there any Matlab function for this?
  댓글 수: 2
Daniel Shub
Daniel Shub 2012년 8월 7일
The RAND function returns a random number between 0 and 1. It is not possible to take 10 of those numbers that will average 47. Even if you scale the output of RAND, the numbers are floating point so the odds of finding a solution that exactly equals 47 is essentially zero. You need to tell us more about the data and what to do if the answer is not exactly 47 and ideally how close to 47 we need to get.
Raj Shankar
Raj Shankar 2012년 8월 7일
Hi Daniel
It is that I have a data of 1800 rows and 4 coloumns.
I have the formula for slope. And also I have the result of average slope value of 1294 valid points from the above bulk of data. Hereby I need to pick out that valid 1294 points that satisfies the average slope value. This 1294 points may be any from the 1800 points.
This is what. How can I do this?

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 7일
a=rand(1000,1)*100; % a your array
c= combnk(a,10);
b=mean(c,2)-47
[i,j]=min(abs(b))
samples=c(j,:) % the result

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2012년 8월 7일
variant
A = randi(4e6,1000);
[d,ii] = sort(A(:));
B = conv(d,.1*ones(10,1),'same');
i1 = find(B <= 47,1,'last');
out = A(sort(ii(i1 + (-4:5))));

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by