Binary Serach of rows of M-by-N Matrix

버전 1.1.0.0 (23.2 KB) 작성자: Dr. Murtaza Ali Khan
Binary Search that is based on sum of column values of rows of input M-by-N Matrix
다운로드 수: 2.1K
업데이트 날짜: 2009/7/9

라이선스 보기

Binary Serach of rows of M-by-N Matrix
Search is based on sum of column values of rows of input M-by-N Matrix
i.e. Rows of input Matrix must already be sorted in ascending order
based on sum of their column values. i.e.
row1sum<row2sum<...rowjsum<...rowmsum
where rowjsum=sum(mat(j,:),2) (i.e sum of column values)

If mat is not sorted use following two statments to sort rows of mat
according to sum of column values
matwithsum=sortrows([sum(mat,2),mat],1);
mat=matwithsum(:,2:end);

INPUT:
mat: Matrix contains values such as
[x1, y1,..., zn;
x2, y2,..., zn;
...
xm, ym,..., zn];

srow: row that is to be searched in mat

OUTPUT:
Using following different value of parameter 'type' following output can be return
1. 'first': returns 'indvec1' i.e index of first occured row in mat that matches to srow.

2. 'all': returns 'indvec1' i.e indices of all rows in mat that matches to srow.

3. 'last': returns 'indvec1' i.e index of last row in mat that matches to srow.

4. 'allcolsum': returns 'indvec1' i.e indices of all k rows of mat such that
sum(mat(j,:),2)=sum(srow,2),
where 1<=j<=k

5. 'colsumandval': return two index vector first is similar to return by "allcolsum" and second is similiar to return by "all' option.

Note that if we are searching e.g. [5 4 2] by option 'first' then there may be many rows whose column sum is equal to given row e.g. [2 4 5],[0 0 11],[4 2 5], [5 4 2] but only
last row i.e. [5,4,2] matches in all columns to given row to be searched.
-------------------------
bsearchmatrows.m (main program)
bsearchmatrowsTest1.m (simple test program)
bsearchmatrowsTest2.m (compare performance with MATLAB builtin metod index=find(ismember(mat,srow, 'rows'));
-------------------
For large data this search is extremely faster than MATLAB built in methods

인용 양식

Dr. Murtaza Ali Khan (2024). Binary Serach of rows of M-by-N Matrix (https://www.mathworks.com/matlabcentral/fileexchange/9095-binary-serach-of-rows-of-m-by-n-matrix), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R13
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Direct Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.0

BSD License

1.0.0.0