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

조회 수: 2 (최근 30일)
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.

채택된 답변

Nirmal
Nirmal 2012년 7월 25일
편집: Nirmal 2012년 7월 25일
plot(x,y((i-1)*5000:i*5000),'g')
when i=1, you are indexing y from 0:5000, matlab doesnt have 0 index.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 25일
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.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by