# Add random numbess to matrix

6 views (last 30 days)

Show older comments

### Accepted Answer

DGM
on 30 Nov 2021

Edited: DGM
on 30 Nov 2021

Define "add 1-5% of its actual value to it"

Consider an array A. Does this mean

% random factor is scalar

B = A + (0.01+0.04*rand(1))*A;

or maybe

% random factor is an array

% each element gets its own random factor

B = A + (0.01+0.04*rand(size(A))).*A;

Imnoise() allows the application of additive gaussian noise using intensity mapping of local noise variance. That might also apply.

### More Answers (1)

dpb
on 1 Dec 2021

If the desire is a bounded, symmetric, continuous distribution that approximates a normal, consider the beta with, eta,gamma equal. The pdf is then bounded between [0, 1] with mean gamm/(eta+gamma) --> gamma/(2*gamma) --> 0.5 for eta==gamma.

As for the normal, you can shift and scale the generated RNVs generated from random by whatever is needed to match the target range.

The 'pdf' normalization inside histogram results in the red overlaid normal; scaling the N() pdf to match the peak bin in the histogram results in the black overlay which emphasizes the extra weight of the beta towards the central tendency as compared to a normal. But, you can produce a bounded random variate this way that with the very nebulous requirements for the underlying error distribution could surely serve the purpose.

The above was generated by

rB55=random('beta',5,5,1e6,1);

histogram(rB55)

hold on

[mn,sd]=normfit(rB55)

pN55=normpdf(x,0.5,sd);

plot(x,pN55,'-r')

plot(x,pN55*2.48/2.64,'-k')

hLg=legend('pdf(\beta(5,5))','N(0.5,sd(\beta)','0.94*N(0.5,sd(\beta)');

where the magic constants were obtained by getting the maxima of the histogram binned values and the pdf peak

The above uses functions in the Statistics Toolbox...

##### 1 Comment

dpb
on 1 Dec 2021

### See Also

### Community Treasure Hunt

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

Start Hunting!