How to determine and plot a probability density function?
Show older comments
I have a vector (8760 x 1) with the hourly electricity prices in a network and another vector (8760 x 1) with the quantity of electricity sold in each hour. I want to know how to get and plot the probability density function of that data. As an example, here are the first eleven elements of each vector:
Prices = [44.2200; 45.1300; 46.2300; 47.9100; 49.5700; 48.6900; 47.2000; 46.5100; 46.5200; 51.5900; 59.0700];
SoldElectricity = [0; 0; 0; 2.1255; 1.9807; 1.8474; 1.0561; 0; 0; 0.3586; 6.0510];
And I want to get a plot like this as a result:

(In the image three different sold electricity vectors were plotted, in my case, I only need to plot one) Any help would be appreciated, thanks!
Accepted Answer
More Answers (1)
You can use the following function form the statistics toolbox
ksdensity(SoldElectricity)
Note that the function outputs a non-parameteric estimate, which may not be desirable. A purely empirical pdf can be designed using histograms
histogram(SoldElectricity,'Normalization','pdf','displaystyle','stairs','binmethod','integers')
See attachment for results
5 Comments
Leon Gutierrez Guerrero
on 17 Jul 2018
Jeff Miller
on 18 Jul 2018
The plot that you said you wanted (i.e., with Probability Density on the vertical axis) does not relate two vectors either. Can you give a better example of the plot you want--something showing probability density as a function of both prices and quantity? It sounds like you really want a bivariate density.
jonas
on 18 Jul 2018
As Jeff Miller has already commented, that makes little sense and is not what you asked in the original submission. Please clarify what your desired output is.
Leon Gutierrez Guerrero
on 18 Jul 2018
israt fatema
on 18 May 2021
Hi Leon, did you find the solution for your problem? Would you mind sharing your solution please?
Thank you.
Categories
Find more on Noncentral t Distribution in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


