error index exceeds dimensions

10 visualizaciones (últimos 30 días)
Evan Weking
Evan Weking el 25 de Oct. de 2016
Comentada: Walter Roberson el 26 de Oct. de 2016
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 comentarios
KSSV
KSSV el 25 de Oct. de 2016
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 el 26 de Oct. de 2016
oh i see, okay i'll try it..
thanks for your suggestion

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Oct. de 2016
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 comentarios
Evan Weking
Evan Weking el 26 de Oct. de 2016
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 el 26 de Oct. de 2016
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

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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