random number from a data set with a specified error

Hi All, I am trying to generate a set of random numbers from a given distribution. The randn option gives a set of values with a definite mean and standard deviation. However, my intention is to generate several sets of random numbers from a known set of data within a specified error. Please suggest. Atanu

 채택된 답변

Geoff
Geoff 2012년 3월 14일
This question is open to interpretation.
What I think you have is a dataset X with known standard deviations S (a vector containing one deviation for each value in X), and you want to generate a whole bunch of pseudo-X datasets that are randomised the known distributions of X.
If that's the case, you can generate a single set as follows:
N = length(X);
pX = X + S .* randn(1,N);
Repeat as many times as you like.
The error will be normally distributed around each point in X by the known standard deviation at that point.
If you have an error rather than standard deviation, and want random noise within that range, you might do it with a linear distribution instead of normal (let's assume E is an absolute error value, so we're varying within X +/- E):
pX = X + (rand(1,N)*2-1) .* E;
-g-

댓글 수: 3

Atanu
Atanu 2012년 3월 14일
Hi,
Here is the matlab file I am using to generate 100 different profiles from the distribution that I have as zndep. I have used an error of 1. Now I want to use the error value of 2.7. How could I do that? Both hist-zndpl.dat and hist-zndpl-cu.dat has one column of data each.
Thanks
Atanu
% errorcheck.m in ZN-dep and ZN-dep-cuShift
clear, close all,
zndep = load('hist-zndpl.dat');
zndepcushift = load('hist-zndpl-cu.dat');
zndep = sort(zndep);
zndepcushift = sort(zndepcushift);
f = (1:length(zndep))./length(zndep) ;
plot(zndep,f,'.-g'), hold on
plot(zndepcushift,f,'.-r')
% now take gaussian error bars around zndep with appropriate %width sig=1kJ/mol
for i=1:100
r = randn(length(zndep),1); % rand #s with sig=1
zni = zndep + r;
plot(sort(zni),f,'-g')
end
Geoff
Geoff 2012년 3월 14일
r = 2.7 * randn(length(zndep),1);
Atanu
Atanu 2012년 3월 14일
Thanks a lot.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2012년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by