MATLAB: Access to class members

accessing class membersoop

Hi guys,
I am having some problem in accessing the class members of one class to another class. I have checked in matlab documentation but i didn#t understood it weel. Could anyone help me in understanding it.
classdef clcore
properties(GetAccess=?clMec)
cpc
csc
end
properties(Dependent, GetAccess=?clMec)
ws
end
methods(GetAccess=?clMec)
function ws=get.ws(obj)
ws=obj.cpc+obj.csc;
end
end
end
classdef clMec
properties
Mecmode
end
methods
%
end
end
and in command window
objcore=clcore(1,2)
I knew the way i have done is wrong but my context is this. Could anyone explain me how to use this getaccess.
thankyou.

Best Answer

The Code Analyzer is a useful feature. It indicates syntax errors in the rightmost column of the editor. And it provides tooltips. Properties has the attribute GetAccess, but methods only has Access. IMO: one should try to keep the little box green at all times.
Your classes are value classes. Is that your intention? See Comparison of Handle and Value Classes
This is one way of "accessing the class members of one class to another class"
>> objcore=clcore(1,2)
objcore =
clcore with no properties. % <<< private properties are not shown
>> objMec = clMec
objMec =
clMec with properties:
Mecmode: []
>> objMec = objMec.access_value_of( objcore )
objMec =
clMec with properties:
Mecmode: 3
>>
where
classdef clMec
properties
Mecmode
end
methods
function obj = access_value_of( obj, friend )
obj.Mecmode = friend.ws;
end
end
end
and
classdef clcore
properties(GetAccess=?clMec)
cpc
csc
end
properties(Dependent, GetAccess=?clMec)
ws
end
methods
function obj = clcore( arg1, arg2 )
obj.cpc = arg1;
obj.csc = arg2;
end
function ws = get.ws(obj)
ws=obj.cpc+obj.csc;
end
end
end