Calculating PDF from data set
49 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hazem Al-Bulqini
el 14 de Sept. de 2020
Comentada: Star Strider
el 14 de Sept. de 2020
I have a random variable k whose size is (1000*1), I want to draw a PDF curve for its values over a range x.
I tried this line:
pdf_normal = pdf('Normal',k,x);
But it return an array all of its values are NaN.
How can I fix that? or is there another way to get what I want?
Note:
k and x have the same size.
0 comentarios
Respuesta aceptada
Star Strider
el 14 de Sept. de 2020
That is likely not the appropriate initial function. The fitdist function would likely do what you want. Then, use the pdf function on the output of fitdist.
Example —
k = randn(1000,1); % Create ‘k’
x = linspace(-5,5); % Create ‘x’
pd = fitdist(k, 'Normal');
y = pdf(pd,x);
figure
plot(x, y)
grid
xlabel('x')
ylabel('PDF')
.
4 comentarios
Star Strider
el 14 de Sept. de 2020
The problem here is that fitdist will not accept an empty argument (my first approach was to simply set those cells to []), so in order to make it compatible, I set the NaN cells to eps. (You can set them to something else if you want to.) You can then trap them and eliminate them before sending them to fitdist.
To reset the NaN cells:
for k1 = 1:size(B,2)
Bidx = cellfun(@(x)~isnan(x), B{k1}, 'UniformOutput',0);
for k2 = 1:size(Bidx,2)
if all(Bidx{k2} == 0)
Bnew{k1}{k2} = cell2mat(Bidx(k2))+eps;
else
Bnew{k1}{k2} = B{k1}{cell2mat(Bidx(k2))};
end
end
end
That appears to work with the test cell array I created to test my code.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
