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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Nirmal
Nirmal el 25 de Jul. de 2012
Editada: Nirmal el 25 de Jul. de 2012
plot(x,y((i-1)*5000:i*5000),'g')
when i=1, you are indexing y from 0:5000, matlab doesnt have 0 index.

Más respuestas (1)

Walter Roberson
Walter Roberson el 25 de Jul. de 2012
Which line does the error occur on?
At the command window, command
dbstop if error
and run the program. When it stops, use
whos
and look at the names of the variables in the workspace. You might find that you have a variable with the same name as one of the MATLAB routine. For example if you had a variable named "axis" then axis([0 5000 0 100]) would be trying to index the variable "axis" with index 0.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by