Why does this code generate an error?
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Chaitanya Bade
 il 5 Apr 2017
  
    
    
    
    
    Commentato: the cyclist
      
      
 il 6 Apr 2017
            Hi all,
The below code is generating an error :
The code used here is:
%BATCH MODE
files = dir('C:\Users\Deakin Uni\Documents\MATLAB\a');
fNames = {files.name};
%for each file
for k= 1: length(fNames)
     % extract file name
     fName = ['C:\Users\Deakin Uni\Documents\MATLAB\MAX', fNames{k}];
     [XDATA, TIMESTEPS] = importfile(fName);
  a1 = XDATA - mean (XDATA);
  plot(TIMESTEPS, a1);
  [peakvals,peaklocs] = findpeaks(a1, 'minpeakdistance',50, 'minpeakheight', 0.00001);
  peaktime = TIMESTEPS(peaklocs);
  createfigure4(TIMESTEPS, a1, peaktime, peakvals)
  saveas(gcf, 'chaitu.fig')
  end
The error here is: Error using xlsread (line 132) XLSREAD unable to open file 'fName'. File 'fName' not found.
Error in importfile (line 36) data = xlsread(workbookFile, sheetName, sprintf('A%d:B%d',startRow(1),endRow(1)));
Thanks in advance
2 Commenti
Risposta accettata
  the cyclist
      
      
 il 5 Apr 2017
        Presumably, the cause is that for some value of k,
['C:\Users\Deakin Uni\Documents\MATLAB\MAX', fNames{k}]
does not resolve to a string that corresponds to a file name in that directory.
I suggest you display the name of each file as you try to access it, and that should lead you to the specific file name that is problematic.
6 Commenti
  the cyclist
      
      
 il 6 Apr 2017
				Nothing stands out to me (after admittedly not very intense scrutiny). Are you familiar with the ability to enter debug mode? I suggest you use that to step through your program line-by-line from k==1, and see if the values of the variables are what you expect them to be. This should give a clue about what went wrong.
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su MATLAB Report Generator 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!