Chapter 10 Sparse Cell Structure Arrays Sparse Arrays

  • Slides: 16
Download presentation
Chapter 10 Sparse, Cell, & Structure Arrays

Chapter 10 Sparse, Cell, & Structure Arrays

Sparse Arrays A sparse array (matrix) is a large matrix in which the vast

Sparse Arrays A sparse array (matrix) is a large matrix in which the vast majority of the elements are zero.

Sparse Matrix Functions sparse: Converts a full matrix into a sparse matrix. full: Converts

Sparse Matrix Functions sparse: Converts a full matrix into a sparse matrix. full: Converts a sparse matrix into a full matrix.

Sparse Array Example Solve the following simultaneous system of equations with sparse matrices: 1.

Sparse Array Example Solve the following simultaneous system of equations with sparse matrices: 1. 0 X 1 + 0. 0 X 2 + 1. 0 X 3 + 0. 0 X 4 = 1. 0 0. 0 X 1 + 2. 0 X 2 + 0. 0 X 3 + 0. 5 X 4 = 2. 0 0. 5 X 1 + 0. 0 X 2 + 3. 0 X 3 + 0. 0 X 4 = -1. 5 0. 0 X 1 + 0. 0 X 2 + 0. 0 X 3 + 2. 0 X 4 = 1. 0

Cell Arrays Array in which each element is a bin which can contain an

Cell Arrays Array in which each element is a bin which can contain an array. Cells of mixed data types are allowed. Use { } instead of ( ) for selecting & displaying the contents of cells.

Creating Cell Arrays C = cell(n) Creates n x n cell array of empty

Creating Cell Arrays C = cell(n) Creates n x n cell array of empty matrices. celldisp(C) Displays the content of cell array C. { } = empty cell

Example Cell Arrays Result of executing the following script? >>A=ones(3, 2); >>B=magic(3); >>C=char(‘Pressure’, ’Temp’,

Example Cell Arrays Result of executing the following script? >>A=ones(3, 2); >>B=magic(3); >>C=char(‘Pressure’, ’Temp’, ’Disp’); >>D=[6+7 j, 15]; >>Cel={A, B; C, D}

Structure Arrays composed of structures. Each element is given a name (field). Each field

Structure Arrays composed of structures. Each element is given a name (field). Each field may be of different type. Address fields with structure & field separated by period.

Structure Functions rmfield >> Remove field n_str=rmfield(str, ’field’) fieldnames(S) Returns field names in structure

Structure Functions rmfield >> Remove field n_str=rmfield(str, ’field’) fieldnames(S) Returns field names in structure S.