If you wish to read/write netCDF-4 files, you've got some choices to make, because as of MATLAB version R2009b, the native netcdf package supports the netCDF library version 3.6.2, which will not read netCDF-4 files.
Since MATLAB can use java jar files, it turns out that the trick for reading OPeNDAP datasets will also work here. In other words, the SNCTOOLS java backend will read netCDF-4 files. To enable the java backend, go the OPeNDAP page and follow the instructions there.
NetCDF-4 files are really HDF5 files under the hood (very special HDF5 files...) As of R2009a, MATLAB does support HDF5 version 1.8.1, meaning that the HDF5 interface can be used to access netCDF-4 files. A decent set of tools is HDF5TOOLS, which is forms a wrapper around MATLAB's native HDF5 low-level interface. However, this will treat netCDF-4 files as if they were HDF5 files, meaning that some of the semantics are lost. For this reason, I would not use HDF5TOOLS to write to netCDF-4 files. It's perfectly safe to read using them, however.
It's also possible to compile mexnc with netCDF-4 support, but you should only do this if you absolutely must WRITE netCDF-4 files. Here's how you might do this on a maci64 machine running R2009b.
./configure --disable-shared --prefix=/Users/jevans/netcdf-4 make make install
./configure --disable-shared --prefix=/Users/jevans/netcdf-4 --enable-netcdf-4 --with-hdf5=/Users/johne/netcdf-4 make make install
NETCDF="/Users/jevans/netcdf-4"
CFLAGS="$CFLAGS -g -I${NETCDF}/include "
CLIBS="${NETCDF}/lib/libnetcdf.a ${NETCDF}/lib/libhdf5_hl.a ${NETCDF}/lib/libhdf5.a -lz $CLIBS "
This tells the mex-file compilation where to find the static netcdf and hdf5 libraries.
mex -v -f ./mexopts.sh -output vanilla_mexnc mexgateway.c netcdf3.c netcdf2.c common.c mv vanilla_mexnc.mex* ../private
>> setpref('MEXNC','USE_TMW',false);
This tells mexnc not to use MATLAB's native netcdf-3 package, but to rather "do it ourselves". By default, mexnc will use the native netcdf-3 package when it detects MATLAB R2008b or higher.