File Exchange

image thumbnail


version (6 KB) by Andrew Stevens
Read data from a bathymetric attributed grid (BAG) file

1 Download

Updated 07 Apr 2017

View Version History

View License

BAG files are common export format from many hydrographic survey software packages (eg. Caris). The file structure of BAG files is based on HDF5 and recent versions of Matlab (as of 2011a) has built-in tools to read these files. The metadata in BAG files is embedded in an XML structure that READ_BAG parses. Currently, only a small subset of the available metadata is currently read. More information about the BAG file format can be found here:
And a repository of bathymetric data stored in BAG file format can be found here:
Example usage:
%1) read the entire contents of the bag file
bag_file = 'foo.bag';
bag = read_bag(bag_file);
% 2) Read a portion of the bag file (between arbitrary xmin, xmax, ymin,ymax)
bag=read_bag(bag_file,'xlim', [xmin xmax],'ylim',[ymin ymax]);
% 3) Sub-sample every 3rd point in the bag file
bag = read_bag(bag_file,'stride',3)

Cite As

Andrew Stevens (2021). read_bag (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Andrew Stevens

There is a known problem with reading the .bag files that is the result of variable format in the file header. The coordinates of the corners of the matrix are buried in a .xml header that my code is trying to read, but it appears the tag that contains the corner points changes from file to file (this code will work on some files and not others). I couldn't find documentation on the file format to fix the problem. I am leaving the code up in the hopes someone is able to solve the problem.

Mike Shives

not working for me.

doc = builder.parse(stream);

returns an error.

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!