Clear function inside a parfor loop: Transparency violation error

5 ビュー (過去 30 日間)
Califfo
Califfo 2020 年 12 月 24 日
コメント済み: Califfo 2020 年 12 月 28 日
Dear community,
I tried to find some answers about the topic in this title, but I found only the problem concerns to set the variable as empty.
I don't clear a variable but a function, as shown in the example below. This produce a transparency violation error. Could someone help me? I need to clear the function in every loops.
Kind regard
Califfo
parfor i=1:N1
for j = 1:N2
clear myfunction
[outputs] = myfunction(inputs);
end
end

採用された回答

Jan
Jan 2020 年 12 月 27 日
What is the purpose of clearing the function? Do you want to get rid of persistently stored variables? This could be done more efficiently, e.g. by:
function outputs = myfunction(inputs)
persistent a,b
if nargin == 0
a = [];
b = [];
return;
end
end
Now call myfunction() instead of clearing it. This avoid a time-consuming reloading of the function from the disk and the reparsing.
  1 件のコメント
Califfo
Califfo 2020 年 12 月 28 日
Thank you Jan for the suggestion, now it works
Califfo

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

その他の回答 (1 件)

Gouri Chennuru
Gouri Chennuru 2020 年 12 月 27 日
Hi,
You can refer to this link
Hope this helps!

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by