object behavior with Octave...

Ben Abbott bpabbott at mac.com
Sat Feb 14 07:16:50 CST 2009


On Feb 13, 2009, at 11:59 PM, James Moliere wrote:

> Hello,
> I'm trying to do some object based programming with Octave.
>
> For example, I can do this
> x.a = 1
> and then to display x.a, I can type
> x.a
> ans = 1
>
> I can also do something like this
> x.f1 = @sin
> x.f2 = @cos
>
> ...running a function would look like...
> x.f1(pi)
> ans = 1.2246e-016
>
> I'd like to do something like an anonymous function similar to
>
> x.f3 =@function response = (arg1, arg2)
> 	response = arg1+arg2;
> endfunction
>
> notice that this structure is starting to look like a class function?
> ...this is what I'm trying to do.
>
> Thanks!
> James Moliere

Please tell us what version of Octave are you running.

Using 3.0.3 or the developers sources you can do ...

	x.f3 = @(arg1,arg2) arg1 + arg2;

If you have something more complex ...

	function result = response (arg1, arg2)
	...
	endfunction
	x.f3 = @response;

Ben



More information about the Help-octave mailing list