Plotting a graph on MATLAB
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am new to matlab and i am trying to plot a graph to do with the birthday paradox. The problem i am having is that when i try to plot the graph of number of people against probability i get one dot in the middle. Even when moving the plot function inside the for loop the plot is still wrong.
this my output but it goes to 100%:
this is my current plot which is wrong:
here's my code:
% Write your code here:
%Inputs
tic;
nPeopleMax=200;
R=50;
%Randomizing
count=0; %counts the number of times atleast one birthday matches
for k=1:R
M=randi(365,nPeopleMax,1);
Sets=nchoosek(M,2);
for i=1:size(Sets,1)
if(Sets(i,1)==Sets(i,2))
count=count+1;
Probability=(count/R)*100;
plot(nPeopleMax,Probability, '.');
disp(['The Probability is ',num2str(Probability), ' %']);
break
end
end
end
toc;
0 Commenti
Risposte (1)
Doddy Kastanya
il 11 Gen 2021
In order to see more "dots", you need to add "hold on" on the line after plot. However, since you want to plot it against the number of people, you might want to use "nPeopleMax" in the plot, since the value will always be 200. Good luck.
0 Commenti
Vedere anche
Categorie
Scopri di più su Birthdays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!