Hi! here is code of my class written below. I am just trying to call method getName() to get the name but it is just displaying class name not value set by the constructor. I need hte value.
classdef myClass
properties
myName;
end
methods
function this = myClass(toon)
this.myName= toon;
end
function this = getName(this)
this.myName;
end
function this=delete(this)
end
end
end
"Syed " <cancer216@hotmail.com> wrote in message
news:hb84po$dvv$1@fred.mathworks.com...
> Hi! here is code of my class written below. I am just trying to call
> method getName() to get the name but it is just displaying class name not
> value set by the constructor. I need hte value.
>
> classdef myClass
> properties
> myName;
> end
> methods
> function this = myClass(toon)
> this.myName= toon;
> end
>
> function this = getName(this)
As defined, this method returns the object that it received as input.
That's not what you want.
> this.myName;
The line of code above retrieves the myName property of the object you
passed in as input ... and does nothing with it. You need to assign that
property value to a value that is returned from this method in order to use
this piece of information outside the method.
Instead you might want to either just allow the user to directly access the
myName property by removing getName completely or define Name as a dependent
property and have the accessor method for that property retrieve the
contents of the myName property (which could then have its access changed to
protected or private). Instructions on how to do the latter are in the
documentation.