What is index out of bound ?
1 次查看(过去 30 天)
显示 更早的评论
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.
回答(1 个)
Image Analyst
2015-4-23
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 个评论
Image Analyst
2015-4-23
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Platform and License 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!