Main Content

hasdata

Determine if minibatchqueue can return mini-batch

Since R2020b

    Description

    tf = hasdata(mbq) returns 1 (true) if mbq can return a mini-batch using the next function, and 0 (false) otherwise.

    Use hasdata in combination with next to iterate over all data in the minibatchqueue object. You can call next on a minibatchqueue object until all data is returned. If mini-batches of data are still available in the minibatchqueue object, hasdata returns 1. When you reach the end of the data, hasdata returns 0. Then, use reset or shuffle to reset the minibatchqueue object and continue obtaining mini-batches with next.

    example

    Examples

    collapse all

    Use hasdata with a while loop to iterate over all data in the minibatchqueue object.

    Create a minibatchqueue object from a datastore.

    ds = digitDatastore;
    mbq = minibatchqueue(ds,MiniBatchSize=256)
    mbq = 
    minibatchqueue with 1 output and properties:
    
       Mini-batch creation:
                   MiniBatchSize: 256
                PartialMiniBatch: 'return'
                    MiniBatchFcn: 'collate'
        PreprocessingEnvironment: 'serial'
    
       Outputs:
                      OutputCast: {'single'}
                 OutputAsDlarray: 1
                 MiniBatchFormat: {''}
               OutputEnvironment: {'auto'}
    

    While data is still available in the minibatchqueue object, obtain the next mini-batch.

    while hasdata(mbq)
        X = next(mbq)
    end

    The loop ends when hasdata returns false, and all mini-batches are returned.

    Input Arguments

    collapse all

    Mini-batch queue, specified as a minibatchqueue object.

    Output Arguments

    collapse all

    True or false result, returned as a 1 or 0 of data type logical.

    Version History

    Introduced in R2020b