-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncodeIntoJSONFormat3.m
68 lines (48 loc) · 2.04 KB
/
EncodeIntoJSONFormat3.m
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function EncodeIntoJSONFormat3(varargin)
if (nargin == 0)
% Obtain file to analyze using the gui file browser
[Name, Filepath] = uigetfile;
% Assemble full path to source file
SourceFile = fullfile(Filepath, Name);
% Unpack file parts to construct save name.
[junk, Name, Ext] = fileparts(Name);
% Load matlab variables into current workspace
load(SourceFile);
end
if (nargin == 1)
SourceFile = varargin(1);
% Extract path and file parts from SourceFile argument
[Filepath, Name, Ext] = fileparts(SourceFile);
% Load matlab variables into current workspace
load(SourceFile);
end
% Construct name of json calcium file to be saved.
SaveName = fullfile(Filepath, [Name, '_new_unique_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, '_new_unique_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