What is the best vectorized way to construct the following matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a vector variable of size nx1 I want to construct a square nxn matrix from this vector. The first column of the matrix is the vector itself. The second column is the vector itself but with the first element set to zero. The ith column of the matrix is constructed from the vector by setting the first i-1 entries to zero...
So we get is a lower triangular matrix with the diagonal = to the given vector.
ex: given
g = [1 2 3 4];
Construct
G = [1 0 0 0;
2 2 0 0;
3 3 3 0;
4 4 4 4;];
댓글 수: 0
채택된 답변
Star Strider
2015년 2월 26일
편집: Star Strider
2015년 2월 26일
This works:
G = tril(repmat([1:4]', 1, 4));
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!