The other day I was doing a Monte Carlo analysis where I had two independent varables and one scalar output. A good visualization for this is a two dimensional histogram. Unfortunatly, these are not directly supported in MATLAB, but thankfully Kangwon Lee has developed one and shared it with the rest of us.
This code came with a good example, and was well documented. These things are often overlooked (Hint, Hint Hint), so I am glad to see they were done this time.
This is the code I used to create the screenshot you see here, mostly a de-generalization of the example with a more intuitive dataset:
N = 160000;
nBins = 30;
z = randn(N, 2);
edges = linspace(-1,1,nBins);
mHist2d = hist2d(z,edges,edges);
edgeLabel = 0.5*(edges(1:end-1)+edges(2:end));
pcolor(edgeLabel, edgeLabel,mHist2d);
colormap(pink); colorbar
title('2d hist of two normally distributed random variables')
By
Doug Hull
Doug first used MATLAB in 1994, could not figure it out until he got some help in 1995. He is now dedicated to making sure that no one else wastes a year of their life not knowing MATLAB like he did.
Recent Comments