Matlab - 如何在一个图表中绘制 monte carlo 路径转换为水平直方图

Matlab - how to plot monte carlo paths transforming into horizontal histogram in one chart

我想创建一个图表来显示模拟产生的所有路径,然后在 t=T 点将其转换为显示最终结果频率的水平直方图。

这可以在 Matlab 的一张图表中完成吗?

我不认为有一个很好的方法来做到这一点,但我设法拼凑了一些看起来与您描述的相似的东西。请参阅下面我的示例,其中包含随机游走的 Monte Carlo 模拟。

% Setup, create test data
col = [0 0.2 0.741] ; % colour
rng(0) ; % reset random number seed

n = 20 ; % number of bins
Te = 1000 ; % simulation length
T = 600 ; % length of trajectory to plot
X = cumsum(randn(Te,1)) ;

丑陋的剧情代码:

% create histogram based on the end of the sample
[H,C] = hist(X(T+1:Te),n) ;

% new figure
fh = figure(999) ;
clf() ;

% trajectory for the first part of the sample
ax0 = subplot(1,2,1) ;
lh = plot(X(1:T),'Parent',ax0) ;
lh.Color = col ;

% histogram for the second part of the sample
ax1 = subplot(1,2,2) ;
bh = barh(ax1,C,H,1) ;
bh.EdgeColor = col ;
bh.FaceColor = col ;
ax1.XTickLabel = '' ;
ax1.YTickLabel = '' ;

% make both axes have the same YLim property and make sure we don't clip anything
YLim(2) = max(ax0.YLim(2),ax1.YLim(2)) ;
YLim(1) = min(ax0.YLim(1),ax1.YLim(1)) ;
ax1.YLim = YLim ;
linkaxes([ax1,ax0],'y') ;

% bump the axes together
ax0.Position = [0.13 0.11 0.440552147239264 0.815] ;

虽然不漂亮,但很管用。结果: