## WEIRD ERROR (INDEX EXCEEDS MATRIX DIMENSIONS)

### Ripul Dutt (view profile)

on 7 Mar 2019
Latest activity Edited by Ripul Dutt

### Ripul Dutt (view profile)

on 7 Mar 2019
I am getting a weird error in the code, I am calling it weird becasue there's nothing wrong with the line of code where I am getting the error.
That line runs perfectly fine by itself. I am creating a matrix of zeros and then filling that matrix in a loop according to some conditions.
My code is below. Error on line 29, after the loop os run once!
%%%%CODE
%channel overlap method
run_hours = 560;
cd('C:\Users\Abdul Wahab\Desktop\Topo_data')
topo = topo_data.ZD;
nx = 796; %number of x points
ny = 522; % number of y points
deriv=zeros(nx,ny,run_hours-1);%creation of a matrix to store the elevation change information
% creation of a volume of 1s and 0s
for k =1:1:run_hours-1
for i=1:1:nx
for j=1:1:ny
if(topo(i,j,k)-topo(i,j,k+1)>=1) || (topo(i,j,k)-topo(i,j,k+1)<=-1)
deriv(i,j,k)=1;
else
deriv(i,j,k)=0;
end
end
end
end
for k=1:1:run_hours-80
perc_change = zeros(80,2,run_hours-80);
for l=k:1:k+80
deriv_t=zeros(nx,ny);
for m=k:1:l
for i=1:1:nx
for j=1:1:ny
deriv_t(i,j)= deriv_t(i,j) + deriv(i,j,m);
end
end
end
% check_sum to assign all values greater than 1 to 1
for i=1:1:nx
for j=1:1:ny
if(deriv_t(i,j)>=1)
deriv_t(i,j)=1;
end
end
end
% calcuate the percentage of delta change upto a given l
ones=0;
zeros=0;
for i=1:1:nx
for j=1:1:ny
if(deriv_t(i,j)==1)
ones=ones+1;
else
zeros=zeros+1;
end
end
end
perc_change(l-k+1,1,k)=l-k+1;
perc_change(l-k+1,2,k)=ones/(ones+zeros);
end
end

Walter Roberson

### Walter Roberson (view profile)

on 7 Mar 2019
Can we have the data file for testing purposes?