SparseExpand
- expand compressed array to sparse array

Miscellaneous functions
(AmiBroker 60)


SYNTAX SparseExpand( query_points, data )
RETURNS ARRAY
FUNCTION The function expands values from compressed 'data' array at points defined by non-zero values of 'query_points'
EXAMPLE only_when = ( Month() % 2 ) == 0; // even months only

x = SparseCompress( only_when, Close ); // compact sparse data

y = MA( x, 10 ); // regular calculation

y = SparseExpand( only_when, y ); // expand sparse data

Plot( C, "Price", colorDefault, styleBar );
Plot( y, "Sparse MA from even months", colorRed );


function SparseCompressEquiv( sparse_array, data_array )
{
     result = Null;
    
     j = BarCount - 1;
     for( i = BarCount - 1; i >= 0; i-- )
     {
       if( sparse_array[ i ] ) result[ j-- ] = data_array[ i ];
     }
    
     return result;
}

function SparseExpandEquiv( sparse_array, data_array )
{
     result = Null;
    
     j = BarCount - 1;
     for( i = BarCount - 1; i >= 0; i-- )
     {
       if( sparse_array[ i ] ) result[ i ] = data_array[ j-- ];
     }
    
     return result;
}
SEE ALSO SparseCompress() function

References:

The SparseExpand function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.