NCEXISTS check if variable exists in NetCDF4 file
Contents
Inputs
- file: data filename
- variable: path of variable in file
Outputs
function exists = ncexists(file, variable)
arguments
file (1,1) string
variable (1,1) string
end
exists = false;
try
ncinfo(file, variable);
exists = true;
catch e
if ~strcmp(e.identifier, "MATLAB:imagesci:netcdf:badLocationString") && ...
~strcmp(e.identifier, "MATLAB:imagesci:netcdf:unknownLocation") && ...
~strcmp(e.message, "NetCDF: Variable not found")
rethrow(e)
end
end
end