spconvert
Import from sparse matrix external format
Syntax
Description
S = spconvert(
constructs
sparse matrix D
)S
from the columns of D
in
a manner similar to the sparse
function.
If
D
is of sizeN
-by-3
, thenspconvert
uses the columns[i,j,re]
ofD
to constructS
, such thatS(i(k), j(k)) = re(k)
.If
D
is of sizeN
-by-4
, thenspconvert
uses the columns[i,j,re,im]
ofD
to constructS
, such thatS(i(k), j(k)) = re(k) + 1i*im(k)
.
Examples
Convert Data File to Sparse Matrix
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.
load uphill.dat
H = spconvert(uphill)
H = 4×4 sparse double matrix (10 nonzeros) (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
D
— Input matrix
matrix
Input matrix, specified as a matrix with either three or four
columns. In both cases, the first two columns of D
are
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.
If D
is already a sparse matrix, then spconvert
returns D
.
Data Types: single
| double
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The spconvert
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)