How do I print probability distribution object into textbox?

2 ビュー (過去 30 日間)
Vadim Patrick Nave
Vadim Patrick Nave 2021 年 4 月 5 日
I got this information from the fitdist function:
Normal distribution
mu = 9.39507 [9.28818, 9.50196]
sigma = 1.52947 [1.45755, 1.60892]
How can I save it into string and print it in a textbox that is located on a figure plot?
Thank you very much dear users, great month and stay safe.

回答 (2 件)

darova
darova 2021 年 4 月 6 日
Here
pd = makedist('Normal');
sig1 = pd.sigma
mu1 = pd.mu
  3 件のコメント
darova
darova 2021 年 4 月 6 日
I know nothing about this. Can you show the code?
Vadim Patrick Nave
Vadim Patrick Nave 2021 年 4 月 6 日
clear all;
%prompt = 'Please enter your file name ';
%name = input(prompt)
T = readtable('results.csv'); %read csv and turn it to a table
a=T; %easier variable
b=a(:,2); %choosing column 2
c=table2array(b); %turning column 2 into an array
d=sqrt((4.*c)/pi); %doing the diameter formula on the area
e=array2table(d); %going back into table format
max=max(d); %find maximum diameter
min=min(d); %find minimum diameter
avg=mean(d); %find average
std=std(d); %find std
a{:, 6} = d; %printing diameter
a{1,7}= max; %printing max diameter
a{1,8}= min; %printing min diameter
a{1,9}= avg; %printing avg diameter
a{1,10}=std; %printing std of the diameters
cdim=ceil(max); %rounding maximum diameter up
cr=linspace(0,cdim,cdim+1); %creating an array of diameters with limit as maximum diameter rounded up
cra=cr.'; %turning array into vertical array
a{1:cdim+1,11}=cra; %printing array into column
a{1,12}=0;
a.Properties.VariableNames = {'Numbers', 'Area','Mean','Min area','Max area','Diameter','Max d ','Min d','Average','Std','Bin Limits','Frequency'};
edges = unique(d); %finding all numbers needed to count from (diameter)
tg=ceil(edges); %rounding up all the diameters to make spaces between lower and higher
binc = [0:cdim];%borders to count
counts = histcounts(d(:),binc);%count of numbers
res = [counts]; %variable of counts
resv=res.'; %turn it to a column
a{2:cdim+1,12}=resv; %print it into the table
X=a{:,12};%Creating vectors from 12 column
Y=a{:,11};%Creating vectors from 11 column
h=height(a);
pd=fitdist(d,'Normal')
figure
subplot(1,2,1)
ploti=plot(Y,X,'b-o') %plot
grid on %plot
grid minor %plot
xlabel('Diameter (in nm)') %plot
ylabel('Frequency') %plot
x = d;
pd = makedist('Normal');
sig1 = pd.sigma
mu1 = pd.mu
histfit (x);
subplot(1,2,2)
%plot(d,y);
dim = [.2 .5 .3 .3];
str={'fml',num2str(sig1),' Minimum particle diameter= ',num2str(min),' Maximum particle diameter= ',num2str(max),' Total number of particles= ',num2str(h) };
%annotation('textbox',dim,'String',str)
annotation('textbox',dim,'String',str,'FitBoxToText','on');
writetable(a,'results_edited_by_matlab.csv'); %out csv file
saveas(ploti,'ploti.jpg'); %saving figure as jpg file
savefig('ploti'); %saving figure to customize it later

サインインしてコメントする。


Steven Lord
Steven Lord 2021 年 4 月 6 日
Since you're using release R2021a you can use the new formattedDisplayText function.
x = randn(1e6, 1);
pd = fitdist(x,'Normal')
pd =
NormalDistribution Normal distribution mu = -0.000150048 [-0.00210869, 0.00180859] sigma = 0.999324 [0.997941, 1.00071]
S = formattedDisplayText(pd)
S =
" NormalDistribution Normal distribution mu = -0.000150048 [-0.00210869, 0.00180859] sigma = 0.999324 [0.997941, 1.00071] "
  2 件のコメント
Vadim Patrick Nave
Vadim Patrick Nave 2021 年 4 月 6 日
No problem, I will try it in several hours when I will be home, thank you
Vadim Patrick Nave
Vadim Patrick Nave 2021 年 4 月 8 日
Well, unfortunately although the MATLAB version in my computer is 2021, the university have the r2020a and not 2021, so I have to use a different method because a lot of work done there, do you have another idea?

サインインしてコメントする。

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by