Object handlers to modify objects across functions
Afficher commentaires plus anciens
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 commentaires
madhan ravi
le 15 Oct 2018
An example
Adam
le 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
le 15 Oct 2018
Modifié(e) : per isakson
le 18 Oct 2018
Adam
le 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
le 5 Nov 2018
Adam
le 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Install Products dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!