Repeating elements in a matrix.

2 ビュー (過去 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);
  1 件のコメント
Gratitude Kim
Gratitude Kim 2017 年 7 月 27 日
Noted with thanks. =)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by