看板 MATLAB 關於我們 聯絡資訊
程式碼如下: j=6; a=2; b=3; random = unidrnd(b,1,a); random = repmat(random,j,1); random = random(:); randnum = rand(b,j); str=repmat('B',a*j,1); secnum=repmat(1:a,j,1); secnum=secnum(:); thirdnum=repmat(1:j,1,a)'; temp=cellstr([str,num2str(random),num2str(secnum),num2str(thirdnum)]); class7=regexprep(temp,' ',''); B=10*randnum(sub2ind([b,j],random,thirdnum)); 這段是別人幫我寫的 目前會產生一段a*j的均勻亂數值 想請問的是如果我把randnum = rand(b,j);這段 改成randnum = randn(b,j); 這樣就應該是常態分配了.......吧 如果不是請指正 另外如果是的話 該怎麼讓產生的常態分配亂數沒有負值呢? 謝謝好心的大大 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.54.170 ※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1464884870.A.377.html
celestialgod: randn產生出來的亂數直接加絕對值就好了吧 06/03 01:30
ljuyentintho: 加絕對值output就不是常態了 06/03 01:32
sin55688: 平移? 06/03 12:31
ljuyentintho: 我是這樣想的 但不知平移多少 06/03 18:27
celestialgod: 喔喔 我誤會你意思了 我以為你要half normal 06/03 20:01
celestialgod: 變異數是1的話 平移4小於0的機率是0.00003 06/03 20:02
celestialgod: 4.5是0.000003,5是0.0000003 看你大概要什麼範圍 06/03 20:02
celestialgod: 不幸出現零就重抽 重抽機率低 06/03 20:03
celestialgod: 這樣也不完全是常態就是 大概只有尾部一點點 06/03 20:03
celestialgod: 不然你就要找truncated normal了 06/03 20:03
simon552614: truncated normal 剛好之前上課寫過 06/04 02:05