Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matlab_general
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
William Lövfors
matlab_general
Commits
1a62a4e3
Commit
1a62a4e3
authored
2 years ago
by
Henrik Podéus Derelöv
Browse files
Options
Downloads
Patches
Plain Diff
Added function to convert mat file to json file
parent
f916e478
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
export_to_json.m
+76
-0
76 additions, 0 deletions
export_to_json.m
with
76 additions
and
0 deletions
export_to_json.m
0 → 100644
+
76
−
0
View file @
1a62a4e3
%% Export mat structures to json
% %% Inputs
% filepath - str including file extension (.mat)
% isparam - optinal, bool
% modelName - optional, string with modelName (name of IQM textfile)
function
[]
=
export_to_json
(
varargin
)
% Assign inputs
filepath
=
varargin
{
1
};
switch
size
(
varargin
,
2
)
case
1
isparam
=
false
;
modelName
=
[];
case
2
if
class
(
varargin
{
2
})
==
"string"
||
class
(
varargin
{
2
})
==
"char"
modelName
=
varargin
{
2
};
isparam
=
false
;
else
modelName
=
[];
isparam
=
varargin
{
2
};
end
case
3
if
class
(
varargin
{
2
})
==
"string"
||
class
(
varargin
{
2
})
==
"char"
modelName
=
varargin
{
2
};
isparam
=
varargin
{
3
};
else
modelName
=
varargin
{
3
};
isparam
=
varargin
{
2
};
end
otherwise
warning
(
'to many inputs. Format is \n filepath, optional-bool, optional-modelName'
)
if
class
(
varargin
{
2
})
==
"string"
||
class
(
varargin
{
2
})
==
"char"
modelName
=
varargin
{
2
};
isparam
=
varargin
{
3
};
else
modelName
=
varargin
{
3
};
isparam
=
varargin
{
2
};
end
end
%% format output
data
=
importdata
(
filepath
);
s
=
[];
%strucure param data with cost and params
if
isparam
s
.
f
=
data
.
fbest
;
s
.
x
=
exp
(
data
.
xbest
);
if
~
isempty
(
modelName
)
[
pnames
,
~
]
=
IQMparameters
(
IQMmodel
([
modelName
'.txt'
]));
s
.
pnames
=
pnames
;
end
% strucutures i.e. data structures
else
s
=
data
;
end
%preview format
jsonencode
(
s
,
PrettyPrint
=
true
)
% print to file
strseg
=
split
(
filepath
,
[
"\"
,
"/"
]);
resname
=
extractBefore
(
strseg
{
end
},
".mat"
);
JSONFILE_name
=
strcat
([
resname
'.json'
]);
fid
=
fopen
(
JSONFILE_name
,
'w'
);
fprintf
(
fid
,
jsonencode
(
s
,
PrettyPrint
=
true
));
fclose
(
fid
);
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment