Generating random numbers using randn in MATLAB












0















I am using randn in MATLAB to generate a set of random numbers for a given mean and standard deviation.



b=5000;
a=500;
y = a.*randn(100,1) + b;
sprintf('%fn',y)


I expect that numbers generated would lie between 4500 to 5500. But, I see values in the range of 3000 to 6000.



Could someone explain why this happens?



Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?










share|improve this question




















  • 3





    Values cannot lie all between plus/minus 1SD around the mean, because the standard deviation is a measure of the average dispersion of data around the mean and you require that average to be a maximum too. The only way this would be possible is with a distribution where numbers only the take the values (mean-sigma) or (mean+sigma), with equal probability. y = a.*(2*(rand(100,1)<.5)-1)+b;

    – Brice
    Nov 20 '18 at 10:44













  • The only wat to force the values to a specific interval is to renounce the the Gaussian distribution. What distribution do you want instead? A truncated Gaussian?

    – Luis Mendo
    Nov 20 '18 at 11:16











  • @LuisMendo The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn.

    – Natasha
    Nov 20 '18 at 15:59
















0















I am using randn in MATLAB to generate a set of random numbers for a given mean and standard deviation.



b=5000;
a=500;
y = a.*randn(100,1) + b;
sprintf('%fn',y)


I expect that numbers generated would lie between 4500 to 5500. But, I see values in the range of 3000 to 6000.



Could someone explain why this happens?



Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?










share|improve this question




















  • 3





    Values cannot lie all between plus/minus 1SD around the mean, because the standard deviation is a measure of the average dispersion of data around the mean and you require that average to be a maximum too. The only way this would be possible is with a distribution where numbers only the take the values (mean-sigma) or (mean+sigma), with equal probability. y = a.*(2*(rand(100,1)<.5)-1)+b;

    – Brice
    Nov 20 '18 at 10:44













  • The only wat to force the values to a specific interval is to renounce the the Gaussian distribution. What distribution do you want instead? A truncated Gaussian?

    – Luis Mendo
    Nov 20 '18 at 11:16











  • @LuisMendo The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn.

    – Natasha
    Nov 20 '18 at 15:59














0












0








0


1






I am using randn in MATLAB to generate a set of random numbers for a given mean and standard deviation.



b=5000;
a=500;
y = a.*randn(100,1) + b;
sprintf('%fn',y)


I expect that numbers generated would lie between 4500 to 5500. But, I see values in the range of 3000 to 6000.



Could someone explain why this happens?



Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?










share|improve this question
















I am using randn in MATLAB to generate a set of random numbers for a given mean and standard deviation.



b=5000;
a=500;
y = a.*randn(100,1) + b;
sprintf('%fn',y)


I expect that numbers generated would lie between 4500 to 5500. But, I see values in the range of 3000 to 6000.



Could someone explain why this happens?



Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?







matlab random






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 9:47







Natasha

















asked Nov 20 '18 at 9:42









NatashaNatasha

1019




1019








  • 3





    Values cannot lie all between plus/minus 1SD around the mean, because the standard deviation is a measure of the average dispersion of data around the mean and you require that average to be a maximum too. The only way this would be possible is with a distribution where numbers only the take the values (mean-sigma) or (mean+sigma), with equal probability. y = a.*(2*(rand(100,1)<.5)-1)+b;

    – Brice
    Nov 20 '18 at 10:44













  • The only wat to force the values to a specific interval is to renounce the the Gaussian distribution. What distribution do you want instead? A truncated Gaussian?

    – Luis Mendo
    Nov 20 '18 at 11:16











  • @LuisMendo The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn.

    – Natasha
    Nov 20 '18 at 15:59














  • 3





    Values cannot lie all between plus/minus 1SD around the mean, because the standard deviation is a measure of the average dispersion of data around the mean and you require that average to be a maximum too. The only way this would be possible is with a distribution where numbers only the take the values (mean-sigma) or (mean+sigma), with equal probability. y = a.*(2*(rand(100,1)<.5)-1)+b;

    – Brice
    Nov 20 '18 at 10:44













  • The only wat to force the values to a specific interval is to renounce the the Gaussian distribution. What distribution do you want instead? A truncated Gaussian?

    – Luis Mendo
    Nov 20 '18 at 11:16











  • @LuisMendo The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn.

    – Natasha
    Nov 20 '18 at 15:59








3




3





Values cannot lie all between plus/minus 1SD around the mean, because the standard deviation is a measure of the average dispersion of data around the mean and you require that average to be a maximum too. The only way this would be possible is with a distribution where numbers only the take the values (mean-sigma) or (mean+sigma), with equal probability. y = a.*(2*(rand(100,1)<.5)-1)+b;

– Brice
Nov 20 '18 at 10:44







Values cannot lie all between plus/minus 1SD around the mean, because the standard deviation is a measure of the average dispersion of data around the mean and you require that average to be a maximum too. The only way this would be possible is with a distribution where numbers only the take the values (mean-sigma) or (mean+sigma), with equal probability. y = a.*(2*(rand(100,1)<.5)-1)+b;

– Brice
Nov 20 '18 at 10:44















The only wat to force the values to a specific interval is to renounce the the Gaussian distribution. What distribution do you want instead? A truncated Gaussian?

– Luis Mendo
Nov 20 '18 at 11:16





The only wat to force the values to a specific interval is to renounce the the Gaussian distribution. What distribution do you want instead? A truncated Gaussian?

– Luis Mendo
Nov 20 '18 at 11:16













@LuisMendo The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn.

– Natasha
Nov 20 '18 at 15:59





@LuisMendo The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn.

– Natasha
Nov 20 '18 at 15:59












2 Answers
2






active

oldest

votes


















0














Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?



No, by definition.



If yo are using the normal distribution (randn) then you can not really limit your numbers to be in a range, as in the normal distribution only infinity and minus infinity have zero probability, the rest, while having a minuscule probability, can happen.



Alternatively, you can use a different distribution, such as uniform (rand) to constrain the randomness to a gap.






share|improve this answer



















  • 1





    That is the case if the implied end of the question is "...and still keep a normal distribution".

    – Peter O.
    Nov 20 '18 at 20:46





















0














The reason why the values do not lie in the interval [4500,5500] is that the numbers coming out of randn() are not confined to the interval [-1,1], which is why your approach does not work as you intend, even though the general approach makes sense. The numbers coming from randn are drawn from the standard normal distribution, which has a standard deviation of one and a mean of zero. Theoretically, any value between -inf and +inf can come out of randn.



You could do one of the following two things, depending on what you want to do after and how that constrains your options:



Option 1 is to generate your random numbers and divide by the maximum absolute value before you do anything else, i.e.:



z = randn(100,1);
z = z / max(abs(z));
y = 5000 + 500*z;


this will make sure that z does not contain any values smaller than -1 or larger than +1 (note that it does guarantee that at least one of these (-1 or +1) will be present in the array z). You can then use your values of b and a to translate the values to random numbers in the interval of your choice.



Edit: note (as pointed out in the comments on this answer) that while the above option will give you random values in the interval of your choice, it will also alter the distribution and standard deviation associated with these values. If it is important for you that the values follow a normal distribution, do not use this option.



Option 2 is to use rand(), which always returns numbers from the interval [0,1]. Note that these come from a uniform distribution, not a normal distribution. You can then first translate these values to the interval [-1,1]:



z = rand(100,1);
z = 2*z - 1; % Translates the interval from [0,1] to [-1,1]


and then generate your numbers as before; y = 5000 + 500*z;.






share|improve this answer





















  • 4





    I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

    – Nicky Mattsson
    Nov 20 '18 at 10:38








  • 2





    Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

    – Brice
    Nov 20 '18 at 10:47











  • You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

    – Floris SA
    Nov 20 '18 at 16:18











  • @FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

    – Natasha
    Nov 20 '18 at 16:31













  • Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

    – Floris SA
    Nov 21 '18 at 12:44













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390132%2fgenerating-random-numbers-using-randn-in-matlab%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?



No, by definition.



If yo are using the normal distribution (randn) then you can not really limit your numbers to be in a range, as in the normal distribution only infinity and minus infinity have zero probability, the rest, while having a minuscule probability, can happen.



Alternatively, you can use a different distribution, such as uniform (rand) to constrain the randomness to a gap.






share|improve this answer



















  • 1





    That is the case if the implied end of the question is "...and still keep a normal distribution".

    – Peter O.
    Nov 20 '18 at 20:46


















0














Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?



No, by definition.



If yo are using the normal distribution (randn) then you can not really limit your numbers to be in a range, as in the normal distribution only infinity and minus infinity have zero probability, the rest, while having a minuscule probability, can happen.



Alternatively, you can use a different distribution, such as uniform (rand) to constrain the randomness to a gap.






share|improve this answer



















  • 1





    That is the case if the implied end of the question is "...and still keep a normal distribution".

    – Peter O.
    Nov 20 '18 at 20:46
















0












0








0







Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?



No, by definition.



If yo are using the normal distribution (randn) then you can not really limit your numbers to be in a range, as in the normal distribution only infinity and minus infinity have zero probability, the rest, while having a minuscule probability, can happen.



Alternatively, you can use a different distribution, such as uniform (rand) to constrain the randomness to a gap.






share|improve this answer













Or is there any way to specify that the values should lie between mean plus/ minus 1 SD ?



No, by definition.



If yo are using the normal distribution (randn) then you can not really limit your numbers to be in a range, as in the normal distribution only infinity and minus infinity have zero probability, the rest, while having a minuscule probability, can happen.



Alternatively, you can use a different distribution, such as uniform (rand) to constrain the randomness to a gap.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 11:15









Ander BiguriAnder Biguri

26.3k105491




26.3k105491








  • 1





    That is the case if the implied end of the question is "...and still keep a normal distribution".

    – Peter O.
    Nov 20 '18 at 20:46
















  • 1





    That is the case if the implied end of the question is "...and still keep a normal distribution".

    – Peter O.
    Nov 20 '18 at 20:46










1




1





That is the case if the implied end of the question is "...and still keep a normal distribution".

– Peter O.
Nov 20 '18 at 20:46







That is the case if the implied end of the question is "...and still keep a normal distribution".

– Peter O.
Nov 20 '18 at 20:46















0














The reason why the values do not lie in the interval [4500,5500] is that the numbers coming out of randn() are not confined to the interval [-1,1], which is why your approach does not work as you intend, even though the general approach makes sense. The numbers coming from randn are drawn from the standard normal distribution, which has a standard deviation of one and a mean of zero. Theoretically, any value between -inf and +inf can come out of randn.



You could do one of the following two things, depending on what you want to do after and how that constrains your options:



Option 1 is to generate your random numbers and divide by the maximum absolute value before you do anything else, i.e.:



z = randn(100,1);
z = z / max(abs(z));
y = 5000 + 500*z;


this will make sure that z does not contain any values smaller than -1 or larger than +1 (note that it does guarantee that at least one of these (-1 or +1) will be present in the array z). You can then use your values of b and a to translate the values to random numbers in the interval of your choice.



Edit: note (as pointed out in the comments on this answer) that while the above option will give you random values in the interval of your choice, it will also alter the distribution and standard deviation associated with these values. If it is important for you that the values follow a normal distribution, do not use this option.



Option 2 is to use rand(), which always returns numbers from the interval [0,1]. Note that these come from a uniform distribution, not a normal distribution. You can then first translate these values to the interval [-1,1]:



z = rand(100,1);
z = 2*z - 1; % Translates the interval from [0,1] to [-1,1]


and then generate your numbers as before; y = 5000 + 500*z;.






share|improve this answer





















  • 4





    I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

    – Nicky Mattsson
    Nov 20 '18 at 10:38








  • 2





    Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

    – Brice
    Nov 20 '18 at 10:47











  • You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

    – Floris SA
    Nov 20 '18 at 16:18











  • @FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

    – Natasha
    Nov 20 '18 at 16:31













  • Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

    – Floris SA
    Nov 21 '18 at 12:44


















0














The reason why the values do not lie in the interval [4500,5500] is that the numbers coming out of randn() are not confined to the interval [-1,1], which is why your approach does not work as you intend, even though the general approach makes sense. The numbers coming from randn are drawn from the standard normal distribution, which has a standard deviation of one and a mean of zero. Theoretically, any value between -inf and +inf can come out of randn.



You could do one of the following two things, depending on what you want to do after and how that constrains your options:



Option 1 is to generate your random numbers and divide by the maximum absolute value before you do anything else, i.e.:



z = randn(100,1);
z = z / max(abs(z));
y = 5000 + 500*z;


this will make sure that z does not contain any values smaller than -1 or larger than +1 (note that it does guarantee that at least one of these (-1 or +1) will be present in the array z). You can then use your values of b and a to translate the values to random numbers in the interval of your choice.



Edit: note (as pointed out in the comments on this answer) that while the above option will give you random values in the interval of your choice, it will also alter the distribution and standard deviation associated with these values. If it is important for you that the values follow a normal distribution, do not use this option.



Option 2 is to use rand(), which always returns numbers from the interval [0,1]. Note that these come from a uniform distribution, not a normal distribution. You can then first translate these values to the interval [-1,1]:



z = rand(100,1);
z = 2*z - 1; % Translates the interval from [0,1] to [-1,1]


and then generate your numbers as before; y = 5000 + 500*z;.






share|improve this answer





















  • 4





    I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

    – Nicky Mattsson
    Nov 20 '18 at 10:38








  • 2





    Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

    – Brice
    Nov 20 '18 at 10:47











  • You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

    – Floris SA
    Nov 20 '18 at 16:18











  • @FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

    – Natasha
    Nov 20 '18 at 16:31













  • Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

    – Floris SA
    Nov 21 '18 at 12:44
















0












0








0







The reason why the values do not lie in the interval [4500,5500] is that the numbers coming out of randn() are not confined to the interval [-1,1], which is why your approach does not work as you intend, even though the general approach makes sense. The numbers coming from randn are drawn from the standard normal distribution, which has a standard deviation of one and a mean of zero. Theoretically, any value between -inf and +inf can come out of randn.



You could do one of the following two things, depending on what you want to do after and how that constrains your options:



Option 1 is to generate your random numbers and divide by the maximum absolute value before you do anything else, i.e.:



z = randn(100,1);
z = z / max(abs(z));
y = 5000 + 500*z;


this will make sure that z does not contain any values smaller than -1 or larger than +1 (note that it does guarantee that at least one of these (-1 or +1) will be present in the array z). You can then use your values of b and a to translate the values to random numbers in the interval of your choice.



Edit: note (as pointed out in the comments on this answer) that while the above option will give you random values in the interval of your choice, it will also alter the distribution and standard deviation associated with these values. If it is important for you that the values follow a normal distribution, do not use this option.



Option 2 is to use rand(), which always returns numbers from the interval [0,1]. Note that these come from a uniform distribution, not a normal distribution. You can then first translate these values to the interval [-1,1]:



z = rand(100,1);
z = 2*z - 1; % Translates the interval from [0,1] to [-1,1]


and then generate your numbers as before; y = 5000 + 500*z;.






share|improve this answer















The reason why the values do not lie in the interval [4500,5500] is that the numbers coming out of randn() are not confined to the interval [-1,1], which is why your approach does not work as you intend, even though the general approach makes sense. The numbers coming from randn are drawn from the standard normal distribution, which has a standard deviation of one and a mean of zero. Theoretically, any value between -inf and +inf can come out of randn.



You could do one of the following two things, depending on what you want to do after and how that constrains your options:



Option 1 is to generate your random numbers and divide by the maximum absolute value before you do anything else, i.e.:



z = randn(100,1);
z = z / max(abs(z));
y = 5000 + 500*z;


this will make sure that z does not contain any values smaller than -1 or larger than +1 (note that it does guarantee that at least one of these (-1 or +1) will be present in the array z). You can then use your values of b and a to translate the values to random numbers in the interval of your choice.



Edit: note (as pointed out in the comments on this answer) that while the above option will give you random values in the interval of your choice, it will also alter the distribution and standard deviation associated with these values. If it is important for you that the values follow a normal distribution, do not use this option.



Option 2 is to use rand(), which always returns numbers from the interval [0,1]. Note that these come from a uniform distribution, not a normal distribution. You can then first translate these values to the interval [-1,1]:



z = rand(100,1);
z = 2*z - 1; % Translates the interval from [0,1] to [-1,1]


and then generate your numbers as before; y = 5000 + 500*z;.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 12:47

























answered Nov 20 '18 at 10:01









Floris SAFloris SA

4789




4789








  • 4





    I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

    – Nicky Mattsson
    Nov 20 '18 at 10:38








  • 2





    Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

    – Brice
    Nov 20 '18 at 10:47











  • You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

    – Floris SA
    Nov 20 '18 at 16:18











  • @FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

    – Natasha
    Nov 20 '18 at 16:31













  • Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

    – Floris SA
    Nov 21 '18 at 12:44
















  • 4





    I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

    – Nicky Mattsson
    Nov 20 '18 at 10:38








  • 2





    Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

    – Brice
    Nov 20 '18 at 10:47











  • You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

    – Floris SA
    Nov 20 '18 at 16:18











  • @FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

    – Natasha
    Nov 20 '18 at 16:31













  • Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

    – Floris SA
    Nov 21 '18 at 12:44










4




4





I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

– Nicky Mattsson
Nov 20 '18 at 10:38







I really do not recommend the first option as it makes the distribution random. If OP really wants a limited normal distribution I would recommend the truncated normal distribution en.wikipedia.org/wiki/Truncated_normal_distribution

– Nicky Mattsson
Nov 20 '18 at 10:38






2




2





Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

– Brice
Nov 20 '18 at 10:47





Truncation will alter the standard deviation of the distribution. The question is poorly stated: is the requested std to be computed before or after truncation?

– Brice
Nov 20 '18 at 10:47













You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

– Floris SA
Nov 20 '18 at 16:18





You are both correct; I will edit my answer to recommend against using the first option. It's a shame MatLab doesn't have a truncated normal distribution built in; there is a file on mathworks file exchange, but looking at the comments, it should probably not be used either.

– Floris SA
Nov 20 '18 at 16:18













@FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

– Natasha
Nov 20 '18 at 16:31







@FlorisSA The mean and standard deviation is from experimental measurement. Since the data points are not available, I am trying to create the data set from the mean and standard deviation. For instance, the measurement could pertain to any physical property, like size, of a biological cell. Since most of the natural phenomena follow normal distribution I have been sampling using randn. Given this, is it appropriate to use truncated normal distribution?

– Natasha
Nov 20 '18 at 16:31















Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

– Floris SA
Nov 21 '18 at 12:44







Looking at your original post and your comment, I would guess the truncated normal distribution is the most appropriate, but that will still leave you with the issue of how to actually implement that in MatLab. Either way, you should probably first get clear for yourself 1) what the (desired) standard deviation is and 2) what the maximum allowed deviation from the mean is. As Brice and Ander have correctly pointed out, these values can not be the same.

– Floris SA
Nov 21 '18 at 12:44




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390132%2fgenerating-random-numbers-using-randn-in-matlab%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?