Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
28
Добавлен:
09.02.2015
Размер:
283.65 Кб
Скачать

In which case they are expanded so that the first three arguments

all have the same length.

For example, this dissects and then reassembles a sparse matrix:

[i,j,s] = find(S);

[m,n] = size(S);

S = sparse(i,j,s,m,n);

So does this, if the last row and column have nonzero entries:

[i,j,s] = find(S);

S = sparse(i,j,s);

All of MATLAB's built-in arithmetic, logical and indexing operations

can be applied to sparse matrices, or to mixtures of sparse and

full matrices. Operations on sparse matrices return sparse matrices

and operations on full matrices return full matrices. In most cases,

operations on mixtures of sparse and full matrices return full

matrices. The exceptions include situations where the result of

a mixed operation is structurally sparse, eg. A .* S is at least

as sparse as S . Some operations, such as S >= 0, generate

"Big Sparse", or "BS", matrices -- matrices with sparse storage

organization but few zero elements.

See also issparse, spalloc, spones, speye, spconvert, full, find, sparfun.

Overloaded methods:

codistributor2dbc/sparse

codistributor1d/sparse

codistributed/sparse

Reference page in Help browser

doc sparse

<full> - Convert sparse matrix to full matrix.

FULL Convert sparse matrix to full matrix.

A = FULL(X) converts a sparse matrix S to full storage

organization. If X is a full matrix, it is left unchanged.

If A is full, issparse(A) returns 0.

See also issparse, sparse.

Overloaded methods:

codistributed/full

Reference page in Help browser

doc full

<find> - Find indices of nonzero elements.

FIND Find indices of nonzero elements.

I = FIND(X) returns the linear indices corresponding to

the nonzero entries of the array X. X may be a logical expression.

Use IND2SUB(SIZE(X),I) to calculate multiple subscripts from

the linear indices I.

I = FIND(X,K) returns at most the first K indices corresponding to

the nonzero entries of the array X. K must be a positive integer,

but can be of any numeric type.

I = FIND(X,K,'first') is the same as I = FIND(X,K).

I = FIND(X,K,'last') returns at most the last K indices corresponding

to the nonzero entries of the array X.

[I,J] = FIND(X,...) returns the row and column indices instead of

linear indices into X. This syntax is especially useful when working

with sparse matrices. If X is an N-dimensional array where N > 2, then

J is a linear index over the N-1 trailing dimensions of X.

[I,J,V] = FIND(X,...) also returns a vector V containing the values

that correspond to the row and column indices I and J.

Example:

A = magic(3)

find(A > 5)

finds the linear indices of the 4 entries of the matrix A that are

greater than 5.

[rows,cols,vals] = find(speye(5))

finds the row and column indices and nonzero values of the 5-by-5

sparse identity matrix.

See also sparse, ind2sub, relop, nonzeros.

Overloaded methods:

codistributed/find

cgprojconnections/find

coninputfactor/find

sweepsetfilter/find

sweepset/find

cgddnode/find

Reference page in Help browser

doc find

<spconvert> - Import from sparse matrix external format.

SPCONVERT Import from sparse matrix external format.

SPCONVERT is used to create sparse matrices from a simple sparse

format easily produced by non-MATLAB sparse programs. SPCONVERT

is the second step in the process:

1) LOAD an ASCII data file containing [i,j,v] or [i,j,re,im]

as rows into a MATLAB variable.

2) Convert that variable into a MATLAB sparse matrix.

S = SPCONVERT(D) converts the matrix D containing row-column-value

triples [i,j,v] as rows into a sparse matrix S such that

for k=1:size(D,1),

S(D(k,1),D(k,2)) = D(k,3).

end

If D is M-by-4 then the third and fourth columns are treated as

the real and imaginary parts of the complex values, so that

for k=1:size(D,1),

S(D(k,1),D(k,2)) = D(k,3) + i*D(k,4).

end

D can contain rows of the form [m n 0] or [m n 0 0] to specify

size(S) is m-by-n. If D is already sparse no conversion is done, so

SPCONVERT can be used after D is loaded from either a MAT or an

ASCII file.

Example: Suppose mydata.dat contains the rows

8 1 6.00

3 5 7.00

4 9 2.00

9 9 0

then the commands

load mydata.dat

A = spconvert(mydata);

produces the 9-by-9 sparse matrix

A =

(8,1) 6

(3,5) 7

(4,9) 2

See also sparse, full.

Reference page in Help browser

doc spconvert

Соседние файлы в папке Библиотеки Matlab