MATLAB Answers

Sum the values of one column based on another column in Table

7 views (last 30 days)
khaled elbatawy
khaled elbatawy on 9 Aug 2020
Commented: KSSV on 9 Aug 2020
Hello , I am new with Matlab and i need help with this Problem .
I have Table of 4 columns and i want to sum the Values in the first column which are corresponds to the similar Values in the second Column.
for example depend on the table below i want to for Range = 862.33 ---> count total = 15
and i do not want it specific for one table , the values in the table can be changed
thank you in advance
Count Range Mean Start End
_____ ______ ______ _____ _____
1 862.33 579.3 168 334
1 862.33 579.3 668 834
1 862.33 579.31 1334 1501
1 864.55 580.42 1168 1668
1 862.33 579.3 2168 2334
1 1012.7 506.35 1834 2001
1 1012.7 506.35 501 1001
1 862.33 579.3 2668 2834
1 862.33 579.31 3501 3668
1 864.55 580.42 3168 3334
1 862.33 579.3 4168 4334
1 1012.7 506.35 3834 4001
1 1012.7 506.35 2501 3001
1 862.33 579.3 4668 4834
1 862.33 579.31 5334 5501
1 864.55 580.42 5168 5668
1 1012.7 506.35 5001 5834
1 862.33 579.3 6168 6334
1 1012.7 506.35 4501 6001
1 862.33 579.3 6668 6834
1 862.33 579.31 7334 7501
1 864.55 580.42 7168 7668
1 862.33 579.3 8168 8334
1 1012.7 506.35 7834 8001
1 1012.7 506.35 6501 7001
1 862.33 579.3 8668 8834
1 862.33 579.31 9334 9501
1 864.55 580.42 9168 9668
0.5 1012.7 506.35 1 8501
0.5 1012.7 506.36 8501 9001
0.5 1012.7 506.35 9001 9834
0.5 1012.7 506.36 9834 10001

  0 Comments

Sign in to comment.

Answers (1)

KSSV
KSSV on 9 Aug 2020
Let T be your table.
R = T.Range ;
val = 862.33 ;
count = nnz(abs(R-val)<=10^-5)

  2 Comments

khaled elbatawy
khaled elbatawy on 9 Aug 2020
thank you for your answer , it helped but still the problem for me , the count for every value in the table , i have created this loop for it
it worked but need not to repeat the counting for the same Values kind of merge all the same value with specific accuracy and the correspond count for each
dsigma_l = [];
n_cyc_t=[];
R = T.Range ;
n_cyc = T.Count;
for l = 1:length(R)
val = R(l) ;
for q=1:length(n_cyc)
count = nnz((abs(R-val)/val)<=10^-5);
end
n_cyc_t=[n_cyc_t count];
dsigma_l = [dsigma_l R(l)];
end
KSSV
KSSV on 9 Aug 2020
May be you are looking for:
R = T.Range ;
[val,ia,ib= = unique ;
N = length(val) ;
count = zeros(N,1) ;
for i = 1:N
count(i) = nnz(abs(R-val(i))<=10^-5);
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by