Chapter 10 Sparse, Cell, & Structure Arrays
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 a sparse matrix into a full matrix.
Sparse Array Example Solve the following simultaneous system of equations with sparse matrices: 1.0 X1 + 0.0 X2 + 1.0 X3 + 0.0 X4 = 1.0 0.0 X1 + 2.0 X2 + 0.0 X3 + 0.5 X4 = 2.0 0.5 X1 + 0.0 X2 + 3.0 X3 + 0.0 X4 = -1.5 0.0 X1 + 0.0 X2 + 0.0 X3 + 2.0 X4 = 1.0
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 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’,’Disp’); >>D=[6+7j, 15]; >>Cel={A, B; C, D}
Structure Arrays Arrays composed of structures Structure Arrays 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 S.