필터 지우기
필터 지우기

create a matrix with ones and zeros

조회 수: 1 (최근 30일)
Tony Montgomery
Tony Montgomery 2014년 9월 6일
댓글: Tony Montgomery 2014년 9월 6일
in need to create an array of 20-by-20 the first row needs to be 19 ones and 1 zero the first column is all ones the last row is is all ones from the first row first column diagnally to the last row last column needs to be filled with ones, the rest are all zero.
now I can type this all out but there must be a better way
my question is how do i create this array?

채택된 답변

Star Strider
Star Strider 2014년 9월 6일
편집: Star Strider 2014년 9월 6일
This looks like what you want:
a = ones(1,20);
M = diag(a);
M(1,:) = [ones(1,19) 0];
M(:,1) = a';
M(20,:) = a;
  댓글 수: 3
Star Strider
Star Strider 2014년 9월 6일
My pleasure!
I just realised that I could have used ‘a’ in M(1:) as well:
M(1,:) = [a(1:19) 0];
Tony Montgomery
Tony Montgomery 2014년 9월 6일
okay another problem close to the first.
need to create a similar array, but instead add variables.
so for example the last row need to be 19 of variable b and 1 one. how can i do that?

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

추가 답변 (0개)

카테고리

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