How do I select data from an interval in a matrix?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
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?
답변 (1개)
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
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!