Skip to content

Cannot set attributes #96

@paulbareilCodotek

Description

@paulbareilCodotek

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?

`classdef TestObject
properties

    attribute        = 12345;
    
end

methods
    
    function obj = set.attribute(obj, value)
        obj.attribute = value;
    end
    function obj = TestObject(value)
        
        
        if nargin == 1
            obj.attribute = value;
            
        else
            error('Provide value')
        end
    end
    
end

end`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions