Information on next block in blocked file-set



blkInfo = nextblock(bs) returns the information on the next block in the BlockedFileSet object bs, then advances the internal pointer of the blocked file-set to the next block. Subsequent calls to the nextblock function continue reading from the endpoint of the previous call.


collapse all

Check if a blocked file-set has another block available to process and read the data iteratively.

Create a blocked file-set bs for a collection of files.

folder = {'accidents.mat','airlineResults.mat','census.mat','earth.mat'}
folder = 1x4 cell
  Columns 1 through 3

    {'accidents.mat'}    {'airlineResults...'}    {'census.mat'}

  Column 4


bs =
bs = 
  BlockedFileSet with properties:

                   NumBlocks: 4
               NumBlocksRead: 0
                   BlockSize: 'file'
                   BlockInfo: Show BlockInfo for all 4 blocks
    AlternateFileSystemRoots: {}

Use the hasNextBlock and nextblock functions to read block information one block at a time while blocks remain in the set.

while hasNextBlock(bs)
   file = nextblock(bs)
file = 
  1x1 BlockInfo
                                       Filename                                       FileSize    OffSet    BlockSize
    ______________________________________________________________________________    ________    ______    _________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/accidents.mat"      7343        0         7343   

file = 
  1x1 BlockInfo
                                         Filename                                           FileSize     OffSet    BlockSize 
    ___________________________________________________________________________________    __________    ______    __________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/airlineResults.mat"    1.5042e+05      0       1.5042e+05

file = 
  1x1 BlockInfo
                                     Filename                                      FileSize    OffSet    BlockSize
    ___________________________________________________________________________    ________    ______    _________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/census.mat"      353         0          353   

file = 
  1x1 BlockInfo
                                     Filename                                     FileSize    OffSet    BlockSize
    __________________________________________________________________________    ________    ______    _________

    "/mathworks/devel/bat/Bdoc20a/build/matlab/toolbox/matlab/demos/earth.mat"     32522        0         32522  

Input Arguments

collapse all

Blocked file-set, specified as a object. To create a BlockedFileSet object, see

Example: nextblock(bs)

Output Arguments

collapse all

This property is read-only.

Information about blocks in the BlockedFileSet object, returned as a BlockInfo object with the following properties:

  • Filename — Name of the file in the BlockedFileSet object. The name contains the full path of the file.

  • FileSize — Size of the file in number of bytes.

  • Offset — Starting offset within the file to be read.

  • BlockSize — Size of the block in number of bytes.


  • The nextblock function returns an error if no more blocks exist in the BlockedFileSet object. To avoid this error, use nextblock along with hasNextBlock and reset. The hasNextBlock function checks if blocks still remain in the blocked file-set, while the reset method resets the internal pointer to the beginning of the blocked file-set.

Introduced in R2020a