Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass by refernce method in matlab

I'm developing a robotics application in Matlab for my thesis. I'm experienced in C#, PHP, js, etc etc.

I would love if objects I create could somehow be passed by reference. I heard that there are things called "handle objects" and others called "value objects". I can't find any specific documentation on how to create a "handle object" and it seems they are usually graphics objects.

I have a few design patterns that are easy to implement when passing by reference is possible. I would like certain objects to share 'simulation spaces', without making each space a global variable. I would like to avoid passing IDs around everywhere, in an effort to keep objects synchronized. I would like to share environmental objects between robots, without worrying about the fact that passing this object actually copies it. (this will lead to bugs over time)

I'm starting to feel like my only solution will be to have a weird global 'object broker' that has the latest copy of many common system objects. I hope to avoid this sort of thing!

Any advice would be amazing!

like image 777
user1949902 Avatar asked Jan 31 '26 11:01

user1949902


1 Answers

Handle objects are created by the following syntax

classdef myClass < handle
   properties
      % properties here
   end
   methods
      % methods here
   end
end

A good place to start looking in the documentation is the classes start page. Note that value and handle classes have only been implemented in R2008a, and are reasonably bug-free since R2009a (though more recent releases have improved performance quite a bit).

If you're coming from other languages, this section about the differences between Matlab and other languages OOP can be useful.

like image 166
Jonas Avatar answered Feb 02 '26 03:02

Jonas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!