clear all;
T = readtable('All results.csv'); %read csv and turn it to a table
%The file name is changeable, put your filename instead of BTC-30002-1 results.csv
a=T; %easier variable
b=a(:,2); %choosing column 2 
c=table2array(b); %turning column 2 into an array
% If using circular particles area as input from column 2, put
% d=sqrt((4.*c)/pi) instead of d=c; and for any other shape use area
% formula accordingly
d=c; %For size but not diameter
e=array2table(d); %going back into table format
max=max(d); %find maximum size
min=min(d); %find minimum size
avg=mean(d); %find average
std=std(d); %find std
a{:, 6} = d; %printing size
a{1,7}= max; %printing max size
a{1,8}= min; %printing min size
a{1,9}= avg; %printing avg size
a{1,10}=std; %printing std of the size
cdim=ceil(max); %rounding maximum size up
cr=linspace(0,cdim,cdim+1); %creating an array of sizes with limit as maximum size 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', 'Length','Mean','Min length','Max length','Size','Max d ','Min d','Average','Std','Bin Limits','Frequency'};
edges = unique(d); %finding all numbers needed to count from (size)
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);
fig=figure
p1=subplot(1,3,1)
ploti=plot(Y,X,'b-o') %plot
x = d;
histfit (x);
pd = fitdist(x,'Normal');
y =  pdf(pd,d);
title('Particle Size Distribution') % TITLE OF LEFT PLOT
xlabel(p1,'Size (nm)') % X LABEL OF LEFT PLOT
ylabel(p1,'Counts') % Y LABEL OF LEFT PLOT
p2=subplot(1,3,2)
ploti1=plot(d,y);
title('Normalized PDF') % TITLE OF RIGHT PLOT
xlabel(p2,'Size (nm)') % X LABEL OF RIGHT PLOT
ylabel(p2,'Probability') % Y LABEL OF RIGHT PLOT
dim = [0.7 0.5 0.3 0.3];
str={'Average Size= ', num2str(avg),'Std. Dvtn.= ',num2str(std),'Minimum particle size= ',num2str(min),'Maximum particle size= ',num2str(max),'Total number of particles= ',num2str(h) };
annotation('textbox',dim,'String',str,'FitBoxToText','on');
 set(fig, 'PaperUnits', 'inches'); %
 x_width=9.25; ;y_width=7.125;
 set(gcf, 'PaperPosition', [0 0 x_width y_width]); %
 saveas(fig,'Results.jpg')
fprintf('Please contact Vadim Nave by Linkedin or nave9595@gmail.com for suggestions and changes in the script')