필터 지우기
필터 지우기

How can I generate random numbers to plot my graph?

조회 수: 11 (최근 30일)
fengsen huang
fengsen huang 2018년 11월 14일
댓글: fengsen huang 2018년 11월 14일
x = randi([-50,50],1000,1);
y = randi([-50,50],1000,1);
So I got given a p-code file where I try out points and see if the artefacts are lying below or not.
The range are -50 to 50 on both x and y axis
I want to use random numbers to help me find out the info, but the code I used are only generating intergers. I want to generate random numbers in 4 decimal place covering the range -50 to 50.
  댓글 수: 1
John D'Errico
John D'Errico 2018년 11월 14일
Did you read the help for rand? It gives an explicit example of how to generate random numbers (NOT integers) in a given range from a to b.

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

채택된 답변

Jan
Jan 2018년 11월 14일
편집: Jan 2018년 11월 14일
x = round(-50 + rand(1000,1) * 100, 4);
y = round(-50 + rand(1000,1) * 100, 4);
See: doc rand and doc round .
Alternatively getting the "4 decimal places" can be achieved by this also:
x = randi([-500000, 500000], 1000, 1) / 10000;
y = randi([-500000, 500000], 1000, 1) / 10000;
  댓글 수: 1
fengsen huang
fengsen huang 2018년 11월 14일
thank you very much, I see you can just use more digit

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by