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) 说明:返回一个列向量 ...
随机推荐
- Jupyter Notebook通过latex输出pdf
主要步骤 1.将ipynb编译成tex ipython nbconvert --to latex Example.ipynb 2. 修改tex,增加中文支持 在\documentclass{artic ...
- Javascript基本算法演练 Seek and Destroy
转载自:http://aeroj-blog.logdown.com/posts/435808 Seek and Destroy You will be provided with an initial ...
- Struts2 二、为Action的参数注入值
为Action参数注入值,主要使用在的场景为,Action的一个参数的值不是固定的是可以改变的,所以不能直接写在Action中,可以通过Struts配置的方式将值配置到Struts中,然后通过注入的方 ...
- MySQL Troubleshoting:Waiting on query cache mutex
今天被MySQL Query Cache 炕了.线上大量 Waiting on query cache mutex 那么什么是 Query Cache? QC 缓存的是整个SELECT的结果集.而非执 ...
- WdatePicker日历控件用法
1. 跨无限级框架显示 不管你把日期控件放在哪里,你都不须要操心会被外层的iframe所遮挡进而影响客户体验,由于My97日期控件是能够跨无限级框架显示的 演示样例2-7 跨无限级框架演示 可无限跨越 ...
- CCF计算机认证——字符串匹配问题(运行都正确,为什么提交后只给50分?)
我的程序: #include<iostream> #include<cctype> #include<string> #include<vector> ...
- C++中将int转变成string和string转变成int
int to string #include<iostream> #include<string> using namespace std; int main() { stri ...
- C++虚函数在内存中的实现
首先来一张图,一目了然: 然后把相应的代码贴上来: class A { int a; public: virtual void f(); virtual void g(int); virtual vo ...
- PHP正则提取HTML中img的url值
<html> <head> <title>获取HTML中的img的src值</title> </head> <body> < ...
- Android DatePicker和TimePicker
监测日期改变的监听器: OnDateChangedListener和OnTimeChangedListener() 当用户改变Datepicker里的年.月.日时,将触发 ...