LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ldesTrajCell.m
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 []
6% if absent/empty.
7%
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.
14
15C = cell(M, R);
16for i = 1:M
17 for r = 1:R
18 C{i, r} = [];
19 end
20end
21if isempty(raw)
22 return;
23end
24
25stations = splitOuter(raw, M);
26for i = 1:M
27 classes = splitOuter(stations{i}, R);
28 for r = 1:R
29 m = classes{r};
30 if ~isempty(m) && ismatrix(m) && size(m, 2) == 2
31 C{i, r} = double(m);
32 end
33 end
34end
35end
36
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.
41parts = cell(1, n);
42if isempty(x)
43 return;
44end
45if iscell(x)
46 for i = 1:min(n, numel(x))
47 parts{i} = x{i};
48 end
49 return;
50end
51if isnumeric(x)
52 nd = ndims(x);
53 sz = size(x);
54 if nd >= 3
55 % Leading dimension indexes the list; drop it for each element.
56 for i = 1:min(n, sz(1))
57 sub = x(i, :, :, :);
58 parts{i} = reshape(sub, sz(2:end));
59 end
60 else % 2-D
61 if n == 1
62 parts{1} = x; % single element is the matrix itself
63 elseif size(x, 1) == n
64 for i = 1:n
65 parts{i} = x(i, :); % each row is one (vector) element
66 end
67 else
68 parts{1} = x; % best effort
69 end
70 end
71end
72end
Definition Station.m:245