Attempting to write my data into a single CSV file.
Show older comments
I am currently trying to record both the users keyboard response, and their reaction time associated with making each response to the image presented. I am struggling to identify a way in which I can write and save both the response and reaction time in the same CSV.file. I was wondering if anyone had any suggestions? I currently have the following code;
d=21; %Number of images to load in is 21.
if d<1 || d>21 %A check to ensure that the correct number of images will be displayed.
disp('Error, the number of images loaded in out of range')
end
rts= (zeros(21, 1)); %rts is a numeric array, 21, 1, made up of zeros.
response=(zeros(21, 1)); % response is a numeric array, 21, 1, made up of zeros.
dirname= 'C:\Users\User\Documents\MATLAB\stimuli\'; %Location of stimuli
count= 0;
d=dir([dirname '*.jpg']);
for a =randperm(numel(d))% return scalar count of elements in matrix
%And randomly present the images under the variable of d.
a= imread(d(a).name); %read in images in desired folder
imshow(a) %show selected images
pause(2); %allow a 2 second pause between successive stimuli.
b= imread('FixationDot.jpg');% read in the fixation dot
imshow(b) %show the fixation dot between every letter
pause(0.5); %allow the fixation dot to remain there for 0.5 seconds
tic
count= count+1;
response(count)= getkey(); %Gain user input
rts(count)= toc; %Record the time taken to produce a response from user
end
M= char(response); %convert ASCII codes to underlying char key press
csvwrite('response.csv', response); %writes user response into a CSV file
csvwrite('reaction_time.csv', rts); %writes users reaction time
Thank you to anyone that can help, I really appreciate it.
Accepted Answer
More Answers (1)
Andreas Kvalbein Fjetland
on 30 Jan 2019
Edited: Andreas Kvalbein Fjetland
on 30 Jan 2019
This should do the trick
response = zeros(21,1);
rts = zeros(21,1);
% Looop
resultTable = table(response,rts);
writetable(resultTable,'fileName.csv')
Please use the code function in the editor next time. Makes your code easier to read and copy.
1 Comment
Kyle Davis
on 30 Jan 2019
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!