MATLAB: Error:Subscript indices must either be real positive integers or logicals?

logicalsreal positive integerssubscript indices error

Hi,
In the code below i get the error "Subscript indices must either be real positive integers or logicals" in line 14:
load GreekCatTRIAL.mat
kkk=1600;
k1=5;
k2=0;
for i=kkk+1:k1:15806-k1;
if (DATE(i)>DATE(i-1));
if(DATE(i)>20000000);kkk=2400;end;
if(DATE(i)>20110000);kkk=4800;end;
k2=k2+1;pause(k1*0.005/20);
clf('reset');
plot(coast(:,1),coast(:,2),'k');
hold;
plot(LON(i-kkk-k1:i),LAT(i-kkk-k1:i),'+',LON(i-k1:i),LAT(i-k1:i),'o', ...
'MarkerEdgeColor','k', 'MarkerFaceColor','r');
axis([14 33 30 44]);
text(15,33,num2str(DATE(i-kkk-k1)));
text(15,32,num2str(DATE(i)));
year1=floor(DATE(i)/10000);
year2=floor(DATE(i-kkk-k1)/10000);
dyear=year1-year2;
text(18,32,num2str(dyear));
month1=floor((DATE(i)-10000*year1)/100);
month2=floor((DATE(i-kkk-k1)-10000*year2)/100);
dmonth=dyear*12+month1-month2;
text(19,32,num2str(dmonth));
% text(20,32,num2str(DATE(i)-DATE(i-kkk-k1)));
drawnow;
% M(k2)=getframe;
end
end
where:
LON is the variable of longtitude of the form 20.38 etc containing 15806 data in 1 column LAT is the latitude of the form 40.35 containing 15806 data in 1 column and DATE is the date of earthquake occurence, of the form 19640120 (yyyy mm dd). Don't know where is the problem.How can I fix it? Any thoughts? Thanks

Best Answer

On the first iteration,
plot(LON(i-kkk-k1:i),LAT(i-kkk-k1:i),'+',LON(i-k1:i),LAT(i-k1:i),'o', ...
'MarkerEdgeColor','k', 'MarkerFaceColor','r');
the subscript elements i = 1601, kkk = 1600, and k1 = 5, so i-kkk-k1 = -4. Since indices in MATLAB have to be greater than zero, a negative index is going to throw an error.