- Define the function f(x) in MATLAB. Make sure the function is defined for the desired range of x values.
- Choose a desired mean value.
- Set up a loop to generate random data points and calculate their mean.
- Repeat the loop until the generated data points have value close to the desired target value.
- Store the data points that meet the criteria.
How to generate a row vector of 6 elements (1x6) out of the given function (fitting the fuction) with a specific MEAN ?
    5 views (last 30 days)
  
       Show older comments
    
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 ?
0 Comments
Answers (1)
  Sai Pavan
      
 on 3 Oct 2023
        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: 
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 
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
