1

I am using some basic Matlab classes with some dynamic defined properties. I added listeners 'PreGet' and 'PostGet' for a property. My property can be a simple variable or a structure.

This is my class:

classdef myClass <   dynamicprops

methods
    function obj = myClass()

        NewProp = 'myProp';
        DynamicProp=addprop(obj,NewProp);
        DynamicProp.SetAccess='public';
        DynamicProp.GetAccess='public';

        DynamicProp.SetObservable=true;
        DynamicProp.GetObservable=true;
        addlistener(obj , NewProp , 'PreGet' ,  @obj.PreReadProperty);
        %addlistener(obj , NewProp , 'PreSet' , @obj.PreSendProperty);
        addlistener(obj , NewProp , 'PostGet' ,  @obj.PostReadProperty);
        %addlistener(obj , NewProp , 'PostSet' , @obj.PostSendProperty);
    end
    function PreReadProperty(obj,  inputMetaProp, varargin)

        DynamicProp=obj.findprop((inputMetaProp.Name));
        disp(obj.(DynamicProp.Name))
        %Body
    end
    %
    function  PostReadProperty(obj,  inputMetaProp, varargin)
        %DynamicProp=obj.findprop(inputMetaProp.Name);
        % Body
    end

end

end

I am trying to catch in a PreReadProperty the value that I access before displaying it.

Example:

>> myVar = myClass;
myVar.myProp = 1;
mytest = myVar.myProp;
     1

>> mytest

mytest =

     1

This works fine for a variable. I can catch it and work with it

I am trying to do the same thing when myVar.myProp is a structure:

>> myVar = myClass;
>> myVar.myProp.myProp1 = 1;
>> myVar.myProp.myProp2 = 2;
    myProp1: 1

>> mytest = myVar.myProp.myProp1;
    myProp1: 1
    myProp2: 2
>> mytest

mytest =

     1

This doesn't work as expected. I tried to browse inputMetaPropand varargin but I still cant get my read value in the PreReadProperty function

When I read myVar.myProp.myProp1 I want to catch its value in PreReadProperty. Is there any way to do this?

Regards

uhnucross
  • 103
  • 1
  • 8

0 Answers0