无需循环:
N = 100000;
t = 1:N;
x = cumsum(2*(rand(1,N)<.5)-1);
plot(t,x)
对于2D情况,您可以使用相同的方法:
N = 100000;
%// t = 1:N; it won't be used in the plot, so not needed
x = cumsum(2*(rand(1,N)<.5)-1);
y = cumsum(2*(rand(1,N)<.5)-1);
plot(x,y)
axis square
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句