⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generate_nc_file.m

📁 netcdf插件安装和.nc格式数据的读取,主要操作mexcdf53.dll和netcdf.dll文件,适于从事海洋和大气专业的的数据格式.作者在实际中用matlab处理了一些此类数据
💻 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 + -