Unrecognized function or variable 'nc_varget'.

Hey Guys!
I am a begginer in MATLAB. I am currently working on a bulky netCDF file downloaded from ISIMIP3b. I wanted to divide my work into two parts: preprocessing and postprocessing. In preprocessing, I want to read a specific variable 'prcp' with the function nc_varget. However, I cannot solve the error "Unrecognized function or variable (nc)". You can help me if you've ever faced such an error and know how to fix it.

2 Commenti

If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Walter Roberson
Walter Roberson il 17 Ott 2022
Modificato: Walter Roberson il 19 Ott 2022
The source code for nc_varget does not use any variable named nc or otherwise have any nc that might lead to that message.
Is it possible that when you called the function you passed in the name of a file with nc extension but forgot to enclose the name in apostrophes?

Accedi per commentare.

 Risposta accettata

Cris LaPierre
Cris LaPierre il 17 Ott 2022
Modificato: Cris LaPierre il 17 Ott 2022
How are you loading and reading in the netCDF file? Without seeing your code, it's hard to say what this error means. However, this is code I have used to load nc files in the past.
ncfile='bsbd-0.9.3.nc'; % filename is bsbd-0.9.3.nc
ncdisp(ncfile)
lon=ncread(ncfile,'lon'); % Load variable 'lon' from nc file
lat=ncread(ncfile,'lat'); % Load variable 'lat' from nc file
depth=ncread(ncfile,'depth'); % Load variable 'depth' from nc file

Più risposte (1)

Habtamu
Habtamu il 19 Ott 2022
Modificato: Habtamu il 19 Ott 2022
Dear contributors,
I appreciate your feedback, and I tried putting it into practice, however I kept getting the same issues. Just a little clarification on the question here. Pre- and post-processing for my data that I downloaded from ISIMIP3b is what I wish to accomplish. 'pr' is one of the variables of the netCDF file, which contains a dimension 720x360x1461 (lon, lat, time). Therefore, I want to iterate the for loop below using the nc varget function, but I keep getting 'Unrecognized function or variable (nc_varget)'
% define run settings
out_var = {'PRECTmms'}; % specify the variables for modification
src_var = {'pr'};
junk_var = {'pr'};
prod_dir = 'atm_forcing.datm7.cruncep_qianFill.0.5d.V4.c130305';
var_dir = 'Precip6Hrly';
var_fnam = 'Prec';
fname = ['/net/so4/landclim_nobackup/wthiery/cesm_output/ISIMIP2b/inputdata_template/atm_forcing.datm7.cruncep_qianFill.0.5d.V4.c130305/' var_dir '/clmforc.cruncep.V4.c2011.0.5d.' var_fnam '.1930-',num2str(mon, '%02d'),'.nc'] % WT
for v=1:length(src_var)
myvar = cell2mat(out_var(v))
data = nc_varget(fname,myvar);
for j=1:nday(mon) % for each timestep in this month
st = (j-1)*4+1;
ed = j*4;
a = squeeze(sum(data(st:ed,:,:)));
for t=st:ed
data_junk = squeeze(data(t,:,:));
fac = data_junk./a;
fac(a==0) = NaN; % set the NaN value to be zero if the original daily data is zero
factor(v,t,:,:) = fac;
end
end
end

4 Commenti

nc_varget is part of an older third-party toolbox that you have to install. I linked to the source in my comment.
These days you would use ncread() or netcdf.getvar()
Thanks for your comment.
The script I am going to use is developed by someone else. My Professora gave me ISIMIP data to run it with the script. I don't think I'm allowed to change the function in there.
Then you need to install that third-party toolbox. https://mexcdf.sourceforge.net/downloads/
Notice the point there, that these days, the tools call the Mathworks functions underneath. If you just need equivalent functionality, then that should be fine, but if you need to "replicate" earlier experiments then it could potentially be important that you match the code as it was at the time.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by