23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2cell2struct<br />

Purpose Convert cell array to structure array<br />

Syntax s = cell2struct(c,fields,dim)<br />

Description s = cell2struct(c,fields,dim) creates a structure array, s, from the<br />

information contained within cell array, c.<br />

cell2struct<br />

The fields argument specifies field names for the structure array. fields can<br />

be a character array or a cell array of strings.<br />

The dim argument controls which axis of the cell array is to be used in creating<br />

the structure array. The length of c along the specified dimension must match<br />

the number of fields named in fields. In other words, the following must be<br />

true.<br />

size(c,dim) == length(fields) % if fields is a cell array<br />

size(c,dim) == size(fields,1) % if fields is a char array<br />

Examples The cell array, c, in this example contains information on trees. The three<br />

columns of the array indicate the common name, genus, and average height of<br />

a tree.<br />

c = {'birch','betula',65; 'maple','acer',50}<br />

c =<br />

'birch' 'betula' [65]<br />

'maple' 'acer' [50]<br />

To put this information into a structure with the fields name, genus, and<br />

height, use cell2struct along the second dimension of the 2-by-3 cell array.<br />

fields = {'name', 'genus', 'height'};<br />

s = cell2struct(c, fields, 2);<br />

This yields the following 2-by-1 structure array.<br />

See Also fieldnames, struct2cell<br />

s(1) s(2)<br />

ans = ans =<br />

name: 'birch' name: 'maple'<br />

genus: 'betula' genus: 'acer'<br />

height: 65 height: 50<br />

2-229

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!