How to generate a random number from a matris

1 回表示 (過去 30 日間)
Mohammad
Mohammad 2023 年 1 月 6 日
編集済み: Rik 2023 年 1 月 6 日
%%we crate a matrix like this and we whant to generate a random number from matrix that made i dont know how!
Y=randi([0,300],[1,500];
  2 件のコメント
Rik
Rik 2023 年 1 月 6 日
So you want to select a number at random from the array Y? Or do you simply want to generate some random number?
Mohammad
Mohammad 2023 年 1 月 6 日
移動済み: Rik 2023 年 1 月 6 日

I whant to genarate a number randomly from y bro

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

回答 (1 件)

Rik
Rik 2023 年 1 月 6 日
編集済み: Rik 2023 年 1 月 6 日
If you want to select a number randomly from Y, you can use randi directly to index:
Y=randi([0,300],[1,500]);
RandomScalar=Y(randi(end))
RandomScalar = 266
This works because randi(imax) will generate a number between 1 and imax. The end keyword can be used to automatically determine the last position in the array.

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by