Matlab reading CDF files

NASA CDF data file format can be read in many coding languages including Matlab. Matlab data file interfaces don’t always yield an obvious error message if something is wrong like a data file doesn’t exist or a variable doesn’t exist in a data file. For CDF, the message for cdfread of a non-existent variable is like:

Error using matlab.internal.imagesci.cdflib

CDF library failure encountered when executing the CDFclosezVar routine: “ILLEGAL_IN_zMODE: Operation is illegal while in zMode.”

One can use try-catch or check that the variable name exists with cdfinfo .Variables column 1.