加载一个或多个图像Matlab GUI

时间:2018-11-07 13:21:23

标签: matlab matlab-guide

我想在Matlab GUI中加载多个图像。下面的算法:

 % --- 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 path] = uigetfile('*.jpg','*.png','Chose files to 
load','MultiSelect','on');
 if isequal(filename,0) || isequal(path,0) 
return
end
if iscell(filename)
img = cell(size(filename));
for ii = 1:numel(filename)
img{ii} = imread(fullfile(path,filename{ii}));
end
else
img{1} = imread(fullfile(path,filename));
end
filename = strcat(path,filename);
fullpathname = strcat(path, filename);
set(handles.edit1,'String', fullpathname);
fileID = fopen(strcat(path, filename), 'r');

我还需要一个或多个可用于查看蜜蜂的图像的文本框,但这会给我带来随后的错误:

Error using imread>parse_inputs (line 457)
The file name or URL argument must be a string.
Error in imread (line 316)
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
Error in untitled>pushbutton1_Callback (line 112)
im = rgb2gray(imread(filename));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in 
@(hObject,eventdata)
untitled('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

您能给我一个提示,我如何定制该算法并使它起作用?

1 个答案:

答案 0 :(得分:1)

代码失败的原因之一是,一旦合并filenamepath,就会错过/(或\,具体取决于您使用的操作系统)。因此,您应该使用fullfile(path,filename)而不是strcat(path,filename)