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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com