Determining the total value of the number in each position of a matrix that corresponds to another same length matrix
Show older comments
Let's say i have a column vector medals = [1;1;5;7;3;1] and i have another column vector year = [2007;2009;2011;2018;2007;2007] and each of the element in 'year' corresponds to the matrix 'medals'. Eg: in 2007,i have 5 medals because year(1) ,year(5) and year(6) are 2007, and the total medals i won is 1+3+1 How do i find the total medals won for each of the year?
Accepted Answer
More Answers (1)
KSSV
on 3 May 2018
medals = [1;1;5;7;3;1] ;
year = [2007;2009;2011;2018;2007;2007] ;
[c,ia,ib] = unique(year) ;
iwant=sum(medals(ib==1))
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!