How can I save "alpha" and "beta" parameters as double using fitdist command?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Luca Morena
le 29 Mai 2023
Commenté : Image Analyst
le 30 Mai 2023
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!
0 commentaires
Réponse acceptée
the cyclist
le 29 Mai 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')
parameterValues = pd.ParameterValues
2 commentaires
Image Analyst
le 30 Mai 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.
Plus de réponses (1)
Image Analyst
le 29 Mai 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.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!