Effacer les filtres
Effacer les filtres

Placing Blocks of fixed size to random positions in a bigger matrix

1 vue (au cours des 30 derniers jours)
Bharathwaj
Bharathwaj le 16 Nov 2011
How do you place a smaller matrix(block) of fixed size in a bigger matrix at random positions?
  1 commentaire
Bharathwaj
Bharathwaj le 25 Nov 2011
what if the placement of the smaller blocks should not overlap with the existing blocks ?

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 16 Nov 2011
M = zeros(5)
m = randi(4,3)
sM = size(M);
sm = size(m);
k=sM-sm+1;
iM = reshape(1:numel(M),sM(1),[]);
iw = iM(1:k(1),1:k(2));
im = bsxfun(@plus,(0:sm(1)-1).',0:sM(1):sM(1)*(sm(2)-1));
M(iw(randi(numel(m)))+im) = m

Plus de réponses (1)

Fangjun Jiang
Fangjun Jiang le 16 Nov 2011
a=rand(3);
A=magic(10);
[m,n]=size(a);
[M,N]=size(A);
i=floor((M-m)*rand)+1;
j=floor((N-n)*rand)+1;
A(i+1:i+m,j+1:j+n)=a
  1 commentaire
Bharathwaj
Bharathwaj le 25 Nov 2011
what if the placement of the smaller blocks should not overlap with the existing blocks ?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by