2017-05-07 32 views
0

我有下面的代碼,生成一個15塊的矩陣,然後將它用作蒙特卡羅方法中的多個起點。我怎樣才能以更聰明的方式獲得同樣精確的結果?Matlab:高效代碼部分,隨機啓動

假設J = 15 * 100是總的模擬和paramNum參數

[10^-10*ones(paramNum,round(J/15)) 10^-9*ones(paramNum,round(J/15)) 10^-8*ones(paramNum,round(J/15)) 10^-7*ones(paramNum,round(J/15)) 10^-6*ones(paramNum,round(J/15)) 10^-5*ones(paramNum,round(J/15)) rand*10^-5*ones(paramNum,round(J/15)) 10^-4*ones(paramNum,round(J/15)) rand*10^-4*ones(paramNum,round(J/15)) 10^-3*ones(paramNum,round(J/15)) 10^-2*ones(paramNum,round(J/15)) 10^-1*ones(paramNum,round(J/15)) 10^-abs(randn/2)*ones(paramNum,round(J/15))]; 

回答

0

數量,你可以做

v = 10.^[-10:-5 rand*10^-5 -4:-1 10^-abs(randn/2)]; 
repmat(repelem(v, 1, round(J/15)), paramNum) .* ... 
repmat(ones(paramNum,round(J/15)), numel(v)) 

或用一個for循環模擬repmat/repelem功能。第一個更短,後者更容易理解。

順便說一句......這是不到15塊......

+0

感謝它給了我一個錯誤:矩陣必須同意 – Thegamer23