Trying to use a for loop to capture data from netCDF output, and then average the data
조회 수: 6 (최근 30일)
이전 댓글 표시
I am trying to grab the "September" and "March" Sea Ice Data from a netCDF output file, and then average the yearly September and March Sea Ice data to produce yearly "minimum" and "maximum" sea ice data. I know the ncread() commands are correct, but my for loop seems to crash (as in MatLab hangs/freezes, with no error message) after calculating all values for A, B, C, D.
What I really am intending to achieve is to have MatLab pull the March sea ice data from year one (data points 18-24), average these, store the result as a new variable, and then move on to the next year (data points 18+(73*1)). And do the same for the September Sea Ice data.
Here is my code thus far:
%read and store UVic Model Variables from NetCDF files
Time = ncread('2000-2500_seaice.nc','time');
SeaIceVol = ncread('2000-2500_seaice.nc','O_icevolN');
SeaIceArea = ncread('2000-2500_seaice.nc','O_iceareaN');
for i=1:501
%Determine which data points fall within "March"
A = 18+(73*(i-1))
B = 24+(73*(i-1))
%Determine which data points fall within "September"
C = 55+(73*(i-1))
D = 61+(73*(i-1))
%Store "March" Only Sea Ice Data
MV(i) = SeaIceVol(A):SeaIceVol(B)
%Take Average of March Values in any given year and store in a new variable
MVbar(i) = mean(MV);
%Store "September" Only Sea Ice Data
SV(i) = SeaIceVol(C):SeaIceVol(D);
%Take Average of September Values in any given year and store in a new variable
SVbar(i) = mean(SV);
MVbar
SVbar
end
Any suggestions?
댓글 수: 3
Ashish Uthama
2013년 1월 23일
Tyler, could you add in the dimensions of Time, SeaIceVol and SeaIceArea? You could also use the debugger to single step through the code and ensure that your indexing inside the loop is giving you the data you think you need. See link for the debugging process.
답변 (1개)
Ashish Uthama
2013년 1월 24일
편집: Ashish Uthama
2013년 1월 24일
Tyler Herrington:
I solved the issue by changing the SeaIceVol(A):SeaIceVol(B) into a series of commas:
for i=1:500
%Determine which data points fall within "March"
A = 18+(73*(i-1));
B = 24+(73*(i-1));
%Determine which data points fall within "September"
C = 55+(73*(i-1));
D = 61+(73*(i-1));
%Store "March" Only Sea Ice Data
MV(i) = SeaIceVol(A), SeaIceVol(A+1), SeaIceVol(A+2), SeaIceVol(A+3), SeaIceVol(B-2), SeaIceVol(B-1), SeaIceVol(B);
%Take Average of March Values in any given year and store in a new variable
MVbar(i) = mean(MV(i));
%Store "September" Only Sea Ice Data
SV(i) = SeaIceVol(C), SeaIceVol(C+1), SeaIceVol(C+2), SeaIceVol(D+3), SeaIceVol(D-2), SeaIceVol(D-1), SeaIceVol(D);
%Take Average of September Values in any given year and store in a new variable
SVbar(i) = mean(SV(i));
end
댓글 수: 2
N/A
2015년 8월 19일
I am currently using the ncread to partially read big (11GB) .nc-files. Matlab starts reading and calculating really fast, but at an unpredictable time the calculation/reading just stop. I monitor this with several windows utilities... hd-usage drops to 0-1% from originally about 90%...
Has anyone got an idea?
참고 항목
카테고리
Help Center 및 File Exchange에서 NetCDF에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!