假设我有一个带有方法SetProperty的句柄类的1x2对象数组。我可以使用arrayfun为每个类调用SetProperty方法,以及它用于设置属性值的向量吗?Matlab Arrayfun with Handle Class
3
A
回答
1
是的,你可以:
arrayfun(@(x,y)x.SetProperty(y), yourHandleObjects, theValues)
3
你也可以设计类,以便调用SetProperty
将矢量:
class Foo < handle
methods(Access=public)
function SetProperty(this,val)
assert(numel(this)==numel(val));
for i=1:numel(this)
this(i).prop = val(i);
end
end
end
end
然后,您可以创建一个向量并调用该方法直接在它上面:
f = repmat(Foo(),[1 2]);
f.SetProperty([5 3]);
+0
我以前也用过这个。尽管如此,我更愿意使用arrayfun,因为我可以控制传递给函数的内容。当我有一堆嵌套类时,这是一个问题,我从来不知道自己是否会引用我想要的类或其超类,这取决于我称之为方法的地方。 – krapht
+0
@AndrewAshworth你在说什么听起来很有趣。你能给个例子吗? (为了我自己的教育目的) –
相关问题
- 1. Matlab的arrayfun
- 2. MATLAB“arrayfun”功能
- 3. Handle TimeOut :: Error with retry
- 4. 在matlab中Arrayfun问题
- 5. Matlab arrayfun与[1x4结构]元素阵列
- 6. jsp:param with Java class
- 7. arduino class with map
- 8. 使用MATLAB循环遍历arrayfun
- 9. 我应该在Matlab中使用arrayfun吗?
- 10. 复制Handle Class的类的方法?
- 11. Handle with Node.js,预编译时出错
- 12. Navigate to Class with namespace
- 13. cout with a class of
- 14. 使用class with smarty
- 15. 误差arrayfun
- 16. HTTP Post with Matlab
- 17. 与arrayfun
- 18. MATLAB to Java with MATLAB compiler
- 19. css class override with style html snippet
- 20. Aptana Code Assist with custom Class Loader
- 21. python class sum with numpy array
- 22. CustomCell without storyCell class with storyboard
- 23. Jackson Custom Serializer for class with annotations
- 24. GSON Class with different body(Error/NoError)
- 25. C++ class with objective-c朋友
- 26. Angular 2 - * ngFor with conditional class
- 27. Matlab histc with vector bin
- 28. arrayfun的“反向”
- 29. 关于arrayfun在matlab中的一个例子
- 30. Matlab - 用arrayfun评估嵌套匿名函数
谢谢!这很简单,我不知道为什么我在语法上遇到了很多麻烦。 – krapht