What is the best vectorized way to construct the following matrix

4 ビュー (過去 30 日間)
Mohamed Abdalmoaty
Mohamed Abdalmoaty 2015 年 2 月 26 日
編集済み: Star Strider 2015 年 2 月 26 日
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;];

採用された回答

Star Strider
Star Strider 2015 年 2 月 26 日
編集済み: Star Strider 2015 年 2 月 26 日
This works:
G = tril(repmat([1:4]', 1, 4));

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