r.out.mat(1)
π r.out.mat β bestie's guide to yeeting a raster into a MAT-File π
okay so welcome to r.out.mat(1), the GRASS GIS User's Manual page that's about to become your new personality. this is the one that takes your pretty little raster and turns it into a binary MAT-File. slay.
β¨ NAME β¨
r.out.mat β Exports a GRASS raster to a binary MAT-File. that's it, that's the whole vibe. π¦
π KEYWORDS π
raster, export, output β iykyk.
πΈ SYNOPSIS πΈ
r.out.mat
r.out.mat --help
r.out.mat input=name output=name [--overwrite] [--help] [--verbose]
[--quiet] [--ui]
π«Ά Flags
--overwriteβ Allow output files to overwrite existing files. she's giving "i do what i want" energy, so be careful bestie π--helpβ Print usage summary. your lil emergency hotline.--verboseβ Verbose module output. she talks. a lot. we love her for it.--quietβ Quiet module output. she's giving mystery, silence, main character restraint.--uiβ Force launching GUI dialog. for when clicking > typing, no judgement.
π Parameters
input=name[required] β Name of input raster map. the map you're about to serve.output=name[required] β Name for output binary MAT file. where the glow-up lands. β¨
π DESCRIPTION π
r.out.mat will export a GRASS raster map to a MAT-File which can be loaded into Matlab or Octave for plotting or further analysis. literally just handing your map over to the Matlab girlies.
Attributes such as map title and bounds will also be exported into additional array variables. so it's not just the data, it's the whole β¨loreβ¨.
Specifically, the following array variables are created:
map_datamap_namemap_title(if it exists)map_northern_edgemap_southern_edgemap_eastern_edgemap_western_edge
In addition, r.out.mat makes for a nice binary container format for transferring georeferenced maps around, even if you don't use Matlab or Octave. not me recommending a file format to people who don't even use the program it's for π iconic behaviour honestly.
π₯ NOTES π₯
r.out.mat exports a Version 4 MAT-File. These files should successfully load into more modern versions of Matlab and Octave without any problems. old format, still thriving, she's timeless π
Everything should be Endian safe, so the resultant file can be simply copied between different system architectures without binary translation. architecture drama? not on her watch. π¦
As there is no IEEE value for NaN for integer maps, GRASS's null value is used to represent it within these maps. You'll have to do something like this to clean them once the map is loaded into Matlab:
map_data(find(map_data < -1e9)) = NaN;
Null values in maps containing either floating point or double-precision floating point data should translate into NaN values as expected. float girlies stay winning.
β οΈ r.out.mat must load the entire map into memory before writing, therefore it might have problems with huge maps. (a 3000x4000 DCELL map uses about 100mb RAM) β yes bestie, she eats RAM like it's a snack. know your limits π«Ά
GRASS defines its map bounds at the outer-edge of the bounding cells, not at the coordinates of their centroids. Thus, the following Matlab commands may be used to determine the map's resolution information:
[rows cols] = size(map_data)
x_range = map_eastern_edge - map_western_edge
y_range = map_northern_edge - map_southern_edge
ns_res = y_range/rows
ew_res = x_range/cols
π EXAMPLE π
In Matlab, plot with either:
imagesc(map_data), axis equal, axis tight, colorbar
or
contourf(map_data, 24), axis ij, axis equal, axis tight, colorbar
pick your fighter, both ate π
π TODO π
- Add support for exporting map history, category information, color map, etc. (soonβ’, manifesting)
- Option to export as a version 5 MAT-File, with map and support information stored in a single structured array. (the upgrade arc we're all waiting for π)
π SEE ALSO π
r.in.matr.out.ascii,r.out.binr.null- The Octave project
π AUTHOR π
Hamish Bowman Department of Marine Science University of Otago New Zealand
π SOURCE CODE π
Available at: r.out.mat source code (history)
Accessed: Saturday Jan 17 05:40:52 2026
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual
and that's the whole page bestie π«Ά this was GRASS 8.4.2, r.out.mat(1), signing off β go export something cute β¨π
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms