r.in.mat(1)
π r.in.mat β the manual page, but make it a group chat π
okay bestie, so r.in.mat is a GRASS GIS module, and its whole vibe is: imports a binary MAT-File(v4) to a GRASS raster. That's it. That's the job. Iconic, honestly.
β¨ KEYWORDS β¨
raster, import
yes she's a raster girlie and yes she's an import girlie, both can be true
πΈ SYNOPSIS πΈ
r.in.mat
r.in.mat --help
r.in.mat input=name [output=name] [--overwrite] [--help]
[--verbose] [--quiet] [--ui]
π Flags:
--overwriteβ lets your output files just likeβ¦ bulldoze whatever's already there. Allow output files to overwrite existing files.--helpβ prints the usage summary so you're not out here guessing.--verboseβ verbose module output, aka she tells you everything.--quietβ quiet module output, aka she tells you nothing.--uiβ force launches the GUI dialog. main character energy, graphically.
π¦ Parameters:
input=name[required] β Name of input MAT-File(v4). She's mandatory, no skipping.output=nameβ Name for output raster map (override). Optional but she can override things.
π DESCRIPTION π
So r.in.mat will import a GRASS raster map from a Version 4 MAT-File that was created with Matlab or Octave. Attributes like map title and bounds also get imported, if they exist. Casual.
Specifically, these array variables get read:
map_datamap_namemap_titlemap_northern_edgemap_southern_edgemap_eastern_edgemap_western_edge
Any other variables chillin' in the MAT-file just get skipped over. Not our business, not our problem. π
The map_name variable is optional β if it exists and it's valid, the new map gets named that. If it doesn't exist, or you specified a name with the output= option, the raster map's name gets set to "MatFile" or whatever name you specified respectively. (maximum 64 characters; normal GRASS naming rules apply β so no, you cannot name it whatever feral thing you want)
The map_title variable is optional too, and the map's title gets set if it exists.
The map_northern_edge and its little friends are mandatory unless you're importing to a "XY" non-georeferenced project (e.g. imagery data). Latitude and longitude values should be in decimal form, fr fr.
π₯ NOTES π₯
r.in.mat imports a Version 4 MAT-File. These files can be successfully created with more modern versions of Matlab and Octave (peep the "EXAMPLES" below, i gotchu).
Everything should be Endian safe, so the file you're importing can just be copied between different system architectures without binary translation. (caveat: see "TODO" below β bestie there's always a caveat)
Since there's no IEEE value for NaN in integer arrays, GRASS's null value may be used to represent it within these maps. Usually Matlab will save any integer based matrix with NaN values as a double-precision floating point array, so this usually isn't an issue. To save space, once the map is loaded into GRASS you can convert it back to an integer map with this command:
r.mapcalc "int_map = int(MATFile_map)"
NaN values in either floating point or double-precision floating point matrices should translate into null values as expected. Slay.
β οΈ r.in.mat must load the entire map array into memory before writing, so it might have problems with huge arrays. (a 3000x4000 DCELL map uses about 100mb RAM) Likeβ¦ she's doing her best but she's not infinite.
GRASS defines its map bounds at the outer-edge of the bounding cells, not at the coordinates of their centroids. So these Matlab commands may be used to determine and check that the map's resolution information will be correct:
[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
Remember: Matlab arrays are referenced as (row,column), i.e. (y,x). Not me forgetting that every single time. π
Also r.in.mat and r.out.mat make for a nice binary container format for transferring georeferenced maps around, even if you don't use Matlab or Octave. So like, free real estate.
π EXAMPLES π
In Matlab, save with:
save filename.mat map_* -v4
In Octave, save with:
save -mat4-binary filename.mat map_*
π§ TODO π§
- Robust support for mixed-Endian importation. (This is a work in progress, please help by reporting any failures to the GRASS bug tracking system;)
- Add support for importing map history, category information, color map, etc. if they exist.
- Option to import a version 5 MAT-File, with map and support information stored in a single structured array.
π KNOWN ISSUES π
If you encounter any problems, please contact the GRASS Development Team. They're lovely, they want to hear from you, no cap.
π SEE ALSO π
r.out.mat, r.in.ascii, r.in.bin, r.mapcalc, r.null.
The Octave project
π AUTHOR π
Hamish Bowman Department of Marine Science University of Otago New Zealand
β SOURCE CODE β
Available at: r.in.mat source code (history)
Accessed: Saturday Jan 17 05:40:47 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 thing bestie β this page lives in the GRASS GIS 8.4.2 Reference Manual (she's the r.in.mat(1) page, of course), sourced straight from the GRASS Development Team, dated Saturday Jan 17 05:40:47 2026, and stamped with that Β© 2003-2025 GRASS Development Team energy. go import something gorgeous π«Άβ¨
π¦ 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