Azzera filtri
Azzera filtri

Trying to use a for loop to capture data from netCDF output, and then average the data

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Ashish Uthama
Ashish Uthama il 23 Gen 2013
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.

Accedi per commentare.

Risposte (1)

Ashish Uthama
Ashish Uthama il 24 Gen 2013
Modificato: Ashish Uthama il 24 Gen 2013
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 Commenti
K E
K E il 5 Ago 2015
Why do you think this worked? I am having problems with ncread crashing Matlab too.
N/A
N/A il 19 Ago 2015
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?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by