MATCHROW (v1.1, may 2008)

版本 1.0.0.0 (2.2 KB) 作者: Jos (10584)
Match elements in the rows of a matrix
3.0K 次下载
更新时间 2008/5/14

查看许可证

编者注: This file was a File Exchange Pick of the Week

MATCHROW - match elements in the rows of a matrix

TF = MATCHROW(M,S) returns a column vector containing a logical 1 (true)where the rows of M contain (in any order) all the elements of S and 0 (false) otherwise. M and S can be a cell array of strings.
If a element occurs N times in S, than it has to be present at least N times in these rows of M as well.

Examples:
M = [ 1 2 3 4 5 ; 1 2 2 4 3; 1 3 4 4 3 ; 3 2 4 2 5 ; 1 4 3 2 4 ] ;
Q = matchrow(M,[1 2 4]) % -> [1 ; 1 ; 0 ; 0 ; 1] ;
M(Q,:) % -> 1 2 3 4 5
% 1 2 2 4 3
% 1 4 3 2 4

Q = matchrow(M,[1 2 4 4])
M(Q,:) % -> 1 4 3 2 4

Q = matchrow({'a','X','c','Y'; 'a','X','Y','d' ;
'b','X','d','e'},{'X','Y'}) % -> [1 ; 1 ; 0] ;

A = rand(999,999) ;
x = 27 ;
tic
find(matchrow(A,A(x,:))) == x % -> true!
toc

MATCHROW is vectorized and pretty quick ...

version 1.1, may 2008

引用格式

Jos (10584) (2025). MATCHROW (v1.1, may 2008) (https://ww2.mathworks.cn/matlabcentral/fileexchange/14520-matchrow-v1-1-may-2008), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R13
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0

- fixed small error