MATLAB with NC Toolbox

How to use the OPeNDAP server in MATLAB with NC Toolbox.

The following explains the steps of loading data served by OPeNDAP using MATLAB.

Download and install MATLAB (if needed):

Download and install the MATLAB OPeNDAP library (if needed):

Start MATLAB:

Setting up NC Toolbox:

Load data using ncdataset and proceed as you normally would:
Note: % operator as comments. Example is using MATLAB R2010.

 
>> 
>> 
 
>> 
>> 
>> 
 
>> 
>> 
>> 
>> 
>> 
>> 
 
 
 
 
 
>> 
>> 
 
>> 
>> 
>> 
>> 
>> 
 
>> 
>> 
 
>> 
>> 
>> 
>> 
% Setting up NC toolbox
addpath('c:/nctoolbox')
setup_nctoolbox
% Load the coastline
load coast
xlon = long;
ylat = lat;
% Find the indexes for 165W-153W, 18N-24N, and Oct 3, 2004.
ds = ncgeodataset('http://apdrc.soest.hawaii.edu/dods/public_data/NLOM/nlom_ssh');
lon = ds.data('lon');
lat = ds.data('lat');
time = ds.data('time');
I = find(lon >= 195 & lon <= 207);
J = find(lat >= 18 & lat <= 24);
% Note: datenum and datevec use the time since Jan 0, 0000.
% We need to add 365 days to fix the dataset
% because this dataset uses since Jan 1, 0001.
% datevec(time(1)+365) = [2002 6 1 0 0 0] {start time: Jun 1, 2002}
% datevec(mytime+365) = [2004 10 3 0 0 0] {my time: Oct 3, 2004}
mytime = datenum([2004 10 3 0 0 0])-365;
K = find(time == mytime);
% Load the NLOM sea surface height from the above information
ssh = ds.data('ssh', [K J(1) I(1)], [K J(end) I(end)]);
worldmap([lat(J(1)) lat(J(end))],[lon(I(1)) lon(I(end))])
setm(gca,'MapProjection','mercator')
gridm off
framem off

% Contour sea surface height
contourfm(lat(J),lon(I), double(squeeze(ssh)), 12, '-')
colorbar
% Plot land outlines
hold on
plotm(ylat,xlon,'k')
title('NLOM 1/16 degree Sea Surface Height [cm] October 3, 2004')
tightmap