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

16 views (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 14 Jul 2021
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 on 14 Jul 2021
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.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Jul 2021
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 Comments
Image Analyst
Image Analyst on 15 Jul 2021
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.
Louise Wilson
Louise Wilson on 15 Jul 2021
Thanks! Answered in replies to Walter's post above.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!