Effacer les filtres
Effacer les filtres

Printing counts result into table in the right order

1 vue (au cours des 30 derniers jours)
Vadim Patrick Nave
Vadim Patrick Nave le 4 Jan 2021
T = readtable('original26.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 avarage
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
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
%counts = histc(d(:), tg) %count the how much numbers are rounded
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{1:cdim,12}=resv %print it into the table
writetable(a,'edited26.csv') %out csv file
The NaN that I marked should be 8 and before it the number should be 53, there is a shift downwards and I can't understand why, possible very easy and stupid reason. This is my expected result in the two right columns:
Thank you and a happy new year.
  3 commentaires
Vadim Patrick Nave
Vadim Patrick Nave le 4 Jan 2021
First of all thank you for your kind answer,
Second - I think it does - in column 7 line 1 it printed me a numeric value...(same for the next columns)
Walter Roberson
Walter Roberson le 5 Jan 2021
You already have a shift by row 3 -- the last column you want to start with three 0 but it only starts with two zero.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Jan 2021
Your expectation is wrong.
Look at row 1 column 8, which you write in min(d) into. It is 2.5948 . Your max is 13.something and your cdim = ceil() of that is 14. So your histc bins are 0:14 . You histcounts() using 0:14 as the bins. The first bin is going to count values in [0,1) and the second bin is going to count values in [1,2) and the third bin is going to count values in [2,3) . We have seen that min() is 2.5948 so there is at least one value in [2,3) so the third bin would have to have a count of at least 1. Your table of expected values shows that you expect to have a count of 0 there. Therefore your expected values are wrong.
As the counts you get and the counts you expect are otherwise in agreement, the easiest resolution is to say that your expectation starts with one too many 0 and that the actual counts you get are correct.
With the maximum being 13.something, that is going to be counted in the 14th bin, which is the one in the row that has 13 in the second last column. The 15th bin, the one labeled 14 in your expectations, would be for values in the range [14,15) but no such values exist. So your expectation of a non-0 or non-nan value in that slot are wrong.
  1 commentaire
Vadim Patrick Nave
Vadim Patrick Nave le 5 Jan 2021
As I said - it indeed was something stupid and I'm so thankfull for you to point this mistake to me!
Thank you very very much Boss!
Have a grate day!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by