Transform a matrix in a special way

조회 수: 4 (최근 30일)
Baptiste Charrier
Baptiste Charrier 2021년 2월 10일
답변: Fangjun Jiang 2021년 2월 10일
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일
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일
B=zeros(5);
B(tril(true(5),-1))=A
B=B'

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by