Thread Subject: problem in calling show function in Object oriented

Subject: problem in calling show function in Object oriented

From: Syed

Date: 14 Oct, 2009 23:37:04

Message: 1 of 4

Hi!
Here is my class below. I am creating points object like pp = point(1,2); and to call show function I do pp.show(); but it give me error "No appropriate method or public field show for class point".

classdef points
    properties
        x
        y
    end
    methods
        function pp= point(x,y)
            this.x=x;
            this.y=y;
        end
        function show()
            disp('hhehe');
        end
    end
end

Kindly help me.

Subject: problem in calling show function in Object oriented

From: Doug Schwarz

Date: 15 Oct, 2009 00:10:44

Message: 2 of 4

In article <hb5nb0$s06$1@fred.mathworks.com>,
 "Syed " <cancer216@hotmail.com> wrote:

> classdef points
> properties
> x
> y
> end
> methods
> function pp= point(x,y)
> this.x=x;
> this.y=y;
> end
> function show()
> disp('hhehe');
> end
> end
> end


Try something like this:


classdef points
    properties
        x
        y
    end
    methods
        function this = point(x,y)
            this.x = x;
            this.y = y;
        end
        function show(this)
            disp('hhehe');
        end
    end
end


By comparing my code with your code it should be obvious what you did
wrong.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: problem in calling show function in Object oriented

From: Syed

Date: 15 Oct, 2009 01:08:03

Message: 3 of 4

Yes I found the error this = point(x,y) but still same error ??? No appropriate method or public field show for class point. Now I think I am having problem calling class functions on object of the class. Kindly try to run the code and suggest me something to fix this problem.
classdef point
    properties
        x
        y
    end
    methods
        function this= point(x,y)
            this.x=x;
            this.y=y;
        end
        function this.show()
            this.disp('something');
        end
        function this.xchange(var)
            this.x=var;
        end
    end
end

Doug Schwarz <see@sig.for.address.edu> wrote in message <see-16B817.20104414102009@news.frontiernet.net>...
> In article <hb5nb0$s06$1@fred.mathworks.com>,
> "Syed " <cancer216@hotmail.com> wrote:
>
> > classdef points
> > properties
> > x
> > y
> > end
> > methods
> > function pp= point(x,y)
> > this.x=x;
> > this.y=y;
> > end
> > function show()
> > disp('hhehe');
> > end
> > end
> > end
>
>
> Try something like this:
>
>
> classdef points
> properties
> x
> y
> end
> methods
> function this = point(x,y)
> this.x = x;
> this.y = y;
> end
> function show(this)
> disp('hhehe');
> end
> end
> end
>
>
> By comparing my code with your code it should be obvious what you did
> wrong.
>
> --
> Doug Schwarz
> dmschwarz&ieee,org
> Make obvious changes to get real email address.

Subject: problem in calling show function in Object oriented

From: Doug Schwarz

Date: 15 Oct, 2009 02:52:13

Message: 4 of 4

[top posting repaired]

In article <hb5slj$33i$1@fred.mathworks.com>,
 "Syed " <cancer216@hotmail.com> wrote:

> Doug Schwarz <see@sig.for.address.edu> wrote in message
> <see-16B817.20104414102009@news.frontiernet.net>...
> > In article <hb5nb0$s06$1@fred.mathworks.com>,
> > "Syed " <cancer216@hotmail.com> wrote:
> >
> > > classdef points
> > > properties
> > > x
> > > y
> > > end
> > > methods
> > > function pp= point(x,y)
> > > this.x=x;
> > > this.y=y;
> > > end
> > > function show()
> > > disp('hhehe');
> > > end
> > > end
> > > end
> >
> >
> > Try something like this:
> >
> >
> > classdef points
> > properties
> > x
> > y
> > end
> > methods
> > function this = point(x,y)
> > this.x = x;
> > this.y = y;
> > end
> > function show(this)
> > disp('hhehe');
> > end
> > end
> > end
> >
> >
> > By comparing my code with your code it should be obvious what you did
> > wrong.
>
> Yes I found the error this = point(x,y) but still same error ??? No
> appropriate method or public field show for class point. Now I think I am
> having problem calling class functions on object of the class. Kindly try to
> run the code and suggest me something to fix this problem.
> classdef point
> properties
> x
> y
> end
> methods
> function this= point(x,y)
> this.x=x;
> this.y=y;
> end
> function this.show()
> this.disp('something');
> end
> function this.xchange(var)
> this.x=var;
> end
> end
> end

Please don't top post.

You didn't read my code carefully enough. You must pass the object into
show() even though you don't use the object inside this simple example
method.

    function show(this)
        disp('hhehe');
    end

Similarly, xchange should be

    function this = xchange(this,var)
        this.x = var;
    end

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com