フィルターのクリア

Generate random numbers within different range at different position in a matrix

2 ビュー (過去 30 日間)
Suppose i have a 3x3 matrix. I want to generate a random number in each position. The condition is that for every position, the range in which the random number should be generated is different. For example, suppose the range at each position of the 3x3 matrix is like this [4,10,33;40,150,255;10,100,136]. So for position (1,1), the random number should be generated within the range [1,4]. For position (1,2), the range is [1,10] and likewise.
I have already done the coding in a loop for the same. I want to do it without for loop. Can someone offer a matrix level operation for this? [I have tried randi command but i am not able to make it work without loop for this problem].

採用された回答

Matt J
Matt J 2017 年 11 月 19 日
編集済み: Matt J 2017 年 11 月 19 日
R=[4,10,33;40,150,255;10,100,136];
result=ceil( R.*rand(size(R)) );
  1 件のコメント
Murari Mandal
Murari Mandal 2017 年 11 月 19 日
Ya. i did the same thing after posting the question. Thank you!

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

その他の回答 (0 件)

カテゴリ

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