i have this two functions how can i plot them together

2 次查看(过去 30 天)
Length=100000
mu=10
sigma=1
X=sigma*randn(Length,1)+mu;
plot(X)
histogram(X)
grid on
n=100
[f,x]=hist(X,n)
bar(x,f/trapz(x,f));hold off;
g = (1/(sqrt(2*pi)*sigma))*exp(-((x-mu).^2)/(2*sigma^2))
plot(X,g) ;hold on ;grid on
can anyone help me please , i don't where is my mistake , my final output should look like the attached picture

回答(1 个)

Brattv
Brattv 2016-4-21
Hi, Your problem is the last line plot(X,g). You are saying that you have a vector g with 100 point, that you want to plot versus a vector X with 100 000 points. Do the following
Use the histogram bin centers from "x" to find the first and last bin in the histogram. You wanted to plot a function with 100 points, which means that you find the step by finding the difference of the first and last bin and divide by 100.
if true
% Find the first and last valye
plotStep = (x(end) - x(1))/100;
% The steps put into a vector
lengthVect = x(1)+plotStep:plotStep:x(end);
% Plotting.
plot(lengthVect,g) ;hold on ;grid on
end

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by