MATLAB Answers

How do I create a for loop to extract data from table?

12 views (last 30 days)
annie
annie on 3 Dec 2019
Commented: annie on 3 Dec 2019
Hii,
I have this table with a lot of data that i need to reorganize. This table consists of data from 9 participants, i want to have all the reaction times in 1 column per videostring, so every ID will have its own row with reactiontimes. In total i have 18 different videostrings, so the matrix will be [9,18]. However, i dont have some missing data, which means that for some videostrings i dont have any response times, here i need to have NaN or something else... See the attachment: dimensions are 159x3 while it should be 162x3 meaning that i miss 3 results. I really get stuck by trying to fix this.
How the matrix should look
(ID) 02stop.mp4 74524driving.mp4 .... (18 videostrings in total)
1 10672 11143 ....
2 198 7220 .....
3 10846 NaN ....
4 ... ...
....
I only got this far...:(
%%
ReactionTime = cat(2,resultsehmitrials(:,3),resultsehmitrials(:,5),resultsehmitrials(:,2)); %1 = videonames 2 = responsetime 3 = participant ID creates the Reactiontimetable
AnswersParticipants = NaN(9,18);
for nParticipanten = 1 : 9
for nVideos = 1 : 18
If someone could help me with to get started with this for loop I would be really thankfull!

  0 Comments

Sign in to comment.

Accepted Answer

Stephan
Stephan on 3 Dec 2019
No loop is needed:
A = unstack(ReactionTime,'RESPONSE_TIME_ehmi','videostring')
since you have invalid names for you video files you get a warning, but no worries - Matlab renames them automatically:
Warning: Table variable names were modified to make them valid MATLAB identifiers.
A =
9×19 table
ID x02809braking_mp4 x02stop_mp4 x16walk_mp4 x17driving_mp4 x29312stop_mp4 x36braking_mp4 x47dontwalk_mp4 x52672go_mp4 x63908dontwalk_mp4 x74524driving_mp4 x95246walk_mp4 x97go_mp4 braking_mp4 dontwalk_mp4 driving_mp4 go_mp4 stop_mp4 walk_mp4
__ _________________ ___________ ___________ ______________ ______________ ______________ _______________ ____________ __________________ _________________ ______________ _________ ___________ ____________ ___________ ______ ________ ________
1 11287 10672 11567 12010 12062 11219 11495 11039 10704 11143 11278 12809 12829 11098 11184 11313 12469 11019
2 7277 198 7347 7243 11303 7123 7220 7147 7940 7187 7136 7189 7456 7201 7436 7219 7330 7242
3 10719 10808 10830 11101 11514 11145 10770 10762 10971 10791 10943 11087 10782 10922 11282 10977 10871 10761
4 7067 7276 7140 7115 7139 7105 7052 7723 7113 8179 7232 4204 7317 7091 7137 7118 7344 7238
5 11502 11790 12862 11116 13584 11223 12468 12106 11454 11519 12720 12206 12437 11578 11516 14618 11894 13620
7 11112 11596 11100 11321 10909 12053 10754 11087 11117 11097 11992 11265 11087 14964 11626 10947 13292 11290
8 NaN 13653 NaN 12826 13949 12519 13904 13722 11854 13252 12233 11998 NaN 11556 12771 10876 11606 12729
9 11236 11879 10989 11160 10807 10950 10947 11128 11122 11428 10740 10694 11571 11305 11087 10897 11235 10907
10 7491 7843 12057 14235 7641 14033 8487 7808 7426 11085 11918 8280 13224 12286 11447 12851 14690 11269

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by