[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: class object methods and 'eval' function

From: pantxo diribarne
Subject: Re: class object methods and 'eval' function
Date: Thu, 15 Sep 2011 14:46:01 +0200

The concatenation works with or without commas on my mac os 10.5.8 with 3.4.0 :

octave-3.4.0> test1 ="hello";
octave-3.4.0> disp ([test1 " world"])
hello world
octave-3.4.0> disp ([test1, " world"])
hello world

Concerning the "ii" :  the example I wrote was extracted from the original function, un-necessarilly complicated (that actually returns what I sent), and I forgot to delete {ii}.

And about the indexation, it works perfectly, I did not know it was possible to index scalar structures with a variable.

Thank you very much,


2011/9/15 Ben Abbott <address@hidden>

On Sep 15, 2011, at 7:42 AM, pantxo diribarne wrote:

> Hello list,
> I am currently writing a class using octave @folder framework.
> I need to use eval to access  the fields of my object in the methods @myclass/get.m and @myclass/set.m but octave returns the same error as if I was trying to access the object fields from outside a method.
> In get.m :
> function varargout = get(p, arg)
>   out = p.boardindex
>   eval (["out = p." arg ";"]);
>   varargout{ii} = out;
> endfunction
> Calling get with  " get (obj, 'boardindex')", where obj is a 'myclass' object, I obtain :
> out =  2
> error: invalid index for class
> ...
> Is there a way to have eval function know that it is evaluated inside a method, or should I find the way not to use eval at all?
> Pantxo

The line below will throw an error.

       eval (["out = p." arg ";"]);

You've forgotten to include the commas.

       eval (["out = p.", arg, ";"]);

However, a better approach is ...

       function varargout = get (p, arg)
         varargout{ii} = p.(arg);

... but you still haven't defined "ii". Did you want ...

       function varargout = get (p, arg)
         varargout = {p.(arg)};

... or did you intend to support multiple arg's?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]