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

1 回表示 (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by