Geoscience Reference
In-Depth Information
data_date_serial = datenum(data{5});
data_time_serial = datenum(data{6});
Finally, we can convert the date and time serial numbers into a data and time
array by typing
data_date = datevec(data_date_serial)
data_time = datevec(data_time_serial)
which yields
data_date =
2013 11 18 0 0 0
2013 11 18 0 0 0
2013 11 18 0 0 0
2013 11 18 0 0 0
2013 11 18 0 0 0
data_time =
1.0e+03 *
2.0130 0.0010 0.0010 0.0100 0.0230 0.0091
2.0130 0.0010 0.0010 0.0100 0.0230 0.0102
2.0130 0.0010 0.0010 0.0100 0.0230 0.0504
2.0130 0.0010 0.0010 0.0100 0.0240 0.0051
2.0130 0.0010 0.0010 0.0100 0.0240 0.0233
h e i rst three columns of the array data_date contain the year, month and
day. h e fourth to sixth columns of the array data_time contain the hour,
minute and second.
We can also write data to a formatted text i le using fprintf . As an example
we again load the data from geochem.txt at er we have commented out the
i rst line and have replaced -999 with NaN . Instead of using load geochem.txt ,
we can type
clear
data = load('geochem.txt');
to load the contents of the text i le into a double-precision array data . We
write the data to a new text i le geochem_formatted.txt using fprintf . Since
the function fprintf writes all elements of the array data to the i le in column
order we need to transpose the data before we save it.
data = data';
We i rst open the i le using the permission w for writing , and discard the
existing contents. We then write data to this i le using the formatting
operators %u for unsigned integers and %6.4f for i xed-point numbers with
a i eld width of six characters and four digits at er the decimal point. h e
Search WWH ::




Custom Search