Importing single and multiple files
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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
0 Commenti
Risposta accettata
  Jan
      
      
 il 10 Feb 2016
        [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.
2 Commenti
Più risposte (1)
  Ingrid
      
 il 10 Feb 2016
        is this what you try to achieve?
if true
  [fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on')
if length(fileList) == 1
  baseFileName = fileList
  fullFileName = fullfile(folder, baseFileName);
  fprintf(1, 'Now reading %s\n',fullFileName );
  raw_data = importdata(fullFileName)
  s = raw_data.data
else
for k = 1:length(fileList)
   baseFileName = fileList{k}
   fullFileName = fullfile(folder, baseFileName);
   fprintf(1, 'Now reading %s\n',fullFileName );
   raw_data = importdata(fullFileName)
   s{k} = raw_data.data
end
s = [s{:}];
end
var = s(:,3)
s(:,3)= s(:,1)
s(:,1)= var
s = sortrows(s)
0 Commenti
Vedere anche
Categorie
				Scopri di più su Standard File Formats in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


