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中求矩阵非零元的坐标的更多相关文章

  1. matlab中find 查找非零元素的索引和值

    来源:https://ww2.mathworks.cn/help/matlab/ref/find.html?searchHighlight=find&s_tid=doc_srchtitle f ...

  2. 将Matlab中的矩阵输出到txt文件

    将矩阵输出到txt文件中的方法,遍寻网络,始见真经!!! fid=fopen('C:Documents and Settingscleantotal.ped','wt');%写入文件路径 matrix ...

  3. MATLAB中绘制图形的时候,坐标和标题倒置

    1.如上图所示,直方图的坐标轴以及标题文字都颠倒了 原因: 在MATLAB显示的subplot函数中,图像与直方图这些不属于一类,所以在显示的时候会出现这种情况 解决办法:1>将图像与直方图分开 ...

  4. 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 ...

  5. 【Matlab】求矩阵行和/列和

    行和 sum(a, 2) 列和 sum(a) 所有元素之和 sum(sum(a)) 某一列元素之和 sum(a(:,1)) %a矩阵的第一列之和 某一行元素之和 sum(a(1,:)) %a矩阵的第一 ...

  6. matlab中矩阵的表示与简单操作

    原文地址为:matlab矩阵的表示和简单操作 一.矩阵的表示在MATLAB中创建矩阵有以下规则: a.矩阵元素必须在”[ ]”内: b.矩阵的同行元素之间用空格(或”,”)隔开: c.矩阵的行与行之间 ...

  7. Matlab中矩阵的数据结构

    在Matlab中,矩阵默认的数据类型是double, 并不是integer. 而且奇怪的是,矩阵乘法默认按照浮点数类型进行, 整数矩阵相乘会报错.另外,可以用a= int16(A)这种形式实现数据类型 ...

  8. Matlab随笔之矩阵入门知识

    原文:Matlab随笔之矩阵入门知识 直接输入法创建矩阵 – 矩阵的所有元素必须放在方括号“[ ]”内: – 矩阵列元素之间必须用逗号“,”或空格隔开,每行必须用“;”隔开 – 矩阵元素可以是任何不含 ...

  9. MATLAB中的多项式运算

    作者:长沙理工大学 交通运输工程学院 王航臣 1.多项式求根 在MATLAB中求取多项式的根用roots函数. 函数:roots 功能:一元高次方程求解. 语法:roots(c) 说明:返回一个列向量 ...

随机推荐

  1. GLFW库文件配置

    VS2012+windows8下面,vs的默认路径在C:\Program Files(x86)\Windows Kits\8.0 下. 将include\GLFW里.h文件加入vs路径Include\ ...

  2. SQL server指定随机数范围

    declare @randnum int=0declare @startnum int =0declare @endnum int=0 set @startnum = 150 set @endnum ...

  3. 习题3.15 自调整表Find例程

    #include<stdio.h> #include<stdlib.h> typedef int * List; /* 自调整表的Find数组实现 */ int Find(Li ...

  4. paip.c++ qt 共享库dll的建立

    paip.c++ qt 共享库dll的建立 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/at ...

  5. 利用freopen()函数和fc命令简化程序调试

    大家在参加ACM比赛或者参加c/c++实验技能竞赛的时候,如果遇到大量的输入和大量的输出时,调试起来很不方便.一来如果结果不正确的话,需要重复输入大量数据:二来如果大量输出的话,得仔细检查输出结果与正 ...

  6. Ibatis代码自动生成工具——Abator安装与应用实例(图解)

    Abator 能自动生成DAO,DTO和sqlMap,大大提高开发效率.Abator 的官方网站:http://ibatis.apache.org/ibator.html 使用也比较简单,以下做个实例 ...

  7. 使用logstash收集日志的可靠性验证

    实时计算里,需要对日志实时收集,logstash可以做到.目前的版本是1.4.2,官方文档在http://www.logstash.net/docs/1.4.2/,里面有详细的配置说明,使用也很简单. ...

  8. 指针和const

    将指针参数声明为指向常量数据的指针有两条理由: 这样可以避免由于无意间修改数据而导致的编译错误.      使用const使得函数能够处理const和非const实参,否则将只能接收非const数据. ...

  9. phpcms-v9 前台模板文件中{pc}标签的执行流程

    前台pc标签的使用:{pc:content 参数名="参数值" 参数名="参数值" 参数名="参数值"} 如: {pc:content ac ...

  10. Core开发-MVC 使用dotnet 命令创建Controller和View

    NET Core开发-MVC 使用dotnet 命令创建Controller和View   使用dotnet 命令在ASP.NET Core MVC 中创建Controller和View,之前讲解过使 ...