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
> 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