File: struct.mdc

package info (click to toggle)
freemat 4.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 141,800 kB
  • ctags: 14,082
  • sloc: ansic: 126,788; cpp: 62,046; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 100
file content (83 lines) | stat: -rw-r--r-- 1,905 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

 Usage

Creates an array of structures from a set of field, value
pairs. The syntax is

     y = struct(n_1,v_1,n_2,v_2,...)

where n_i are the names of the fields in the structure
array, and v_i are the values. The values v_i must either
all be scalars, or be cell-arrays of all the same
dimensions. In the latter case, the output structure array
will have dimensions dictated by this common size. Scalar
entries for the v_i are replicated to fill out their
dimensions. An error is raised if the inputs are not
properly matched (i.e., are not pairs of field names and
values), or if the size of any two non-scalar values cell-
arrays are different.
Another use of the struct function is to convert a class
into a structure. This allows you to access the members of
the class, directly but removes the class information from
the object.


 Example

This example creates a 3-element structure array with three
fields, foo bar and key, where the contents of foo and bar
are provided explicitly as cell arrays of the same size, and
the contents of bar are replicated from a scalar.

  --> y = struct('foo',{1,3,4},'bar',
  {'cheese','cola','beer'},'key',508)

  y =
  1x3 struct array with fields:
      foo
      bar
      key
  --> y(1)

  ans =
      foo: 1
      bar: cheese
      key: 508
  --> y(2)

  ans =
      foo: 3
      bar: cola
      key: 508
  --> y(3)

  ans =
      foo: 4
      bar: beer
      key: 508

An alternate way to create a structure array is to
initialize the last element of each field of the structure

  --> Test(2,3).Type = 'Beer';
  --> Test(2,3).Ounces = 12;
  --> Test(2,3).Container = 'Can';
  --> Test(2,3)

  ans =
      Type: Beer
      Ounces: 12
      Container: Can
  --> Test(1,1)

  ans =
      Type: 0
      Ounces: 0
      Container: 0


* FreeMat_Documentation
* Variables_and_Arrays
* Generated on Thu Jul 25 2013 17:18:30 for FreeMat by
  doxygen_ 1.8.1.1