2017-05-07 27 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