我在parfor
循环中调用外部函数,如下所示。
parfor idx = 1:2
import com.comsol.model.*
import com.comsol.model.util.*
model = ModelUtil.create('Model');
model.modelNode.create('comp1');
model.geom.create('geom1', 2);
model.geom('geom1').feature.create('sq1', 'Square');
model.geom('geom1').feature('sq1').set('size', '0.03125');
model.geom('geom1').feature('sq1').setIndex('pos', '0', 0);
model.geom('geom1').feature('sq1').setIndex('pos', '0', 1);
model.geom('geom1').run;
end
Error: MATLAB cannot determine whether "ModelUtil" refers to a function or variable.
See Parallel for Loops in MATLAB, "Unambiguous Variable Names".
阅读the "Unambiguous Variable Names" part in the MATLAB parfor
documentation后,我非常理解为什么会出现这种错误。但是,我不知道如何解决它。
答案 0 :(得分:2)
我遇到了与.Net对象相同的问题。和你一样,我发现它在非并行模式下运行良好,问题只发生在parfor。
这不是路径问题,这纯粹是一个Matlab语法/解析器问题。
作为一种解决方法,我将操作包装在一个单独的Matlab函数中,这样在parfor的范围内它就不再模糊了。在(否则是不必要的)函数中,即使从parfor中调用,也可以轻松解析类。
答案 1 :(得分:0)
Vector的解决方案对我不起作用。问题在于,不同的工作人员看不到您正在使用的库:您必须使用parfor
更新javaaddpath
中的javapath。