findrow.m

来自「模糊控制工具箱,很好用的,有相应的说明文件,希望对大家有用!」· M 代码 · 共 35 行

M
35
字号
function rowNum=findrow(str,strMat)
%FINDROW Find the rows of a matrix that match the input string.
%   ROWNUM = FINDROW(STR,STRMAT) returns the index to the row or rows
%   in the matrix STRMAT that are identical to the vector STR.
%   Blanks (ASCII 32) and zeros are not considered. An empty matrix 
%   is returned if there is no match.
%
%   For example:
%
%   strMat = fstrvcat('one','fish','two','fish',[1 2 3 4 5 6]);
%   rowNum = findrow('fish',strMat)

%   Ned Gulley, 4-26-94
%   P. Gahinet 10-99
%   Copyright 1994-2002 The MathWorks, Inc. 
%   $Revision: 1.14 $  $Date: 2002/04/14 22:19:49 $

% Remove leading and trailing blanks form STR
str = fliplr(deblank(fliplr(deblank(str))));

% Initialize boolean vector that picks matching rows
nrows = size(strMat,1);
IsMatching = zeros(1,nrows);

% Process each row
for ctrow=1:nrows,
   % Remove leading and trailing blanks
   s = fliplr(deblank(fliplr(deblank(char(strMat(ctrow,:)))))); 
   IsMatching(ctrow) = strcmp(str,s);
end

rowNum = find(IsMatching);


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?