Index exceeds array bounds

조회 수: 2 (최근 30일)
Jonas Damsbo
Jonas Damsbo 2018년 12월 16일
답변: madhan ravi 2018년 12월 16일
Hi
When I run my code, I got the error "Index exceed array bounds. I am not sure what it's mean?
I got it in the line "z{i} = ncread(ncfiles(i).name,'z',[1 1 n],[nx ny 1]);"
for i = 1:Nfiles
lon{i} = ncread(ncfiles(i).name, 'longitude'); nx = length(lon{i});
lat{i} = ncread(ncfiles(i).name, 'latitude'); ny = length(lat{i});
time{i} = ncread(ncfiles(i).name, 'time'); nt = length(time{i});
z{i} = ncread(ncfiles(i).name, 'z'); nz = length(z{i});
end
%Midler geopotentialet til et månedsmiddel
zmean = zeros([nx ny]);
blocks = zeros([nx]);
for n = 1:nt
z{i} = ncread(ncfiles(i).name,'z',[1 1 n],[nx ny 1]);
zx(:,1:ny) = z{i}(:,ny:-1:1);
zmean = zmean + zx;
%pcolor(lon,lat,z');
%shading interp
%drawnow
GHGS = (zx(:,[151+[-1 0 1]])-zx(:,[131+[-1 0 1]]))/20;
GHGN = (zx(:,[171+[-1 0 1]])-zx(:,[151+[-1 0 1]]))/20;
for i=1:ny
blocks(i)=blocks(i)+1;
if GHGS > 0;
disp('The point is blocked')
elseif GHGN < -10;
disp('The point is blocked')
end
end
end

답변 (1개)

madhan ravi
madhan ravi 2018년 12월 16일
I am not going to understand what you mean but see the example below:
x=1:10
x(11) % you will get the error INDEX EXCEEDS ARRAY BOUNDS
When you try to access the element of an array than it's existence you will get an error.

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by