필터 지우기
필터 지우기

Help with random in Matlab 2007b

조회 수: 2 (최근 30일)
Cristian
Cristian 2012년 11월 24일
Hi, I need to take a value. The string can be from 1 to 10 billion for example, doesn't matter how many values are there, I need to take just 1 that is completely random.
I have tried randi and randsample and they are not working, can you please point me in the right direction ?
Thank you!

채택된 답변

Matt Fig
Matt Fig 2012년 11월 24일
편집: Matt Fig 2012년 11월 24일
Those functions did not exist in ver 2007b. Use this:
% Create a random number drawn from 1 to 10
A = ceil(rand*10);
You can also write your own version of the RANDI function if you need to do so.
  댓글 수: 2
Cristian
Cristian 2012년 11월 24일
I don't need my own function, I just have to take a simple number. Thank you, will try it.
Image Analyst
Image Analyst 2012년 11월 24일
편집: Image Analyst 2012년 11월 24일
Then just do this:
myRandomNumber = uint64(ceil(1e10*rand))
note that you'll need uint64 data class to get integers more than about 4.29 billion because
>> intmax('uint32')
ans =
4294967295
>> intmax('uint64')
ans =
18446744073709551615
and any numbers that you use that integer with will also have to be uint64 also.

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

추가 답변 (0개)

카테고리

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