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
Luca Morena
Luca Morena 2023년 5월 30일
I only needed to take a and b out of fitdist, this works! thanks!
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