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!