Attempted to access A(0,0); index must be a positive integer or logical.
3 views (last 30 days)
Show older comments
when i run this code it tells me A(0,0); index must be a positive integer or logical.
clc;
clear;
close all;
A=xlsread('DEM_Topography.xlsx');
C=xlsread('pyramiddem2.xlsx');
B=C(1:13,1:13);
i=1;
j=1;
for i=1:33
for j=1:75
volA(i,j)=((A(i-1,j-1)+A(i,j-1)+A(i-1,j)+A(i,j))/4)*2500;
end
end
for jj=1:5
for ii=1:25
for i=1:13
for j=1:13
vol(i,j)=B(i,j)-volA(i+ii,j+jj);
if vol(i,j) < 0;
vol(i,j)=0;
end
end
end
x(ii,jj)=sum(sum(vol));
end
end
y=x/1000;
disp(y)
%Price of Volume of sand
for ij=1:5
for iv=1:25
if y(iv,ij) > 5000
price_sand(iv,ij)=(100*(y(iv,ij)-5000));
else
price_sand(iv,ij)=(160*(5000-y(iv,ij)));
end
if price_sand(iv,ij) > 150000;
price_sand(iv,ij) = 0;
end
end
end
disp('Price of sand zeros indicate over $150,000')
disp(price_sand)
0 Comments
Answers (1)
dpb
on 7 Sep 2014
Ayup...
for i=1:33
for j=1:75
volA(i,j)=((A(i-1,j-1)+A(i,j-1)+A(i-1,j)+A(i,j))/4)*2500;
when, i,_j_==1, the i-1 and j-1 indices are zero, indeed. Zero is not a positive integer and Matlab arrays are 1-based.
Start the loop indices at 2 instead. Also the loop could be replaced with filter2
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!