How can I save "alpha" and "beta" parameters as double using fitdist command?

2 visualizaciones (últimos 30 días)
Hi everyone,
I'm having problems when trying to save "alpha" and "beta" parameters when using the fitdist command.
CC is a vector of 1000 elements, I need to save a and b. I need this because I have 50 vectors for which I need to find the beta distribution that better represent my distribution of 1000 elements, and I would like to use a loop to automatically save in a .txt or .xlxs file all those a and b values. but PD is a betaDistribution object and I encounter some errors when trying to take a and b out of PD. In the Beta probability distribution object Matlab page, I can't find the command to save a and b. Of course one option would be to save them manually.
Thanks in advance,
Have a nice day!

Respuesta aceptada

the cyclist
the cyclist el 29 de Mayo de 2023
I'm not sure what part is giving you trouble. Here is how to pull the parameter values out of the distribution object. (The full double-precision value is extracted, but only significant figures after the decimal are displayed.)
The variable parameterValues can then be saved to file.
load patients
x = Weight;
pd = fitdist(x/max(x),'Beta')
pd =
BetaDistribution Beta distribution a = 3.37624 [2.35993, 4.83022] b = 0.961082 [0.905778, 1.01976]
parameterValues = pd.ParameterValues
parameterValues = 1×2
3.3762 0.9611
  2 comentarios
Luca Morena
Luca Morena el 30 de Mayo de 2023
I only needed to take a and b out of fitdist, this works! thanks!
Image Analyst
Image Analyst el 30 de Mayo de 2023
You can get those directly, as I showed below. Plus you need to put them into an array because you said you have 50 files that you have to do this for. I also showed that below. I also showed how to save all 50 of them to a file with writetable.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 29 de Mayo de 2023
Try this (untested):
% Preallocate a and b column vectors. One element for each file.
a = zeros(50, 1);
b = zeros(50, 1);
% Get distributions from 50 files.
for k = 1 : 50 % for all 50 files
% Get distribution for this file
pd = fitdist(x/max(x),'Beta')
% Extract a and b values from the output and store them in column vectors.
a(k) = pd.a
b(k) = pd.b
end
% Create table from the two column vectors:
t = table(a, b, 'VariableNames', {'a', 'b'})
% Write table out to disk:
writetable(t, 'ab.xlsx')
Adapt as needed.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by