I have to create a matrix using only zeros, ones and eye

18 ビュー (過去 30 日間)
N/A
N/A 2019 年 1 月 21 日
コメント済み: Kevin Phung 2019 年 1 月 21 日
This is the matrix:
1 1 1 1 1
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
so far I wrote B=ones(1,5); C=eye(4,5); A=[B;C]
But this command didn't come out right. Can someone please help me.

採用された回答

Kevin Phung
Kevin Phung 2019 年 1 月 21 日
編集済み: Kevin Phung 2019 年 1 月 21 日
your command A = [B;C] concatenated them vertically.
Try:
C = eye(5)
C(1,:) = 1; % turns every element along the first row to 1.
  2 件のコメント
Stephen23
Stephen23 2019 年 1 月 21 日
編集済み: Stephen23 2019 年 1 月 21 日
>> C = eye(5);
>> C(1,:) = 1
C =
1 1 1 1 1
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Kevin Phung
Kevin Phung 2019 年 1 月 21 日
I would like to clarify that I made the exact same changes right before I saw your comment!
Originally I had something like
C(1,:) = B;

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

その他の回答 (1 件)

Rob Purser
Rob Purser 2019 年 1 月 21 日
A = eye(5);
A(1,:) = ones(1,5);

カテゴリ

Help Center および File ExchangeDesign and Simulate SerDes Systems についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by