フィルターのクリア

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) ?

採用された回答

Sean de Wolski
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 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by