How can I run a code for multiple rows which I found from another variable?
3 次查看(过去 30 天)
显示 更早的评论
Quinty van der Heijden
2022-3-7
评论: Quinty van der Heijden
2022-3-16
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 个评论
采纳的回答
Prahlad Gowtham Katte
2022-3-14
编辑:Prahlad Gowtham Katte
2022-3-14
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 External Language Interfaces 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!