# How to generate a row vector of 6 elements (1x6) out of the given function (fitting the fuction) with a specific MEAN ?

조회 수: 3 (최근 30일)
Sambit Supriya Dash 2022년 5월 28일
답변: Sai Pavan 2023년 10월 3일
I have a function f(x), from the fuction (fitting the fuction) how to extract data points which will have a specific MEAN and if possible Standard Deviation also ?

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

### 답변 (1개)

Sai Pavan 2023년 10월 3일
Hi Sambit,
I understand that you are trying to generate a row vector with a specific mean out of a given function.
You can use the following approach to extract data points from a function f(x) that have a specific mean:
1. Define the function f(x) in MATLAB. Make sure the function is defined for the desired range of x values.
2. Choose a desired mean value.
3. Set up a loop to generate random data points and calculate their mean.
4. Repeat the loop until the generated data points have value close to the desired target value.
5. Store the data points that meet the criteria.
Please refer to the below code snippet to generate a (1x6) row vector with a target mean value of 6.
f = @(x) x.^2 + 2*x + 1; % Sample function
meanTarget = 6; % target mean value
dataPoints = [];
meanValue = 0; % current mean value
while abs(meanValue - meanTarget) > 0.01 % run the loop until mean of generated random numbers is close to target mean
x = randn(1, 6);
y = f(x);
meanValue = mean(y);
if abs(meanValue - meanTarget) <= 0.01 % if the current mean is close to target mean, store the vector
dataPoints = [dataPoints; x; y];
end
end
disp("Extracted Data Points:");
disp(dataPoints);
Hope it helps.
Regards,
Sai Pavan

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

### 카테고리

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

### Community Treasure Hunt

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

Start Hunting!

Translated by