| Embedded IDE Link™ CC | ![]() |
| On this page… |
|---|
When you create an object that accesses a structure symbol declared in your source code, the object constructor createobj returns a structure object. createobj uses the information in your source code to set the properties of the object appropriately to match the code. Within the properties and their values you find all the information about the symbol, so that MATLAB understands how to handle the symbol in your MATLAB workspace.
Like memory and register class objects, structure objects do not inherit properties from a parent class.
Object properties can include both properties that the object inherits from its superclass, if any, and some properties that are unique to the class itself. For this reason, many objects in Embedded IDE Link CC share common properties; as you use the objects you will become familiar with the common and special properties for each.
| Property Name | Property Type | Default Value | Description |
|---|---|---|---|
address | mxArray | None | Address of the function |
arrayorder | {col-major, | row-major | Ordering of values when moving data from linear memory storage to N-D arrays in MATLAB |
filename | mxArray | None | Name of the file that contains the function |
member | cell array | None | Object that contains a list of the structure members |
membname | cell array | None | Object that contains the names of the members of the structure |
memboffset | int | 0 | Offset of the member from the starting address of the structure |
name | string | None | Name of the C or assembly function |
numberofstorageunits | double | 1 | Number of memory units needed to represent the object |
size | mxArray | 1 | Specifies the size of the array created in MATLAB from the data received from memory |
storageunitspervalue | double | 1 | Memory units per value in memory on the DSP |
Like properties, methods for objects may come from the superclass or derive only from the class itself. For example, the cast and convert methods do not appear in all objects; listing them here indicates that the object does not inherit these methods but provides them itself.
| Name | Overloaded? | Description |
|---|---|---|
| copy | Yes | Return a copy of the object |
| display | Yes | Return information about the object |
| getmember | No | Return an object that accesses one member of a structure |
| read | Yes | Read a structure from the symbol table |
| write | Yes | Write changes or values to the structure in memory |
structure objects present some unexpected behavior when you try to access the elements referred to by the structure object. Consider the following example that creates a structure object and accesses the members.
Suppose we have a structure variable in CCS:
creal32_T mw_output[512];
In MATLAB, create an object to mw_output. The size (512) is correctly propagated to the structure object:
a = createobj(cc,'mw_output'); STRUCTURE Object stored in memory: Symbol name : mw_output Address : [ 2147652624 0] Address units per value : 8 au Size : [ 512 ] Total Address Units : 4096 au Array ordering : row-major Members : 're', 'im'
If you now look at a member re of the structure the size is not 512 any more. It returns a size of 1.
a.member.re NUMERIC Object stored in memory: Symbol name : re Address : [ 2147652624 0] Data type : float Word size : 32 bits Address units per value : 4 au Representation : float Size : [ 1 ] Total address units : 4 au Array ordering : row-major Endianness : little
Now look at another member. Again, the size is 1.
a.member.im NUMERIC Object stored in memory: Symbol name : im Address : [ 2147652628 0] Data type : float Word size : 32 bits Address units per value : 4 au Representation : float Size : [ 1 ] Total address units : 4 au Array ordering : row-major Endianness : little
The size of the members cannot reflect the size of the structure object.
If you have
struct tag {
int a;
int b;
} mystruct[10];
In memory, the values are arranged in the following way:
memory1: mystruct[0] -> member a value
memory2: mystruct[0] -> member b value
memory3: mystruct[1] -> member a value
memory4: mystruct[1] -> member b value
...
memory19: mystruct[9] -> member a value
memory20: mystruct[9] -> member b value
Therefore, when you do the following functions:
structobj = createobj(cc,'mystruct') aobj = structobj.member.a;
and aobj.size is same as structobj.size, you will be reading the wrong set of values, as shown by the example that shows the structure memory values and layout.
Setting the value of aobj to 1 provides a safe way to allow you to access the members of a structure.
The most reliable way to access a structure objects members is to read the structure into MATLAB and reference the members there. In the next code example you see how to do this.
x = createobj(cc,'m')
STRUCTURE Object stored in memory:
Symbol name : m
Address : [ 13544 0]
Address units per value : 12 au
Size : [ 2 ]
Total Address Units : 12 au
Array ordering : row-major
Members : 'a', 'b'
out = read(x)
out =
1x2 struct array with fields:
a
b
out(1)
ans =
a: 3
b: 1.5000
out(2)
ans =
a: 12648430
b: 1.7724e-038
read(x,'a')
ans =
3 12648430
Use the read function to return the value of a for the first element in the structure.
read(x,1,'a')
ans =
3
read(x,2,'a')
ans =
12648430
![]() | Function Objects — Their Methods and Properties | Type Objects — Their Methods and Properties | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |