error index exceeds dimensions
10 views (last 30 days)
Show older comments
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 Comments
KSSV
on 25 Oct 2016
Check dimensions of froot,freq,val,point they must be less then 301 and you are accessing 301 index of those.
Answers (1)
Walter Roberson
on 25 Oct 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 Comments
Walter Roberson
on 26 Oct 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
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!