error in netcdf file (vardata = ncObj.read(varName, varargin{:});) worked earlier.

Hi, I have written a code to read data from .nc file. Some days earlier it was fine. However, suddenly it is showing following errors. I also tried re-writing the code using online help but no success. My code is simple.
files = dir('*.nc');
numfiles = length(files);
nc = cell(1, numfiles);
for k=1:numfiles;
nc= netcdf.open(files(k).name);
altti{k}=ncread(files(k).name,'tpaltitude_top');
end;
There are also other lines but I am getting error from 1st line. The error is as follows,
Error using internal.matlab.imagesci.nc/getGroupAndVarid (line 2076)
Could not find variable or group 'tpaltitude_top' in file.
Error in internal.matlab.imagesci.nc/read (line 594)
[gid, varid] = getGroupAndVarid(this, location);
Error in ncread (line 59)
vardata = ncObj.read(varName, varargin{:});
Error in column_brightness_plot (line 11)
altti{k}=ncread(files(k).name,'tpaltitude_top');
I have checked using ncdisp('') that 'tpaltitude_top" does exist in .nc files. Need help. Thanks in advance.

9 Comments

These two lines don't belong to the example
nc = cell(1, numfiles);
nc = netcdf.open(files(k).name);
ncread opens and closes the file.
What do you mean? I didn't get you.
I mean that since ncread itself opens and closes the file, there is no reason to include those two lines in the code in the question. To me it looks strange, but I have not checked whether it can cause any problems.
I have tried running the code by incorporating your suggestion but no success. Still the same error.
You check whether the said variables present in file. Just using ncdisp and ncread will do all the business.
Could you zip the .nc file and attach the zip for our testing?
Thank you so much. Now I sorted it out. I apologise. A .nc file from another satellite was also there in the same directory that was creating problem. I removed it by checking manually. I was in trouble for last 3 days. Thank you much.
Madan kumar would you please check my code for the same error.
https://uk.mathworks.com/matlabcentral/answers/441758-unable-to-extract-data-for-extact-days-in-netcdf-files-to-text-files-swat-tempreture-data-max-min-r?s_tid=prof_contriblnk

Sign in to comment.

Answers (0)

Asked:

on 18 Dec 2017

Commented:

on 27 Jan 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!