Create a random Matrix with numbers in a distribution
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Guillaume
2017년 9월 7일
Much simpler:
pixvalue = 0 : 0.2*pi : 2*pi;
phmatx = pixvalue(randi(numel(pixvalue), 256, 1))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!