error index exceeds dimensions

10 次查看(过去 30 天)
Evan Weking
Evan Weking 2016-10-25
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