In: Computer Science
Matlab work. Pleaae dont copy from any source.
Write a function that will accept a structure as an argument and return two cell arrays containing the names of the fields of that structure and the data types of each field. Be sure to check that the input argument is a structure, and generate an error message if it is not.
A structure array is a data type that groups related
data using data containers called fields. Each field can
contain any type of data. Access data in a field using dot notation
of the form structName.fieldName
.
Creation
When you have data to put into a new structure, create the structure using dot notation to name its fields one at a time:
s.a = 1; s.b = {'A','B','C'}
s = struct with fields: a: 1 b: {'A' 'B' 'C'}
You also can create a structure array using the
struct
function, described below. You can specify many
fields simultaneously, or create a nonscalar structure array.
Syntax
s = struct
s = struct(field,value)
s = struct(field1,value1,...,fieldN,valueN)
s = struct([])
s = struct(obj)
Description
s = struct
creates a scalar (1-by-1) structure with
no fields.
example
s = struct(
field,value
) creates a
structure array with the specified field and value. The
value
input argument can be any data type, such as a
numeric, logical, character, or cell array.
If value
is not a cell array, or if
value
is a scalar cell array, then s
is a
scalar structure. For instance, s = struct('a',[1 2
3])
creates a 1-by-1 structure, where s.a = [1 2
3]
.
If value
is a nonscalar cell array, then
s
is a structure array with the same dimensions as
value
. Each element of s
contains the
corresponding element of value
. For example, s =
struct('x',{'a','b'})
returns s(1).x = 'a'
and
s(2).x = 'b'
.
If value
is an empty cell array {}
,
then s
is an empty (0-by-0) structure.