矩阵中的0置为Inf(邻接矩阵)
ind=find(x==0);
x(ind)=inf;
index=isnan(z);
z(index)=0;
在Matlab中,有一个logical数据类型,和C++中的bool值相同。find()函数将logical值0也视为数值0,logical值1视为数值1,因此可以用上面的方法找到矩阵中满足一定条件的元素。
如果X是向量,则 返回与 方向相同的向量 。
如果X是多维数组,则 返回结果的线性索引的列向量。
k = find(X)
k = find(X,n)
k = find(X,n,direction)
[row,col] = find( ___ )
[row,col,v] = find( ___ )
k = find(X) returns a vector containing the linear indices of each nonzero element in array X
k = find(X,n) returns the first n indices corresponding to the nonzero elements in X.
k = find(X,n,direction), where direction is ‘last’, finds the last n indices corresponding to nonzero elements in X. The default for direction is ‘first’, which finds the first n indices corresponding to nonzero elements.
[row,col] = find(___) returns the row and column subscripts of each nonzero element in array X using any of the input arguments in previous syntaxes.
[row,col,v] = find(___) also returns vector v, which contains the nonzero elements of X.