Opening nc file and reading sections of data

5 visualizaciones (últimos 30 días)
Logan Tegler
Logan Tegler el 5 de Ag. de 2021
Comentada: Logan Tegler el 20 de Ag. de 2021
Hi all --
I have an nc file with several variables I am trying to open and read at specific depths. I was able to get it to run yesterday, but today it is throwing the following error: "Index in position 1 exceeds array bounds (must not exceed 1)." This error wasn't there yesterday!
Variable Details:
LON
Size: 180x360x102
Dimensions: latitude,longitude,depth
Datatype: single
Attributes:
Description = 'longitude (degrees east)'
LAT
Size: 180x360x102
Dimensions: latitude,longitude,depth
Datatype: single
Attributes:
Description = 'latitude (degrees north)'
DEPTH
Size: 180x360x102
Dimensions: latitude,longitude,depth
Datatype: single
Attributes:
Description = 'depth (m)'
Cd_avg
Size: 180x360x102x12
Dimensions: latitude,longitude,depth,month
Datatype: single
Here is my code and thanks for any help!
filename='modelobs_v1a.nc'
ncdisp(filename);
Cdavg=ncread(filename, 'Cd_avg');
long=ncread(filename, 'LON');
lat=ncread(filename, 'LAT');
depth=ncread(filename, 'DEPTH');
firstIdx = [1 1 1 12];
lastIdx = [180 360 1 12];
t = filename('Cd_aveg', firstIdx, lastIdx); % default stride here is [1 1 1 1]
t2 = squeeze(t);
size(t2);
%t2 should show up as Cd_avg over global lat/long

Respuesta aceptada

Rik
Rik el 5 de Ag. de 2021
Your second code paragraph assumes filename is a function, while the first sets it as a variable.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by