How do I select data from an interval in a matrix?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Geoff Hayes
el 7 de Jun. de 2018
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?
Respuestas (1)
Geoff Hayes
el 8 de Jun. de 2018
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 comentarios
Geoff Hayes
el 11 de Jun. de 2018
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?
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!