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

조회 수: 68 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by