필터 지우기
필터 지우기

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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by