Plotting a graph on MATLAB
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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%:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/485253/image.jpeg)
this is my current plot which is wrong:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/485258/image.jpeg)
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 comentarios
Respuestas (1)
Doddy Kastanya
el 11 de En. de 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 comentarios
Ver también
Categorías
Más información sobre Birthdays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!