Page 30 - MATLAB Recipes for Earth Sciences
P. 30
2.6 Scripts and Functions 21
Fig. 2.2 Screenshot of MATLAB Text Editor showing the content of the fi le geochem.txt. The
first line of the text is commented by a percent sign at the beginning of the line, followed by
the actual data matrix.
MAT-fi les are double-precision, binary fi les using .mat as extension. The
advantage of these binary mat-files is that they are independent from the
computer platforms running different floating-point formats. The command
save geochem_new.mat geochem
saves only the variable geochem instead of the entire workspace. The op-
tion -ascii, for example
save geochem_new.txt geochem -ascii
again saves the variable geochem, but in an ASCII fi le named geochem_new.
txt. In contrast to the binary fi le geochem_new.mat, this ASCII file can be
viewed and edited by using the MATLAB Editor or any other text editor.
2.6 Scripts and Functions
MATLAB is a powerful programming language. All fi les containing
MATLAB code use .m as extension and are therefore called M-fi les. These
files contain ASCII text and can be edited using a standard text editor.
However, the built-in Editor color highlights various syntax elements such
as comments (in green), keywords such as if, for and end (blue) and charac-
ter strings (pink). This syntax highlighting eases MATLAB coding.