help-octave
[Top][All Lists]
Advanced

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

Re: Create Structure


From: Thomas D. Dean
Subject: Re: Create Structure
Date: Sun, 12 Jun 2016 00:07:04 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

On 06/11/2016 11:51 PM, Thomas D. Dean wrote:
I have a character array with 156 names and a corresponding array of
values;

octave:341> a=["n1";"n2";"n3"]
octave:342> b=[1;2;3]
octave:343> x=struct(a(1,1:2),b(1),a(2,1:2),b(2),a(3,1:2),b(3))
octave:344> x
x =

   scalar structure containing the fields:

     n1 =  1
     n2 =  2
     n3 =  3

Is there a function to do this?  Do I have to go to an oct file?

I have looked at cellfun, and structfun, but, could not make either
work.  Most likely, I do not understand this...

x=struct()
for idx=1:3
  x = setfield(x,a(idx,1:3),b(idx))
endfor

Tom Dean



reply via email to

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