|
54 | 54 | %
|
55 | 55 |
|
56 | 56 | newdata=data;
|
57 |
| - opt=varargin2struct(varargin{:}); |
| 57 | + opt=struct; |
| 58 | + if(nargin==2) |
| 59 | + opt=varargin{1}; |
| 60 | + elseif(nargin>2) |
| 61 | + opt=varargin2struct(varargin{:}); |
| 62 | + end |
58 | 63 |
|
59 | 64 | %% process non-structure inputs
|
60 | 65 | if(~isstruct(data))
|
|
75 | 80 | len=length(data);
|
76 | 81 | needbase64=jsonopt('Base64',0,opt);
|
77 | 82 | format=jsonopt('FormatVersion',2,opt);
|
78 |
| - prefix=jsonopt('Prefix',sprintf('x0x%X','_'+0),opt); |
79 |
| - if(~any(ismember(N_('_ArrayType_'),fn)) && any(ismember('x_ArrayType_',fn))) |
| 83 | + prefix=jsonopt('Prefix','x0x5F',opt); |
| 84 | + if(~isfield(data,N_('_ArrayType_')) && isfield(data,'x_ArrayType_')) |
80 | 85 | prefix='x';
|
81 | 86 | opt.prefix='x';
|
82 | 87 | end
|
|
95 | 100 | end
|
96 | 101 |
|
97 | 102 | %% handle array data
|
98 |
| - if(any(ismember(N_('_ArrayType_'),fn)) && (any(ismember(N_('_ArrayData_'),fn)) || any(ismember(N_('_ArrayZipData_'),fn)))) |
| 103 | + if(isfield(data,N_('_ArrayType_')) && (isfield(data,N_('_ArrayData_')) || isfield(data,N_('_ArrayZipData_')))) |
99 | 104 | newdata=cell(len,1);
|
100 | 105 | for j=1:len
|
101 |
| - if(any(ismember(N_('_ArrayZipSize_'),fn)) && any(ismember(N_('_ArrayZipData_'),fn))) |
| 106 | + if(isfield(data,N_('_ArrayZipSize_')) && isfield(data,N_('_ArrayZipData_'))) |
102 | 107 | zipmethod='zip';
|
103 |
| - if(any(ismember(N_('_ArrayZipType_'),fn))) |
| 108 | + if(isfield(data,N_('_ArrayZipType_'))) |
104 | 109 | zipmethod=data(j).(N_('_ArrayZipType_'));
|
105 | 110 | end
|
106 |
| - if(any(ismember(zipmethod,{'zlib','gzip','lzma','lzip','lz4','lz4hc'}))) |
| 111 | + if(~isempty(strmatch(zipmethod,{'zlib','gzip','lzma','lzip','lz4','lz4hc'}))) |
107 | 112 | decompfun=str2func([zipmethod 'decode']);
|
108 | 113 | if(needbase64)
|
109 | 114 | ndata=reshape(typecast(decompfun(base64decode(data(j).(N_('_ArrayZipData_')))),data(j).(N_('_ArrayType_'))),data(j).(N_('_ArrayZipSize_'))(:)');
|
|
119 | 124 | end
|
120 | 125 | ndata=cast(data(j).(N_('_ArrayData_')),char(data(j).(N_('_ArrayType_'))));
|
121 | 126 | end
|
122 |
| - if(any(ismember(N_('_ArrayZipSize_'),fn))) |
| 127 | + if(isfield(data,N_('_ArrayZipSize_'))) |
123 | 128 | ndata=reshape(ndata(:),fliplr(data(j).(N_('_ArrayZipSize_'))(:)'));
|
124 | 129 | ndata=permute(ndata,ndims(ndata):-1:1);
|
125 | 130 | end
|
126 | 131 | iscpx=0;
|
127 |
| - if(any(ismember(N_('_ArrayIsComplex_'),fn))) |
| 132 | + if(isfield(data,N_('_ArrayIsComplex_'))) |
128 | 133 | if(data(j).(N_('_ArrayIsComplex_')))
|
129 | 134 | iscpx=1;
|
130 | 135 | end
|
131 | 136 | end
|
132 |
| - if(any(ismember(N_('_ArrayIsSparse_'),fn)) && data(j).(N_('_ArrayIsSparse_'))) |
133 |
| - if(any(ismember(N_('_ArraySize_'),fn))) |
| 137 | + if(isfield(data,N_('_ArrayIsSparse_')) && data(j).(N_('_ArrayIsSparse_'))) |
| 138 | + if(isfield(data,N_('_ArraySize_'))) |
134 | 139 | dim=double(data(j).(N_('_ArraySize_'))(:)');
|
135 | 140 | if(iscpx)
|
136 | 141 | ndata(end-1,:)=complex(ndata(end-1,:),ndata(end,:));
|
|
154 | 159 | end
|
155 | 160 | ndata=sparse(ndata(1,:),ndata(2,:),ndata(3,:));
|
156 | 161 | end
|
157 |
| - elseif(any(ismember(N_('_ArraySize_'),fn))) |
| 162 | + elseif(isfield(data,N_('_ArraySize_'))) |
158 | 163 | if(iscpx)
|
159 | 164 | ndata=complex(ndata(1,:),ndata(2,:));
|
160 | 165 | end
|
|
175 | 180 | end
|
176 | 181 |
|
177 | 182 | %% handle table data
|
178 |
| - if(any(ismember(N_('_TableRecords_'),fn))) |
| 183 | + if(isfield(data,N_('_TableRecords_'))) |
179 | 184 | newdata=cell(len,1);
|
180 | 185 | for j=1:len
|
181 | 186 | ndata=data(j).(N_('_TableRecords_'));
|
|
205 | 210 | end
|
206 | 211 |
|
207 | 212 | %% handle map data
|
208 |
| - if(any(ismember(N_('_MapData_'),fn))) |
| 213 | + if(isfield(data,N_('_MapData_'))) |
209 | 214 | newdata=cell(len,1);
|
210 | 215 | for j=1:len
|
211 | 216 | key=cell(1,length(data(j).(N_('_MapData_'))));
|
|
223 | 228 | end
|
224 | 229 |
|
225 | 230 | %% handle graph data
|
226 |
| - if(any(ismember(N_('_GraphNodes_'),fn)) && exist('graph','file') && exist('digraph','file')) |
| 231 | + if(isfield(data,N_('_GraphNodes_')) && exist('graph','file') && exist('digraph','file')) |
227 | 232 | newdata=cell(len,1);
|
228 | 233 | isdirected=1;
|
229 | 234 | for j=1:len
|
|
241 | 246 | nodetable=table;
|
242 | 247 | end
|
243 | 248 |
|
244 |
| - if(any(ismember(N_('_GraphEdges_'),fn))) |
| 249 | + if(isfield(data,N_('_GraphEdges_'))) |
245 | 250 | edgedata=data(j).(N_('_GraphEdges_'));
|
246 |
| - elseif(any(ismember(N_('_GraphEdges0_'),fn))) |
| 251 | + elseif(isfield(data,N_('_GraphEdges0_'))) |
247 | 252 | edgedata=data(j).(N_('_GraphEdges0_'));
|
248 | 253 | isdirected=0;
|
249 |
| - elseif(any(ismember(N_('_GraphMatrix_'),fn))) |
| 254 | + elseif(isfield(data,N_('_GraphMatrix_'))) |
250 | 255 | edgedata=jdatadecode(data(j).(N_('_GraphMatrix_')),varargin{:});
|
251 | 256 | end
|
252 | 257 |
|
|
273 | 278 | end
|
274 | 279 |
|
275 | 280 | %% handle bytestream and arbitrary matlab objects
|
276 |
| - if(sum(ismember({N_('_ByteStream_'),N_('_DataInfo_')},fn))==2) |
| 281 | + if(isfield(data,N_('_ByteStream_')) && isfield(data,N_('_DataInfo_'))==2) |
277 | 282 | newdata=cell(len,1);
|
278 | 283 | for j=1:len
|
279 | 284 | if(isfield(data(j).(N_('_DataInfo_')),'MATLABObjectClass'))
|
|
0 commit comments