How can I run a code for multiple rows which I found from another variable?
1 回表示 (過去 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 で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!