Data Structures

Introduction

1. Data structures are variables that store more than one value.
2. An array is a data structure in which all of the values are logically related.
3. A cell array is a kind of data structure that stores values of different types.
4. Cell arrays can be vectors or matrices; the different values are referred to as the elements of the array.
5. Structures are data structures that group together values that are logically related, but are not the same thing and not necessarily the same type.

Creating cell arrays

1. To create cell arrays curly braces are used instead of square brackets.
2. To create a row vector cell array, the values are separated by commas.
3. To create a column vector cell array, the values are instead separated by semicolons.
4. The type of cell arrays is cell.
5. Another method of creating a cell array is to simply assign values to specific array elements and build it up element by element.

Referring to and display elements

1. Using curly braces for the subscripts will reference the contents of a cell; called content indexing.

2. Using parentheses for the subscripts references the cells; this is called cell indexing.

3. The celldisp function displays the contents of all elements of the cell array.

4. To delete an element from a vector cell array or to delete an entire row or column, cell indexing is used.

Storing strings in cell arrays

1. As cell arrays can store different types of values, strings of different lengths can be stored in the elements.
2. The length of each string can be displayed using a for loop to loop through the elements of the cell array.

3. The function cellstr converts from a character array padded with blanks to a cell array in which the trailing blanks have been removed.

4. The char function can convert from a cell array to a character matrix.
5. The function iscellstr will return logical true if a cell array is a cell array of all strings or logical false if not.

Create and Modify Structure Variables

1. Creating structure variables can be accomplished by using the struct function.

2. An alternative method of creating structures is by using the dot operator to refer to the fields within the structure.

3. The disp function will display either the entire structure or an individual field.
4. By using fprintf, only individual fields can be printed.

5. The function rmfield removes a field from a structure.

Passing Structures to Functions

Related structure functions

1. The function isstruct will return logical 1 for true if the variable argument is a structure variable or 0 if not.
2. The isfield function returns logical true if a field name is a field in the structure argument or logical false if not.

3. The fieldnames function will return the names of the fields that are contained in a structure variable.

Vectors of Structures

1. In many applications, including database applications, information would normally be stored in a vector of structures, rather than in individual structure variables.

2. For loop can also be used to display each element in the packages vector.

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s