The source code for the parfor-loop could not be found

Hi. I'm using the parfor in order to change some labels name:
Data = cell(1, length(DirList));
numberOfDbExamples = length(DirList);
parfor k = 1:numberOfDbExamples
Data{k} = load(fullfile(Folder, DirList(k).name));
[newLabelNames, newMask] = changeLabelNames(Data{k}.labelNames, Data{k}.mask);
Data{k}.labelNames = newLabelNames;
Data{k}.mask = newMask;
end
I get this error:
The source code (C:----) for the parfor-loop that is trying to execute on the worker could not be found.
Caused by:
Undefined function changeLabelNames for input arguments of type table.
Error using remoteParallelFunction
Do you have an idea of how fix it?

3 件のコメント

Walter Roberson
Walter Roberson 2022 年 9 月 30 日
Where have you stored changeLabelNames relative to the current directory at the time of execution of the parfor ? And is it in its own file changeLabelNames.m or is it a local function inside your script ? Is it possibly a method of some object class?
Are you expecting your mat files to have a variable named labelNames and expecting it to be a table() object ?
John
John 2022 年 9 月 30 日
The function is stored as changeLabelNames.m and it is located in the same folder of the script.
Mehdi
Mehdi 2023 年 1 月 20 日
can you explain how you solved this problem? I faced similar error!

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 30 日

0 投票

6 件のコメント

Mehdi
Mehdi 2023 年 1 月 20 日
can you explain how you solved this problem? I faced similar error!
Walter Roberson
Walter Roberson 2023 年 1 月 20 日
When there are hidden calls to a function, such as by
fmincon('NameOfFunction', x0)
then you might need to use addAttachedFiles
Mehdi
Mehdi 2023 年 1 月 20 日
編集済み: Mehdi 2023 年 1 月 20 日
I build a function to put my parfor loop inside it and par for loop looks as below:
parfor i=1:M
Hf = matlabFunction(H(i),'Vars',[xx yy]);
Hf = @(xx,yy)Hf(xx,yy).*ones(size(xx));
kdl(i,1) = k__d*a(2)*(b(2)/4)*integral2(Hf,-1,1,-1,1);
end
Where and how I have to use addAttachedFiles?
before the loop, inside, after???
Walter Roberson
Walter Roberson 2023 年 1 月 20 日
I recommend using two different variable names for the two different anonymous functions.
Integral2 requires that the function accepts two arrays of the same size, and returns an array that size. Your second function handle contains the subexpression .*ones(size(xx)) . The multiplication will generate an error if the output of the matlabFunction-generated handle is not one of
  • scalar
  • row vector with the same number of rows as xx has
  • column vector with the same number of columns as xx has
  • 2d array with the same number of rows and columns as xx has
In the last case (array is already that size) then the multiplication by ones is redundant. In the other cases where the output of the generated function is being expanded to the proper size then the implication is that the output of the generated handle is not calculating each location individually, and so would be calculating incorrectly for the purposes of integral2()
Either you do not need the .*ones because the generated function already has the correct output size... or else your generated function is not suitable for use with integral2()
Walter Roberson
Walter Roberson 2023 年 1 月 20 日
@Mehdi I just noticed your https://www.mathworks.com/matlabcentral/answers/1897595-why-receive-error-integrand-output-size-does-not-match-the-input-size?s_tid=srchtitle in which you are expecting that your function might return a constant and so not automatically vectorized by matlabFunction . There are better ways of dealing with that situation.
Walter Roberson
Walter Roberson 2023 年 1 月 22 日

サインインしてコメントする。

その他の回答 (1 件)

John
John 2023 年 1 月 21 日

0 投票

I did something similar to what Walter mentioned, but I don't remember exactly.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by