Randomly create lower and upper of matrix separately.

조회 수: 43 (최근 30일)
Abe
Abe 2014년 12월 28일
댓글: Abe 2014년 12월 28일
I would like to create a randomly lower triangle of the matrix, and then create an upper triangle of matrix separately. After that I want to compound both of these in one matrix. More deeply, I want to control each cell in both half matrix.
  댓글 수: 3
John D'Errico
John D'Errico 2014년 12월 28일
What do you mean to "control each cell"?
You can always access any element of a matrix.
Abe
Abe 2014년 12월 28일
I meant above, I want to create a random number in each cell of the lower - matrix, and then separately do the same with upper-matrix. The conclusion will be I have 1/2 of matrix (Upper matrix) generated alone, and the other half (lower matrix) generated lonely too. So when add the 2 halves I see one matrix with keeping the same generated numbers. I hope now it's clear. Thank you for asking.

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

채택된 답변

Shoaibur Rahman
Shoaibur Rahman 2014년 12월 28일
l = tril(rand(m,n),-1); % lower triangle
u = triu(rand(m,n),1); % upper triangle
d = diag(rand(1,m),0); % diagonal elements
A = l+u+d % final matrix, combined all
If you don't want to generate the diagonal elements separately, then replace either -1 in lower triangle or 1 in upper triangle by 0, and then A = l+u
  댓글 수: 1
Abe
Abe 2014년 12월 28일
Thanks a lot, it's working with me right now

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by