Matlab difference between normalized histogram and pdf I don't understand why there is a difference between the pdf and the normalized histogram (based on randn) I plotted in matlab. Especially from -2 to -3 the difference is huge.

Why is the normalized histogram so far of from the ideal pdf?  
Here is my code:  
q = [-3:6/99:3]; % x-Axis
f_q = (1/sqrt(2*pi*1))*exp(-0.5*((q-0)/1).^2); % Gauss pdf

n_in = 100;
y = randn(1,10000);
[n x] = hist(y,n_in); % hist func
n_norm = (n ./length(y)) ./(x(2)-x(1)); % normalize hist func
figure;
subplot(3,1,1);
plot(q,f_q);
title('Gauss-WDF')

subplot(3,1,2);
histogram(y,'Normalization', 'pdf');
title('Histogram-func');

subplot(3,1,3);
plot(q,n_norm);
title('hist-func');

EDIT:
Plot with exually distributed axis.

The histogram is based on a normal distributed random function.
So it should follow the pdf of a normal distribution. But apparently it doesn't as you can obviously see. I don't understand why.
 A: If you look carefully, plots 1 and 2 are essentially the same. You've plotted them on different axes, which obfuscates things, but the probability densities at the peaks are essentially identical (roughly 0.4), and the tails of the distributions are roughly the same.
Now, it should be obvious that a pdf and a histogram won't match exactly, since the pdf is an exact expression for the probability density, and a normalized histogram is an empirical distribution formed by sampling the pdf a finite number of times (in your case, 10000). For more details, see this excellent answer
You are correct that plot 3 is different from plots 1 and 2. But that's because you attempted to write your own code for normalizing the histogram instead of using the built-in function (as you did in plot 2), and your code has a bug!
The first line of your code constructs a vector q that goes from -3 to 3. The MATLAB function hist returns bin centers as well as bin counts. In your case, the bin centers are x, and the bin counts are n. After normalizing, n becomes n_norm. When you plot the histogram, you should plot n_norm against x. Instead, you plot n_norm against q. The problem is that x ends up spanning a much larger range than q, since it extends from the smallest number you sample from randn to the largest. (And, 0.3% of values will fall outside the range -3 to 3 for a unit normal.)
When I fix this bug, all three plots look basically the same, except for the jaggedness/wiggles that is inherent to empirical distributions.
So, the lesson is: don't reinvent the wheel. ;-)
