1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
% Tutorial for using ncArray
% It is advised to run this script in an empty directory.
% It will delete and overwrite files named file1.nc, file2.nc and file3.nc.
% size of the example data (2x3)
n = 3;
m = 2;
% create 3 files (file1.nc, file2.nc,...) with a 2x3 variable called SST
data = zeros(n,m);
disp('create example files: file1.nc, file2.nc, file3.nc')
for i = 1:3
data(:) = i;
files{i} = sprintf('file%d.nc',i);
delete(files{i});
ncarray_example_file(files{i},data);
end
% Using ncArray
SST = ncArray('file1.nc','SST');
disp('load the entire file')
data = SST(:,:,:);
disp('get the attribute units')
units = SST.units;
disp('load a particular value');
data = SST(3,2,1);
% Using ncCatArray
disp('concatenate the files over the 3rd dimension (here time)')
SST = ncCatArray(3,{'file1.nc','file2.nc','file3.nc'},'SST');
% or just
% SST = ncCatArray(3,'file*.nc','SST');
disp('load all 3 files');
data = SST(:,:,:);
disp('load a particular value (1,2,1) of the 3rd file');
data = SST(1,2,3);
|