【发布时间】:2015-06-02 13:37:33
【问题描述】:
我正在使用 Matlab-2012a 开发基本的 GUI。我想显示选择并使用按钮显示图像。
这是我的代码:
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global TrainingData;
global filenames;
TrainingData={};
[filenames, pathname] = uigetfile({'*.jpg';'*.png';'*.bmp'});
if ~ischar(filenames) % on cancel press you display a message of error with errordlg
errordlg('Error!','No file selected'); % displays an error message by means of errordlg function
return;
end
axes(handles.myaxesImage);
imshow(filenames);
我可以浏览图像,但无法显示相同的图像。我收到以下错误消息:
Reference to non-existent field 'axesImage'.
Error in GUI>pushbutton2_Callback (line 93)
axes(handles.axesImage);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)GUI('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
有什么建议吗?
提前谢谢你。
【问题讨论】:
-
是handles.axesimage 还是handles.myaxesimage?错误消息和您的代码不匹配。此外,在使用 imshow 之前,您似乎需要调用 imread。
-
@Benoit_11 它的“handles.axesimage”
标签: image matlab user-interface