MATLAB: Importing single and multiple files

fprintfloadplot

Hello, I want to import single as well as multiple files, by first code i am able to import multiple files but if i select single file it shows error, please help me to get the result. I have done some changes in code 2 but still error is there.
* * * * * * * * * * * * * * * |* *Item one**|***************
if true
[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on')
for k = 1:length(fileList)
baseFileName = fileList{k}
fullFileName = fullfile(folder, baseFileName)
fprintf(1, 'Now reading %s\n', fullFileName)
end
  • * * * * * * * * * * * * * * * * * * * * * * * * * * * *Item two*****************************
if true
[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on')
for k = 1:length(fileList)
if k==1
baseFileName = fileList
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n',fullFileName );
raw_data = importdata(fullFileName)
s = raw_data.data
else
baseFileName = fileList{k}
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n',fullFileName );
raw_data = importdata(fullFileName)
s = raw_data.data
end
var = s(:,3)
s(:,3)= s(:,1)
s(:,1)= var
s = sortrows(s)
end

Best Answer

[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on');
fileList = cellstr(fileList);
for k = 1:length(fileList)
...
Now fileList is a cell string in all cases.
Related Question