Create a random Matrix with numbers in a distribution

I need to create a matrix of size (256,1). But each entry should be random one from (0:(0.2pi):2pi). I have written a code but. Is there an easy way to do that ?
function phmatx=randmat()
pixvalue=0:.2*pi:2*pi;
phmatx=zeros(256,1);
for i=1:256
phmatx(i,1)=pixvalue(randperm(11,1));
end
end

 採用された回答

Guillaume
Guillaume 2017 年 9 月 7 日

0 投票

Much simpler:
pixvalue = 0 : 0.2*pi : 2*pi;
phmatx = pixvalue(randi(numel(pixvalue), 256, 1))

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

タグ

質問済み:

2017 年 9 月 7 日

コメント済み:

2017 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by