MATLAB: Subscript indices must either be real positive integers or logicals; Perimeter issue

errorread data

I'm just having a small issue with my code. The code reads a file, plots the data and closes. Simple right? Well, the code is over 500000+ lines long, and after 5000 points, a new line begins. I keep getting the error "Subscript indices must either be real positive integers or logicals" for when I run this. The data goes down in one straight column, with no line separation, like this:
4
5
6
7
This is what the code looks like:
fid = fopen('***.dat');
p = fscanf(fid, '%g',[1,inf])';
x=1:1:5000;
y=p(:,1);
for i=1:100;
plot(x,y((i-1)*5000:i*5000),'g')
hold all
end
plot(x(1:1:5000),y(500001:505001),'b') %Last line is special, so it is separate
axis([0 5000 0 100])
fid=fclose(fid);
Is there some obvious flaw I'm overlooking? Thanks.

Best Answer

plot(x,y((i-1)*5000:i*5000),'g')
when i=1, you are indexing y from 0:5000, matlab doesnt have 0 index.