Special matrix with zeros and ones

5 visualizaciones (últimos 30 días)
ABDULAZIZ
ABDULAZIZ el 6 de Mzo. de 2015
Editada: ABDULAZIZ el 6 de Mzo. de 2015
Hello Everyone,
I have a special matrix and can not create it in faster way
The example of a matrix is as follows:
m=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1]
I can build it up by using ones and zeros, but it will take me a long time to do that, specially when I have a very big matrix.
Thanks in advance.
  2 comentarios
Jan
Jan el 6 de Mzo. de 2015
I've formatted your code.
James Tursa
James Tursa el 6 de Mzo. de 2015
It's going to take us even longer unless we know the pattern rules. Can you explain a bit more about what the pattern is for a "very big matrix"?

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 6 de Mzo. de 2015
Editada: Jan el 6 de Mzo. de 2015
Are you looking for kron?
kron(eye(4), ones(1, 4))
kron is not efficient. This might be faster, but less nice:
n = 4;
ind = repmat(n, 1, n*n-1);
ind(n:n:n*n-1) = n + 1;
M = zeros(n, n*n);
M(cumsum([1, ind])) = 1;

Más respuestas (2)

Rodney Buller
Rodney Buller el 6 de Mzo. de 2015
Have you given this a try?
m=zero[4 16] m(1,1:4)=1; m(2,5:8)=1; m(3,9:12)=1; m(4,13:16)=1;
Assign a matrix as large as you need then, assigning values afterwards. variable(row,column)=assignment val
  1 comentario
ABDULAZIZ
ABDULAZIZ el 6 de Mzo. de 2015
Editada: ABDULAZIZ el 6 de Mzo. de 2015
Thank you,
This answer is correct , but it will take too much time for data entry when I have a very big matrix. Thanks again for your effort

Iniciar sesión para comentar.


ABDULAZIZ
ABDULAZIZ el 6 de Mzo. de 2015
Thanks Jan Yes 100%, that what I have been looking for. Thank you very so much.

Categorías

Más información sobre Creating and Concatenating 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