1function m = ldesJson2mat(x, nr, nc)
2% M = LDESJSON2MAT(X, NR, NC)
3% Convert a jsondecode
'd matrix into a numeric NR x NC matrix. Handles numeric
4% 2-D arrays, cell arrays (ragged / containing JSON null, which jsondecode maps
5% to []), and empties (returns []). JSON null entries become NaN. When NR,NC are
6% supplied the result is oriented to NR x NC. Shared by the LDES wrapper methods
7% that parse the fully JSON-mediated result of the LDES engine.
8if nargin < 2, nr = []; end
9if nargin < 3, nc = []; end
19 vals = nan(1, numel(ri));
22 if ~isempty(v) && isnumeric(v)
27 vals = reshape(double(ri), 1, []);
33 elseif size(vals, 2) == size(m, 2)
34 m = [m; vals]; %#ok<AGROW>
36 m = []; % ragged beyond repair
43% jsondecode collapses a 1x1 array to a scalar; ensure requested orientation.
44if isvector(m) && ~isempty(nr) && ~isempty(nc) && numel(m) == nr * nc
45 m = reshape(m, nc, nr).';
47% Orient to nr x nc
if a plain transpose matches.
48if ~isempty(nr) && ~isempty(nc) && ~isequal(size(m), [nr nc]) && isequal(size(m), [nc nr])