MATLAB: Making a histogram with two variables in the same graph

barshistogram

I have two variables, z1 and z2, which are two vectors with 1000 enteries. They represent distances calculated by two algoritmes for the traveling salesman problem.
Both vectors have values ranging from roughly 12 000 to 19 000 (km). I want a histogram showing both variables, with bins starting from 12 000 ending at 19 000 with a range of 100 per bin. the variables should both be a different color (lets say z1 red and z2 blue).
How could I do this?

Best Answer

binEdges = 12000:100:19000;
h1 = histogram(z1,binEdges);
hold on
h2 = histogram(z2,binEdges);