索引超出矩阵维度 - MATLAB GUI

时间:2013-05-13 11:36:35

标签: matlab matlab-figure matlab-guide

在我的GUI中显示http://s1273.photobucket.com/user/Chethan_tv/media/CBIR_zpsb48bce14.jpg.html

打开按钮用于查看各轴上显示的图像。轴显示图像,打开按钮应显示更大尺寸的相应图像。

%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

下面的代码在display_results函数

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);

我的open按钮功能

   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);

但是当我按下位于axes6下面的open按钮时,我会收到类似

的错误
??? 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

我的代码中哪一部分错了?

0 个答案:

没有答案