% Use UIGETFILE to allow for the selection of a custom file/files.
[filename, pathname] = uigetfile( ...
{'*.csv', 'All CSV-Files (*.csv)'; ...
'*.*','All Files (*.*)'}, ...
'Select File', 'MultiSelect','on');
% for one file, filename is a CHAR
% for multiple n files, filename is a 1xn CELL
% If "Cancel" is selected then return
if isequal([filename,pathname],[0,0])
return
% Otherwise construct the fullfilename and load the file.
else % data are given to data structures with the same names as files'
if iscell(filename) == 0; % only 1 file is chosen, filename is CHAR
File = fullfile(pathname,filename);
tempData = dlmread(File,',',11,0);
eval([filename '=tempData']);
else % multiple files are chosen, filename is CELL
[nRows, nFiles] = size(filename); % number of files
for i = 1 : nFiles
File = fullfile(pathname,char(filename(i)));
tempData = dlmread(File,',',11,0);
eval([cell2mat(filename(i)) '=tempData']);
end
end
end
No comments:
Post a Comment