How can I run a code for multiple rows which I found from another variable?
1 view (last 30 days)
Show older comments
Quinty van der Heijden
on 7 Mar 2022
Commented: Quinty van der Heijden
on 16 Mar 2022
I want to find out the total time of a participant not watching a video. I have managed to get all the data that I need for one video of a participant:
Start_End = [StartVideo EndVideo];
% Add time of unclassified values to see how much time the participant did not look
Unclassified = find(ismember(AllData.GazeEventType(RowIdx_Participant,:),'Unclassified','rows'));% Find unclassified rows for this participant
Unclassified_1 = intersect((StartVideo(1):EndVideo(1)),Unclassified); %Find unclassified rows in first movie
UnclassifiedFirstVideo = AllData.RecordingTimestamp(Unclassified_1); %Find timestamp of unclassified rows in first movie
TimeUnclassifiedFirstVideo = UnclassifiedFirstVideo(end)-UnclassifiedFirstVideo(1); %Total time not watching first movie
% Subtract endtime from begintime to see how much time is passed in one trial
TimeFirstVideo = AllData.RecordingTimestamp(EndVideo(1)-StartVideo(1));
TotalWatchingTime = TimeFirstVideo-TimeUnclassifiedFirstVideo ; %Total watching time
But I don't know how to do this for all videos (20 in total). I know the rows:
So, what I want in the end is the following, but than in simple code rather than writing out 20 lines:
Unclassified_1 = intersect((StartVideo(1):EndVideo(1)),Unclassified); / Unclassified_1 = intersect(1924:2279),Unclassified);
Unclassified_1 = intersect((StartVideo(2):EndVideo(2)),Unclassified); / Unclassified_1 = intersect(2428:2786),Unclassified);
Unclassified_1 = intersect((StartVideo(3):EndVideo(3)),Unclassified); / Unclassified_1 = intersect(2935:3293),Unclassified); etc.
Can you help me? Thanks!
0 Comments
Accepted Answer
Prahlad Gowtham Katte
on 14 Mar 2022
Edited: Prahlad Gowtham Katte
on 14 Mar 2022
Hello,
I understand that you want to get the times for each row and you can accomplish that using a for loop and array indices. The following code can be used to achieve the objective.
Start_End = [StartVideo EndVideo];
TotalWatchingTime=zeros(20,1);
for i=1:20 %i here indicates the ith video
% Add time of unclassified values to see how much time the participant did not look
Unclassified = find(ismember(AllData.GazeEventType(RowIdx_Participant,:),'Unclassified','rows'));% Find unclassified rows for this participant
Unclassified(i) = intersect((StartVideo(1):EndVideo(1)),Unclassified); %Find unclassified rows in ith video
Unclassified_Video = AllData.RecordingTimestamp(Unclassified(i)); %Find timestamp of unclassified rows in ith video
TimeUnclassifiedVideo(i) = Unclassified_Video(end)-Unclassified_Video(1); %Total time not watching ith video
% Subtract endtime from begintime to see how much time is passed in one trial
Time_Video = AllData.RecordingTimestamp(EndVideo(i)-StartVideo(i));
TotalWatchingTime(i) = Time_Video-TimeUnclassifiedVideo(i) ; %Total watching time for ith video.
end
Hope it helps
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!