- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个句柄类:
classdef A<handle
properties
a;
end
methods
function obj = A(a)
obj.a=a;
end
end
end
我有一个 A
对象的元胞数组:
arr={};
for i=1:3
arr{i}=A(i);
end
我想做的是将该元胞数组传递给 parfor
循环,以便每个对象的值都会发生变化:
parfor i=1:3
arr{i}.a=i*5;
end
然而,这段代码根本没有改变arr
。事实上,here它指出
Changes made to handle classes on the workers during loop iterations are not automatically propagated to the client.
我怎样才能克服这个问题?
最佳答案
一个有趣的问题;我实际上从未遇到过这个问题。了解关于 parfor
限制的一切总是好的,所以我做了一些谷歌搜索并想出了 this :
I have received an answer to this issue from technical support. Apparently the Mathworks regard it as a 'feature' that changes to objects are not returned - though I can't see that it's a very useful feature. Anyway, the way to get modified class properties returned from a parfor loop is to make an explicit change which can be recognised by parfor. Here are two examples which work for the above example object:
parfor n = 1:num
exArray(n).data = n:n+5;
endor
parfor n = 1:num
temp = exArray(n);
setData(temp,n:n+5);
exArray(n) = temp;
endActually, if you change any object property it also seems to work. So for example this also works, if there is a second property data2 which is set explicitly, both data and data2 are correctly returned:
parfor n = 1:num
setData(exArray(n),n:n+5);
exArray(n).data2 = n:n+5;
end
示例对象由
给出classdef Example < handle
properties
data
end
methods
function obj = Example(data)
obj.data = data;
end
function setData(obj,data)
obj.data = data;
end
function data = getData(obj)
data = obj.data;
end
end
end
并且数组被简单地初始化为
% Initialise array of objects
for n = 1:num
exArray(n) = Example(zeros(1,6));
end
关于matlab - parfor 和句柄类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12200236/
我设置了 Helm 柄和 Helm 柄。我有tiller-deploy。昨天,我可以定期运行了。但今天我收到此错误消息 Error: could not find a ready tiller pod
我以前已将分er安装到特定的 namespace 中。 我设置了一个环境变量来设置'tiller'命名空间-但我不记得该环境变量的名称-而且似乎无法通过网络搜索找到它。 这是什么 key ? 最佳答案
当我在 View 模型中使用如下界面时 class MainViewModel @ViewModelInject constructor( private val trafficImagesR
我正在尝试找到如何在某个 fragment 相关场景中定义 Hilt 的解决方案。我有以下设置: Activity 父 fragment 1 子 fragment 1 子 fragment 2 ...
Hilt 指出如果没有@Provides 注解就不能提供这个接口(interface): interface PlannedListRepository { fun getAllLists()
我的问题非常简单明了:两个注释/示例之间有什么区别: 例子一 @Singleton class MySingletonClass() {} @Module @InstallIn(FragmentCom
我是一名优秀的程序员,十分优秀!