标签:== font alt direction ast ima ppi last epp
找到非零元素的索引和值
[row,col,v] = find( ___ ) 返回向量v,其中包含X的非零元素
X = [1 0 2; 0 1 1; 0 0 4]
X =
1 0 2
0 1 1
0 0 4
k = find(X)
k =
1
5
7
8
9
% 顺序是从上往下从左至右进行排列的
k2 = find(~X)
k2 =
2
3
4
6
X = magic(4)
X =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
k = find(X<10,5)
k =
2
3
4
5
7
X(k)
ans =
5
9
4
2
7
x = 1:2:20
x =
1 3 5 7 9 11 13 15 17 19
k = find(x==13)
k =
7
y = 0:0.1:1
y =
Columns 1 through 7
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000
Columns 8 through 11
0.7000 0.8000 0.9000 1.0000
k = find(y==0.3)
k =
Empty matrix: 1-by-0
k = find(abs(y-0.3) < 0.001)
k =
4
X = magic(6);
X(1:2:end) = 0 % 索引从左上角往下后往右
X =
0 0 0 0 0 0
3 32 7 21 23 25
0 0 0 0 0 0
8 28 33 17 10 15
0 0 0 0 0 0
4 36 29 13 18 11
% 寻找最后几个非零元素的索引
k = find(X,4,'last')
k =
30
32
34
36
X = [18 3 1 11; 8 10 11 3; 9 14 6 1; 4 3 15 21]
X =
18 3 1 11
8 10 11 3
9 14 6 1
4 3 15 21
[row,col] = find(X>0 & X<10,3)
row =
2
3
4
col =
1
1
1
X = [3 2 0; -5 0 7; 0 0 1]
X =
3 2 0
-5 0 7
0 0 1
[row,col,v] = find(X)
row =
1
2
1
2
3
col =
1
1
2
3
3
v =
3
-5
2
7
1
标签:== font alt direction ast ima ppi last epp
原文地址:https://www.cnblogs.com/cloud-ken/p/11262878.html