Random number generator for matrix

5 ビュー (過去 30 日間)
N/A
N/A 2022 年 7 月 29 日
コメント済み: Abderrahim. B 2022 年 7 月 30 日
My goal is to create a random number generator for a matrix of size 3x3, for n matrices (meaning as many n matrices as I designate) that will produce random numbers within the bounds [a,b] for the main diagonal of the matrix (elements 11, 22 and 33 in the matrix).
I invision the random generator, as described above, to generate a sample of something like:
matrix 1:
[2, 0, 0;
0, 90, 0;
0 , 0 ,1]
matrix 2:
[3, 0, 0;
0, 12, 0;
0 , 0 ,63]
matrix 3:..
matrix n
I appreciate any and all help with this.

採用された回答

Abderrahim. B
Abderrahim. B 2022 年 7 月 29 日
編集済み: Abderrahim. B 2022 年 7 月 29 日
Hi!
Perhaps this:
bounds = [10 20] ; % [a b ]
randA = diag(diag(randi(bounds, 3,3)))
randA = 3×3
13 0 0 0 13 0 0 0 19
Hope this helps
  4 件のコメント
N/A
N/A 2022 年 7 月 29 日
Appreciate your help (and genius) greatly.
Matthew
Abderrahim. B
Abderrahim. B 2022 年 7 月 30 日
My pleasure!

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

その他の回答 (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