Creating regenerative random numbers

The code creates 10 random ellipses
N = 10;
for R = 1:N %for loop to repeat 10 times
t = linspace(0,2*pi); % t defined angle??? not sure
xc = randn; %defines one of axis as random
x = xc + randn*cos(t);
yc = randn;
y = yc + randn*sin(t);
plot(x,y)
patch(x,y,rand)
hold on %puts all ellipses on same graph
end
How do I add to the code to make it so that everytime i run this code i get the same graph with the same random numbers inputed?

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 3일

0 개 추천

rng(655321) %or use any other positive integer constant

댓글 수: 3

Emma
Emma 2021년 3월 3일
where in the script do i put this line?
Emma
Emma 2021년 3월 3일
nevermind got it!
Steven Lord
Steven Lord 2021년 3월 3일
This documentation page has more information about controlling the random number generator.

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2021년 3월 3일

댓글:

2021년 3월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by