Opening nc file and reading sections of data

조회 수: 5 (최근 30일)
Logan Tegler
Logan Tegler 2021년 8월 5일
댓글: Logan Tegler 2021년 8월 20일
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

채택된 답변

Rik
Rik 2021년 8월 5일
Your second code paragraph assumes filename is a function, while the first sets it as a variable.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by