www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ImportCDFFilesUsingLowLevelFunctionsExample.m
%% Import CDF Files Using Low-Level Functions % This example shows how to use low-level functions to read data from a CDF % file. The MATLAB(R) low-level CDF functions correspond to routines in the % CDF C API library. To use the MATLAB CDF low-level functions effectively, % you must be familiar with the CDF C interface. %% Open CDF File % Open the sample CDF File, |example.cdf|. % Copyright 2015 The MathWorks, Inc. cdfid = cdflib.open('example.cdf'); %% Get Information About File Contents % Use |cdflib.inquire| to get information about the number of variables in % the file, the number of global attributes, and the number of attributes % with variable scope. info = cdflib.inquire(cdfid) %% Get Information About Variables % Use |cdflib.inqurieVar| to get information about the individual % variables in the file. Variable ID numbers start at zero. info = cdflib.inquireVar(cdfid,0) %% info = cdflib.inquireVar(cdfid,1) %% Read Variable Data Into Workspace % Read the data in a variable into the MATLAB workspace. The first variable % contains CDF Epoch time values. The low-level interface returns these as % |double| values. data_time = cdflib.getVarRecordData(cdfid,0,0) %% % Convert the time value to a date vector. timeVec = cdflib.epochBreakdown(data_time) %% Read Global Attribute From File % Determine which attributes in the CDF file are global. info = cdflib.inquireAttr(cdfid,0) %% % Read the value of the attribute. You must use the % |cdflib.getAttrgEntry| function for global attributes. value = cdflib.getAttrgEntry(cdfid,0,0) %% Close CDF File % Use |cdflib.close| to close the CDF file. cdflib.close(cdfid);