Object handlers to modify objects across functions
显示 更早的评论
I want to create a matrix of objects(eg: nodes). The matrix needs to be accesses across all functions. Initializing the matrix as 'global' does not seem to work. Could anybody point me to how I can go about doing this using object handlers?
6 个评论
madhan ravi
2018-10-15
An example
Adam
2018-10-15
All functions of what? What is wrong with passing it as an argument to those functions that need it? Is this a custom object that you have written? In which case, if you are familiar with object-oriented programming then 'access across all functions' would seem to imply that you want a class which encompasses all those functions and stores your matrix within it - then it is accessible to them.
Diptangshu Sen
2018-10-15
编辑:per isakson
2018-10-18
Adam
2018-10-16
Why do you keep putting things like endfunction and endfor? These are not valid syntax. From what you are saying though you are managing to at least run your code.
For me it works fine if I remove all those and replace them with just end
Obviously your tree is only in the scope of that function though so it won't exist outside of it at all, let alone your nodes within it no longer having the expected values.
Diptangshu Sen
2018-11-5
Adam
2018-11-6
As per my first comment, either passing it as an argument to those functions that need it or creating a class that connects the tree object to the functions that act on it seem to be the obvious solutions.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!