How can I Ensure Transparency in parfor-Loops when using cell2table ?

조회 수: 2(최근 30일)
I am using parfor which contains a for loop and in it I have:
ranked_global_firstorder=sortrows(empty_cell_fo,[2],'descend');
ranked_global_firstorder=cell2table(ranked_global_firstorder);
ranked_global_firstorder.Properties.VariableNames=["m","ranked_global_first_order"];
descending_per_Ns_fo(:,k-1)=[table(m);ranked_global_firstorder(:,1)];
I am getting the following error:
Error using cell2table (line 39)
Transparency violation error.
See Ensure Transparency in parfor-Loops or spmd Statements.
If anyone can offer any insight into how I can solve this, I would be very grateful. I am new to parfor and while I did read certain stackexchange pages, I cannot figure it out. Thank you very much in advance. Cheers.
  댓글 수: 2
Marina-Effrosyni Panteli
Marina-Effrosyni Panteli 2022년 11월 7일
Thank you for your reply.
I am using MATLAB R2019a.
The name of the file is Global_Sens.m (did I understand your question correctly?)
empty_cell_fo has been filled in prior to the lines of code I shared. However, I noticed that before the for loop I mention but still in the parfor loop, I have another case of cell2table where the cell is empty. Is an empty cell an issue and if so, how do I go around this?
Thanks again, Walter.

댓글을 달려면 로그인하십시오.

답변(1개)

Edric Ellis
Edric Ellis 2022년 11월 7일
Most of the table-building functions can have this problem if you do not specify 'VariableNames', like this (tested in R2019a):
parfor i = 1
c = {1, "foo";
2, "bar";
3, "baz"};
t{i} = cell2table(c, 'VariableNames', {'numbers', 'words'});
end
Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 2).
disp(t{1})
numbers words _______ _____ 1 "foo" 2 "bar" 3 "baz"

Community Treasure Hunt

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

Start Hunting!

Translated by