Filter löschen
Filter löschen

error while browsing an image in GUI

2 Ansichten (letzte 30 Tage)
sara sar
sara sar am 29 Sep. 2018
Kommentiert: Image Analyst am 29 Sep. 2018
I made GUI that allow the user to browse image. I wrote this function:
function pushbutton1_Callback(hObject, eventdata, handles)
[filename pathname] = uigetfile('*.*','File Selector');
image = [filename pathname];
axes(handles.axes1);
imshow(image);
end
But the image did not appear. Here is the error message that was appeared in the command window :
Could any one explain to me whats wrong and how can I browse an image? *I insert the image in the same folder of matlab file.

Akzeptierte Antwort

Image Analyst
Image Analyst am 29 Sep. 2018
Don't call your variable image - that's the name of a built in function. Try this:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
axes(handles.axes1);
imshow(fullFileName);
  2 Kommentare
sara sar
sara sar am 29 Sep. 2018
Thanks a lot! it works.
I have another question please, what should I change in the code if I want to browse a video?
Image Analyst
Image Analyst am 29 Sep. 2018
use movie() instead of imshow().

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by