How can I add zeros between elements of a matrix?
    27 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have a vector [1,2,3];
and I want to obtain [1,0,2,0,3,0];
How can this be achieved?
0 comentarios
Respuestas (2)
  Stephen23
      
      
 el 31 de Ag. de 2020
        >> A = [1,2,3];
Method one: indexing:
>> B = zeros(size(A).*[1,2]);
>> B(1:2:end) = A
B =
   1   0   2   0   3   0
Method two: reshape:
>> B = A;
>> B(2,:) = 0;
>> B = B(:).'
B =
   1   0   2   0   3   0
0 comentarios
Ver también
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!


