From: adam on
It's a bit embarassing^^ I've just relised, that the problem with Hist, Hold on and Plot was just that I never saw the function because it was all the way at the bottom...

So I've solved the problem now.

Thanks a lot to both of you for your help!
From: Andrew on
I see that others answered your question in the time it took me to type this. Oh well. Here's my reply anyways.

%%%%%%%%%
What exactly do you want on your x-axis? In your histogram, the xlabels will be bins that correspond to the 'y-values' of your data, and the y-axis corresponds to the count. What should the x-axis of you plot() be?

You could fudge the plot by scaling the values on to correspond with your bins:

hf = figure;
ha = axes;

hist_data_x = 1:100;
hist_data_y = 10*rand(size(hist_data_x)); % 100 random data point between 0 and 10
[n, xbins] = hist(hist_data_y); % use default of ten bins
bar(ha, xbins, n);

plot_data_x = linspace(-pi, pi, 40);
plot_data_y = sin(plot_data_x);
x_scale = max(xbins);
y_scale = max(n);

% shift plot data to zero and rescale
hold(ha, 'all');
plot(ha, ...
(plot_data_x - min(plot_data_x))/range(plot_data_x) * x_scale, ...
(plot_data_y - min(plot_data_y))/range(plot_data_y) * y_scale, ...
'linewidth', 2, 'color', 'r');


You could also write something similar to plotyy and have data going into two different axes ha1 and ha2 on the same figure hf.