为什么innerjoin不适用于parfor

时间:2018-05-06 01:42:15

标签: matlab parfor

在matlab中使用parfor编写代码时。我有一个错误,因为使用如下的innerjoin。我发现因

而出现透明度错误
N_boot = 5;
coeff_out2 = zeros(N_boot,N_coef);
sampled_id01 = zeros(Ndecisions,1);
sampled_id2 = table(sampled_id01, 'VariableNames', {'decision_id00'});
resample_dta = [];
parfor i = 1:N_boot
dta2 = dta;
dta2.Properties.VariableNames{1} = 'decision_id00';
decisions2 = unique(dta2.decision_id00);
Ndecisions2 = size(decisions2,1);
sampled_id01 = randsample(decisions2,Ndecisions2,true);
sampled_id2 = table(sampled_id01, 'VariableNames', {'decision_id00'});
resample_dta = innerjoin(sampled_id2,dta2,'Keys','decision_id00');
resample_dta = table2array(resample_dta);
result1 = mean(resample_dta(:,1:4));
coeff_out2(i,:) = result1;
end

此代码一直在说

Error using tabular/innerjoin (line 96)
Transparency violation error.

我不知道为什么如上所述使用innerjoin会导致透明度错误。当我只使用for-loop时,没有问题。

1 个答案:

答案 0 :(得分:1)

不幸的是,innerjoin使用inputname函数,导致“透明度违规”错误。有一个简单的解决方法,就是将调用包装到innerjoin,如下所示:

innerjoinFcn = @(varargin) innerjoin(varargin{:});
parfor ...
    ...
    resample_dta = innerjoinFcn(sampled_id2,dta2,'Keys','decision_id00');
end