MATLAB: Placing Blocks of fixed size to random positions in a bigger matrix block processingrandom How do you place a smaller matrix(block) of fixed size in a bigger matrix at random positions? Best Answer 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 Related SolutionsMATLAB: Image contrast estimation. How to speed up this code meanImage = conv2(double(grayImage), ones(9)/81, 'same');stdImage = stdfilt(grayImage, true(9));C = meanImage ./ stdImage; MATLAB: How to compare one column of one matrix with all columms of other matrix one by one? matlab 2014b R2016b or later:N - permute(M, [1 3 2])Pre-R2016b:bsxfun(@minus, N, permute(M, [1 3 2]))will give you a 7x8x8 matrix where each (:, i, j) is N(:, i) - M(:, j) Related QuestionHow to choose a random coordinate (location like i,j) in a matrixHow to split a 3D matrix in two volumes separated by an arbitrary planeSUBS function not working properly – R2020aHow to vectorize the following code snippetNeed help in indexing
Best Answer