Я не может генерировать гистограмму в Matlab с помощью массиване в состоянии генерировать гистограмму в MATLAB, используя массив
% initialising the five arrays to hold the averages of five probabilities of interests
ar1=zeros(1,100);
ar2=zeros(1,100);
ar3=zeros(1,100);
ar4=zeros(1,100);
ar5=zeros(1,100);
%initialising the variable to count the number of experiments
k=1;
while k<=100,
%generating the required random numbers for the proble
%pi is the probablity in winning the ith game
p1=rand(1);
p2=rand(1)*p1;
p3=rand(1)*p2;
p4=rand(1)*p3;
%initialising variable to count the number of tournaments
count_tour=1;
%initialising the variables in order to get the sum of all probabilties of interests and then we can get our respective averages
t1=0; t2=0; t3=0; t4=0; t5=0;
%starting the loop for 50 tournaments
while count_tour<=50,
%Total probabilties of winning the ith game
W1=p1;
W2=p1*(1+p2-p1);
W3=(p1*p2*p3)+((p1*p1)*(2-p1-p2))+((p4)*(1-p1)*(1-p1));
%probabilty that player had won the first game given that he won the second game
W4=(p1*p2)/W2;
%probabilty of winning all three games
W5=p1*p2*p3;
%getting the sum of all probabilies in 50 tournaments
t1=t1+W1;
t2=t2+W2;
t3=t3+W3;
t4=t4+W4;
t5=t5+W5;
count_tour=count_tour+1;
end
%getting the averages of probabilties of interest in 50 tournaments
av1=t1/50;
av2=t2/50;
av3=t3/50;
av4=t4/50;
av5=t5/50;
ar1(k)=ar1(k)+av1;
ar2(k)=ar2(k)+av2;
ar3(k)=ar3(k)+av3;
ar4(k)=ar4(k)+av4;
ar5(k)=ar5(k)+av5;
k=k+1;
end
figure();
h1=histogram(ar1);
h2=histogram(ar2);
h3=histogram(ar3);
h4=histogram(ar4);
h5=histogram(ar5);
Когда я запускаю свой код, как я получаю гистограмму' ar5', что то, что я бы ожидать. Поэтому вам, вероятно, нужно более четко объяснить свою цель. – EBH