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

4 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.
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
case 5102
case 5103
case 5277
case 5278
case 5279
case 5280
case 5281
otherwise error('Unknown ST serial');
%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
%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):
%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
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.
Louise Wilson
Louise Wilson on 15 Jul 2021
Thanks! Answered in replies to Walter's post above.

Sign in to comment.


Find more on Loops and Conditional Statements in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!