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

 Risposta accettata

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 Commenti

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
r = 2.7 * randn(length(zndep),1);
Thanks a lot.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Random Number Generation in Centro assistenza e File Exchange

Richiesto:

il 13 Mar 2012

Community Treasure Hunt

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

Start Hunting!

Translated by