Hi !
I have this kind of matrix :
A=[1 2 3 4 5 6 7 8 9 10]
And I would like to transform it in this way:
B=[0 1 2 3 4 ; 0 0 5 6 7 ; 0 0 0 8 9 ; 0 0 0 0 10 ; 0 0 0 0 0]
I am looking for a simple method to do it, may you help me please ?

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 10 日
編集済み: Walter Roberson 2021 年 2 月 10 日

0 投票

fiddle with
B = zeros(5)
B(tril(B,-1)==1) = A;
I posted exact code about two weeks ago. Needs a couple of flips.

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2021 年 2 月 10 日

1 投票

B=zeros(5);
B(tril(true(5),-1))=A
B=B'

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by