Computing CDF????
Mostrar comentarios más antiguos
Hi all,
Does anyone of you know how to calculate cdf plot using following data sets:
A = [10 10 10 5 3 3 3 2 0]; B = [10 10 10 5 5 3 3 2 2 2 1 0]; how can obtain cdf from A and B?
Best Regards Talha
Respuesta aceptada
Más respuestas (4)
Image Analyst
el 19 de Dic. de 2011
Try this code. It's actually just two calls - one to hist() and one to cumsum(), but it's a full-fledged demo with all kinds of fancy plotting and does it for both A and B, so it looks long and complicated but it's actually not. (It only took about 3 minutes to code up this demo). Don't be afraid - just copy, paste, and run:
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
A = [10 10 10 5 3 3 3 2 0];
B = [10 10 10 5 5 3 3 2 2 2 1 0];
% Compute the histogram of A and B.
[countsA, binsA] = hist(A);
[countsB, binsB] = hist(B);
% Compute the cumulative distribution function of A and B.
cdfA = cumsum(countsA) / sum(countsA);
cdfB = cumsum(countsB) / sum(countsB);
% Plot the probability distribution of A.
subplot(2,2, 1);
bar(binsA, countsA);
title('Histogram of A', 'FontSize', fontSize);
ylabel('Count A', 'FontSize', fontSize);
xlabel('Values of A', 'FontSize', fontSize);
grid on;
% Plot the probability distribution of B.
subplot(2,2, 2);
bar(binsB, countsB);
title('Histogram of B', 'FontSize', fontSize);
ylabel('Count B', 'FontSize', fontSize);
xlabel('Values of B', 'FontSize', fontSize);
grid on;
% Plot the cumulative distribution function of A.
subplot(2,2, 3);
bar(binsA, cdfA); % You can use plot() if you want to.
title('CDF of A', 'FontSize', fontSize);
grid on;
ylabel('Percentage A (/100)', 'FontSize', fontSize);
xlabel('Values of A', 'FontSize', fontSize);
% Plot the cumulative distribution function of B.
subplot(2,2, 4);
bar(binsB, cdfB); % You can use plot() if you want to.
title('CDF of B', 'FontSize', fontSize);
ylabel('Percentage B (/100)', 'FontSize', fontSize);
xlabel('Values of B', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
Talha Rahman
el 19 de Dic. de 2011
0 votos
Ssssssss fffgffggg
el 9 de Jul. de 2017
0 votos
how to plot exp cdf with histogram?????
2 comentarios
Ssssssss fffgffggg
el 9 de Jul. de 2017
rand(1,10000)
Image Analyst
el 9 de Jul. de 2017
This does not answer the original poster's question. To get a CDF and histogram they should call cumsum() and histogram(), not rand(). Anyway, they posted it 6 years ago so it's likely they don't need an answer anymore, despite the fact that they never accepted the answer that was offered.
Camilo Malagon Nieto
el 30 de Mayo de 2018
Editada: Camilo Malagon Nieto
el 30 de Mayo de 2018
This will be my answer:
There is not a function that automatically takes a data vector and creates a vector with CDF values.
You need first to see your data by plotting it with a histogram
hist(X)
then use the distribution tool to see what distributions may suit your data
disttool
then use the distribution fitting tool to see how that distribution actually fits your data
dfittool
Then create a new distribution Object that fits your data
NewDist=fitdist(X,'Normal');
Than use the new distibution to plot the CDF
cdfplot(NewDist)
if you need values from the CDF you will have to create a values vector and the values to plot and get the CDFs for them
t=0:0,1:10;
Xcdf = cdf(NewDist,t);
Then you can plot the same
plot(t,Xcdf);
1 comentario
Camilo Malagon Nieto
el 30 de Mayo de 2018
Worth to notice that the data provided by the question does not have statistical meaning due to the poor amount of samples.
Categorías
Más información sobre Exploration and Visualization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!