how can i place an array a= [2,2,2] randomly (vertically or horizontally) into a matrix b=zeros(10x10) ?
조회 수: 2 (최근 30일)
이전 댓글 표시
how can i place an array a= [2,2,2] randomly (vertically or horizontally) into a matrix b=zeros(10x10) ?
댓글 수: 0
채택된 답변
Sean de Wolski
2013년 11월 26일
%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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!