필터 지우기
필터 지우기

Generating random numbers in order?

조회 수: 14 (최근 30일)
Joe
Joe 2013년 4월 7일
댓글: Walter Roberson 2021년 12월 9일
How would you generate random numbers so that they are in ascending or descending order? Is there a way to create a function similar to linspace in that it generates linearly spaced values in a certain interval but with random numbers each time you execute the function?

채택된 답변

Roger Stafford
Roger Stafford 2013년 4월 7일
If a and b are the lower and upper limits you have in mind for the numbers, do this:
x = sort((b-a)*rand(n,1)+a,'ascend' or 'descend');

추가 답변 (1개)

NIKHIL KUMAR
NIKHIL KUMAR 2021년 12월 9일
x = sort((10-1)*rand(n,1)+1,'ascend' or 'descend');
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 12월 9일
This is the same as what Roger suggested in 2013.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by