What is index out of bound ?

2 views (last 30 days)
Prakash Sharma
Prakash Sharma on 23 Apr 2015
Commented: Walter Roberson on 6 May 2015
Sir i have two files . When i run these codes I get this error.
duplicate
Attempted to access test(29,258,2); index out of bounds because size(test)=[512,512,1].
Error in duplicate>Segment_Callback (line 337)
cimg(i,j,2) = test(i,j,2);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in duplicate (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)duplicate('Segment_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
What the error means and how can I solve it? It is very urgent.. Can you please help me soon.

Answers (1)

Image Analyst
Image Analyst on 23 Apr 2015
You're trying to assign the green color channel to another image:
cimg(i,j,2) = test(i,j,2);
but it's not a color image and does not have a second color plane. What you should do if you want to have a color image is this:
[rows, columns, numberOfColorChannels] = size(test);
if numberOfColorChannels == 1
% It's a gray scale image. Create a color image from it.
cimg = cat(3, test, test, test);
else
cimg = test; % Already RGB, just assign all color channels to cimg.
end
  3 Comments
Image Analyst
Image Analyst on 23 Apr 2015
In place of the whole i,j loop. You obviously can't use that code because it throws an error. My code will not. If you have one with test(i,j,3) get rid of that also.
Prakash Sharma
Prakash Sharma on 23 Apr 2015
Thank you very much Sir, it worked. I have an extended code related to this. i will be very thankful to u if you kindly help me this time also. these are the codes
I am getting this error
Index exceeds matrix dimensions.
Error in singha>VALIDATE_Callback (line 506) s2 = std2(cimg(:,:,2));
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in singha (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)singha('VALIDATE_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Sign in to comment.

Categories

Find more on Platform and License 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!