필터 지우기
필터 지우기

How Can i sum same values in an arry untill it change to a diffrent number and sum these aswell

조회 수: 2 (최근 30일)
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
w.s.
w.s. 2016년 11월 28일
I want to count the times 25 goes in a row until 26 is showing. then I want to count 26 until 25 Is showing again.
TeamPasses =
26
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
end
in the end I want to have a new matrix which include
team 2 2
team 1 4
team 2 4
team 1 4
team 2 3
team 1 4
team 2 3
team 1 2
team 2 5
end
more clear now?
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

bio lim
bio lim 2016년 11월 28일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Encryption / Cryptography에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by