help-octave
[Top][All Lists]
Advanced

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

Re: Structures


From: Mike B.
Subject: Re: Structures
Date: Thu, 11 Feb 2010 22:28:57 -0800 (PST)

Thanks Jaroslav.

I'm using Octave 3.0.5 and when I tried 
> pkg install general-1.2.0.tar.gz
got
gzip: /home/mike/general-1.2.0.tar.gz: decompression OK, trailing garbage 
ignored
error: the following dependencies where unsatisfied:
   general needs octave >= 3.2.4

Anyway to get this working on 3.0.5?.

Thanks,
Mike.

--- On Thu, 11/2/10, Jaroslav Hajek <address@hidden> wrote:

> One good option is to use the string dictionary class from
> the general package:
> 
> octave:1> A.f1 = 1
> A =
> {
>   f1 =  1
> }
> 
> octave:2> A.f2 = A.f1 * 2
> A =
> {
>   f1 =  1
>   f2 =  2
> }
> 
> octave:3> A.f3 = "abc"
> A =
> {
>   f1 =  1
>   f2 =  2
>   f3 = abc
> }
> 
> octave:4>
> octave:4> B.f2 = A.f1 *5
> B =
> {
>   f2 =  5
> }
> 
> octave:5> B.f3 = "def"
> B =
> {
>   f2 =  5
>   f3 = def
> }
> 
> octave:6> A = dict (A)
> A =
> 
> dict: {
>   f1 :  1
>   f2 :  2
>   f3 : abc
> }
> octave:7> B = dict (B)
> B =
> 
> dict: {
>   f2 :  5
>   f3 : def
> }
> octave:8> C = join (A, B)
> C =
> 
> dict: {
>   f1 :  1
>   f2 :  5
>   f3 : def
> }
> 
> To access the merged values in a particular order:
> 
> octave:9> values = C({"f2", "f1", "f3", "f1"})
> values =
> 
> {
>   [1,1] =  5
>   [1,2] =  1
>   [1,3] = def
>   [1,4] =  1
> }
> 
> To convert the dictionary back to a struct:
> 
> octave:10> struct (C)
> ans =
> {
>   f1 =  1
>   f2 =  5
>   f3 = def
> }
> 
> hth
> 
> -- 
> RNDr. Jaroslav Hajek, PhD
> computing expert & GNU Octave developer
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
> 


      New Email names for you! 
Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. 
Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/



reply via email to

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