How to import current CO2 data from NOAA

The NOAA page Trends in Atmospheric Carbon Dioxide contains monthly CO2 data collected in Mauna Loa, Hawaii since March 1958. Clicking on the "Data" tab takes us to the page with the data files.

We are interested in the CO2 monthly mean data and want to import this into Matlab.

Column 4 of the data ("average") contains the monthly mean CO2 mole fraction determined from daily averages. The mole fraction of CO2, expressed as parts per million (ppm) is the number of molecules of CO2 in every one million molecules of dried air (water vapor removed).

url = 'ftp://aftp.cmdl.noaa.gov/products/trends/co2/co2_mm_mlo.txt'; % URL for monthly mean data
str = urlread(url);     % read data from url into string
                        % str contains 7 numbers per line, comment lines start with "#"
data = textscan(str,'%f %f %f %f %f %f %f','CommentStyle','#');  % data is cell array
data = cell2mat(data);  % convert to array

% data is now N by 7 array where N is the number of months available

N = size(data,1);       % number of months
tv = (1:N)';            % column vector with  1,...,N
cv = data(:,4);         % vector of monthly CO2 averages from column 4

ind = (cv~=-99.99);     % indices of rows where cv is not -99.99 (stands for missing data)
t = tv(ind);            % use only rows with valid data
conc = cv(ind);

% t is vector of available months 1,...,N with some values skipped (where no data available)
% conc is vector of corresponding monthly CO2 averages

plot(t,conc);
grid on; axis tight
xlabel('months since March 1958'); title('CO2 concentration (mole fraction in ppm)')