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
MATLAB中求矩阵非零元的坐标的更多相关文章
- matlab中find 查找非零元素的索引和值
来源:https://ww2.mathworks.cn/help/matlab/ref/find.html?searchHighlight=find&s_tid=doc_srchtitle f ...
- 将Matlab中的矩阵输出到txt文件
将矩阵输出到txt文件中的方法,遍寻网络,始见真经!!! fid=fopen('C:Documents and Settingscleantotal.ped','wt');%写入文件路径 matrix ...
- MATLAB中绘制图形的时候,坐标和标题倒置
1.如上图所示,直方图的坐标轴以及标题文字都颠倒了 原因: 在MATLAB显示的subplot函数中,图像与直方图这些不属于一类,所以在显示的时候会出现这种情况 解决办法:1>将图像与直方图分开 ...
- matlab中求逆矩阵的高斯消元法实现的代码
function qiuni =INV_GET(a)N=length(a);M=eye(N);%得到上三角矩?for i=1:N max=a(i,i); A=i; for j=i+1:N if(abs ...
- 【Matlab】求矩阵行和/列和
行和 sum(a, 2) 列和 sum(a) 所有元素之和 sum(sum(a)) 某一列元素之和 sum(a(:,1)) %a矩阵的第一列之和 某一行元素之和 sum(a(1,:)) %a矩阵的第一 ...
- matlab中矩阵的表示与简单操作
原文地址为:matlab矩阵的表示和简单操作 一.矩阵的表示在MATLAB中创建矩阵有以下规则: a.矩阵元素必须在”[ ]”内: b.矩阵的同行元素之间用空格(或”,”)隔开: c.矩阵的行与行之间 ...
- Matlab中矩阵的数据结构
在Matlab中,矩阵默认的数据类型是double, 并不是integer. 而且奇怪的是,矩阵乘法默认按照浮点数类型进行, 整数矩阵相乘会报错.另外,可以用a= int16(A)这种形式实现数据类型 ...
- Matlab随笔之矩阵入门知识
原文:Matlab随笔之矩阵入门知识 直接输入法创建矩阵 – 矩阵的所有元素必须放在方括号“[ ]”内: – 矩阵列元素之间必须用逗号“,”或空格隔开,每行必须用“;”隔开 – 矩阵元素可以是任何不含 ...
- MATLAB中的多项式运算
作者:长沙理工大学 交通运输工程学院 王航臣 1.多项式求根 在MATLAB中求取多项式的根用roots函数. 函数:roots 功能:一元高次方程求解. 语法:roots(c) 说明:返回一个列向量 ...
随机推荐
- C# 连接 Mysql 中文乱码问题
网上有很多解决乱码的方法,什么 set names utf8 .什么在插入数据前进行编码,亲自试了都没有效果,在网上寻觅了很久,终于找到一种方法,并亲试成功: 首先要保证你的数据库是UTF8字符集 ...
- Jquery弹窗插件Lhgdialog的用法
Lhgdialog的用法 大家都知道用js可以实现,但是在使用js实现的弹窗时得考虑很东西:浏览器的兼容.页面的交互等等问题. 在这里简单介绍一下lhgdialog的用法. 参数有: Title:弹窗 ...
- Android 它们的定义View (一)
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 非常Android入门程序员AndroidView.可能都是比較恐 ...
- varnish和squid的对比
Varnish与Squid的对比 说到Varnish,不能不提Squid,Squid是一个高性能的代理缓存服务器,它和varnish之间有诸多的异同点,这里分析如下: 下面是他们之间的相同点: ...
- mysql数据库日期是varchar类型的时间比较查询
单纯的字符串比较结果不精确. select * from 表明 where times> '2088/12/8 10:02:40' (×) 转换函数如下(数据库为varchar): selec ...
- Sql Server数据库--》事务
事务:更多的是一种处理机制(同生共死) 事务是对增删改而言的(因为她们会改变数据) 事务是对多条语句而言,多个sql语句组成,整体执行 事务的4个特点叫做ACID:分别为: 1,A:原子性->事 ...
- Spring事务异常回滚,捕获异常不抛出就不会回滚(转载) 解决了我一年前的问题
最近遇到了事务不回滚的情况,我还考虑说JPA的事务有bug? 我想多了....... 为了打印清楚日志,很多方法我都加tyr catch,在catch中打印日志.但是这边情况来了,当这个方法异常 ...
- “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载)
解决方案: “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载) 遇到的问题: 在.h头文件中采用namespace 命名空间报错 test.h namespace LMR ...
- EC读书笔记系列之17:条款41、42、43、44、45、46
条款41 了解隐式接口与编译器多态 记住: ★classes和templates都支持接口和多态 ★对classes而言接口是显式的(explicit),以函数签名为中心.多态则是通过virtual函 ...
- lightoj 1030
递推,倒着递推. #include<stdio.h> #define maxn 1010 #define min(a,b) (a)>(b)?(b):(a) int main() { ...