What does x=randint(1,1,[1,n]); ?

60 ビュー (過去 30 日間)
Jenny
Jenny 2018 年 1 月 9 日
移動済み: Rik 2022 年 9 月 26 日
What does x=randint(1,1,[1,n]); ?

採用された回答

M
M 2018 年 1 月 9 日
I may be wrong, but I think randint was part of the Communication System Toolbox and its functionality has been replaced by the randi function, for which you can find details here .
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 9 日
Correct. randint(1,1,[1,n]) would now be written as randi([1,n],1,1)
Jenny
Jenny 2018 年 1 月 10 日
Thank you.

サインインしてコメントする。

その他の回答 (3 件)

pankaj singh
pankaj singh 2018 年 3 月 10 日
Please note that randint is an obsolete function in the Matlab. You can use randi instead.
randint generates the matrix of uniformly distributed random integers. e.g.
out = randint(M,N);
generates M-by-N matrix of random binary numbers, i.e., 0 and 1 occur with equal probability.
Your example is similar to
out = randint(M,N,[IRANGE(1), IRANGE(2)]]);
where an M-by-N matrix is generated and the elements of the matrix will be in the range mentioned in the square brackets.
Therefore,
x=randint(1,1,[1,n]);
will generate a 1-by-1 matrix or just a number within the range [1, n], where n can be any integer.

DHRUVIN SUTHAR
DHRUVIN SUTHAR 2019 年 7 月 13 日
Hi, I wanted to genrate the single random value in between 5 to 10 and I am trying to use randint function as a randi but I getting an error. could anyone please suggest me any idea?
x =randi(1,1,[5,10]); but I am getting an error "Error using randi;
Size inputs must be scalar."
  5 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 23 日
randint(1,ndata*col,M)
would return a 1 x (ndata*col) row vector in which each element was an integer in the range [0 M-1]
The more modern equivalent would be
randi([0 M-1], 1, ndata*col)
pankaj singh
pankaj singh 2022 年 9 月 26 日
Thanks a lot

サインインしてコメントする。


Zeeshan Ahmad
Zeeshan Ahmad 2020 年 4 月 19 日
Randint is no more working, you have to use randi but it will make difference,
like if you are writing randint(9600,1)
now for randi you have to write randi(1,9600)
  3 件のコメント
Zeeshan Ahmad
Zeeshan Ahmad 2020 年 4 月 19 日
bother let take a example. randi(1,9600) will generate the data of 9600x9600
and randi(9600,1) will give you any single value, (between 0-9600) for example on first run it gate me 5860
now to come to your point.
your ans was correct as "randint(1,1,[1,n]) would now be written as randi([1,n],1,1)"
i was just giving an example to new people who take code from mathworks and cant run it in advance versions.
Walter Roberson
Walter Roberson 2020 年 4 月 19 日
randi(9600,1) will give you any single value, (between 0-9600)
This is a difference between randi and randint. randi(9600,1) would give you a single value in the range 1 to 9600, whereas randint(9600,1) would give you 9600 values in the range 0 to 1, and randint(1,1,9600) would give you a single value in the range 0 to 9599, but randint(1,1,[1 9600]) would give you a single value in the range 1 to 9600.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by