I have some problem about showing path of a picture in guide! how can i do this? Please help me! thank you very much!
1 view (last 30 days)
Show older comments
filename = uigetfile('*.*', 'MultiSelect', 'on');
image = imread(filename);
axes(handles.axes1);
imshow(image);
guidata(hObject, handles);
set(handles.path,'string',image);
1 Comment
Rik
on 17 Jan 2018
image is not a string, it is an image. Also, if you are selecting multiple images, what should this code do? And what if non-image files are selected?
Answers (1)
Jan
on 17 Jan 2018
[filename, filepath] = uigetfile('*.*', 'MultiSelect', 'on');
if isequal(filename, 0)
disp('User aborted file choosing');
return;
end
% Due to "MultipSelect" filename can be a string or cell string.
% Make it a cell string in every case:
filename = cellstr(filename);
for k = 1:numel(filename)
% Append the folder:
file = fullfile(filepath, filename{k});
img = imread(file);
imshow(img, 'Parent', handles.axes1);
set(handles.path,'string', file); % Not "image"
end
"guidata(hObject, handles)" is not useful, if you did not change the handles struct.
Note that the shown code would overwrite the image for each selected file. If 'MultiSelect' should be useful, you have to use different axes to display the images.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!