Matrix with some sort of pattern

조회 수: 2 (최근 30일)
Andreas
Andreas 2013년 4월 24일
이동: Matt J 2022년 11월 17일
Hi everybody, i would like to make a matrices like this [1,1,1,1,1,0,0,0,0,0;0,0,0,0,0,1,1,1,1,1;] or this [-1 0 0;-1 0 0;-1 0 0;-1 -1 0;-1 -1 0; -1 -1 0;-1 -1 -1;-1 -1 -1;-1 -1 -1] in such a way that 'for' loop would be unnecessary.i was thinking something about repmat or so,because of the pattern that this kind of matrices seem to have.any ideas??? Thank you!!

채택된 답변

Matt J
Matt J 2013년 4월 24일
You could use KRON
>> kron(eye(2), ones(1,5))
>> kron(tril(ones(3)),-ones(3,1))
  댓글 수: 2
Andreas
Andreas 2013년 4월 24일
이동: Matt J 2022년 11월 17일
Matt J. YOU are amazing. Thanx.
Mishaal Amir
Mishaal Amir 2022년 11월 17일
How to do this for an 9 by 9 matrix, with the number 9s surrounding the borders and the 0s in the center of the matrix?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by