i have this two functions how can i plot them together

1 回表示 (過去 30 日間)
marwa mhd
marwa mhd 2016 年 4 月 21 日
回答済み: Brattv 2016 年 4 月 21 日
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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by