clear all, clc,
projectdir = 'C:\Users\INPE\Desktop\NewData\COSMIC\2006\';
dinfo = dir(fullfile(projectdir,'**','*_nc')); %eg atmPrf_C004.2010.093.12.28.G28_2013.3520_nc
filenames = fullfile( projectdir, {dinfo.name} );
nfiles = length(filenames);
for K = 1 : nfiles
thisfile = filenames{K};
temperature = ncread(thisfile, 'Temp');
end
here is the code