Continuous and repetitive gaussian random function in matlab

1 Ansicht (letzte 30 Tage)
I want to create a random rough surface profile as input form my method. I can able to create random variation in numbers using randn function but each time i simulate i get different input data which changes output. If it is possible to store and use the data or to generate a continuous function of random data which can be repetative if done simulaion that would be helpful
  2 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 17 Sep. 2019
Hello Rakesh, can you show the plot you are looking for (use paint or any drawing tool)?
RAKESH MAHARANA
RAKESH MAHARANA am 23 Sep. 2019
Its not any specific profile. The profile i want to generate is random but continuous. It should not change with simulation unless i change it . The two graps are profile i obtained using random function in matlab but every time i run in matlab profile changes so output changes

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephan
Stephan am 17 Sep. 2019
If i understood you correctly, you want to get the same random values every time you run your code. This is reached by the rng function.
rand(1,10)
ans =
0.4387 0.3816 0.7655 0.7952 0.1869 0.4898 0.4456 0.6463 0.7094 0.7547
s = rng
s =
struct with fields:
Type: 'twister'
Seed: 0
State: [625×1 uint32]
rng(s)
rand(1,10)
ans =
0.2760 0.6797 0.6551 0.1626 0.1190 0.4984 0.9597 0.3404 0.5853 0.2238
rng(s)
rand(1,10)
ans =
0.2760 0.6797 0.6551 0.1626 0.1190 0.4984 0.9597 0.3404 0.5853 0.2238
  2 Kommentare
RAKESH MAHARANA
RAKESH MAHARANA am 23 Sep. 2019
Hi stephen, i understand your answer. I can repeat same random numbers if i use rng function. If i want to generate another set of numbers then? . I want to generate a set of random numbers within a specific limit and it should not change during continuous simulation but also after some point i want to generate another set and use it .
RAKESH MAHARANA
RAKESH MAHARANA am 23 Sep. 2019
function [omega,sro1,sro3]=roughsurf(D);
% surface roughness calculation
% range of surface roughness
i=0;
k=0;% length point of slab
a=1;% constant input for random calculation
m1=0;% mean calculation of both height and diameter
m2=0;
ro1=0;
ro2=0;
s1=0;
s3=0;
sro1=0;% reflection coefficient value of roughness
sro3=0;
for i=0:0.01:D
heigh1(a)=randn(1);
diame1(a)=randn(1);
m1=mean(heigh1);
m2=mean(diame1);
s1=std(heigh1);
s3=std(diame1);
sro1=std(heigh1-s1)/12000;
sro3=std(diame1-s3)/12000;
ro1=mean(heigh1-m1);
ro2=mean(diame1-m2);
if ((ro1~=0)&&(ro2~=0))
om1(a)=atan(2*ro1/ro2);
else
om1(a)=atan(2*heigh1/diame1);
end;
k=om1(a);
a=a+1;
end
plot(om1);
sro3;
sro1;
omega=k;
end
Every time function is called for a specific value of D it is generating random numbers .For 1 main program simulation it should have more than 100 iterations of this loop, and also i am unable to generate plot inside the calling function

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by