i dont get why it says Unrecognized function or variable 'Nbin when i run it
조회 수: 4 (최근 30일)
이전 댓글 표시
clear
clc
clf
sum1=0;
N = 10000;
xx=0:0.01:19;
y1=(xx/2.89).*exp(-xx.^2/5.78);
plot(xx,y1,'b','linewidth',3)
hold on
y=rand(1,N); %y=0:0.01:19;
x=1.7*sqrt(-2*log(y));
sum1=sum1+x;
plot(x,y,'r','linewidth',3)
hold on %den petuxenoume siglisi ton 2 diagramaton
mesi_timi_theoritiki=sqrt((pi*2.89)/2);
mesi_timi_peiramatiki=sum1/N;% oi peiramatiki mesi timi einai migadikis morfhs
x=katanomi1(N);
[count,center]=hist(x,Nbin);
Delta=center(2)-center(1);
pithanotita=count/N;
piknotita=pithanotita/Delta;
hold on
plot(center,piknotita,'ro','linewidth',3)
hold off
set(gca,'frontsize',16)
xlabel('Τιμές της τυχαίας μεταβλητής')
ylabel('Πυκνότητα πιθανότητας')
title('Συνάρτηση πυκνότητας πιθανότητας (pdf)')
댓글 수: 1
답변 (1개)
Mike Croucher
2022년 1월 26일
편집: Mike Croucher
2022년 1월 26일
It's because you have this line
[count,center]=hist(x,Nbin);
Nbin needs to be defined as the number of bins you want in the histogram and you have not defined it.
Try this:
clear
clc
clf
sum1=0;
N = 10000;
Nbin = 10; % Number of bins for histogram
xx=0:0.01:19;
y1=(xx/2.89).*exp(-xx.^2/5.78);
plot(xx,y1,'b','linewidth',3)
hold on
y=rand(1,N); %y=0:0.01:19;
x=1.7*sqrt(-2*log(y));
sum1=sum1+x;
plot(x,y,'r','linewidth',3)
hold on %den petuxenoume siglisi ton 2 diagramaton
mesi_timi_theoritiki=sqrt((pi*2.89)/2);
mesi_timi_peiramatiki=sum1/N;% oi peiramatiki mesi timi einai migadikis morfhs
x=katanomi1(N);
[count,center]=hist(x,Nbin);
Delta=center(2)-center(1);
pithanotita=count/N;
piknotita=pithanotita/Delta;
hold on
plot(center,piknotita,'ro','linewidth',3)
hold off
set(gca,'frontsize',16)
xlabel('Τιμές της τυχαίας μεταβλητής')
ylabel('Πυκνότητα πιθανότητας')
title('Συνάρτηση πυκνότητας πιθανότητας (pdf)')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!