0

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?

Chethan
  • 213
  • 3
  • 7
  • 19
  • Impossible to debug for you, you will need to `dbstop if error`, then run it and when it error it will stop within the callback, check out what is N and is there is data there, then after you-re done `dbquit`,and finally `dbclear if error`. – Oleg May 13 '13 at 21:15
  • after debugging N gets a value 6 if i press first `open` button which is below axes6. Then it gives 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{:}); – Chethan May 14 '13 at 02:58
  • It means that the `MyData.Images` doesn't have a sixth element. Place a breakpoint somewqhere inside for `N=6:1:10 ... end` to check that all images are loaded correctly. – Oleg May 14 '13 at 07:39

0 Answers0