我想创建一个图表,它会显示模拟产生的所有路径,然后在t = T点将其转换为水平直方图,显示最终结果的频率。
这可以在Matlab的一个图表中完成吗?
答案 0 :(得分:1)
我不认为有一种非常好的方法可以做到这一点,但我设法将一些与你描述的相似的东西混在一起。请参阅下面的示例,其中包含随机游走的蒙特卡罗模拟。
% 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] ;
它不漂亮但它有效。结果: