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!