1function C = ldesTrajCell(raw, M, R)
2% C = LDESTRAJCELL(RAW, M, R)
3% Normalize a jsondecode
'd transient trajectory (logical nesting
4% [station][class][row][2]) into an M x R cell array C where C{i,r} is the
5% (nRows x 2) [value, time] matrix for class r at the i-th stateful node, or []
8% jsondecode collapses this nesting inconsistently depending on raggedness:
9% - fully rectangular -> numeric 4-D [M x R x nRows x 2]
10% - ragged outer -> cell{M}, each element numeric 3-D [R x nRows x 2]
11% (or [] for an empty station, or a nested cell)
12% - R == 1 collapses -> a station element may be a plain [nRows x 2] matrix
13% This helper resolves all of these to a uniform M x R cell of 2-D matrices.
25stations = splitOuter(raw, M);
27 classes = splitOuter(stations{i}, R);
30 if ~isempty(m) && ismatrix(m) && size(m, 2) == 2
37function parts = splitOuter(x, n)
38% SPLITOUTER Split the leading logical dimension of a jsondecode'd value into a
39% 1 x n cell. Handles cell inputs, numeric N-D arrays (leading dim = list
40% index), a single collapsed 2-D matrix (n==1), and empties.
46 for i = 1:min(n, numel(x))
55 % Leading dimension indexes
the list; drop it
for each element.
56 for i = 1:min(n, sz(1))
58 parts{i} = reshape(sub, sz(2:end));
62 parts{1} = x; % single element
is the matrix itself
63 elseif size(x, 1) == n
65 parts{i} = x(i, :); % each row
is one (vector) element
68 parts{1} = x; % best effort