Need help to save data from getkey into the file by using fprint

9 views (last 30 days)
Hi guys
I am writing a code to save data from the keyboard after presenting some photos to the participants.
1- I need to save the data including the information of the participants in line one
2- in line two I need to save the id for the photo being presented
3- within a tab I need to save the category for the photo being presented
4- within another tab in line two i need to save the participant's answer to the photo which would be a single key press through getkey
5- and also within another tab space I need to save the duration for the answer
I have already defined all of the above mentioned as :
fid: handle for the file fiel: file for the name of the photo being presented T: the category for the file A: to keep the getkey() result R: to keep the time duration for the answer
My question now is how to save them all correctly in a file using fprint?
Thank you for your help

Accepted Answer

maliheh
maliheh on 2 Jan 2013
Dear Matt
Thanks a lot for the solution. Please let me to work on it and if I could not manage I will print my script here for your help.
Cheers! maliheh

More Answers (2)

Matt Kindig
Matt Kindig on 2 Jan 2013
Hi Maliheh,
Based on what you have specified above, I think this will work:
%note that you will need to define the participants_info and photo_id variables, which you have not yet specified.
fout = fopen('/path/to/output_file.txt', 'wt');
fprintf(fout, '%s\n', participants_info);
fprintf(fout, '%d\t%s\t%s\t%s', photo_id, T, A, R);
fclose(fout);

maliheh
maliheh on 2 Jan 2013
Hi again
Here is my code after considering your advice: -Please not that there are a few participants and that is why I used x -file a variable which keeps the photo name, - T is the category of the photo -A is a variable which keeps the getkey()info -R is a variable which keeps the reaction time - the name and age of the participants should be saved in the first line of the text file. - all the saved data will be used for analyzing.
fid=fopen ('U:\participant{x}.txt,'a+'); if fid ~= -1
fprintf(fid, '%s\n', participant{x}); fprintf(fid,'%s\t%s\t%d\t%f', file, T, A, R);
i have git an error : Eoression or statement is incorrect--possibly unbalanced (,{ or[.
I appreciate your help.
cheers! maliheh

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!