Rev | Line | |
---|
[37] | 1 | function k = findrows(A, b) |
---|
| 2 | %FINDROWS Find indices of a given row within a matrix. |
---|
| 3 | % |
---|
| 4 | % FINDROWS(A, B) returns a column vector with the indices of the rows |
---|
| 5 | % in the matrix A that are identical to the row vector B. If no rows |
---|
| 6 | % in A are identical to B, an empty vector is returned. |
---|
| 7 | % |
---|
| 8 | % The methods uses a for-loop, but it uses less memory and is in many |
---|
| 9 | % cases a lot faster than the vectorized methods |
---|
| 10 | % |
---|
| 11 | % find( all( A == repmat(b, size(A, 1), 1), 2 ) ) |
---|
| 12 | % find( all( A == b(ones(size(A, 1), 1),:), 2 ) ) |
---|
| 13 | % |
---|
| 14 | % See also FIND, FINDCOLS. |
---|
| 15 | |
---|
| 16 | % Author: Peter J. Acklam |
---|
| 17 | % Time-stamp: 2002-03-03 13:51:15 +0100 |
---|
| 18 | % E-mail: pjacklam@online.no |
---|
| 19 | % URL: http://home.online.no/~pjacklam |
---|
| 20 | |
---|
| 21 | if isempty(A) |
---|
| 22 | k = []; |
---|
| 23 | return |
---|
| 24 | end |
---|
| 25 | |
---|
| 26 | k = find( A(:,1) == b(1)); |
---|
| 27 | top = size(A, 2); |
---|
| 28 | for j = 2:top |
---|
| 29 | k = k(A(k,j) == b(j)); |
---|
| 30 | if isempty(k) |
---|
| 31 | return |
---|
| 32 | end |
---|
| 33 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.