How can I get data from histogram ?

23 ビュー (過去 30 日間)
Tania Islam
Tania Islam 2019 年 12 月 13 日
コメント済み: Tania Islam 2019 年 12 月 16 日
Hi,
I want a CDF curve from my dataset. For that, at first I am plotting the dataset into histogram using histogram function. My dataset contain error of times of 1000 samples. Among 1000, we may have only distinct 200 values (others are repetition, so I want the numbe of occurrance of each values). Thats why I plot them to histogram to get the values and the propbabaility of the values.
Priviously I was using %[counts_5_10, centers_5_10] = hist(data);. This code was fine for me. How can I get this information from the new histogram function?
In the previous code I cannot fixed the binwidth.
Following is my old and new code.
I cannot extract the X-axes dataset (unique values among the 1000)
old code:
%[counts_5_10, centers_5_10] = hist(data);
probability=counts_L_7(1,:)/1000;
CDF=cumsum(probability/sum(probability));
New code:
h = histogram(data,'BinWidth',0.005);
N= h.Values% repetition of number of error values
Edges = h.BinEdges% this is the error values
probability=N/1000;
CDF=cumsum(probability./sum(probability));

採用された回答

Ridwan Alam
Ridwan Alam 2019 年 12 月 13 日
編集済み: Ridwan Alam 2019 年 12 月 13 日
I believe you are looking for histcounts() instead of histogram().
[counts, centers] = histcounts(data,'BinWidth',0.005);
probability=counts/1000; % =counts/sum(counts);
CDF=cumsum(probability/sum(probability));
Btw, if you don't need probability, the CDF can be directly calculated as follows:
[CDF, centers] = histcounts(data,'BinWidth',0.005,'normalization','cdf');
  9 件のコメント
Ridwan Alam
Ridwan Alam 2019 年 12 月 14 日
編集済み: Ridwan Alam 2019 年 12 月 15 日
Adding Adam's suggestion to the answer:
BinWidth = 0.005;
[CDF, edges] = histcounts(data,'BinWidth',BinWidth,'normalization','cdf'); % feel free to use the other solution using 'counts'
centers = edges(2:end) - BinWidth/2;
% with this 'centers' will have the same size as CDF.
Tania Islam
Tania Islam 2019 年 12 月 16 日
Thank you so much for your kind suggestions and time.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by