how can i place an array a= [2,2,2] randomly (vertically or horizontally) into a matrix b=zeros(10x10) ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
roshan varkey
el 26 de Nov. de 2013
Respondida: Sean de Wolski
el 26 de Nov. de 2013
how can i place an array a= [2,2,2] randomly (vertically or horizontally) into a matrix b=zeros(10x10) ?
0 comentarios
Respuesta aceptada
Sean de Wolski
el 26 de Nov. de 2013
%Sizes:
nz = 10;
z = zeros(nz);
a = [2 2 2];
na = numel(a);
%Engine:
dim = rand>0.5; %do we transpose
pos = randi(nz-na+1,[1 2]); %where?
z(pos(1):pos(1)+na-1,pos(2)) = a; %insert
if dim
z = z.';
end
0 comentarios
Más respuestas (0)
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!