博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MATLAB中求矩阵非零元的坐标
阅读量:6302 次
发布时间:2019-06-22

本文共 2968 字,大约阅读时间需要 9 分钟。

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

转载于:https://www.cnblogs.com/wangduo/p/5342282.html

你可能感兴趣的文章
华为畅玩5 (CUN-AL00) 刷入第三方twrp Recovery 及 root
查看>>
LeetCode----67. Add Binary(java)
查看>>
母版页 MasterPage
查看>>
[转] ReactNative Animated动画详解
查看>>
DNS原理及其解析过程
查看>>
记录自写AFNetWorking封装类
查看>>
没想到cnblog也有月经贴,其实C#值不值钱不重要。
查看>>
【转】LUA内存分析
查看>>
springboot使用schedule定时任务
查看>>
[转] Entity Framework Query Samples for PostgreSQL
查看>>
XDUOJ 1115
查看>>
PHP学习(四)---PHP与数据库MySql
查看>>
模版方法模式--实现的capp流程创建与管理
查看>>
软件需求分析的重要性
查看>>
eclipse的scala环境搭建
查看>>
UVA465:Overflow
查看>>
HTML5-placeholder属性
查看>>
Android选择本地图片过大程序停止的经历
查看>>
poj 2187:Beauty Contest(旋转卡壳)
查看>>
《Flask Web开发》里的坑
查看>>