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 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by