error index exceeds dimensions

조회 수: 8 (최근 30일)
Evan Weking
Evan Weking 2016년 10월 25일
댓글: Walter Roberson 2016년 10월 26일
hello, i'm new in MATLAB, i want to ask,, i have an image and i already transform them into binary image the image is like this :
i want to convert my binary image become straight line
here is the code :
global X;
X = handles.m;
X = gca;
global freq;
X.Scale = 'log';
int X p1 p2;
double froot(301),freq(301),val(301),point(301);
double val1 val2; result; %#ok<VUNUS,NODEF>
for X=0; X<301; %#ok<VUNUS>
froot(X) = 8e-3 + (100e-3)/301.0*X; %#ok<AGROW>
freq(X) = (1.0/froot(X))*(1.0/froot(X)); %#ok<AGROW>
point(X) = 301.0*freq(X)/20000.0; %#ok<AGROW>
p1 = trunc(int(point(X)));
p2 = p1+1;
val1 = val(p1);
val2 = val(p2);
result = val1+(val2-val1)/(p2-p1)*(point(X)-p1); %#ok<NASGU>
end
guidata(hObject,handles);
axes(handles.axes3);
imshow(X);
msgbox('Transform SUCCESSFUL !');
but when i execute the program,, an error message appear like this :
??? Index exceeds matrix dimensions.
Error in ==> processing>pushbutton10_Callback at 177
double froot(301),freq(301),val(301),point(301);
i can't figure it out where the problem was,, i need help
Thanks
  댓글 수: 2
KSSV
KSSV 2016년 10월 25일
Check dimensions of froot,freq,val,point they must be less then 301 and you are accessing 301 index of those.
Evan Weking
Evan Weking 2016년 10월 26일
oh i see, okay i'll try it..
thanks for your suggestion

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 10월 25일
MATLAB does not declare variables. Your line
double froot(301),freq(301),val(301),point(301);
is instead a call to double() followed by a series of other commands, and is equivalent to
double( 'froot(301)' )
freq(301)
val(301)
point(301);
  댓글 수: 2
Evan Weking
Evan Weking 2016년 10월 26일
thanks for your answer,, i fixed my code just like you suggest, but another error message appeared like this :
??? Attempted to access freq(301); index out of bounds because numel(freq)=0.
Error in ==> processing>pushbutton10_Callback at 178
freq(301)
is it means that i must change freq index value to 0 ? thanks
Walter Roberson
Walter Roberson 2016년 10월 26일
In MATLAB,
for X=0; X<301; %#ok<VUNUS>
is the same as
for X=0
X<301; %do a logical test and throw the result away because the semi-colon says not to print it
...
If you want a loop from 0 to 300 you need
for X = 0 : 300
Remember though that MATLAB indexing starts at 1

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by