NCEXISTS check if variable exists in NetCDF4 file

Contents

Inputs

Outputs

function exists = ncexists(file, variable)

try
  ncinfo(file, variable);
  exists = true;
catch e
  if e.identifier ~= "MATLAB:imagesci:netcdf:unknownLocation"
    rethrow(e)
  end

  exists = false;
end

end