Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: problem with calling a class method
Replies: 3   Last Post: Nov 27, 2012 12:23 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Stan24

Posts: 10
Registered: 11/24/12
Re: problem with calling a class method
Posted: Nov 24, 2012 8:28 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Nasser M. Abbasi" <nma@12000.org> wrote in message <k8q75q$feb$1@speranza.aioe.org>...
> On 11/24/2012 3:36 AM, Stan24 wrote:
> > Hi,
> > How do I call a method with a parameter control handler?
> > The following example returns the error:
> > Undefined function 'setIndex' for input arguments of type 'double'.
> > Thanks,
> > Stan
> >
> > classdef MyClass< handle
> > properties
> > hpm_1; hpm_2; % popupmenu handlers
> > ...
> > end
> > methods
> > ...
> > function setIndex(obj, val)
> > set(obj, 'Value', val);
> > end
> > function Item(obj)
> > setIndex(obj.hpm_1, 1);
> > setIndex(obj.hpm_2, 1);
> > end
> > end
> >

>
>
> I have no used Matlab classes for a while. But you do
> not even have a constructor. Also you are not initializing
> the handles values inside the class (hpm_1, hpm_2).
>
> I'd suggest adding a constructor, in there you set
> these handles. Then later you can change them.
>
> In this example, I passed h1=1, h2=2 for the
> constructor. In your case, you need to use real handles
> ofcourse.
>
> You call it like this:
>
> ----------------------
> clear all
> h1=1; h2=2; o = MyClass(h1,h2)
>
> o =
>
> MyClass handle
>
> Properties:
> hpm_1: 1
> hpm_2: 2
>
> Methods, Events, Superclasses
>
> o.Item()
> -----------------------------
>
> The class will be:
>
> ---------------------------
> classdef MyClass< handle
> properties
> hpm_1; hpm_2; % popupmenu handlers
> end
> methods
>
> CONSTRUCTOR
> function obj = MyClass(hpm_1, hpm_2)
> obj.hpm_1=hpm_1;
> obj.hpm_2=hpm_2;
> end
> function setIndex(~, theHandle , val)
> set(theHandle, 'Value', val);
> end
> function Item(obj)
> obj.setIndex(obj.hpm_1, 1);
> obj.setIndex(obj.hpm_2, 1);
> end
> end
> end
> ---------------------------------
>
> again, I have not used Matlab classes for long time.
>
> --Nasser
>
>
>
> But try this
>


Thanks a lot. Your solution is very good.

function setIndex(~, theHandle , val)
...
end




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.