How to upload image using push button?

Below is the code I'm using and it works for browse the folder.But the image didn't come out.
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [FileName,PathName]=uigetfile({'*.bmp,*.jpg'},'Select a image file'); axes(handles.axes1); imshow([Path_Name,File_Name]);
Here is the error when I run the code:
Undefined function or variable 'Path_Name'.
Error in iris1>pushbutton1_Callback (line 83) imshow([Path_Name,File_Name]);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in iris1 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in@(hObject,eventdata)iris1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Does anyone can suggest me a solution? Thank you.

 採用された回答

Jan
Jan 2017 年 4 月 28 日
編集済み: Jan 2017 年 4 月 28 日

1 投票

Seriously? :-)
[FileName, PathName] = uigetfile({'*.bmp,*.jpg'},'Select a image file');
axes(handles.axes1);
imshow([Path_Name, File_Name]);
The error message tells you clearly, that the variable "Path_Name" does not exist. You have called it "PathName" without underscore.
Prefer the more stable:
[FileName, PathName] = uigetfile({'*.bmp,*.jpg'},'Select a image file');
imshow(fullfile(PathName, FileName), 'Parent', handles.axes1);
fullfile considers the file-separators. Defining the 'Parent' property is a little bit faster and more secure than relying on the current object: If a user clicks on any object between the two lines the image is displayed anywhere else.

3 件のコメント

Baiti
Baiti 2017 年 4 月 29 日
I have try those code and it really works for me. I'm appreciate it. Thank you.
sahil Dobariya
sahil Dobariya 2020 年 6 月 27 日

Using above code how can I convert it to grayscale for axes2

Image Analyst
Image Analyst 2020 年 6 月 27 日
[baseFileName, folder] = uigetfile({'*.bmp,*.jpg'},'Select an image file');
fullFileName = fullfile(folder, baseFileName);
rgbImage = imread(fullFileName);
imshow(rgbImage, 'Parent', handles.axes1);
% Convert to gray scale.
grayImage = rgb2gray(rgbImage);
imshow(grayImage, 'Parent', handles.axes2);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2017 年 4 月 28 日

コメント済み:

2020 年 6 月 27 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by