ncwrite issue + loop through many netcdf files
Ältere Kommentare anzeigen
I've looked through some of the questions already answered regarding nccreate and ncwrite, but I still find myself stumped. Would be very appreciative if someone could explain some components of the documentation in layman's terms. (I'm still relatively new to matlab and it goes over my head).
Ultimately, I am trying to go through many netcdf files, modify a variable and rewrite the the variable onto new netcdfs. I am more unsure about the ncwrite part than the loop, but I haven't gotten to checking on my loop part yet. The netcdf files differ only by the year in the name....
Some of the code was written here with the help from a previously answered question on stackoverflow.
myVarName = 'uwnd';
for yr=1948:1950
inFile = strcat('uwnd.',num2str(yr),'.nc');
disp(inFile);
outFile = strcat('uwnd.',num2str(yr),'_.nc');
disp(outFile);
% Read variable
inVar = ncread(inFile,myVarName); %read in the uwnd variable
lev=ncread(inFile,'level'); %read in level
lev=find(lev==250); %look for the level that i'll be using
lat=ncread(inFile,'lat'); %read in the latitude
lat = find(lat>=-90 & lat<=0); %look for lat that i'll be using
% Replace this line with your equation
outVar = squeeze(inVar(:,lat,lev,:)); %make final variable "inVar" with correct lat, level, all lon and all time
uwnd_=outVar;
% Write variable
nccreate('Outfile','uwnd_');
ncwrite('Outfile', 'uwnd_', 'outVar');
end
I believe that I am missing something for the start,stride in ncwrite, but I don't really understand the documentation for that yet.
Any words of advice would be helpful. Thank you!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu NetCDF Files finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!