Geoscience Reference
In-Depth Information
103
104
105
106
data2 =
0.3657 0.0636
0.2208 0.1135
0.5353 0.5191
0.5009 0.5216
0.5415 NaN
0.5010 NaN
We now concatenate the two cells into one double-precision array
data
. First,
we have to change the class of
C{1}
into
double
or the class of the entire array
data
will be
uint32
. Typing
data(:,1) = double(C{1})
data(:,2:3) = C{2}
yields
101.0000 0.3657 0.0636
102.0000 0.2208 0.1135
103.0000 0.5353 0.5191
104.0000 0.5009 0.5216
105.0000 0.5415 NaN
106.0000 0.5010 NaN
h e format of the data is as expected.
h e next examples demonstrate how to read the i le
geophys.txt
, which
contains a single header line but also the date (in an
MM/DD/YY
format)
and time (in an
HH:MM:SS.SS
format). We again use
textscan
to read the
i le,
clear
fid = fopen('geophys.txt');
data = textscan(fid,'%u %f %f %f %s %s','Headerlines',1);
fclose(fid);
where we skip the header, read the i rst column (the sample ID) as a 32-bit
unsigned integer (
uint32
) with specii er
%u
, the next three columns
X
,
Y
, and
Z
as 64-bit double-precision l oating-point numbers (
double
) with specii er
%f
, and then the date and time as character strings with specii er
%s
. We then
convert the date and time to serial numbers, where a serial date number of 1
corresponds to
Jan-1-0000
. h e year
0000
is merely a reference point and is
not intended to be interpreted as a real year.