Working with netCDF data in Matlab

It took a bit of time, but here are some simple procedures to work with netCDF output that I get from my atmospheric chemistry model runs in Matlab.

Here is an example for pollutant concentrations obtained in .nc format from a CAABA/MECCA run:

% Read 4D-double data from .nc file for the following variables
time = ncread('caaba_mecca.nc','time');
o3_data = ncread('caaba_mecca.nc','O3');
oh_data = ncread('caaba_mecca.nc','OH');
no_data = ncread('caaba_mecca.nc','NO');
no2_data = ncread('caaba_mecca.nc','NO2');
ch4_data = ncread('caaba_mecca.nc','CH4');
co_data = ncread('caaba_mecca.nc','CO');

% Extract concentration data from 4D double matrix and write to new variable
o3_data2 = squeeze(o3_data(1,1,1,:));
oh_data2 = squeeze(oh_data(1,1,1,:));
no_data2 = squeeze(no_data(1,1,1,:));
no2_data2 = squeeze(no2_data(1,1,1,:));
ch4_data2 = squeeze(ch4_data(1,1,1,:));
co_data2 = squeeze(co_data(1,1,1,:));

Starting here you can resume regular Matlab code to work with the variables defined

Published by

greg

Atmospheric chemistry researcher and university teacher. Data analysis/chemometrics specialist (PCA, PCR, Cluster analysis, SOM)

Leave a Reply

Your email address will not be published. Required fields are marked *