4. Maximum absolute values

Use maxabs(db) to measure the largest absolute numeric value in a scalar database structure. Use max_discrepancy(a,b) to compare matching cell collections, structures, or solved models. Both reductions traverse every numeric element in their supported contents.

4.1. Database magnitude

Structure fields can contain numeric arrays, time series, nested structures, or cells of these values. Empty numeric arrays and empty collections contribute zero. Complex values contribute their absolute magnitudes.

db = struct();
db.x = [3, -4];
db.nested = struct('shock', {{[1, -5], []}});
magnitude = maxabs(db);          % 5
magnitude = maxabs(db, true);    % also print field magnitudes

The optional second argument of this user entry point remains a logical debug flag. To compare two databases, call max_discrepancy.

A NaN anywhere in the numeric contents gives NaN. An infinite magnitude gives Inf when no NaN is present. Time-series fields contribute their underlying numeric observations, including missing observations represented by NaN.

4.2. Strict comparisons

Comparisons require the same container shapes, structure field sets, and numeric leaf dimensions. Field order can differ. Every element of a structure array is compared. Singleton expansion and field intersection are not used. Integer array classes must match, such as uint64 with uint64.

a = struct('x', [1, 2], 'nested', struct('y', 3));
b = struct('x', [1, 4], 'nested', struct('y', 1));
discrepancy = max_discrepancy(a, b);                 % 2
discrepancy = max_discrepancy({[1, 2]}, {[1, 4]});    % 2

For matching schemas, any nonfinite input in a compared numeric array gives NaN, including Inf compared with Inf. A NaN result does not establish agreement. An empty matched collection gives zero. Unsupported contents produce an error identifying the affected path.

The existing entry points retain their mismatch conventions:

Entry point

Mismatched schema or dimensions

max_discrepancy(cellA, cellB)

Inf

max_discrepancy(structA, structB)

Error RISE:struct:SchemaMismatch

max_discrepancy(modelA, modelB)

Inf

Schema and dimension mismatches are checked before numeric values. Time-series leaves must have the same start date, frequency, observation count, and variable names. A mismatch returns Inf through every comparison entry point, including when the time series are nested in a database structure. Compatible time-series pairs compare their underlying numeric observations with the same NaN policy.

For solved models, comparison covers every parameterization, the solution coefficient arrays through the selected solution order, transition matrices, and measurement-error covariance arrays. Both models must provide matching solution structures, including their regime and parameterization dimensions.

4.3. Inspiration

Brenden Epps’s MAXABS(x) returns the maximum absolute value of x (File Exchange 37075) provided the inspiration. No source code was copied.