To estimate the probability density function of a random variable, the kernel density estimation algorithm can be used. To do this, you can use the “ksdensity” function in MATLAB - https://www.mathworks.com/help/stats/ksdensity.html#:~:text=ksdensity(x)%20returns%20a%20probability%20density%20estimate%2C%20f%2C%20for%20the%20sample%20data%20in%20the%20vector%20or%20two%2Dcolumn%20matrix%20x.
Hope this helps!