Object handlers to modify objects across functions
Show older comments
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 Comments
madhan ravi
on 15 Oct 2018
An example
Adam
on 15 Oct 2018
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
on 15 Oct 2018
Edited: per isakson
on 18 Oct 2018
Adam
on 16 Oct 2018
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
on 5 Nov 2018
Adam
on 6 Nov 2018
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.
Accepted Answer
More Answers (0)
Categories
Find more on Install Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!