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 Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by