Graphics Programs Reference
In-Depth Information
ries, most data arrive as ASCII fi les. Consider a simple data set stored in a
table such as
SampleID Percent C Percent S
101 0.3657 0.0636
102 0.2208 0.1135
103 0.5353 0.5191
104 0.5009 0.5216
105 0.5415 -999
106 0.501 -999
The fi rst row contains the variable names. The columns provide the data for
each sample. The absurd value
-999
marks missing data in the data set. Two
things have to be changed in order to convert this table into MATLAB format.
First, MATLAB uses
NaN
as the arithmetic representation for
Not-a-Number
that can be used to mark gaps. Second, you should comment the fi rst line by
typing a percent sign,
%
, at the beginning of the line.
%SampleID Percent C Percent S
101 0.3657 0.0636
102 0.2208 0.1135
103 0.5353 0.5191
104 0.5009 0.5216
105 0.5415 NaN
106 0.501 NaN
MATLAB ignores any text appearing after the percent sign and continues
processing on the next line. After editing this table in a text editor, such as
the
MATLAB Editor
, it is saved as ASCII text fi le
geochem.txt
in the current
working directory (Fig. 2.2). MATLAB now imports the data from this fi le
with the
load
command:
load geochem.txt
MATLAB loads the contents of fi le and assigns the matrix to a variable
named after the fi lename
geochem
. Typing
whos
yields
Name Size Bytes Class
geochem 6x3 144 double array
Grand total is 18 elements using 144 bytes
The command
save
now allows to store workspace variables in a binary
format.
save geochem_new.mat