필터 지우기
필터 지우기

Repeating elements in a matrix.

조회 수: 1 (최근 30일)
Gratitude Kim
Gratitude Kim 2017년 7월 27일
댓글: Gratitude Kim 2017년 7월 27일
A=zeros(3,4)
A =
0 0 0 0
0 0 0 0
0 0 0 0
>> [nRows,nCols] = size(A); A(1:(nRows+1):nRows*nCols) = 1
A =
1 0 0 0
0 1 0 0
0 0 1 0
Appreciate your kind assistance on how can I write so that my matrix becomes :
A=[1 1 0 0; 0 1 1 0; 0 0 1 1]
Thanks

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 7월 27일
편집: Andrei Bobrov 2017년 7월 27일
A=zeros(3,4);
n = size(A,1);
A([1:n+1:end,n+1:n+1:end]) = 1
or
t = true(3,4);
out = tril(t,1) & triu(t);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Power and Energy Systems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by