Documentation

spconvert

Import from sparse matrix external format

Description

example

S = spconvert(D)constructs sparse matrixSfrom the columns ofDin a manner similar to thesparsefunction.

  • IfDis of sizeN-by-3, thenspconvertuses the columns[i,j,re]ofDto constructS, such thatS(i(k), j(k)) = re(k).

  • IfDis of sizeN-by-4, thenspconvertuses the columns[i,j,re,im]ofDto constructS, such thatS(i(k), j(k)) = re(k) + 1i*im(k).

Examples

collapse all

Create an ASCII file,uphill.dat, which contains the following values. Save the file in your current directory.

1 1 1.000000000000000 1 2 0.500000000000000 2 2 0.333333333333333 1 3 0.333333333333333 2 3 0.250000000000000 3 3 0.200000000000000 1 4 0.250000000000000 2 4 0.200000000000000 3 4 0.166666666666667 4 4 0.142857142857143 4 4 0.000000000000000

It is common to purposefully make the last line of the file include the desired size of the matrix with a value of 0. This practice ensures that the converted sparse matrix has that size.

Load the data into MATLAB®and convert it into a sparse matrix.

loaduphill.datH = spconvert(uphill)
H = (1,1) 1.0000 (1,2) 0.5000 (2,2) 0.3333 (1,3) 0.3333 (2,3) 0.2500 (3,3) 0.2000 (1,4) 0.2500 (2,4) 0.2000 (3,4) 0.1667 (4,4) 0.1429

In this case, the last line in the file is not necessary because the earlier lines already specify that the matrix is at least 4-by-4.

Input Arguments

collapse all

Input matrix, specified as a matrix with either three or four columns. In both cases, the first two columns ofDare subscripts and the third column is composed of data values. A four column matrix specifies the real (third column) and imaginary (fourth column) parts of complex numbers.

IfDis already a sparse matrix, thenspconvertreturnsD.

Data Types:single|double

Extended Capabilities

See Also

|

Introduced before R2006a