필터 지우기
필터 지우기

Creating a diagonal matrix

조회 수: 3 (최근 30일)
Gratitude Kim
Gratitude Kim 2017년 8월 1일
답변: Andrei Bobrov 2017년 8월 5일
Hi, I have written such codes.
Col=4;
Row=3
A1=zeros(Row,Col);
n = size(A1,1);
A1([1:n+1:end,n+1:n+1:end]) = 1
Output:
A1 =
1 1 0 0
0 1 1 0
0 0 1 1
I obtained output A1. Appreciate if you are able to help me to modify the code so it can become [1 1 1 0; 0 1 1 1]. Appreciate your kind assistance.
  댓글 수: 1
Guillaume
Guillaume 2017년 8월 1일
It's unclear what you're asking. Wouldn't
A1 = [1 1 1 0; 0 1 1 1]
answer your question?
Note that your code makes a 3x4 matrix whereas you're now asking for a 2x4 matrix.

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2017년 8월 1일
A1(3:end,:) = []

Andrei Bobrov
Andrei Bobrov 2017년 8월 5일
t = true(2,4);
out = tril(t,2) & triu(t);

카테고리

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