help-octave
[Top][All Lists]
Advanced

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

strange struct syntax


From: Francesco Potortì
Subject: strange struct syntax
Date: Wed, 05 May 2021 10:44:11 +0200

I read the manual, and as far I understand, this is documented as it
is.  Yet, it looks very strange and adds to the difficulty of mastering
the syntax of cell arrays and structures, so I am asking for further
confirmation. 

Is this perfectly normal?


octave> a={"Name Surname"}
  a =
  {
    [1,1] = Name Surname
  }

octave> a(1)
  ans =
  {
    [1,1] = Name Surname
  }

## Now, I want to create a struct with only one field, which is a cell
## array of strings.

## This one works alright
octave> clear s
octave> s.names = a(1)
  s =
    scalar structure containing the fields:
      names =
      {
        [1,1] = Name Surname
      }

## This one does not.  The manual explains why
octave> s = struct("names", a(1))
  s =
    scalar structure containing the fields:
      names = Name Surname

## This one does what I want.  Completely  unintuitive to me
octave> s = struct("names", { a(1) })
  s =
    scalar structure containing the fields:
      names =
      {
        [1,1] = Name Surname
      }

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(gate 20, 1st floor, room C71)         Web:    http://fly.isti.cnr.it



reply via email to

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