|
10 | 10 | % arrays or cell arrays of char. |
11 | 11 | % |
12 | 12 | % ThresholdRules must be attached to sensors before calling this |
13 | | -% function. Sensors with no rules or rules with empty conditions are |
14 | | -% skipped. State keys not found in the metadata are skipped silently. |
| 13 | +% function. Sensors with no rules are skipped. Rules with empty |
| 14 | +% conditions (unconditional) contribute no state keys. State keys not |
| 15 | +% found in the metadata are skipped silently. |
15 | 16 | % |
16 | 17 | % Each sensor receives its own StateChannel instance (no shared |
17 | 18 | % handles). Compressed data is cached so each field is processed once. |
|
101 | 102 | end |
102 | 103 | end |
103 | 104 |
|
104 | | - |
105 | 105 | function result = compressTransitions(X, Y_dense) |
106 | 106 | %COMPRESSTRANSITIONS Compress dense state signal to sparse transitions. |
107 | 107 | % result = compressTransitions(X, Y_dense) returns struct with fields |
108 | 108 | % X and Y containing only the transition points (plus the first point). |
109 | 109 | % Handles both numeric arrays and cell arrays of char. |
110 | 110 |
|
111 | 111 | if iscell(Y_dense) |
112 | | - changes = [true, ~strcmp(Y_dense(1:end-1), Y_dense(2:end))]; |
| 112 | + cmp = ~strcmp(Y_dense(1:end-1), Y_dense(2:end)); |
| 113 | + changes = [true, reshape(cmp, 1, [])]; |
113 | 114 | else |
114 | 115 | changes = [true, reshape(diff(Y_dense) ~= 0, 1, [])]; |
115 | 116 | end |
116 | 117 |
|
117 | 118 | % Ensure row orientation (1xN) per StateChannel contract |
118 | 119 | result.X = reshape(X(changes), 1, []); |
119 | | - result.Y = Y_dense(changes); |
120 | | - if ~iscell(result.Y) |
121 | | - result.Y = reshape(result.Y, 1, []); |
122 | | - end |
| 120 | + result.Y = reshape(Y_dense(changes), 1, []); |
123 | 121 | end |
0 commit comments