MATLAB中求矩阵非零元的坐标

MATLAB中求矩阵非零元的坐标:

方法1:

index=find(a);
[i,j]=ind2sub(size(a),index);
disp([i,j])

 

方法2:

[i,j]=find(a>0|a<0) %列出所有非零元的坐标 
[i,j]=find(a==k) %找出等于k值的矩阵元素的坐标

 

所用函数简介:

IND2SUB Multiple subscripts from linear index.

IND2SUB is used to determine the equivalent subscript values
corresponding to a given single index into an array.

[I,J] = IND2SUB(SIZ,IND) returns the arrays I and J containing the
equivalent row and column subscripts corresponding to the index
matrix IND for a matrix of size SIZ.
For matrices, [I,J] = IND2SUB(SIZE(A),FIND(A>5)) returns the same
values as [I,J] = FIND(A>5).

[I1,I2,I3,...,In] = IND2SUB(SIZ,IND) returns N subscript arrays
I1,I2,..,In containing the equivalent N-D array subscripts
equivalent to IND for an array of size SIZ.

Class support for input IND:
float: double, single

See also sub2ind, find.

 

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

 

SUB2IND Linear index from multiple subscripts.

SUB2IND is used to determine the equivalent single index
corresponding to a given set of subscript values.

IND = SUB2IND(SIZ,I,J) returns the linear index equivalent to the
row and column subscripts in the arrays I and J for a matrix of
size SIZ.

IND = SUB2IND(SIZ,I1,I2,...,IN) returns the linear index
equivalent to the N subscripts in the arrays I1,I2,...,IN for an
array of size SIZ.

I1,I2,...,IN must have the same size, and IND will have the same size
as I1,I2,...,IN. For an array A, if IND = SUB2IND(SIZE(A),I1,...,IN)),
then A(IND(k))=A(I1(k),...,IN(k)) for all k.

Class support for inputs I,J:
float: double, single

See also ind2sub.



来自:http://zhidao.baidu.com/link?url=imuLeLDv16Bsg-xcu4O1M8hVzjdCiRfq6PYHu4MR-o1q9AeMWy-UM3AdZTA7av9k1WLExeyYPVDumS46TNNr1q

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值