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('','time');
o3_data = ncread('','O3');
oh_data = ncread('','OH');
no_data = ncread('','NO');
no2_data = ncread('','NO2');
ch4_data = ncread('','CH4');
co_data = ncread('','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


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 *