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

1 次查看(过去 30 天)
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!

采纳的回答

the cyclist
the cyclist 2023-5-29
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 个评论
Image Analyst
Image Analyst 2023-5-30
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2023-5-29
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.

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by