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.

7 Commenti

Rik
Rik il 6 Ago 2020
I'm on mobile so I can't test your code, but it looks like a constructor is missing.
Hi,
Could anyone explain me this?
Thankyou
Deepak Gupta
Deepak Gupta il 10 Ago 2020
You have multiple classes in one file. In matlab, one class can be defined in one file.
I don't understand what is 'GetAccess=?' in your class.
When you are creating an object of the class, you are passing some arguments but your class doesn't have any constructors to handle these arguments.
Walter Roberson
Walter Roberson il 10 Ago 2020
You do not appear to have a method named the same thing as your class, so you do not have any constructor for your classes. You also have no static methods for your classes, so you cannot be using the class as a framework to hold static methods. There is therefore no way to construct a member of your class, or to use any method in your class.
Thankyou for your reply Deepak. The way which i mentioned in the program can be used to use the objects directly withoutyout making subclass or superclass.
Thankyou fo your reply Walter. Could you please how can i make it in a correct way or may be some hints which i can work with.
Thnakyou
Steven Lord
Steven Lord il 11 Ago 2020
Show us a small example that is complete that shows the problem. We should be able to execute the example using your exact reproduction steps. This will help us understand where you're having difficulty.

Accedi per commentare.

 Risposta accettata

per isakson
per isakson il 11 Ago 2020
Modificato: per isakson il 11 Ago 2020
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

3 Commenti

Hi Isakson,
The answer which you gave me for Access to class members was helpful. Is it possible for you to give me a solution if there is a subclass for clMec for example clEEC and the properties are are used from clcore. Could you please tell me how to do that.
Thankyou
per isakson
per isakson il 13 Ago 2020
Modificato: per isakson il 13 Ago 2020
"a solution if there is a subclass for clMec for example clEEC" I'm not sure what kind of solution you are looking for.
Did you understand the code I provided in my answer? Do you think that this code is an answer to your original question? Exactly the same solution can be applied to "a subclass for clMec".
Please, try to elabotate a bit on what kind of solution you want.
Thankyou for your reply. My requirement is I have a class called clCore which has geometrical parameters then I have a subclass called clcoreconstruction Which chooses which geometry have to be done,then there are 2 subclasses for clcoreconstruction name cluucore cluicore. In these classes geometries have to be done.What I have to do is I need to access the parameters from clCore make a switch case in clconstruction whether I need cluucore or cluicore. I could solve this with superclass subclass concept but I couldn’t do it with getaccess. Iam a bit confused in solving this. So if you could add 2 child classes in clMec and make a switch case in between them I think it will be helpful. I have a lot of inheritance in my programming so I think I could solve them. Thankyou

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Construct and Work with Object Arrays in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by