Insert "1" at specific ranges in a matrix
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    monkey_matlab
      
 el 27 de Nov. de 2016
  
    
    
    
    
    Editada: Andrei Bobrov
      
      
 el 28 de Nov. de 2016
            Hello,
I am trying to generate a 40 x 360 matrix that has 1's every 9 columns. After the 9th column, the 1's should now be in the second row and from columns 10-18. After the 18th column, the 1's will now be in the 3rd row and from columns 19-27 and so on...
The matrix will look like this:
1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 ...
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 ...
...
Is there an easy way to generate this matrix?
This is what I have so far :-(
aa = zeros(40,360);
bb = ones(1,9);
Thanks for your help!
0 comentarios
Respuesta aceptada
  Image Analyst
      
      
 el 27 de Nov. de 2016
        Here's a way that you may consider "simple":
aa = zeros(40,360);
for row = 1 : size(aa, 1)
  col = 9*(row-1)+1;
  aa(row, col:col+8) = 1;
end
0 comentarios
Más respuestas (1)
  Andrei Bobrov
      
      
 el 28 de Nov. de 2016
        
      Editada: Andrei Bobrov
      
      
 el 28 de Nov. de 2016
  
      z =repmat({ones(1,9)},40,1);
out = blkdiag(z{:});
or
out = kron(eye(40),ones(1,9));
0 comentarios
Ver también
Categorías
				Más información sobre MATLAB Coder en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


