Error/fault in code, 'Unrecognized function or variable'

17 次查看(过去 30 天)
I have the following loop within my script. The intention is to process thousands of files within a folder through the function PG_DFT. This works fine, but at a certain point I get an error:
Unrecognized function or variable 'PG_DFT'.
This is strange because when I run the code again from where the error occurred, everything works fine. The loop will process up to thousands of files before stopping and reporting the error. And when I run it again from where it left off, everything is fine. This is very confusing.
for i=1:files %for each file
disp(d(i).name); %display filename
filename=fullfile(folder, d(i).name); %get full filename
wavinfo=audioinfo(filename); %get file info
SN=strsplit(d(i).name,'.'); %split filename by '.'
SN1=char(SN(1)); %get serial no.
serialNo=str2num(SN1);
date=char(SN(2)); %get date from filename
date=datenum(date, 'yymmddHHMMSS'); %convert date to datenum format
outputdate(:,row+1)=date; %create vector with dates
switch serialNo %get calibration correction
case 5099 %if serial no. is...
S=-176.4; %S = -...
case 5100 %**all of these values apply to
S=-176; %HIGH GAIN setting only**
case 5101
S=-176.2;
case 5102
S=-176.6;
case 5103
S=-176.5;
case 5277
S=-176.3;
case 5278
S=-175.9;
case 5279
S=-176.4;
case 5280
S=-176.4;
case 5281
S=-176.6;
otherwise error('Unknown ST serial');
end
%Run PSD only if file is 2 mins long (1:59):
%i.e. 119seconds*144000samples
if (wavinfo.TotalSamples>=nup)
[xbit, fs]=audioread(filename, [nlo,nup]);
%read in file
xbit=detrend(xbit);
%removes DC offset
[A]= PG_DFT(xbit,fs,S,N,r,winname,envi,lcut,hcut,atype,tstamp,disppar);
%calculate TOLs (calibrated)
out_f=A(1,:); %get TOL freq bins
A=A(2:end,2:end); %remove freq and time interval data
A=mean(A,1); %take mean across file (get one val per TOL)
output(row,:) = A;
clearvars A
%fill successive rows with output from PG_DFT
row = row + 1;
%move onto next row of output matrix
%If file is too short (rare):
else
%fill data row with zeros
output(row,2:35)=zeros; %fill row with zeroes
formatSpec=('Error: %s has an unexpected file length! Not processed\n');
fprintf(2, formatSpec, filename);
row=row + 1;
%list of filenames where rows were filled with zeroes is issued in
%a separate _shortfiles.csv
end
end
  4 个评论
Walter Roberson
Walter Roberson 2021-7-14
Yes, that could do it. If you lose contact with Google Drive for a moment, you can get exactly that kind of problem.
You should make sure that your code is local to the system running MATLAB. You are already using fullfile() so it should not be any problem to split your code from your data.
Louise Wilson
Louise Wilson 2021-7-14
Yep I can easily move things around it to run it more robustly. I hadn't even realised I was doing that until now, it wasn't my intention, but a result of having things backed up in multiple places! Thank you.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2021-7-14
Well evidently it doesn't know that function. Why do you think it should? Do you have an m-file named that in the current folder or on the search path? Is it defined elsewhere in your script?
What does this say
>> which -all PG_DFT
It will probably say there is no such function.
  4 个评论
Image Analyst
Image Analyst 2021-7-15
Try getting rid of clearvars in the loop. Just set any variables you want reset to null instead. See if that helps. Is the H drive a local drive that you always have access to, or is it a network/cloud drive that might possibly be unseeable at some point in time? See if the error happens if you have everything on a local drive.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by