-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodeIntoJSONFormat2.m
More file actions
46 lines (35 loc) · 1.45 KB
/
EncodeIntoJSONFormat2.m
File metadata and controls
46 lines (35 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function EncodeIntoJSONFormat2(SourceFile)
% Load matlab variables into current workspace
load(SourceFile);
% Extract path and file parts from SourceFile argument
[Filepath, Name, Ext] = fileparts(SourceFile);
% Construct name of json calcium file to be saved.
SaveName = fullfile(Filepath, [Name, '_C.json']);
%%%% Begin Calcium Data processing %%%%
% Parse data into json format
C_data = jsonencode(C);
% Save parsed json data to a file in same directory as mat file.
fid = fopen(SaveName, 'w');
fwrite(fid, C_data, 'char');
fclose(fid);
%%%% End Calcium Data processing %%%%
%%%% Begin Behavioral Data processing %%%%
% Write table contents into struct as required by the json encoder
Behavior_struct = struct;
column_names = B.Properties.VariableNames;
for i = 1:length(column_names)
column = column_names{i};
Behavior_struct.(column) = B.(column);
end
% Parse behavioral data into json format
B_data = jsonencode(Behavior_struct);
% Construct name of json behavioral file to be saved.
SaveName = fullfile(Filepath, [Name, '_B.json']);
% Save parsed json data to a file in same directory as mat file.
fid = fopen(SaveName, 'w');
fwrite(fid, B_data, 'char');
fclose(fid);
%%%% End Calcium Data processing %%%%
% Clear variables from workspace
clear('B','C')
end