help-octave
[Top][All Lists]
Advanced

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

Re: Structure items as vectors?


From: Sergei Steshenko
Subject: Re: Structure items as vectors?
Date: Mon, 14 Apr 2008 07:36:31 -0700 (PDT)

--- David Bateman <address@hidden> wrote:

> Schirmacher, Rolf wrote:
> > Hello,
> >
> > I want to use structured information for numerical computations. I have a
> > structure like
> >
> > octave.exe> some.data.structure(1).item = 1;
> > octave.exe> some.data.structure(2).item = 2;
> >
> > and later on, I want to do calculations with a vector of "item"s. What I get
> > is a list like
> >
> > octave.exe> some.data.structure.item
> > ans =
> >
> > (,
> >   [1] =  1
> >   [2] =  2
> > ,)
> >
> > octave.exe> some.data.structure(:).item
> > ans =
> >
> > (,
> >   [1] =  1
> >   [2] =  2
> > ,)
> >
> >
> > On the other hand, I can access the individual elements as scalars like
> >
> > octave.exe> some.data.structure(1).item
> > ans =  1
> >
> >
> > How can I retrive the data as a vector, i.e. overcome such errors most
> > easily? 
> >
> > octave.exe> items_doubled = 2 .* some.data.structure(:).item
> > error: binary operator `.*' not implemented for `scalar' by `cs-list'
> > operations
> > error: evaluating binary operator `.*' near line 59, column 19
> > error: evaluating assignment expression near line 59, column 15
> >
> >   
> 
> The returned value above is a comma-separated list in exactly the same
> manner as Matlab returns the above. Try "[some.data.structure.item]",
> which converts your comma seperated list into a matrix. Or if you can't
> be sure the data is numeric, try "{some.data.structure.item}" which
> converts it to a cell array.
> 
> D.
> 
> 
> 
> 
> 
> -- 
> David Bateman                                address@hidden
> Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
> Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
> 91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 
> 
> The information contained in this communication has been classified as: 
> 
> [x] General Business Information 
> [ ] Motorola Internal Use Only 
> [ ] Motorola Confidential Proprietary
> 
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
> 

There is a couple of useful functions allowing to know for sure what kind of 
object it is, namely
'class', 'ismatrix'.

Here is an example:

"
help class
octave:1> help class
 -- Built-in Function:  class (EXPR)
     Return the class of the expression EXPR, as a string.

class is a built-in function

Additional help for built-in functions and operators is
available in the on-line version of the manual.  Use the command
`doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the address@hidden
mailing list.
octave:2> a.b.c.d =1
a =
{
  b =
  {
    c =
    {
      d: 1x1 scalar
    }

  }

}

octave:3> class(a)
ans = struct
octave:4> a.b.c.e = [1,2,3]
a =
{
  b =
  {
    c =
    {
      d: 1x1 scalar
      e: 1x3 matrix
    }

  }

}

octave:5> class(a.b.c.e)
ans = double
octave:6> ismatrix(a.b.c.e)
ans =  1
octave:7>  a.b.c.f{2} = [10,20,30]
a =
{
  b =
  {
    c =
    {
      d: 1x1 scalar
      e: 1x3 matrix
      f: 1x2 cell
    }

  }

}

octave:8> a.b.c.f{3} = [40,50]
a =
{
  b =
  {
    c =
    {
      d: 1x1 scalar
      e: 1x3 matrix
      f: 1x3 cell
    }

  }

}

octave:9> class(a.b.c.f)
ans = cell
octave:10> class("hello")
ans = char
octave:11> 
".

Regards,
  Sergei.

Applications From Scratch: http://appsfromscratch.berlios.de/


      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


reply via email to

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