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

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.

 Akzeptierte Antwort

Kevin Phung
Kevin Phung am 21 Jan. 2019
Bearbeitet: Kevin Phung am 21 Jan. 2019
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 Kommentare

Stephen23
Stephen23 am 21 Jan. 2019
Bearbeitet: Stephen23 am 21 Jan. 2019
>> 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
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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Gefragt:

N/A
am 21 Jan. 2019

Kommentiert:

am 21 Jan. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by