Hello, This is a screenshot of a table I have constructed for work.
Just to play it safe, I blacked out the column names, though it would be hard to assume anything with just 7 rows of the table to go off of. We will call the 5 fields "column1, column2, etc."
So I am able to create the hisogram of any of the columns, besides 3, but that isn't needed because it is all '94'.
I do:
histogram([a(1:135756).column1])
and the histogram works perfectly.
How would I do a CDF or PDF of this data?
I have tried:
histogram([a(1:135756).column1],'Normalization',pdf)
or
histogram([a(1:135756).column1],'Normalization',cdf)
but nothing changes from the original histogram.
Thank you!

 채택된 답변

Bruno Luong
Bruno Luong 2020년 8월 24일
편집: Bruno Luong 2020년 8월 24일

1 개 추천

A=[a(1:135756).column1];
figure
subplot(2,1,1);
histogram(A,'Normalization','pdf');
ylabel('pdf');
subplot(2,1,2);
histogram(A,'Normalization','cdf');
ylabel('cdf');

추가 답변 (1개)

Alan Stevens
Alan Stevens 2020년 8월 24일

0 개 추천

You can get a CDF as follows:
% Modified Kaplan-Meier CDF
% assumes each point is representative of 1/N of the population.
a = sort(a(:,1)); % so all the data for a are sorted in ascending order
N = length(a);
for k = 1:N
CDF(k) = (k - 0.5)/N;
end
plot(a,CDF)
Because you have a large number of points you could simply numerically differentiate the CDF to get a PDF.

댓글 수: 4

Sclay748
Sclay748 2020년 8월 24일
hi Alan, I got an error for using sort. Says incorrect argument data type in call to function 'sort'.
Alan Stevens
Alan Stevens 2020년 8월 24일
I've asumed a is just a column vector. If it's a different structure of some sort you will need either to convert it to a simple vector, or find some way of sorting the more complicated structure.
Hmm it cries for replacing the for-loop
a1 = sort([a(1:135756).column1]);
N = length(a1);
CDF = (0.5:N-0.5) / N;
plot(a1, CDF);
Sclay748
Sclay748 2020년 8월 24일
편집: Sclay748 2020년 8월 24일
Bruno, that worked. Is it supposed to be a single curved line?
I thought it would still plot the bars, but arranged by CDF. Or that is atleast how my boss's turned out when he showed me an example using histogram(......,'Normalization',cdf)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 8월 24일

댓글:

2020년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by