Matrix with some sort of pattern

5 visualizaciones (últimos 30 días)
Andreas
Andreas el 24 de Abr. de 2013
Movida: Matt J el 17 de Nov. de 2022
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!!

Respuesta aceptada

Matt J
Matt J el 24 de Abr. de 2013
You could use KRON
>> kron(eye(2), ones(1,5))
>> kron(tril(ones(3)),-ones(3,1))
  2 comentarios
Andreas
Andreas el 24 de Abr. de 2013
Movida: Matt J el 17 de Nov. de 2022
Matt J. YOU are amazing. Thanx.
Mishaal Amir
Mishaal Amir el 17 de Nov. de 2022
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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by