Hi all,
I am having trouble creating JSON files that contain stimulus times. I have the stimulus times for my target stimuli and my distractor stimuli in the appropriately named cell arrays, each containing 12 cells (hence y=1:12). What I want to do is take the contents of the each cell and write it into the appropriate json file, so that
Level 3_JSON1.json contains the contents of the 1st cell of the targets cell array, and the 1st cell of the distractor cell array. it then does this for the 2nd, 3rd, etc. up until the 12th and final cells. So we will end up with 12 json files. The contents of each json file also need to have the following format
{
"audioData":[5972,20250,22901,31500,41650,51342,54028]
"distractorData":[2544,3350,4567]
}
My code (shown at the bottom) successfully creates the JSON files, and the formatting of the text is correct in MatLab. But I have three problems;
- Nothing is being outputted to the JSON files. they are completely blank when i open them!
- While the formatting is correct, rather than the entire arrays being in between the brackets, ie [5972,20250,22901,31500,41650,51342,54028], it only prints values 1 at a time! so it would look like . I think this is probably an issue with my formatSpec??
{
"audioData":[5972]
"distractorData":[20250]
}
and then continues going value by value.
3, This is probably related to problem #2, but you'll notice that rather than displaying target value #1 (5972) and then distractor value #1 (2544), it displays target value #1 and then target value #2 (20250). It keeps drawing from the target array until there are no more, and then it draws from the distractor array. this is obviously a problem!
I'm super bad at text formatting and working with files, so thanks for any/all help!
level_number='Level 3'
formatSpec='{\n\t"audioData":[%d]\n\t"DistractorData":[%d]\n}\n';
for y=1:12
JSON_name= sprintf('%s_JSON%d.json',level_number,y);
fid=fopen(JSON_name,'w')
fprintf(formatSpec,targets{y},distractors{y})
end
fclose('all')