📄 generate_nc_file.m
字号:
%An example to generate an nc file
% ---------------------------- DEFINE THE FILE --------------------------- %
ncquiet % No NetCDF warnings.
nc = netcdf('ncexample.nc', 'clobber'); % Create NetCDF file,输入文件名.
nc.description = 'NetCDF Example'; % Global attributes,基本信息.
nc.author = 'Dr. Charles R. Denham';
nc.date = 'June 9, 1997';
nc('latitude') = 10; % Define dimensions,数组维数.
nc('longitude') = 10;
nc{'latitude'} = 'latitude'; % Define variables,定义变量.
nc{'longitude'} = 'longitude';
nc{'depth'} = {'latitude', 'longitude'};
nc{'latitude'}.units = 'degrees'; % Attributes,单位信息.
nc{'longitude'}.units = 'degrees';
nc{'depth'}.units = 'meters';
% ---------------------------- STORE THE DATA ---------------------------- %
latitude = [0 10 20 30 40 50 60 70 80 90]; % Matlab data,变量数值.
longitude = [0 20 40 60 80 100 120 140 160 180];
depth = rand(length(latitude), length(longitude));
nc{'latitude'}(:) = latitude; % Put all the data,对nc文件赋各变量的值.
nc{'longitude'}(:) = longitude;
nc{'depth'}(:) = depth;
nc = close(nc); % Close the file,关闭文件.
% ---------------------------- RECALL THE DATA ---------------------------%读文件
nc = netcdf('ncexample.nc', 'nowrite'); % Open NetCDF file.
description = nc.description(:) % Global attribute.
variables = var(nc); % Get variable data.
for i = 1:length(variables)
disp([name(variables{i}) ' =']), disp(' ')
disp(variables{i}(:))
end
nc = close(nc); % Close the file.
% --------------------------------- DONE --------------------------------- %
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -