Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jsonlab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Contributions
jsonlab
Commits
1597106f
Commit
1597106f
authored
Jul 12, 2018
by
Qianqian Fang
Browse files
Options
Downloads
Patches
Plain Diff
add patch provided by pjkoprowski to support MATLAB table, add RowNames support, fix #29
parent
f16cc57d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
savejson.m
+40
-4
40 additions, 4 deletions
savejson.m
with
40 additions
and
4 deletions
savejson.m
+
40
−
4
View file @
1597106f
...
...
@@ -174,7 +174,11 @@ elseif(ischar(item))
elseif
(
isa
(
item
,
'string'
))
txt
=
str2json
(
name
,
item
{:},
level
,
varargin
{:});
elseif
(
isobject
(
item
))
if
(
~
exist
(
'OCTAVE_VERSION'
,
'builtin'
)
&&
istable
(
item
))
txt
=
matlabtable2json
(
name
,
item
,
level
,
varargin
{:});
else
txt
=
matlabobject2json
(
name
,
item
,
level
,
varargin
{:});
end
else
txt
=
mat2json
(
name
,
item
,
level
,
varargin
{:});
end
...
...
@@ -434,8 +438,13 @@ txt=sprintf('%s%s%s',txt,padding1,'}');
%%-------------------------------------------------------------------------
function
txt
=
matlabobject2json
(
name
,
item
,
level
,
varargin
)
if
numel
(
item
)
==
0
%empty object
st
=
struct
();
elseif
numel
(
item
)
==
1
%
st
=
struct
();
if
numel
(
item
)
>
0
%non-empty object
txt
=
str2json
(
name
,
char
(
item
),
level
,
varargin
(:));
return
else
% "st = struct(item);" would produce an inmutable warning, because it
% make the protected and private properties visible. Instead we get the
% visible properties
...
...
@@ -448,6 +457,33 @@ if numel(item) > 0 %non-empty object
end
txt
=
struct2json
(
name
,
st
,
level
,
varargin
{:});
%%-------------------------------------------------------------------------
function
txt
=
matlabtable2json
(
name
,
item
,
level
,
varargin
)
if
numel
(
item
)
==
0
%empty object
st
=
struct
();
else
% "st = struct(item);" would produce an inmutable warning, because it
% make the protected and private properties visible. Instead we get the
% visible properties
st
=
struct
();
propertynames
=
properties
(
item
);
if
(
isfield
(
item
.
Properties
,
'RowNames'
)
&&
~
isempty
(
item
.
Properties
.
RowNames
))
rownames
=
item
.
Properties
.
RowNames
;
for
p
=
1
:(
numel
(
propertynames
)
-
1
)
for
j
=
1
:
size
(
item
(:,
p
),
1
)
st
.
(
rownames
{
j
})
.
(
propertynames
{
p
})
=
item
{
j
,
p
};
end
end
else
for
p
=
1
:(
numel
(
propertynames
)
-
1
)
for
j
=
1
:
size
(
item
(:,
p
),
1
)
st
(
j
)
.
(
propertynames
{
p
})
=
item
{
j
,
p
};
end
end
end
end
txt
=
struct2json
(
name
,
st
,
level
,
varargin
{:});
%%-------------------------------------------------------------------------
function
txt
=
matdata2json
(
mat
,
level
,
varargin
)
...
...
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