Hello,
I have 2 questions to ask:
  1. I need to generate 5 gaussian distribution data having specified stabndard deviation and particular min and max value.
  2. I need to genearate 5 gaussian distribution data having minimum distance between 2 point of 2 meter and maximum distance between 2 points as 3.5 meter.
As i had used randn function but not getting data with that particular specification.
Please help regaerding that.
Thanks

 Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 22 de En. de 2019

1 voto

Well, slightly unclear question, but I'll try answering: "you need to generating some given number of random points from a Gaussian distribution with the following criteria". Since the Gaussian distribution is continuous and has infintely wide tails the only way I can see you achive this is to generate the required number of points, test if the requirements are met and then keep those otherwise draw another batch of points, repeat until stopping criteria.
Maybe there are more clever ways to achive this without introducing strange biases making the distribution of points be way off Gaussian - but that seems peculiar.
HTH

9 comentarios

Moby Philip
Moby Philip el 22 de En. de 2019
  • @ Walter Roberson I need to generate some random data but when i am plotting them the minimum distance between those 2 points shoul be 2 meter and maximum distance between those 2 points should be 3.5 meter. As, i dont want to use any system toolbox only have to use a matlab script.
  • I also thought like that @ Bjorn Gustavsson but i have to siimultaneously run the code and check that required specification met. And UI have to choose only those data whose specification met my requirement.
Thanks.
Well, then loop and test!
foundem = 0
while fuondem == 0
points = MV + STVV*randn(nr_points);
if conditions4OK(points)
foundem = 1;
end
end
You might have to modify this a bit - and as per Walter's answer, depending on your conditions this might take a while - you might put in something that limits the run-time in the while-loop (look at etime) and return an empty array for the points to indicate a fail.
Moby Philip
Moby Philip el 22 de En. de 2019
Thanks for the reply @Bjorn Gustavsson but will you please take a small time and explain the code. It would be really be appreciated.
Thanks.
Walter Roberson
Walter Roberson el 22 de En. de 2019
Random numbers generated with randn() do not have any unit. randn() has no idea whether a result of -3.348980 represents nanometers or light years.
Bjorn Gustavsson
Bjorn Gustavsson el 23 de En. de 2019
To give you further guidance than the clue given by Walter: since the random numbers given by randn are numbers without units the MV and STDV in my suggestion surely must come with physically meaningful factors, i.e. with physical units. Then after that, but before the condition you are allowed to insert additional commands to extract information about the numbers you've gotten. Take a look at the help for sort, max min and diff, then think about how to combine those to get the information necessary to check the conditions, also look at the help for if.
HTH
Walter Roberson
Walter Roberson el 23 de En. de 2019
The probability of generating two numbers 8 standard deviations apart is 1 in about 225 million -- and the other numbers might not happen to have the required distance properties.
Bjorn Gustavsson
Bjorn Gustavsson el 23 de En. de 2019
Where do you get the "8 standard deviations apart" from? OP writes "specified stabndard (sic) deviation" I take that to mean that the OP are supposed to fund such a standard deviatin as to generate random number sequences with fulfilliing the requirements. The numerically impossible task is to draw 2 random numbers with 2 particular values (the max and min values in part 1), that is unlikely even in a finite precision 32-bit floating-point world.
Walter Roberson
Walter Roberson el 23 de En. de 2019
Editada: Walter Roberson el 23 de En. de 2019
Since we are not told otherwise after repeated questions, we have to speculate that the standard deviation is 1 m, and thus that the minimal solution (if it could be randomly generated) would be [-4 -2 0 2 4] which is a span of 8 standard deviations.
Bjorn Gustavsson
Bjorn Gustavsson el 23 de En. de 2019
Yeah, continuing to argue this way or that way is rather pointless - the only thing we know at this point is that at least one of us are interpreting the task incorrectly.

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 22 de En. de 2019

0 votos

  1. Gaussian distribution is always infinite in both tails. It is a contradiction to use gaussian with min and max values.
  2. Statistics Toolbox offers makedist() and truncate() that together can create a truncated Gaussian.
  3. #2 is definitely not gaussian distribution.
  4. Your absolute distince of 2 does not mean much unless we know the standard distribution. Otherwise you are dealing with a minimum span of 8 standard deviations, like [0 2 4 6 8] 5 points no two closer than 2 together, total span is 8. 8 standard deviations is not very common; you would have to generate for a pretty long time to satisify the conditions randomly.
Moby Philip
Moby Philip el 24 de En. de 2019

0 votos

Hello Walter and Bjorn thanks for your reply,really appreciate that. I really understood how to approach it with the help of Bjorn reply.
Thanks

Categorías

Productos

Versión

R2017a

Preguntada:

el 22 de En. de 2019

Respondida:

el 24 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by