Object-Object Interactions: Passing information about one object to another
显示 更早的评论
I am writing a program that creates objects (let us call them A, B, C, and D) and then passes information about three of the objects to the last object (e.g. reports properties of A, B, and C to object D). D then performs computations on the information that it receives from A, B, and C. Does MATLAB have some existing code element that would facilitate passing information about certain objects to other objects? I would rather not make the information about A, B, and C a property of object D.
Any advice would be much appreciated! Many thanks.
1 个评论
per isakson
2015-1-9
You provide little context. Didn't you search the documentation or don't you think that the described approaches are good enough?
Please eleborate your question
回答(1 个)
Image Analyst
2015-1-9
Yes. It's called a function . Pass the "reports" property of A, B, and C into a function, and also pass in the entire D object.
output = ProcessObjects(A.reports, B.reports, C.reports, D);
Then define the function
function output = ProcessObjects(report1, report2, report3, D)
% Then do something with the inputs and create an output
output = ..... whatever......
1 个评论
Image Analyst
2015-1-9
You can also make a "method" of D that takes the "reports" properties of other objects and does something with them.
类别
在 帮助中心 和 File Exchange 中查找有关 Simulink Model 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!