How to determine and plot a probability density function?

12 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Jeff Miller
Jeff Miller am 19 Jul. 2018
The discretize function will do most of the job. You may have to play around with it a bit, but something like this should work:
bins = 43.5:1:60.5; % define some bins that cover the range of interest
assignments = discretize(Prices,bins); % get a vector telling you which bin each price is in
% compute how much was sold in each bin
bintotals = zeros(size(bins));
for ibin=1:numel(bins)
bintotals(ibin) = sum(SoldElectricity(assignments==ibin));
end
binprobs = bintotals / sum(bintotals); % compute the proportion of the total in each bin
plot(bins,binprobs);

Weitere Antworten (1)

jonas
jonas am 16 Jul. 2018
Bearbeitet: jonas am 16 Jul. 2018
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 Kommentare
Leon Gutierrez Guerrero
Leon Gutierrez Guerrero am 18 Jul. 2018
Sorry for the misunderstanding, I’m probably confusing concepts. To clarify, I will explain what I need to do with an example I worked out in excel using the vectors mentioned in my first submission: The values of the vector ‘Prices’ goes from $44.22 to $59.07, so I defined 16 bins as follows:
Then I included a column with the total electricity sold at each price range (according to vector ’SoldElectricity’):
And finally, I divided each value of the second column by the total amount of energy sold (13.41926667MWh) to obtain the probability:
The plot of the probability vs price is this:
I did this manually in excel, but I need to do it automatically in Matlab for 8760 values. Thanks for your help!
israt fatema
israt fatema am 18 Mai 2021
Hi Leon, did you find the solution for your problem? Would you mind sharing your solution please?
Thank you.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by