-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot set attributes #96
Comments
Honestly, I have no idea. Transplant doesn't do anything crazy, though: It calls subsasgn on the object, nothing more. Does your class work with |
I was able to debug the Python and Matlab code. I haven't found the exact source of the problem yet, still trying to wrap my head around the way it works. But from what I understand, the problem is the 'del proxy' The python code below calls matlab with the substruct function to get the structure necessary to make the call, then the subsasgn makes the call correctly and somewhere in the process, on the Matlab side, a new proxied_objects object is created at the last cell array index.
That new proxied_object is correct. It has the changed value. However, when the following function is called, the object we just created and modified is deleted.
I do not know yet why the del function is called and why a new proxied_objects is created instead of being modified, but the problem lies there. It also explains why a copyable mixin class has no problem since the copy is shallow. |
Got it. The
While, when subclassing So the actual modified object is discarded right now, but when trying this directly in Matlab it seems to automatically reapply the object. Do you see any way to go around this? Other than |
Thank you for your analysis! That sounds like a nasty problem. If I understand you correctly, I think we would have to (conditionally?) overwrite In either case, I'm afraid I don't have access to Matlab any longer, which means I can't test any changes myself. But I'll happily review and accept a pull request! |
Yes that seems to be the case. I will investigate a little further on the Matlab side to be sure to understand the problem correctly. You built such a good package, I feel like I have to contribute a little if I can. I do not have much time, but will come back on this. |
ok, I made some quick Matlab tests If you have the following class in Matlab `classdef TestObject
end` Then if you create 2 objects and reference it on the second object test = TestObject(1); If you do !!!. So the problem is NOT transplant. It seems Matlab "standard" classes cannot be referenced! Making it inherit copy was not a requirement, it need at least to inherit from "handle" to work as a referenceable class. https://www.mathworks.com/help/matlab/handle-classes.html |
Oh, Matlab! I do wonder what considerations and constraints have lead to the maze of curveballs that is the Matlab object system. At any rate, thank you for sharing your analysis. I find it oddly satisfying to dive deeply into strange code such as Matlab's. |
Hi, I cannot set attributes if the class does not import mixin. The following matlab TestObject is in a @TestObject folder and TestObject.m file. I can create an instance of this class in Matlab and change the attribute. I can do:
test = TestObject(2); and if I print test.attribute, it returns 2. If I then do test.attribute = 3;, it will change its value.
However, doing this in Python does not work. The values stays at 2. If I change the Matlab class header to
classdef TestObject < matlab.mixin.Copyable
, then it works. However, I need to interface to matlab code that does not implement the mixin class. How can I change the attribute of the Matlab class then?The text was updated successfully, but these errors were encountered: