i dont get why it says Unrecognized function or variable 'Nbin when i run it

4 ビュー (過去 30 日間)
Tasos Apostolopoulos
Tasos Apostolopoulos 2022 年 1 月 26 日
コメント済み: Torsten 2022 年 1 月 26 日
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 件のコメント
Torsten
Torsten 2022 年 1 月 26 日
Yes, you must give a value to Nbin when you call "hist".

サインインしてコメントする。

回答 (1 件)

Mike Croucher
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)')

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by