Index exceeds matrix dimensions - MATLAB GUI
1 次查看(过去 30 天)
显示 更早的评论
In my GUI shown below <http://s1273.photobucket.com/user/Chethan_tv/media/CBIR_zpsb48bce14.jpg.html>
open push button is used to view image displayed on respective axes. axes display an image, open buttons should display the corresponding image in bigger size.
%below 3 lines are in GUI *_opening function
handles.MyData.ListFileName = 'FileName';
handles.MyData.FileNames = {}; % here we store all the image names
handles.MyData.Images = {}; % here we store all images
below code is in display_results function
function displayResults(filename,hObject, eventdata, handles)
fid=fopen(handles.MyData.ListFileName);
for N=6:1:10
imagename = fgetl(fid);
if ~ischar(imagename), break, end % Meaning: End of File...
[x,map]=imread(imagename);
rgb=ind2rgb(x,map);
ax = handles.(sprintf('axes%d', N));
image(rgb, 'Parent', ax);
set(ax, 'Visible','off');
%xlabel(imagename);
% store file name and image itself for later use
handles.MyData.Images{N} = rgb;
handles.MyData.FileNames{N} = imagename;
% we have buttons like open1 open2 open3 etc...
% add some info to the open buttons
% so they will be aware which image they display
btn = handles.(sprintf('open%d', N));
set(btn, 'UserData',N);
end
fclose(fid);
% Update handles structure
guidata(hObject, handles);
My open pushbutton function is
function open1_Callback(hObject, eventdata, handles)
% hObject handle to open1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
N = get(hObject,'UserData');
rgb = handles.MyData.Images{N};
ax = handles.(sprintf('axes%d', N));
% create figure in 'modal' mode, so user have to close it to continue
figure('WindowStyle','modal', 'Name',handles.MyData.FileNames{N} );
% show image
image(rgb, 'Parent', ax);
set(ax, 'Visible','off');
guidata(hObject, handles);
but when i press open button which is below axes6, i'm getting error like
??? Index exceeds matrix dimensions.
Error in ==> Fig5>open6_Callback at 163
rgb = handles.MyData.Images{N};
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> Fig5 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)Fig5('open6_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Which part of my code is wrong?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!