필터 지우기
필터 지우기

Generate random numbers within a range?

조회 수: 2 (최근 30일)
Matrix-Matlab
Matrix-Matlab 2017년 3월 5일
댓글: John D'Errico 2017년 3월 5일
Hello everyone.
I am new to Matlab and therefore have a few questions regarding generation of random numbers.
My task is to randomly generate numbers for age between 18 and 121 - we need 11000 numbers. Afterwards we need to figure out male and female (0 is females) which I'm having difficulties with.
I know I have to use rand function but I cant figure out how to complete these tasks.
Can someone please help me with some guidance for this? Thank you in advance.
Kind regards, Emil
  댓글 수: 1
John D'Errico
John D'Errico 2017년 3월 5일
Read the help for rand. Do so CAREFULLY. If necessary, do so twice. Look at the examples given in
doc rand
Your vague question about males and females is impossible to even try to answer, because there is no real question there.
So spend some time actually learning MATLAB. Read the help. My guess is, you need to read the getting started tutorials first.

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

답변 (1개)

Image Analyst
Image Analyst 2017년 3월 5일
Emil, try this:
rInteger = randi([18,121], 1, 11000) % Whole numbers.
rFloating = 18 + (121-18) * rand(1, 11000) % Includes fractional parts

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by