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일

0 개 추천

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일
Yes, thats perfect.
I suppose I can run a for loop that would produce n randomly generated matrices?
Yes
n = 4 ;
bounds = [10 20] ; % [a b ]
for ii = 1:n
randA = diag(diag(randi(bounds, 3,3)))
end
randA = 3×3
20 0 0 0 19 0 0 0 11
randA = 3×3
10 0 0 0 18 0 0 0 15
randA = 3×3
12 0 0 0 14 0 0 0 13
randA = 3×3
17 0 0 0 12 0 0 0 12
N/A
N/A 2022년 7월 29일
Appreciate your help (and genius) greatly.
Matthew
Abderrahim. B
Abderrahim. B 2022년 7월 30일
My pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

N/A
2022년 7월 29일

댓글:

2022년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by