How Can i sum same values in an arry untill it change to a diffrent number and sum these aswell
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
w.s.
el 28 de Nov. de 2016
Comentada: w.s.
el 29 de Nov. de 2016
So lets say this is the matrix
TeamPasses = 26 25 25 25 25 26 26 26 26 25 25 25 25 26 26 26 25 25 25 25 26 26 26 25 25 26 26 26 26 26
for example, 25 is team 1 and 26 is team 2. Every time a player passes a ball during possession a 25 or 26 is written down. I want to know the amount of passes during possession. so how can I sum 25 until it changes in 26 and sum these aswell?
Thanks
2 comentarios
Respuesta aceptada
bio lim
el 28 de Nov. de 2016
TeamPasses = [26 25 25 25 25 26 26 26 26 25 25 25 25 26 26 26 25 25 25 25 26 26 26 25 25 26 26 26 26 26];
coffee = find(diff([-1 TeamPasses -1]) ~= 0);
length = diff(coffee);
team1 = length(1+(TeamPasses(1)==25):2:end)';
team2 = length(1+(TeamPasses(1)==26):2:end)';
Output:
team1 =
1
4
3
3
5
team2 =
4
4
4
2
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!