www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ReadValueOfVariableInNetCDFFileExample.m
%% Read Value of Variable in NetCDF File %% % Open the example file, |example.nc|. % Copyright 2015 The MathWorks, Inc. ncid = netcdf.open('example.nc','NC_NOWRITE'); %% % Get the name of the first variable in the file. varname = netcdf.inqVar(ncid,0) %% % Get variable ID of the first variable, given its name. varid = netcdf.inqVarID(ncid,varname) %% % Get the value of the variable. Use the variable ID as the second input to % the |netcdf.getVar| function. data = netcdf.getVar(ncid,varid) %% % Display the data type of the output value. whos data %% % Get the value of the |avogadros_number| variable again, specifying that % the output data type should be |single|. data = netcdf.getVar(ncid,varid,'single'); %% % Display the data type of the output value. whos data %% % Close the NetCDF file. netcdf.close(ncid)