Simple help needed with identity matrices and selection

조회 수: 3 (최근 30일)
Tanner
Tanner 2014년 9월 9일
편집: José-Luis 2014년 9월 9일
I'm just starting out in MATLAB and doing some homework for a class. What I'm trying to do is select the top-right and bottom-left quadrants of a 6x6 identity matrix and turn those smaller quadrants into identity matrices of themselves without inputting the elements individually. This is the best I could come up with, but clearly the quadrants I'm trying to select just turn into ones instead of identity matrices.
>> A=eye(6,6)
A =
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
>> A(1:3,4:6)=eye; A(4:6,1:3)=eye
A =
1 0 0 1 1 1
0 1 0 1 1 1
0 0 1 1 1 1
1 1 1 1 0 0
1 1 1 0 1 0
1 1 1 0 0 1
any help would be greatly appreciated!
  댓글 수: 1
Tanner
Tanner 2014년 9월 9일
Nevermind I just figured it out! If anyone is wondering the problem was that in my second command I should have input:
>>A(1:3,4:6)=eye(3,3);A(4:6,1:3)=eye(3,3)

댓글을 달려면 로그인하십시오.

답변 (1개)

José-Luis
José-Luis 2014년 9월 9일
편집: José-Luis 2014년 9월 9일
Almost there:
A=eye(6,6);
A(1:3,4:6)=eye(3); A(4:6,1:3)=eye(3);
eye without arguments returns 1.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by