필터 지우기
필터 지우기

How do I select data from an interval in a matrix?

조회 수: 7 (최근 30일)
jakobjakob
jakobjakob 2018년 6월 7일
댓글: Geoff Hayes 2018년 6월 11일
See data in file. I have done research on viewing behavior in football matches. I want to create a graph with the frequency on the y-axis and on the x-axis the viewing behavior over the 10 seconds before the first touch of the ball. I want the viewing behavior in the 10 seconds before the first touch (=aanname) from my matrix. How do I do this?
In other words: I want to have data from a certain interval. There are 240 first touches, so I want a loop that gets all the viewing in one time. Can someone help me? I want to create a matrix with all this viewing behavior.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2018년 6월 7일
jakob - what can you tell us about the columns in the attached file? The first seems to be a timestamp. What kinds of "viewing behaviour" do you measure in the ten seconds before the first touch? Is there a column that describes this?
jakobjakob
jakobjakob 2018년 6월 7일
I'm sorry the file is in dutch. The first collumn is time indeed. The last collumn is about viewing behaviour. It is what they are focusing on, for example a opponent or the goal.

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

답변 (1개)

Geoff Hayes
Geoff Hayes 2018년 6월 8일
jakob - since aanname appears in column five, then you can find the indices (rows) of all of the elements of your data that indicate a "first touch of the ball"
firstTouchOfBallIndices = find(strcmpi(alldata(:,5),'aanname') == 1);
You can then loop over each of these indices to find the timestamp of that first touch of the ball
for k=1:length(firstTouchOfBallIndices)
firstTouchIndex = firstTouchOfBallIndices(k);
firstTouchTimestamp = alldata{firstTouchIndex,1};
end
Then iterate backwards from that index until you have covered the previous ten seconds. For each of those previous records that satisfy that condition, just increment your counter for the viewing behaviour for that record.
There seem to be four viewing behaviours, is this correct?
''
'1/3 (verdediging)'
'2/3 (middenveld)'
'3/3 (aanval)'
(and one record at row 1687 is NaN). So your code could become
load alldata.mat
firstTouchOfBallIndices = find(strcmpi(alldata(:,5),'aanname') == 1);
for k=1:length(firstTouchOfBallIndices)
firstTouchIndex = firstTouchOfBallIndices(k);
firstTouchTimestamp = alldata{firstTouchIndex,1};
j = firstTouchIndex - 1;
while j >= 1 && (firstTouchTimestamp - alldata{j,1}) <= 10.0
viewingBehaviour = alldata{j,6};
j = j - 1;
% increment your counter of viewing behaviours
end
end
Try the above and see what happens!
  댓글 수: 2
jakobjakob
jakobjakob 2018년 6월 8일
편집: jakobjakob 2018년 6월 8일
It doesn't work. BTW the viewing behaviours are in column 9, not in 6. Do you see what is wrong with my script? This is my script. It doesn't count anything. The output I want is the time of the viewing behaviours in the 10sec before the first touch of the ball. That means that the player has to be the same as the player of the first touch. And in column 4 there has to be 'Voor'. Can you help me further?
THIS IS MY SCRIPT
index_aanname = find(strcmp(alldata(:,5), 'Aanname') == 1);
TA = tijdnum(index_aanname);
TA10 = TA - 10;
SA = speler(index_aanname);
%viewing behaviours
bal = 0 ;
medespeler_met_bal = 0 ;
medespeler_zonder_bal = 0 ;
tegenstander = 0 ;
open_ruimte = 0 ;
overzicht_veld = 0 ;
overig = 0 ;
for k = 1:length(index_aanname)
firstTouchIndex = index_aanname(k);
firstTouchTimestamp = alldata{firstTouchIndex,1};
j = firstTouchIndex - 1;
while j >= 1 && (firstTouchTimestamp - alldata{j,1}) <= 10.0
viewingBehaviour = alldata{j,9};
j = j - 1;
if strcmp(kijkrichting(i),'Bal') == 1
bal = bal + 1
elseif strcmp(kijkrichting(i),'Medespeler met bal') == 1
medespeler_met_bal = medespeler_met_bal + 1;
elseif strcmp(kijkrichting(i),'Medespeler zonder bal') == 1
medespeler_zonder_bal = medespeler_zonder_bal + 1;
elseif strcmp(kijkrichting(i),'Tegenstander') == 1
tegenstander = tegenstander + 1;
elseif strcmp(kijkrichting(i),'Open ruimte') == 1
open_ruimte = open_ruimte + 1;
elseif strcmp(kijkrichting(i),'Overzicht veld') == 1
overzicht_veld = overzicht_veld + 1;
elseif strcmp(kijkrichting(i),'Overig') == 1
overig = overig + 1;
end
end
end
Geoff Hayes
Geoff Hayes 2018년 6월 11일
Looks like you have asked this at https://www.mathworks.com/matlabcentral/answers/404803-what-is-wrong-with-my-script and it has been answered there. Have you tried stepping through the code to determine what is going on?

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by