matlab中find函数参数代表什么意思?我看过help,但有些不懂.看下面代码,请指教X =3 2 0-5 0 70 0 1 [r,c,v] = find(X>2)returns a vector of row indices of the nonzero entries of N where N=(X>2)r =12a vector of column indices of the

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/01 06:27:41
matlab中find函数参数代表什么意思?我看过help,但有些不懂.看下面代码,请指教X =3 2 0-5 0 70 0 1 [r,c,v] = find(X>2)returns a vector of row indices of the nonzero entries of N where N=(X>2)r =12a vector of column indices of the

matlab中find函数参数代表什么意思?我看过help,但有些不懂.看下面代码,请指教X =3 2 0-5 0 70 0 1 [r,c,v] = find(X>2)returns a vector of row indices of the nonzero entries of N where N=(X>2)r =12a vector of column indices of the
matlab中find函数参数代表什么意思?
我看过help,但有些不懂.看下面代码,请指教
X =
3 2 0
-5 0 7
0 0 1
[r,c,v] = find(X>2)
returns a vector of row indices of the nonzero entries of N where N=(X>2)
r =
1
2
a vector of column indices of the nonzero entries of N where N=(X>2)
c =
1
3
and a logical array that contains the nonzero elements of N where N=(X>2).
v =
1
1

matlab中find函数参数代表什么意思?我看过help,但有些不懂.看下面代码,请指教X =3 2 0-5 0 70 0 1 [r,c,v] = find(X>2)returns a vector of row indices of the nonzero entries of N where N=(X>2)r =12a vector of column indices of the
[r,c,v]=find(A),找到矩阵A中不为0的元素并返回
r找到的行,v找到的列,不为0元素的值
例如你用[r c v]=find([3 0;0 4]);
也就是矩阵|3 0|,从中找不为0的数,就会返回
|0 4|
r =
1
2
c =
1
2
v =
3
4
其中r c v的长度相等,一一对应表示
找到非零元素是 1行1列的3,而2行2列的4
然而通常多数用find来需找符合逻辑判断条件的元素的下标
其实,这个时候是分开两部来做的
首先逻辑判断条件实际上是一个表达式,可以返回一个逻辑矩阵
返回的矩阵中对应原来符合逻辑条件的元素的位置就会是1,不符合条件的就是0
你可以试一下 刚才的矩阵
X=[3 0;0 4];
X>2
ans =
1 0
0 1
返回的矩阵中符合条件大于2的位置是1,不符合的位置是0
然后我们再用find去寻找时r,c返回了不为0的元素的行列位置,而v返回的值就都是1了
由于通常我们用find函数多是find一个逻辑表达式,也就是不是0就是1的矩阵
所以的到的v都是1,平常我们就没有必要反会它了
但是实际上find是找所有非零元素的,如果有一天你需要得到矩阵中多有非零元素的值
的时候,别忘了可以利用这个返回的v