How to call a user-defined function within a parfor loop

2 views (last 30 days)
I have searched the Matlab answers forum and cannot find an answer to my problem. The function EWT_Meyer_FilterBank is not getting passed to the workers. Even when I try to use addAttachedfiles(), I continue to get the error -->
{An UndefinedFunction error was thrown on the workers for
'EWT_Meyer_FilterBank'. This might be because the file containing
'EWT_Meyer_FilterBank' is not accessible on the workers. Use
addAttachedFiles(pool, files) to specify the required files to be attached.
Caused by:
Undefined function 'EWT_Meyer_FilterBank' for input arguments of type
'double'.
MUSICdata = load ('MUSICboundaries.mat');
EMGdata = load ('parsedcell.mat');
parsed = EMGdata.parsed;
musicbs = MUSICdata.musicbs;
ewt_pInf = cell(40,23,6,12);
parfor s = 1:40
myPool = gcp;
addAttachedFiles(myPool,{'EWT_Meyer_FilterBank.m', 'EWT_Meyer_Scaling.m','EWT_Meyer_Wavelet.m'});
for m = 1:23
for tr = 1:6
bound = cell2mat(musicbs(s,m,tr));
sig = cell2mat(parsed(s,m,tr));
for ch = 1:12
f = sig(:,ch);
% We extend the signal by miroring to deal with the boundaries
l=round(length(f)/2);
f2=[f(l-1:-1:1);f;f(end:-1:end-l+1)];
ff=fft(f2);
boundaries = bound(ch,:);
% We build the corresponding filter bank
mfb=EWT_Meyer_FilterBank(boundaries,length(ff));
% We filter the signal to extract each subband
ewt=cell(length(mfb),1);
for k=1:length(mfb)
ewt{k}=real(ifft(conj(mfb{k}).*ff));
ewt{k}=ewt{k}(l:end-l);
end
ewtM = cell2mat(ewt);
ewt_pInf(s,m,tr,ch) = {ewt};
end
end
end
end

Answers (1)

Edric Ellis
Edric Ellis on 29 Jan 2019
You should call addAttachedFiles outside the parfor loop.

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!