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 次查看(过去 30 天)
显示 更早的评论
filename = uigetfile('*.*', 'MultiSelect', 'on');
image = imread(filename);
axes(handles.axes1);
imshow(image);
guidata(hObject, handles);
set(handles.path,'string',image);
1 个评论
Rik
2018-1-17
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?
回答(1 个)
Jan
2018-1-17
[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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!