필터 지우기
필터 지우기

Creating a diagonal matrix

조회 수: 2 (최근 30일)
Gratitude Kim
Gratitude Kim 2017년 8월 5일
편집: Andrei Bobrov 2017년 8월 6일
I will like to create such diagonal matrix. A=[1 1 1 0 0 0; 0 1 1 1 0 0; 0 0 1 1 1 0; 0 0 0 1 1 1] Appreciate your kind assitance.

답변 (4개)

Matt J
Matt J 2017년 8월 5일
A=conv2(eye(4),[1,1,1])

John D'Errico
John D'Errico 2017년 8월 5일
편집: John D'Errico 2017년 8월 5일
That is not a diagonal matrix, not by the common definition of the term. It has non-zero diagonals, but that is as far as I might go.
Still trivial though.
triu(tril(ones(4,6),2))
ans =
1 1 1 0 0 0
0 1 1 1 0 0
0 0 1 1 1 0
0 0 0 1 1 1
Or...
toeplitz([1 0 0 0]',[1 1 1 0 0 0])
ans =
1 1 1 0 0 0
0 1 1 1 0 0
0 0 1 1 1 0
0 0 0 1 1 1

Andrei Bobrov
Andrei Bobrov 2017년 8월 5일
편집: Andrei Bobrov 2017년 8월 6일
full(spdiags(ones(4,3),0:2,4,6))
or
t = true(4,6);
out = tril(t,2) & triu(t)
or
a = triu(ones(4,3));
out = [a,rot90(a,2)]

Matt J
Matt J 2017년 8월 5일
편집: Matt J 2017년 8월 5일
You could also use interpMatrix ( Download ) in a somewhat weird way,
A=full( interpMatrix( [1,1,1] , 1,4,1,'allcontrib') )

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by